Skip to content

Commit f4db4bb

Browse files
committed
Cleanups.
1 parent 1a89f1e commit f4db4bb

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

js/structured-filter.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,20 @@
1414

1515
(function( $, undefined){
1616

17-
var i18n={
17+
// - field types
18+
var fTypes={
19+
text:'text',
20+
bool:'boolean',
21+
number:'number',
22+
date:'date',
23+
time:'time',
24+
list:'list',
25+
listOpts: 'list-options',
26+
listDropdown: 'list-dropdown'
27+
},
28+
29+
// - i18n strings (to translate in other languages)
30+
i18n={
1831
sEqual:'equals',
1932
sNotEqual:'not equal',
2033
sStart:'starts with',
@@ -45,6 +58,8 @@
4558
bSubmit:'Submit',
4659
bCancel:'Cancel'
4760
},
61+
62+
// - list of operators (for conditions)
4863
evoAPI={
4964
sEqual:'eq',
5065
sNotEqual:'ne',
@@ -59,16 +74,6 @@
5974
sSmaller:'lt',
6075
sBetween:'bw'
6176
},
62-
fTypes={
63-
text:'text',
64-
bool:'boolean',
65-
number:'number',
66-
date:'date',
67-
time:'time',
68-
list:'list',
69-
exList: 'list-options',
70-
selList: 'list-dropdown'
71-
},
7277
isNotFirefox = navigator.userAgent.toLowerCase().indexOf('firefox')===-1;
7378

7479
$.widget( 'evol.structFilter', {
@@ -159,7 +164,7 @@ $.widget( 'evol.structFilter', {
159164
that._field=that._getFieldById(fieldID);
160165
var fType=that._type=that._field.type;
161166
that._setEditorOperator();
162-
if([fTypes.list, fTypes.bool, fTypes.exList, fTypes.selList].indexOf(fType) > -1){
167+
if(fType===fTypes.bool || fType.startsWith('list')){
163168
that._setEditorValue();
164169
}
165170
}else{
@@ -176,10 +181,10 @@ $.widget( 'evol.structFilter', {
176181
that._setEditorValue();
177182
}).on('change keyup', '#value,#value2', function(evt){
178183
evt.stopPropagation();
179-
var type=that._type,
184+
var fType=that._type,
180185
value=$(this).val(),
181-
valid=(value!=='') || ([fTypes.list, fTypes.bool, fTypes.exList, fTypes.selList].indexOf(type) > -1);
182-
if(type==fTypes.number){
186+
valid= value!=='' || fType===fTypes.bool || fType.startsWith('list');
187+
if(fType==fTypes.number){
183188
valid=valid && !isNaN(value);
184189
}else if(that._operator==evoAPI.sBetween){
185190
valid=that._editor.find('#value').val()!=='' && that._editor.find('#value2').val()!=='';
@@ -346,8 +351,8 @@ $.widget( 'evol.structFilter', {
346351
h+=EvoUI.inputHidden('operator',evoAPI.sInList);
347352
this._operator=evoAPI.sInList;
348353
break;
349-
case fTypes.exList:
350-
case fTypes.selList:
354+
case fTypes.listOpts:
355+
case fTypes.listDropdown:
351356
case fTypes.bool:
352357
//h.push(i18n.sEqual);
353358
h+=EvoUI.inputHidden('operator',evoAPI.sEqual);
@@ -423,14 +428,14 @@ $.widget( 'evol.structFilter', {
423428
EvoUI.inputCheckboxes(fld.list)+
424429
'</span>';
425430
break;
426-
case fTypes.exList:
431+
case fTypes.listOpts:
427432
h+='<span id="value">';
428433
h+=fld.list.map(function(item){
429434
return EvoUI.inputRadio(fld.id, item.id, item.label, v==item.id, 'value' + item.id);
430435
}).join('');
431436
h +='</span>';
432437
break;
433-
case fTypes.selList:
438+
case fTypes.listDropdown:
434439
h+='<select id="value">'+EvoUI.optNull;
435440
h+=fld.list.map(function(item){
436441
return EvoUI.inputOption(item.id, item.label);
@@ -463,7 +468,7 @@ $.widget( 'evol.structFilter', {
463468
case fTypes.list:
464469
$value.find('#'+v.split(',').join(',#')).prop('checked', 'checked');
465470
break;
466-
case fTypes.exList:
471+
case fTypes.listOpts:
467472
case fTypes.bool:
468473
$value.find('#value'+v).prop('checked', 'checked');
469474
break;
@@ -476,7 +481,7 @@ $.widget( 'evol.structFilter', {
476481
}
477482
}
478483
}else{
479-
addOK=(fType==fTypes.list || fType==fTypes.listSelect || fType==fTypes.bool);
484+
addOK=(fType==fTypes.list || fType==fTypes.listDropdown || fType==fTypes.bool);
480485
}
481486
}
482487
this._bAdd.button(addOK?'enable':'disable').show();
@@ -525,13 +530,13 @@ $.widget( 'evol.structFilter', {
525530
var val=(v.find('#value1').prop('checked'))?1:0;
526531
fv.label=(val==1)?i18n.yes:i18n.no;
527532
fv.value=val;
528-
}else if(this._type==fTypes.exList){
533+
}else if(this._type==fTypes.listOpts){
529534
op.label=i18n.sEqual;
530535
op.value=evoAPI.sEqual;
531536
var sel = v.find('input:checked');
532537
fv.label = sel.parent().text();
533538
fv.value = sel.prop('id').slice(5);
534-
}else if(this._type==fTypes.selList){
539+
}else if(this._type==fTypes.listDropdown){
535540
op.label=i18n.sEqual;
536541
op.value=evoAPI.sEqual;
537542
var vval=v.val();

0 commit comments

Comments
 (0)