Skip to content

Commit 4bc22e6

Browse files
authored
Cleanup unused ajax endpoints for reports and js (#1660)
* Cleanup unused ajax endpoints for reports and js * Remove stale code
1 parent 6a8d70a commit 4bc22e6

File tree

5 files changed

+84
-133
lines changed

5 files changed

+84
-133
lines changed

CHANGES.rst

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
2.0.0rc3 (unreleased)
55
---------------------
66

7+
- #1660 Cleanup unused ajax endpoints for reports and js
78
- #1659 Fix language in datepicker widgets
89

910

src/bika/lims/browser/reports/__init__.py

-59
Original file line numberDiff line numberDiff line change
@@ -315,62 +315,3 @@ def __call__(self):
315315
self.request.RESPONSE.write(result)
316316

317317
return
318-
319-
320-
class ReferenceAnalysisQC_Samples(BrowserView):
321-
322-
def __init__(self, context, request):
323-
BrowserView.__init__(self, context, request)
324-
self.context = context
325-
self.request = request
326-
327-
def __call__(self):
328-
plone.protect.CheckAuthenticator(self.request)
329-
# get Supplier from request
330-
supplier = self.request.form.get('SupplierUID', '')
331-
supplier = self.reference_catalog.lookupObject(supplier)
332-
if supplier:
333-
# get ReferenceSamples for this supplier
334-
samples = self.bika_catalog(portal_type='ReferenceSample',
335-
path={"query": "/".join(
336-
supplier.getPhysicalPath()),
337-
"level": 0})
338-
ret = []
339-
for sample in samples:
340-
sample = sample.getObject()
341-
UID = sample.UID()
342-
title = sample.Title()
343-
definition = sample.getReferenceDefinition()
344-
if definition:
345-
title = "%s (%s)" % (title, definition.Title())
346-
ret.append((UID, title))
347-
return json.dumps(ret)
348-
349-
350-
class ReferenceAnalysisQC_Services(BrowserView):
351-
352-
def __init__(self, context, request):
353-
BrowserView.__init__(self, context, request)
354-
355-
def __call__(self):
356-
plone.protect.CheckAuthenticator(self.request)
357-
# get Sample from request
358-
sample_uid = self.request.form.get('SampleUID', '')
359-
uc = getToolByName(self.context, 'uid_catalog')
360-
brains = uc(UID=sample_uid)
361-
if brains:
362-
sample = brains[0].getObject()
363-
# get ReferenceSamples for this supplier
364-
analyses = self.bika_analysis_catalog(
365-
portal_type='ReferenceAnalysis',
366-
path={"query": "/".join(sample.getPhysicalPath()), "level": 0})
367-
ret = {}
368-
for analysis in analyses:
369-
if analysis.getServiceUID in ret:
370-
ret[analysis.getServiceUID]['analyses'].append(analysis.UID)
371-
else:
372-
ret[analysis.getServiceUID] = {
373-
'title': analysis.Title,
374-
'analyses': [analysis.UID]}
375-
ret = [[k, v['title'], v['analyses']] for k, v in ret.items()]
376-
return json.dumps(ret)

src/bika/lims/browser/reports/configure.zcml

-17
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,4 @@
4545
permission="zope.Public"
4646
/>
4747

48-
<!-- AJAX views for StandardAnalysis query form -->
49-
50-
<browser:page
51-
for="*"
52-
name="referenceanalysisqc_samples"
53-
class="bika.lims.browser.reports.ReferenceAnalysisQC_Samples"
54-
permission="zope.Public"
55-
/>
56-
57-
<browser:page
58-
for="*"
59-
name="referenceanalysisqc_services"
60-
class="bika.lims.browser.reports.ReferenceAnalysisQC_Services"
61-
permission="zope.Public"
62-
/>
63-
64-
6548
</configure>
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,50 @@
1-
/**
2-
* Controller class for Bika LIMS Reports
1+
2+
/* Please use this command to compile this file into the parent `js` directory:
3+
coffee --no-header -w -o ../ -c bika.lims.reports.coffee
34
*/
4-
function ReportFolderView() {
5-
6-
var that = this;
7-
8-
/**
9-
* Entry-point method for AnalysisServiceEditView
10-
*/
11-
that.load = function() {
12-
13-
$("a[id$='_selector']").click(function(event){
14-
$(".criteria").toggle(false);
15-
event.preventDefault();
16-
var div_id = $(this).attr("id").split("_selector")[0];
17-
$("[id='"+div_id+"']").toggle(true);
18-
});
19-
20-
// AJAX: Set ReferenceSamples dropdown when Supplier is selected
21-
$("#SupplierUID").change(function(){
22-
var val = $(this).val();
23-
$.getJSON("referenceanalysisqc_samples",
24-
{"SupplierUID":val,
25-
"_authenticator": $("input[name='_authenticator']").val()},
26-
function(data){
27-
$("#SampleUID").empty().append("<option value=''></option>");
28-
if(data){
29-
for(var i=0;i<data.length;i++){
30-
var sample = data[i];
31-
$("#SampleUID").append("<option value='"+sample[0]+"'>"+sample[1]+"</option>");
32-
}
33-
}
34-
}
35-
);
36-
});
37-
38-
// AJAX: Set ReferenceServices dropdown when ReferenceSample is selected
39-
$("#SampleUID").change(function(){
40-
var val = $(this).val();
41-
$.getJSON("referenceanalysisqc_services",
42-
{"SampleUID":val,
43-
"_authenticator": $("input[name='_authenticator']").val()},
44-
function(data){
45-
$("#ReferenceServiceUID").empty().append("<option value=''></option>");
46-
if(data){
47-
for(var i=0;i<data.length;i++){
48-
var service = data[i];
49-
$("#ReferenceServiceUID").append("<option value='"+service[0]+"'>"+service[1]+"</option>");
50-
}
51-
}
52-
}
53-
);
54-
});
55-
56-
// Reference QC: reset the dropdowns on page reload
57-
$("#SupplierUID").val("");
585

6+
(function() {
7+
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
8+
9+
window.ReportFolderView = (function() {
10+
function ReportFolderView() {
11+
this.on_toggle_change = bind(this.on_toggle_change, this);
12+
this.bind_eventhandler = bind(this.bind_eventhandler, this);
13+
this.load = bind(this.load, this);
5914
}
60-
}
15+
16+
ReportFolderView.prototype.load = function() {
17+
console.debug("ReportFolderView::load");
18+
return this.bind_eventhandler();
19+
};
20+
21+
22+
/* INITIALIZERS */
23+
24+
ReportFolderView.prototype.bind_eventhandler = function() {
25+
26+
/*
27+
* Binds callbacks on elements
28+
*/
29+
console.debug("ReportFolderView::bind_eventhandler");
30+
return $("body").on("click", "a[id$='_selector']", this.on_toggle_change);
31+
};
32+
33+
ReportFolderView.prototype.on_toggle_change = function(event) {
34+
35+
/**
36+
* Event handler when the toggle anchor is clicked
37+
*/
38+
var div_id;
39+
console.debug("°°° ReportFolderView::on_toggle_change °°°");
40+
event.preventDefault();
41+
$(".criteria").toggle(false);
42+
div_id = event.currentTarget.id.split("_selector")[0];
43+
return $("[id='" + div_id + "']").toggle(true);
44+
};
45+
46+
return ReportFolderView;
47+
48+
})();
49+
50+
}).call(this);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
### Please use this command to compile this file into the parent `js` directory:
2+
coffee --no-header -w -o ../ -c bika.lims.reports.coffee
3+
###
4+
5+
6+
class window.ReportFolderView
7+
8+
load: =>
9+
console.debug "ReportFolderView::load"
10+
11+
# initialize toggle anchors
12+
@bind_eventhandler()
13+
14+
15+
### INITIALIZERS ###
16+
17+
bind_eventhandler: =>
18+
###
19+
* Binds callbacks on elements
20+
###
21+
console.debug "ReportFolderView::bind_eventhandler"
22+
23+
# When the anchor for a given report is selected, display the report form
24+
$("body").on "click", "a[id$='_selector']", @on_toggle_change
25+
26+
27+
on_toggle_change: (event) =>
28+
###*
29+
* Event handler when the toggle anchor is clicked
30+
###
31+
console.debug "°°° ReportFolderView::on_toggle_change °°°"
32+
33+
event.preventDefault()
34+
$(".criteria").toggle false
35+
div_id = event.currentTarget.id.split("_selector")[0]
36+
$("[id='"+div_id+"']").toggle true

0 commit comments

Comments
 (0)