|
17 |
i18nClass: 'umc.modules.pkgdb', |
17 |
i18nClass: 'umc.modules.pkgdb', |
18 |
|
18 |
|
19 |
// Some status variables |
19 |
// Some status variables |
20 |
_patterns_allowed: false, // true if operator is selectable |
20 |
_pattern_needed: true, // true if a pattern is required by this key+operator |
21 |
_pattern_is_list: false, // true if pattern is ComboBox (not TextBox) |
21 |
_pattern_is_list: false, // true if pattern is ComboBox. false if TextBox. |
|
|
22 |
_submit_allowed: false, // true if current input allows SUBMIT (including that no queries are pending) |
22 |
|
23 |
|
|
|
24 |
// true while the corresponding query is pending |
25 |
_keys_pending: true, |
26 |
_operators_pending: false, |
27 |
_proposals_pending: false, |
28 |
|
23 |
postMixInProperties: function() { |
29 |
postMixInProperties: function() { |
24 |
|
30 |
|
25 |
dojo.mixin(this,{ |
31 |
dojo.mixin(this,{ |
|
36 |
dynamicOptions: {page:this.pageKey}, |
42 |
dynamicOptions: {page:this.pageKey}, |
37 |
onDynamicValuesLoaded: dojo.hitch(this, function(values) { |
43 |
onDynamicValuesLoaded: dojo.hitch(this, function(values) { |
38 |
this._set_selection_to_first_element('key'); |
44 |
this._set_selection_to_first_element('key'); |
39 |
}), |
45 |
this._set_query_pending('key',false); |
40 |
onChange: dojo.hitch(this, function(value) { |
|
|
41 |
this.onQueryChanged('key',value); |
42 |
}) |
46 |
}) |
43 |
}, |
47 |
}, |
44 |
{ |
48 |
{ |
|
53 |
}), |
57 |
}), |
54 |
onDynamicValuesLoaded: dojo.hitch(this, function(values) { |
58 |
onDynamicValuesLoaded: dojo.hitch(this, function(values) { |
55 |
this._handle_operators(values); |
59 |
this._handle_operators(values); |
56 |
}), |
60 |
this._set_query_pending('operator',false); |
57 |
onChange: dojo.hitch(this, function(value) { |
|
|
58 |
this.onQueryChanged('operator',value); |
59 |
}) |
61 |
}) |
60 |
}, |
62 |
}, |
61 |
{ |
63 |
{ |
|
70 |
}), |
72 |
}), |
71 |
onDynamicValuesLoaded: dojo.hitch(this, function(values) { |
73 |
onDynamicValuesLoaded: dojo.hitch(this, function(values) { |
72 |
this._handle_proposals(values); |
74 |
this._handle_proposals(values); |
73 |
}), |
75 |
this._set_query_pending('proposal',false); |
74 |
onChange: dojo.hitch(this, function(value) { |
|
|
75 |
this.onQueryChanged('pattern_list',value); |
76 |
}) |
76 |
}) |
77 |
}, |
77 |
}, |
78 |
{ |
78 |
{ |
|
80 |
name: 'pattern_text', |
80 |
name: 'pattern_text', |
81 |
label: this._("Pattern"), |
81 |
label: this._("Pattern"), |
82 |
style: 'width:350px;', |
82 |
style: 'width:350px;', |
83 |
onChange: dojo.hitch(this, function(value) { |
|
|
84 |
this.onQueryChanged('pattern_text',value); |
85 |
}), |
86 |
// inherits from dijit.form.ValidationTextBox, so we can use its |
83 |
// inherits from dijit.form.ValidationTextBox, so we can use its |
87 |
// validation abilities |
84 |
// validation abilities |
88 |
regExp: '^[A-Za-z0-9_.*?-]+$', // [:alnum:] and these: _ - . * ? |
85 |
regExp: '^[A-Za-z0-9_.*?-]+$', // [:alnum:] and these: _ - . * ? |
89 |
required: true // force nonempty |
|
|
90 |
} |
86 |
} |
91 |
], |
87 |
], |
92 |
layout: |
88 |
layout: |
|
117 |
this.showWidget('pattern_text',false); |
113 |
this.showWidget('pattern_text',false); |
118 |
this.showWidget('pattern_list',false); |
114 |
this.showWidget('pattern_list',false); |
119 |
this.showWidget('operator',false); |
115 |
this.showWidget('operator',false); |
|
|
116 |
|
117 |
// whenever one of our 'pending' vars is changed... |
118 |
this.watch('_keys_pending',dojo.hitch(this,function(name,oldval,value) { |
119 |
this._handle_query_changes(name,value); |
120 |
})); |
121 |
this.watch('_operators_pending',dojo.hitch(this,function(name,oldval,value) { |
122 |
this._handle_query_changes(name,value); |
123 |
})); |
124 |
this.watch('_proposals_pending',dojo.hitch(this,function(name,oldval,value) { |
125 |
this._handle_query_changes(name,value); |
126 |
})); |
127 |
|
128 |
// whenever one of the dialog values is being changed... |
129 |
dojo.connect(this.getWidget('key'),'onChange',dojo.hitch(this, function(value) { |
130 |
this._handle_query_changes('key',value); |
131 |
})); |
132 |
dojo.connect(this.getWidget('operator'),'onChange',dojo.hitch(this, function(value) { |
133 |
this._handle_query_changes('operator',value); |
134 |
})); |
135 |
dojo.connect(this.getWidget('pattern_text'),'onChange',dojo.hitch(this, function(value) { |
136 |
this._handle_query_changes('pattern_text',value); |
137 |
})); |
138 |
dojo.connect(this.getWidget('pattern_list'),'onChange',dojo.hitch(this, function(value) { |
139 |
this._handle_query_changes('pattern_list',value); |
140 |
})); |
120 |
}, |
141 |
}, |
121 |
|
142 |
|
122 |
// --------------------------------------------------------------------- |
143 |
// --------------------------------------------------------------------- |
|
158 |
if (crit != '_') |
179 |
if (crit != '_') |
159 |
{ |
180 |
{ |
160 |
query['key'] = crit; |
181 |
query['key'] = crit; |
161 |
if (this._patterns_allowed) |
182 |
if (this._submit_allowed) |
162 |
{ |
183 |
{ |
163 |
query['operator'] = this.getWidget('operator').get('value'); |
184 |
query['operator'] = this.getWidget('operator').get('value'); |
164 |
if (this._pattern_is_list) |
185 |
if (this._pattern_is_list) |
|
195 |
// suitable for a given key |
216 |
// suitable for a given key |
196 |
_operators_query: function() { |
217 |
_operators_query: function() { |
197 |
|
218 |
|
|
|
219 |
if (this._operators_pending) |
220 |
{ |
221 |
//alert("OPERATORS already pending!"); |
222 |
} |
223 |
this._set_query_pending('operator',true); |
198 |
try |
224 |
try |
199 |
{ |
225 |
{ |
200 |
// While the query is underway I can always see the 'invalid' indicator |
|
|
201 |
// at the 'operator' ComboBox. So I try to set the ComboBox to a |
202 |
// neutral value. |
203 |
this.getWidget('operator').set('value',null); |
204 |
|
205 |
var value = this.getWidget('key').get('value'); |
226 |
var value = this.getWidget('key').get('value'); |
206 |
|
227 |
|
207 |
return umc.tools.umcpCommand('pkgdb/operators',{ |
228 |
return umc.tools.umcpCommand('pkgdb/operators',{ |
|
222 |
// key and operator. (pageKey is added silently) |
243 |
// key and operator. (pageKey is added silently) |
223 |
_proposals_query: function() { |
244 |
_proposals_query: function() { |
224 |
|
245 |
|
|
|
246 |
if (this._proposals_pending) |
247 |
{ |
248 |
//alert("PROPOSALS already pending!"); |
249 |
} |
250 |
this._set_query_pending('proposal',true); |
225 |
try |
251 |
try |
226 |
{ |
252 |
{ |
227 |
// While the query is underway I can always see the 'invalid' indicator |
|
|
228 |
// at the 'pattern_list' ComboBox. So I try to set the ComboBox to a |
229 |
// neutral value. |
230 |
this.getWidget('pattern_list').set('value',null); |
231 |
|
232 |
var key = this.getWidget('key').get('value'); |
253 |
var key = this.getWidget('key').get('value'); |
233 |
|
254 |
|
234 |
return umc.tools.umcpCommand('pkgdb/proposals',{ |
255 |
return umc.tools.umcpCommand('pkgdb/proposals',{ |
|
258 |
// entirely. |
279 |
// entirely. |
259 |
// |
280 |
// |
260 |
_handle_operators: function(values) { |
281 |
_handle_operators: function(values) { |
|
|
282 |
|
283 |
var p_label = this._("Pattern"); |
284 |
var o_show = false; |
285 |
var p_show = true; |
261 |
if (dojo.isArray(values)) |
286 |
if (dojo.isArray(values)) |
262 |
{ |
287 |
{ |
263 |
if (values.length) |
288 |
if (values.length) |
264 |
{ |
289 |
{ |
265 |
this._set_selection_to_first_element('operator'); |
290 |
this._set_selection_to_first_element('operator'); |
266 |
this._allow_patterns(true); |
291 |
this._pattern_needed = true; |
|
|
292 |
o_show = true; |
267 |
} |
293 |
} |
268 |
else |
294 |
else |
269 |
{ |
295 |
{ |
270 |
this._allow_patterns(false); |
296 |
this._pattern_needed = false; |
|
|
297 |
p_show = false; |
271 |
} |
298 |
} |
272 |
} |
299 |
} |
273 |
else |
300 |
else |
274 |
{ |
301 |
{ |
275 |
this._set_single_operator(values); |
302 |
this._pattern_needed = true; |
|
|
303 |
p_label = values; |
276 |
} |
304 |
} |
|
|
305 |
|
306 |
this.showWidget('operator',o_show); |
307 |
|
308 |
if (p_show) |
309 |
{ |
310 |
this.showWidget('pattern_text',!this._pattern_is_list); |
311 |
this.showWidget('pattern_list',this._pattern_is_list); |
312 |
} |
313 |
else |
314 |
{ |
315 |
this.showWidget('pattern_text',false); |
316 |
this.showWidget('pattern_list',false); |
317 |
} |
318 |
|
319 |
this.getWidget('pattern_text').set('label',p_label); |
320 |
this.getWidget('pattern_list').set('label',p_label); |
277 |
}, |
321 |
}, |
278 |
|
322 |
|
279 |
// handles the result (and especially: the result type) of the |
323 |
// handles the result (and especially: the result type) of the |
280 |
// proposals returned by the 'pkgdb/proposals' query |
324 |
// proposals returned by the 'pkgdb/proposals' query |
281 |
_handle_proposals: function(values) { |
325 |
_handle_proposals: function(values) { |
282 |
|
326 |
|
283 |
if (! this._patterns_allowed) { return; } // nothing to do here. |
|
|
284 |
|
285 |
var is_single = dojo.isString(values); |
327 |
var is_single = dojo.isString(values); |
286 |
this._pattern_is_list = !is_single; // remember for later. |
328 |
this._pattern_is_list = !is_single; // remember for later. |
287 |
if (is_single) |
329 |
if (is_single) |
|
292 |
{ |
334 |
{ |
293 |
this._set_selection_to_first_element('pattern_list'); |
335 |
this._set_selection_to_first_element('pattern_list'); |
294 |
} |
336 |
} |
295 |
// values are set. now show/hide appropriately. |
337 |
// values are set. now show/hide appropriately, but only if needed. |
296 |
this.showWidget('pattern_text',is_single); |
338 |
if (this._pattern_needed) |
297 |
this.showWidget('pattern_list',!is_single); |
339 |
{ |
|
|
340 |
this.showWidget('pattern_text',is_single); |
341 |
this.showWidget('pattern_list',!is_single); |
342 |
} |
298 |
}, |
343 |
}, |
299 |
|
344 |
|
300 |
// If we get a single operator we use it as a label for the |
345 |
// sets state of 'this query is pending' in a boolean variable |
301 |
// text input. Here is the function that switches the corresponding |
346 |
// and in the 'disabled' state of the corresponding dialog element(s) |
302 |
// status values. |
347 |
_set_query_pending: function(element,on) { |
303 |
_set_single_operator: function(operator) { |
|
|
304 |
|
348 |
|
305 |
this._patterns_allowed = true; |
349 |
var bv = '_' + element + 's_pending'; |
306 |
this.showWidget('operator',false); |
350 |
this.set(bv,on); |
307 |
this._set_selection_to_first_element('operator'); |
|
|
308 |
this.getWidget('operator').set('value',operator); |
309 |
|
310 |
this.getWidget('pattern_text').set('label',operator); |
311 |
this.getWidget('pattern_list').set('label',operator); |
312 |
|
351 |
|
313 |
this.showWidget('pattern_text',true); |
352 |
// To make it 100% safe against impatient users... but the downside is that |
314 |
this.showWidget('pattern_list',false); |
353 |
// the dialog elements would flicker on every selection change at the 'key' |
315 |
}, |
354 |
// ComboBox... |
|
|
355 |
// |
356 |
// var ele = this.getWidget(element); |
357 |
// if (ele) |
358 |
// { |
359 |
// // applies to 'key' and 'operator' ComboBox |
360 |
// ele.set('disabled',on); |
361 |
// } |
362 |
// else |
363 |
// { |
364 |
// // applies to these two 'pattern' entry elements |
365 |
// this.getWidget('pattern_text').set('disabled',on); |
366 |
// this.getWidget('pattern_list').set('disabled',on); |
367 |
// } |
316 |
|
368 |
|
317 |
// switches exutability of this query on or off: shows or hides |
|
|
318 |
// the 'operator' and 'pattern' elements. Additionally remembers |
319 |
// the last given pattern so subsequent handlers know the state. |
320 |
_allow_patterns: function(allow) { |
321 |
this._patterns_allowed = allow; |
322 |
|
323 |
this.showWidget('operator',allow); |
324 |
|
325 |
// at least, if NOT allowed -> hide both 'pattern_*' widgets. |
326 |
// showing one of them depending on allowed values must |
327 |
// be deferred until we have the 'proposals' data back. |
328 |
if (! allow) |
329 |
{ |
330 |
this.showWidget('pattern_text',false); |
331 |
this.showWidget('pattern_list',false); |
332 |
} |
333 |
else |
334 |
{ |
335 |
this.getWidget('pattern_text').set('label',this._("Pattern")); |
336 |
this.getWidget('pattern_list').set('label',this._("Pattern")); |
337 |
} |
338 |
}, |
369 |
}, |
339 |
|
370 |
|
340 |
_set_selection_to_first_element: function(name) { |
371 |
_set_selection_to_first_element: function(name) { |
|
351 |
// feature if the form doesn't honor it? |
382 |
// feature if the form doesn't honor it? |
352 |
onSubmit: function() { |
383 |
onSubmit: function() { |
353 |
|
384 |
|
354 |
var keys = this.getWidget('key'); |
385 |
// the 'onChange' handler of the textbox is not invoked until the focus |
355 |
var ok = ((keys.get('value') != '_') && (keys.getAllItems().length > 1)); |
386 |
// has left the field... so we have to do a last check here in case |
356 |
if (ok) |
387 |
// the text changed. |
|
|
388 |
this._handle_query_changes(); |
389 |
|
390 |
if (this._submit_allowed) |
357 |
{ |
391 |
{ |
358 |
// this widget must not be honored since it is invisible |
392 |
this.onExecuteQuery(this.getQuery()); |
359 |
var ignore = (this._pattern_is_list ? 'pattern_text' : 'pattern_list'); |
393 |
} |
|
|
394 |
}, |
395 |
|
396 |
// an internal callback for everything that changes a query, operator or pattern. |
397 |
// should call the external callback 'onQueryChanged' only if something has |
398 |
// changed. This maintains all internal variables that reflect the state of |
399 |
// the current entry and the executability of the query. |
400 |
_handle_query_changes: function(name,value) { |
401 |
|
402 |
// start with: allowed if none of our dynamicValues queries is pending |
403 |
var allow = ! (this._keys_pending || this._operators_pending || this._proposals_pending); |
404 |
|
405 |
// only allow if the 'key' position is not '--- select one ---' |
406 |
allow = allow && (this.getWidget('key').get('value')!='_'); |
407 |
|
408 |
// check validation for all elements that must be valid |
409 |
if (allow) |
410 |
{ |
360 |
for (var w in this._widgets) |
411 |
for (var w in this._widgets) |
361 |
{ |
412 |
{ |
362 |
var widget = this._widgets[w]; |
413 |
var widget = this._widgets[w]; |
363 |
if (widget.name != ignore) |
414 |
var n = widget['name']; |
|
|
415 |
var toprocess = true; |
416 |
if (n.substr(0,8) == 'pattern_') |
364 |
{ |
417 |
{ |
|
|
418 |
if (this._pattern_needed) |
419 |
{ |
420 |
if ( ((this._pattern_is_list) && (n == 'pattern_text')) |
421 |
|| ((!this._pattern_is_list) && (n == 'pattern_list'))) |
422 |
{ |
423 |
toprocess = false; |
424 |
} |
425 |
} |
426 |
else |
427 |
{ |
428 |
// no pattern required: pattern_text AND pattern_list should |
429 |
// should be ignored |
430 |
toprocess = false; |
431 |
} |
432 |
} |
433 |
if (toprocess) |
434 |
{ |
365 |
if (! widget.isValid()) |
435 |
if (! widget.isValid()) |
366 |
{ |
436 |
{ |
367 |
ok = false; |
437 |
allow = false; |
368 |
} |
438 |
} |
369 |
} |
439 |
} |
370 |
} |
440 |
} |
371 |
} |
441 |
} |
372 |
if (ok) |
442 |
|
|
|
443 |
if (allow != this._submit_allowed) |
373 |
{ |
444 |
{ |
374 |
this.onExecuteQuery(this.getQuery()); |
445 |
this._submit_allowed = allow; |
|
|
446 |
this.enableSearchButton(allow); |
375 |
} |
447 |
} |
376 |
}, |
448 |
}, |
377 |
|
449 |
|
|
389 |
this.enableEntryElements(false); |
461 |
this.enableEntryElements(false); |
390 |
}, |
462 |
}, |
391 |
|
463 |
|
392 |
// invoked whenever a substantial dialog element is being changed. The |
464 |
// the invoking Page or Module can listen here to know that the query is become |
393 |
// ancestor can listen here and clear (or switch invisible) the result |
465 |
// ready or disabled. Internal function _handle_query_changes() maintains all |
394 |
// grid. Args are the name of the field being changed, and the new value. |
466 |
// state variables and calls this only if the state has changed. |
395 |
onQueryChanged: function(field,value) { |
467 |
onQueryChanged: function(query) { |
396 |
if (field == 'key') |
|
|
397 |
{ |
398 |
this.enableSearchButton(value != '_'); |
399 |
} |
400 |
} |
468 |
} |
401 |
|
469 |
|
402 |
}); |
470 |
}); |