Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup unused ajax endpoints for reports and js #1660

Merged
merged 2 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.0.0rc3 (unreleased)
---------------------

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


Expand Down
59 changes: 0 additions & 59 deletions src/bika/lims/browser/reports/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,62 +315,3 @@ def __call__(self):
self.request.RESPONSE.write(result)

return


class ReferenceAnalysisQC_Samples(BrowserView):

def __init__(self, context, request):
BrowserView.__init__(self, context, request)
self.context = context
self.request = request

def __call__(self):
plone.protect.CheckAuthenticator(self.request)
# get Supplier from request
supplier = self.request.form.get('SupplierUID', '')
supplier = self.reference_catalog.lookupObject(supplier)
if supplier:
# get ReferenceSamples for this supplier
samples = self.bika_catalog(portal_type='ReferenceSample',
path={"query": "/".join(
supplier.getPhysicalPath()),
"level": 0})
ret = []
for sample in samples:
sample = sample.getObject()
UID = sample.UID()
title = sample.Title()
definition = sample.getReferenceDefinition()
if definition:
title = "%s (%s)" % (title, definition.Title())
ret.append((UID, title))
return json.dumps(ret)


class ReferenceAnalysisQC_Services(BrowserView):

def __init__(self, context, request):
BrowserView.__init__(self, context, request)

def __call__(self):
plone.protect.CheckAuthenticator(self.request)
# get Sample from request
sample_uid = self.request.form.get('SampleUID', '')
uc = getToolByName(self.context, 'uid_catalog')
brains = uc(UID=sample_uid)
if brains:
sample = brains[0].getObject()
# get ReferenceSamples for this supplier
analyses = self.bika_analysis_catalog(
portal_type='ReferenceAnalysis',
path={"query": "/".join(sample.getPhysicalPath()), "level": 0})
ret = {}
for analysis in analyses:
if analysis.getServiceUID in ret:
ret[analysis.getServiceUID]['analyses'].append(analysis.UID)
else:
ret[analysis.getServiceUID] = {
'title': analysis.Title,
'analyses': [analysis.UID]}
ret = [[k, v['title'], v['analyses']] for k, v in ret.items()]
return json.dumps(ret)
17 changes: 0 additions & 17 deletions src/bika/lims/browser/reports/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,4 @@
permission="zope.Public"
/>

<!-- AJAX views for StandardAnalysis query form -->

<browser:page
for="*"
name="referenceanalysisqc_samples"
class="bika.lims.browser.reports.ReferenceAnalysisQC_Samples"
permission="zope.Public"
/>

<browser:page
for="*"
name="referenceanalysisqc_services"
class="bika.lims.browser.reports.ReferenceAnalysisQC_Services"
permission="zope.Public"
/>


</configure>
104 changes: 47 additions & 57 deletions src/senaite/core/browser/static/js/bika.lims.reports.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,50 @@
/**
* Controller class for Bika LIMS Reports

/* Please use this command to compile this file into the parent `js` directory:
coffee --no-header -w -o ../ -c bika.lims.reports.coffee
*/
function ReportFolderView() {

var that = this;

/**
* Entry-point method for AnalysisServiceEditView
*/
that.load = function() {

$("a[id$='_selector']").click(function(event){
$(".criteria").toggle(false);
event.preventDefault();
var div_id = $(this).attr("id").split("_selector")[0];
$("[id='"+div_id+"']").toggle(true);
});

// AJAX: Set ReferenceSamples dropdown when Supplier is selected
$("#SupplierUID").change(function(){
var val = $(this).val();
$.getJSON("referenceanalysisqc_samples",
{"SupplierUID":val,
"_authenticator": $("input[name='_authenticator']").val()},
function(data){
$("#SampleUID").empty().append("<option value=''></option>");
if(data){
for(var i=0;i<data.length;i++){
var sample = data[i];
$("#SampleUID").append("<option value='"+sample[0]+"'>"+sample[1]+"</option>");
}
}
}
);
});

// AJAX: Set ReferenceServices dropdown when ReferenceSample is selected
$("#SampleUID").change(function(){
var val = $(this).val();
$.getJSON("referenceanalysisqc_services",
{"SampleUID":val,
"_authenticator": $("input[name='_authenticator']").val()},
function(data){
$("#ReferenceServiceUID").empty().append("<option value=''></option>");
if(data){
for(var i=0;i<data.length;i++){
var service = data[i];
$("#ReferenceServiceUID").append("<option value='"+service[0]+"'>"+service[1]+"</option>");
}
}
}
);
});

// Reference QC: reset the dropdowns on page reload
$("#SupplierUID").val("");

(function() {
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

window.ReportFolderView = (function() {
function ReportFolderView() {
this.on_toggle_change = bind(this.on_toggle_change, this);
this.bind_eventhandler = bind(this.bind_eventhandler, this);
this.load = bind(this.load, this);
}
}

ReportFolderView.prototype.load = function() {
console.debug("ReportFolderView::load");
return this.bind_eventhandler();
};


/* INITIALIZERS */

ReportFolderView.prototype.bind_eventhandler = function() {

/*
* Binds callbacks on elements
*/
console.debug("ReportFolderView::bind_eventhandler");
return $("body").on("click", "a[id$='_selector']", this.on_toggle_change);
};

ReportFolderView.prototype.on_toggle_change = function(event) {

/**
* Event handler when the toggle anchor is clicked
*/
var div_id;
console.debug("°°° ReportFolderView::on_toggle_change °°°");
event.preventDefault();
$(".criteria").toggle(false);
div_id = event.currentTarget.id.split("_selector")[0];
return $("[id='" + div_id + "']").toggle(true);
};

return ReportFolderView;

})();

}).call(this);
36 changes: 36 additions & 0 deletions src/senaite/core/browser/static/js/coffee/bika.lims.reports.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
### Please use this command to compile this file into the parent `js` directory:
coffee --no-header -w -o ../ -c bika.lims.reports.coffee
###


class window.ReportFolderView

load: =>
console.debug "ReportFolderView::load"

# initialize toggle anchors
@bind_eventhandler()


### INITIALIZERS ###

bind_eventhandler: =>
###
* Binds callbacks on elements
###
console.debug "ReportFolderView::bind_eventhandler"

# When the anchor for a given report is selected, display the report form
$("body").on "click", "a[id$='_selector']", @on_toggle_change


on_toggle_change: (event) =>
###*
* Event handler when the toggle anchor is clicked
###
console.debug "°°° ReportFolderView::on_toggle_change °°°"

event.preventDefault()
$(".criteria").toggle false
div_id = event.currentTarget.id.split("_selector")[0]
$("[id='"+div_id+"']").toggle true