Skip to content

Commit c83acd3

Browse files
authored
Merge pull request #221 from naralabs/bug/NDEV-69-worksheet-add-analyses-filters
NDEV-69 Filters by Service, Category and Client do not work when adding Analyses into a Worksheet
2 parents 740c025 + 3e39eec commit c83acd3

File tree

5 files changed

+73
-44
lines changed

5 files changed

+73
-44
lines changed

bika/lims/browser/js/bika.lims.worksheet.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function WorksheetAddAnalysesView() {
4343

4444
// search form - selecting a category fills up the service selector
4545
$('[name="list_getCategoryTitle"]').live("change", function(){
46-
val = $('[name="list_getCategoryTitle"]').val();
46+
val = $('[name="list_getCategoryTitle"]').find(":selected").val();
4747
if(val == 'any'){
4848
$('[name="list_Title"]').empty();
4949
$('[name="list_Title"]').append("<option value='any'>"+_('Any')+"</option>");
@@ -53,7 +53,7 @@ function WorksheetAddAnalysesView() {
5353
url: window.location.href.split("?")[0].replace("/add_analyses","") + "/getServices",
5454
type: 'POST',
5555
data: {'_authenticator': $('input[name="_authenticator"]').val(),
56-
'getCategoryTitle': val},
56+
'getCategoryUID': val},
5757
dataType: "json",
5858
success: function(data, textStatus, $XHR){
5959
current_service_selection = $('[name="list_Title"]').val();
@@ -65,7 +65,9 @@ function WorksheetAddAnalysesView() {
6565
} else {
6666
selected = '';
6767
}
68-
$('[name="list_Title"]').append("<option "+selected+"value='"+data[i]+"'>"+data[i]+"</option>");
68+
$('[name="list_Title"]').append(
69+
"<option "+selected+"value='"+data[i][0]+
70+
"'>"+data[i][1]+"</option>");
6971
}
7072
}
7173
});
@@ -102,6 +104,8 @@ function WorksheetAddAnalysesView() {
102104
replaceTarget: true,
103105
data: form.formToArray(),
104106
success: function () {
107+
// Reload bika listing transitions watchers
108+
window.bika.lims.BikaListingTableView.load();
105109
}
106110
}
107111
var url = window.location.href.split("?")[0].split("/add_analyses")[0];

bika/lims/browser/worksheet/ajax.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ def __init__(self, context, request):
2626
def __call__(self):
2727
plone.protect.CheckAuthenticator(self.request)
2828
bsc = getToolByName(self.context, 'bika_setup_catalog')
29-
return json.dumps([c.Title for c in
30-
bsc(portal_type = 'AnalysisService',
31-
getCategoryTitle = self.request.get('getCategoryTitle', ''),
32-
inactive_state = 'active',
33-
sort_on = 'sortable_title')])
29+
brains = bsc(
30+
portal_type='AnalysisService',
31+
getCategoryUID=self.request.get('getCategoryUID', ''),
32+
inactive_state='active',
33+
sort_on='sortable_title')
34+
voc = [[brain.UID, brain.Title] for brain in brains]
35+
return json.dumps(voc)
3436

3537

3638
class AttachAnalyses():

bika/lims/browser/worksheet/templates/add_analyses.pt

+14-10
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@
4343
<input type="hidden" name="submitted" value="1"/>
4444
<input tal:replace="structure context/@@authenticator/authenticator"/>
4545
<label for="getWorksheetTemplate" i18n:translate="">Select template</label>
46-
<select id="ProfileSelector" name="getWorksheetTemplate">
46+
<select id="ProfileSelector" name="getWorksheetTemplate"
47+
tal:define="ws_templates_list view/getWorksheetTemplates">
4748
<option value=""></option>
48-
<tal:profile repeat="profile view/getWorksheetTemplates">
49+
<tal:profile repeat="profile ws_templates_list">
4950
<option
5051
tal:attributes="
51-
value python:profile[0];
52+
value python:profile;
5253
selected python: view.request.get('WorksheetTemplate', '') == profile[0] and 'selected' or ''"
53-
tal:content="python:profile[1]"/>
54+
tal:content="python:ws_templates_list.getValue(profile)"/>
5455
</tal:profile>
5556
</select>&nbsp;
5657
<input type="submit"
@@ -66,44 +67,47 @@
6667
i18n:translate="">Category</label>
6768
<select id="CategorySelector"
6869
tal:attributes="name string:${form_id}_getCategoryTitle"
70+
tal:define="categories_list view/getCategories"
6971
class="listing-filter">
7072
<option value="any" i18n:translate="">Any</option>
71-
<tal:options repeat="category view/getCategories">
73+
<tal:options repeat="category categories_list">
7274
<option
7375
tal:attributes="
7476
value python:category;
7577
selected python: view.request.form.get(form_id+'_getCategoryTitle', '') == category and 'selected' or ''"
76-
tal:content="python:category"/>
78+
tal:content="python:categories_list.getValue(category)"/>
7779
</tal:options>
7880
</select>
7981

8082
<label tal:attributes="for string:${form_id}_Title"
8183
i18n:translate="">Service</label>
8284
<select id="ServiceSelector"
8385
tal:attributes="name string:${form_id}_Title"
86+
tal:define="services_list view/getServices"
8487
class="listing-filter">
8588
<option value="any" i18n:translate="">Any</option>
86-
<tal:options repeat="service view/getServices">
89+
<tal:options repeat="service services_list">
8790
<option
8891
tal:attributes="
8992
value python:service;
9093
selected python: view.request.form.get(form_id+'_Title', '') == service and 'selected' or ''"
91-
tal:content="python:service"/>
94+
tal:content="python:services_list.getValue(service)"/>
9295
</tal:options>
9396
</select>
9497

9598
<label tal:attributes="for string:${form_id}_getClientTitle"
9699
i18n:translate="">Client</label>
97100
<select id="ClientSelector"
98101
tal:attributes="name string:${form_id}_getClientTitle"
102+
tal:define="clients_list view/getClients"
99103
class="listing-filter">
100104
<option value="any" i18n:translate="">Any</option>
101-
<tal:options repeat="client view/getClients">
105+
<tal:options repeat="client clients_list">
102106
<option
103107
tal:attributes="
104108
value python:client;
105109
selected python: view.request.form.get(form_id+'_getClientTitle', '') == client and 'selected' or ''"
106-
tal:content="python:client"/>
110+
tal:content="python:clients_list.getValue(client)"/>
107111
</tal:options>
108112
</select>&nbsp;
109113
<a tal:attributes="href view/view_url" i18n:translate=""

bika/lims/browser/worksheet/views/add_analyses.py

+43-25
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from bika.lims.browser.worksheet.tools import checkUserManage
2222
from bika.lims.browser.worksheet.tools import showRejectionMessage
2323
from bika.lims.utils import t
24+
from bika.lims.vocabularies import CatalogVocabulary
2425

2526

2627
class AddAnalysesView(BikaListingView):
@@ -102,9 +103,6 @@ def __call__(self):
102103

103104
showRejectionMessage(self.context)
104105

105-
translate = self.context.translate
106-
107-
form_id = self.form_id
108106
form = self.request.form
109107
rc = getToolByName(self.context, REFERENCE_CATALOG)
110108
if 'submitted' in form:
@@ -123,6 +121,25 @@ def __call__(self):
123121
_("No analyses were added to this worksheet."))
124122
self.request.RESPONSE.redirect(self.context.absolute_url() +
125123
"/add_analyses")
124+
elif (
125+
'list_getCategoryTitle' in form or
126+
'list_Title' in form or
127+
'list_getClientTitle' in form
128+
):
129+
# Apply filter elements
130+
# Note that the name of those fields is '..Title', but we
131+
# are getting their UID.
132+
category = form.get('list_getCategoryTitle', '')
133+
if category:
134+
self.contentFilter['getCategoryUID'] = category
135+
136+
service = form.get('list_Title', '')
137+
if service:
138+
self.contentFilter['getServiceUID'] = service
139+
140+
client = form.get('list_getClientTitle', '')
141+
if client:
142+
self.contentFilter['getClientUID'] = client
126143

