Skip to content

Commit

Permalink
Copy to columns on the right
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonski committed Dec 11, 2024
1 parent e866a91 commit 86f1970
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 31 deletions.
8 changes: 5 additions & 3 deletions src/bika/lims/browser/analysisrequest/templates/ar_add2.pt
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,9 @@

<ul class="nav nav-tabs float-right" id="sample-tabs" style="margin-bottom:-1px;">
<tal:columns tal:repeat="arnum python:range(view.ar_count)">
<li class="nav-item">
<li class="nav-item" tal:attributes="class string:nav-item nav-item-${arnum}">
<a tal:attributes="class python:'nav-link active' if arnum == 0 else 'nav-link';
data-primary-sample-index string:${arnum};
data-target string:sample-column-${arnum}"
href="#">
<span i18n:translate="">Sample</span>
Expand All @@ -384,6 +385,7 @@
<li class="nav-item">
<a class="nav-link"
data-target="show-all"
data-primary-sample-index="0"
href="#">
<span i18n:translate="">Show all</span>
</a>
Expand Down Expand Up @@ -558,8 +560,8 @@
<div class="text-center" tal:condition="python:view.show_copy_button_for()">
<!-- Copy Button -->
<a class="copy d-block"
title="Copy the value of the first sample to the others"
data_toggle="tooltip">
title="Copy the currently displayed column value to the other columns on the right"
data_toggle="tooltip">
<i class="fas fa-angle-double-right"></i>
</a>
</div>
Expand Down
63 changes: 47 additions & 16 deletions src/senaite/core/browser/static/js/bika.lims.analysisrequest.add.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class window.AnalysisRequestAdd
# disable browser autocomplete
$('input[type=text]').prop 'autocomplete', 'off'

@primary_sample_index = 0

# storage for global Bika settings
@global_settings = {}

Expand Down Expand Up @@ -1227,6 +1229,16 @@ class window.AnalysisRequestAdd
return this.is_div(el) and el.classList.contains("ArchetypesDateTimeWidget")


###*
* Visually highlight the navigation tab
###
flash_nav_tab: (tab, duration=500) =>
tab.classList.add("bg-light", "text-secondary")
setTimeout () =>
tab.classList.remove("bg-light", "text-secondary")
, duration


######################
### EVENT HANDLERS ###
######################
Expand Down Expand Up @@ -1258,6 +1270,11 @@ class window.AnalysisRequestAdd
$("td.sample-column").addClass("d-none");
$("td.#{target}").removeClass("d-none");

# remember the displayed column
primary = parseInt($el.data("primary-sample-index"), 10)
@primary_sample_index = if isNaN(primary) then 0 else primary
console.log("PRIMARY sample index is #{@primary_sample_index}")


###*
* Generic event handler for when a reference field value changed
Expand Down Expand Up @@ -1609,7 +1626,9 @@ class window.AnalysisRequestAdd
tr = $el.closest('tr')[0]
$tr = $(tr)

td1 = $(tr).find('td[arnum="0"]').first()
start_index = @primary_sample_index

td1 = $(tr).find("td[arnum=#{start_index}]").first()
$td1 = $(td1)

ar_count = parseInt($('input[id="ar_count"]').val(), 10)
Expand All @@ -1628,7 +1647,7 @@ class window.AnalysisRequestAdd

$.each [1..ar_count], (arnum) ->
# skip the first (source) column
return unless arnum > 0
return unless arnum > start_index

# find the reference widget of the next column
_td = $tr.find("td[arnum=#{arnum}]")
Expand All @@ -1649,7 +1668,6 @@ class window.AnalysisRequestAdd

# trigger form:changed event
$(me).trigger "form:changed"
return

# Copy <input type="checkbox"> fields
$td1.find("input[type=checkbox]").each (index, el) ->
Expand All @@ -1660,7 +1678,7 @@ class window.AnalysisRequestAdd
# iterate over columns, starting from column 2
$.each [1..ar_count], (arnum) ->
# skip the first column
return unless arnum > 0
return unless arnum > start_index
_td = $tr.find("td[arnum=#{arnum}]")
_el = $(_td).find("input[type=checkbox]")[index]
$(_el).prop "checked", checked
Expand All @@ -1682,7 +1700,7 @@ class window.AnalysisRequestAdd
value = $el.val()
$.each [1..ar_count], (arnum) ->
# skip the first column
return unless arnum > 0
return unless arnum > start_index
_td = $tr.find("td[arnum=#{arnum}]")
_el = $(_td).find("select")[index]
$(_el).val value
Expand All @@ -1694,7 +1712,7 @@ class window.AnalysisRequestAdd
value = $el.val()
$.each [1..ar_count], (arnum) ->
# skip the first column
return unless arnum > 0
return unless arnum > start_index
_td = $tr.find("td[arnum=#{arnum}]")
_el = $(_td).find("input[type=text]")[index]
$(_el).val value
Expand All @@ -1706,7 +1724,7 @@ class window.AnalysisRequestAdd
value = $el.val()
$.each [1..ar_count], (arnum) ->
# skip the first column
return unless arnum > 0
return unless arnum > start_index
_td = $tr.find("td[arnum=#{arnum}]")
_el = $(_td).find("input[type=number]")[index]
$(_el).val value
Expand All @@ -1718,7 +1736,7 @@ class window.AnalysisRequestAdd
value = $el.val()
$.each [1..ar_count], (arnum) ->
# skip the first column
return unless arnum > 0
return unless arnum > start_index
_td = $tr.find("td[arnum=#{arnum}]")
_el = $(_td).find("textarea")[index]
me.native_set_value(_el, value)
Expand All @@ -1730,7 +1748,7 @@ class window.AnalysisRequestAdd
checked = $(el).is ":checked"
$.each [1..ar_count], (arnum) ->
# skip the first column
return unless arnum > 0
return unless arnum > start_index
_td = $tr.find("td[arnum=#{arnum}]")
_el = $(_td).find("input[type=radio]")[index]
$(_el).prop "checked", checked
Expand All @@ -1742,7 +1760,7 @@ class window.AnalysisRequestAdd
value = $el.val()
$.each [1..ar_count], (arnum) ->
# skip the first column
return unless arnum > 0
return unless arnum > start_index
_td = $tr.find("td[arnum=#{arnum}]")
_el = $(_td).find("input[type='date']")[index]
$(_el).val value
Expand All @@ -1754,7 +1772,7 @@ class window.AnalysisRequestAdd
value = $el.val()
$.each [1..ar_count], (arnum) ->
# skip the first column
return unless arnum > 0
return unless arnum > start_index
_td = $tr.find("td[arnum=#{arnum}]")
_el = $(_td).find("input[type='time']")[index]
$(_el).val value
Expand All @@ -1766,11 +1784,21 @@ class window.AnalysisRequestAdd
value = $el.val()
$.each [1..ar_count], (arnum) ->
# skip the first column
return unless arnum > 0
return unless arnum > start_index
_td = $tr.find("td[arnum=#{arnum}]")
_el = $(_td).find("input[type='hidden']")[index]
$(_el).val value


# highlight changed columns
$.each [1..ar_count], (arnum) ->
# skip the first (source) column
return unless arnum > start_index

console.log "Copy #{value} to column #{arnum}"
tab = document.querySelector(".nav-item-#{arnum} a")
me.flash_nav_tab(tab)

# trigger form:changed event
$(me).trigger "form:changed"

Expand Down

0 comments on commit 86f1970

Please sign in to comment.