Skip to content

Commit

Permalink
Issue 2214: AR add controls (#2217)
Browse files Browse the repository at this point in the history
* AR Add controls in Add Form

Fixed markup and styles for bika default skin.
Use a form instead of a JS callback to achieve the same.
This avoids latencies in the callback handler and no additional code is required

* Handle non-existing values gracefully
  • Loading branch information
ramonski authored Sep 13, 2017
1 parent 08733b1 commit 532f2f4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 54 deletions.
31 changes: 17 additions & 14 deletions bika/lims/browser/analysisrequest/templates/ar_add2.pt
Original file line number Diff line number Diff line change
Expand Up @@ -274,20 +274,23 @@
<h1 id="ar-header">
<img tal:condition="view/icon | nothing" tal:attributes="src view/icon"/>
<span i18n:translate="">Request new analyses</span>
<span id="ar-count-control" class="form-inline">
<input type="number"
name="ar_count"
min="1"
class="form-control"
style="width:4em"
tal:attributes="value view/ar_count"/>
<a href=""
id="ar_count_change"
tal:attributes="href string:${view/get_view_url}"
class="btn btn-default btn-sm">
<span i18n:translate="">Reload Form</span>
</a>
</span>
<div style="display:inline-block;padding-left:0.5em;">
<form method="GET" class="form-inline">
<input type="hidden"
name="copy_from" tal:attributes="value request/copy_from|nothing"/>
<input type="number"
name="ar_count"
min="1"
class="form-control context_action_link"
style="width:4em;border-radius:0;border:1px solid #ddd;padding:2px;"
tal:attributes="value view/ar_count|1"/>
<button type="submit"
class="btn btn-link context_action_link">
<img src="#"
tal:attributes="src string:${context/absolute_url}/++resource++bika.lims.images/add.png"/>
</button>
</form>
</div>
</h1>
</metal:title>
<metal:description fill-slot="content-description">
Expand Down
20 changes: 0 additions & 20 deletions bika/lims/browser/js/bika.lims.analysisrequest.add.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
this.on_ajax_start = bind(this.on_ajax_start, this);
this.ajax_post_form = bind(this.ajax_post_form, this);
this.on_copy_button_click = bind(this.on_copy_button_click, this);
this.on_ar_count_change = bind(this.on_ar_count_change, this);
this.on_service_category_click = bind(this.on_service_category_click, this);
this.on_service_listing_header_click = bind(this.on_service_listing_header_click, this);
this.on_reportdrymatter_click = bind(this.on_reportdrymatter_click, this);
Expand Down Expand Up @@ -99,7 +98,6 @@
$("tr[fieldname=Profiles] input[type='text']").on("selected", this.on_analysis_profile_selected);
$("tr[fieldname=Profiles] img.deletebtn").live("click", this.on_analysis_profile_removed);
$("img.copybutton").on("click", this.on_copy_button_click);
$("#ar-count-control input[name=ar_count]").on("change", this.on_ar_count_change);

/* internal events */
$(this).on("form:changed", this.recalculate_records);
Expand Down Expand Up @@ -1089,24 +1087,6 @@
}
};

AnalysisRequestAdd.prototype.on_ar_count_change = function(event) {

/*
* Eventhandler for ar_count number field
*/
var $el, ar_count, el, href, link, new_href;
el = event.target;
$el = $(el);
ar_count = $el.val();
href = location.href;
if (href.search("ar_count") < 0) {
href += href.split('?')[1] ? '&ar_count=1' : '?ar_count=1';
}
new_href = href.replace(/ar_count=[0-9]+/, "ar_count=" + ar_count);
link = $("#ar_count_change", $el.parent());
return link.attr("href", new_href);
};

AnalysisRequestAdd.prototype.on_copy_button_click = function(event) {

/*
Expand Down
19 changes: 0 additions & 19 deletions bika/lims/browser/js/coffee/bika.lims.analysisrequest.add.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ class window.AnalysisRequestAdd
$("tr[fieldname=Profiles] img.deletebtn").live "click", @on_analysis_profile_removed
# Copy button clicked
$("img.copybutton").on "click", @on_copy_button_click
# AR Controls
$("#ar-count-control input[name=ar_count]").on "change", @on_ar_count_change

### internal events ###

Expand Down Expand Up @@ -1214,23 +1212,6 @@ class window.AnalysisRequestAdd
services.addClass "expanded"


on_ar_count_change: (event) =>
###
* Eventhandler for ar_count number field
###
el = event.target
$el = $(el)
ar_count = $el.val()
href = location.href
# append ar_count to the url if it is missing
if href.search("ar_count") < 0
href += if href.split('?')[1] then '&ar_count=1' else '?ar_count=1'
new_href = href.replace(/ar_count=[0-9]+/, "ar_count=#{ar_count}")
link = $("#ar_count_change", $el.parent())
# set the new link
link.attr("href", new_href)


on_copy_button_click: (event) =>
###
* Eventhandler for the field copy button per row.
Expand Down
2 changes: 1 addition & 1 deletion docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
3.2.1rc2 (unreleased)
---------------------

- No changes yet
- Issue-2214: AR Add Controls need to be styled correctly


3.2.1rc1 (2017-09-12)
Expand Down

0 comments on commit 532f2f4

Please sign in to comment.