127144
self._process_request()
128145

@@ -197,32 +214,33 @@ def folderitem(self, obj, item, index):
197214
return item
198215

199216
def getServices(self):
200-
bsc = getToolByName(self.context, 'bika_setup_catalog')
201-
return [c.Title for c in
202-
bsc(portal_type = 'AnalysisService',
203-
getCategoryUID = self.request.get('list_getCategoryUID', ''),
204-
inactive_state = 'active',
205-
sort_on = 'sortable_title')]
217+
vocabulary = CatalogVocabulary(self)
218+
vocabulary.catalog = 'bika_setup_catalog'
219+
categoryUID = self.request.get('list_getCategoryUID', '')
220+
if categoryUID:
221+
return vocabulary(
222+
portal_type='AnalysisService',
223+
getCategoryUID=categoryUID,
224+
sort_on='sortable_title'
225+
)
226+
return vocabulary(
227+
portal_type='AnalysisService',
228+
sort_on='sortable_title'
229+
)
206230

207231
def getClients(self):
208-
pc = getToolByName(self.context, 'portal_catalog')
209-
return [c.Title for c in
210-
pc(portal_type = 'Client',
211-
inactive_state = 'active',
212-
sort_on = 'sortable_title')]
232+
vocabulary = CatalogVocabulary(self)
233+
return vocabulary(portal_type='Client', sort_on='sortable_title')
213234

214235
def getCategories(self):
215-
bsc = getToolByName(self.context, 'bika_setup_catalog')
216-
return [c.Title for c in
217-
bsc(portal_type = 'AnalysisCategory',
218-
inactive_state = 'active',
219-
sort_on = 'sortable_title')]
236+
vocabulary = CatalogVocabulary(self)
237+
vocabulary.catalog = 'bika_setup_catalog'
238+
return vocabulary(
239+
portal_type='AnalysisCategory', sort_on='sortable_title')
220240

221241
def getWorksheetTemplates(self):
222242
""" Return WS Templates """
223-
profiles = []
224-
bsc = getToolByName(self.context, 'bika_setup_catalog')
225-
return [(c.UID, c.Title) for c in
226-
bsc(portal_type = 'WorksheetTemplate',
227-
inactive_state = 'active',
228-
sort_on = 'sortable_title')]
243+
vocabulary = CatalogVocabulary(self)
244+
vocabulary.catalog = 'bika_setup_catalog'
245+
return vocabulary(
246+
portal_type='WorksheetTemplate', sort_on='sortable_title')

bika/lims/vocabularies/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ def __call__(self, **kwargs):
4747
site = getSite()
4848
request = aq_get(site, 'REQUEST', None)
4949
catalog = getToolByName(site, self.catalog)
50+
allow_blank = False
5051
if 'allow_blank' in kwargs:
51-
allow_blank = True
52+
allow_blank = kwargs.get('allow_blank')
5253
del (kwargs['allow_blank'])
5354

5455
self.contentFilter.update(**kwargs)

0 commit comments

Comments
 (0)