-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_jquery_equationeditor.html
More file actions
298 lines (264 loc) · 8.86 KB
/
test_jquery_equationeditor.html
File metadata and controls
298 lines (264 loc) · 8.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Combobox</title>
<link href="jquery-ui-1.11.4/jquery-ui.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/ise.treeintable.css">
<link rel="stylesheet" type="text/css" href="css/ise.treeintable.css">
<script src="jquery-ui-1.11.4/external/jquery/jquery.js"></script>
<script src="jquery-ui-1.11.4/jquery-ui.js"></script>
<!--
<script type="text/javascript" src="js/jquery.ise.datastore.js"></script>
<script type="text/javascript" src="js/jquery.ise.treeintable.js"></script>
<script type="text/javascript" src="js/jquery.ise.conditioneditor.js"></script>
<script type="text/javascript" src="js/esprima.js"></script>
-->
<script type="text/javascript" src="js/jquery.ise.versatilecombobox.js"></script>
<script type="text/javascript" src="js/jquery.ise.equationeditor.js"></script>
<style>
</style>
<script>
$(function() {
var metadata= {
"fields": [{
"label": "Name",
"value": "Name",
"type": "string"
}, {
"label": "Age",
"value": "Age",
"type": "numerical"
}, {
"label": "SSN",
"value": "SSN",
"type": "string"
}, {
"label": "sourceIP",
"value": "sourceIP",
"type": "string"
}, {
"label": "targetIP",
"value": "targetIP",
"type": "string"
}, {
"label": "amount",
"value": "amount",
"type": "numerical"
}, {
"label": "bonus",
"value": "bonus",
"type": "numerical"
}, {
"label": "registered",
"value": "registered",
"type": "boolean"
}],
"operators": [{
"label": "=",
"value": "=",
"type": "numerical"
}, {
"label": "!=",
"value": "!=",
"type": "numerical"
}, {
"label": ">=",
"value": ">=",
"type": "numerical"
}, {
"label": "<=",
"value": "<=",
"type": "numerical"
}, {
"label": "<",
"value": "<",
"type": "numerical"
}, {
"label": ">",
"value": ">",
"type": "numerical"
}, {
"label": "is",
"value": "is",
"type": "boolean"
}, {
"label": "isNot",
"value": "isNot",
"type": "boolean"
}, {
"label": "matches",
"value": "matches",
"type": "string"
},{
"label": "startsWith",
"value": "startsWith",
"type": "string"
}, {
"label": "endsWith",
"value": "endsWith",
"type": "string"
}, {
"label": "like",
"value": "like",
"type": "string"
}, {
"label": "contains",
"value": "contains",
"type": "string"
}, {
"label": "range",
"value": "range",
"type": "string"
}]
}
var metadataUtil ={
getObjectHelper : function(metaList, item, attributeName){
if (!attributeName){
attributeName = "value";
}
var metaFlds = metaList
for (var i =0; i<metaFlds.length;i++){
if (metaFlds[i][attributeName].toLowerCase() == item[attributeName].toLowerCase()){
return metaFlds[i];
}
}
return null;
},
getFieldObject : function(item, attributeName){
var metaFields = metadata.fields;
return this.getObjectHelper(metaFields, item, attributeName);
},
getOperatorObject:function(item, attributeName){
var metaOps = metadata.operators;
return this.getObjectHelper(metaOps, item, attributeName);
},
getOperatorsByType :function(type){
var ops = [];
var metaOps = metadata.operators;
for (var i =0; i<metaOps.length;i++){
if (metaOps[i].type.toLowerCase() == type.toLowerCase()){
ops.push(metaOps[i]);
}
}
return ops;
},
getFieldsByType : function(type){
var fields=[];
var metaFlds = metadata.fields;
for (var i =0; i<metaFlds.length;i++){
if (metaFlds[i].type.toLowerCase() == type.toLowerCase()){
fields.push(metaFlds[i]);
}
}
return fields;
}
}
var fieldOptions= metadata.fields;
var operatorOptions = [];//metadataUtil.getOperatorsByType("numerical");
var valueOptions = []; // metadataUtil.getOperatorsByType("numerical");
$( "#combobox" ).equationeditor({
fieldselectOptions : fieldOptions,
operatorselectOptions : operatorOptions,
valueselectOptions : valueOptions,
onFormCreateComplete: function(fieldwidget, operatorwidget, valuewidget){
// Overriding onFormCreateComplete() give you a chance to inject customized code to the widget.
console.log("customized onFormCreateComplete()");
//Disable the operatorWidget and valueWidget first. It forces user to pick from field-combo.
operatorwidget.disable();
valuewidget.disable();
var equationeditor = this;
/*
This is a demostration. In real life application, we should use meta-data. based on selected field's data type,
we adjust operator combo's options and value combo's option accordingly.
Say, for "age" field, you make opeator to have "=, !=, >.." options. Force value field to accept numerical value only.
As well, for "name" field, you can have operator the have "startWith, contains, like, endWith" options.
*/
//I am overriding onFieldInputChange() API.
//When user changes "field" value, we can update "operator" and "value" widget according to specific business logic.
equationeditor.onFieldInputChange = function(widget){
var fieldwidget = equationeditor.getFieldWidget();
var operatorwidget = equationeditor.getOperatorWidget();
var valuewidget = equationeditor.getValueWidget();
if (this.debug) console.log("customized onFieldInputChange() " +JSON.stringify(widget.selectedValue));
var fieldValue = fieldwidget.selectedValue;
if (!fieldValue) return;
// enable operator-combo and valuewidget-combo
operatorwidget.enable();
valuewidget.enable();
var fieldObj = metadataUtil.getFieldObject(fieldValue, "value");
if (fieldObj){
operatorwidget.reset();
// if (fieldObj.type == "string") --> fill operatorwidget.selectOptions with "startsWith, endsWith..., etc"
operatorwidget.selectOptions = metadataUtil.getOperatorsByType(fieldObj.type);
operatorwidget.selectOptions= operatorwidget.selectOptions.concat(metadataUtil.getOperatorsByType("boolean"));
}
if (fieldObj.type != "boolean"){
// say user picks "name" field (a string type field), we want to populate value-combo with all string type fields except "name"
var typeFields = metadataUtil.getFieldsByType(fieldObj.type);
var idx = typeFields.indexOf(fieldObj);
typeFields.splice(idx, 1);
valuewidget.selectOptions = typeFields;
}
///* We can examine every select field's value and update operator-combo and value-combo accordingly.
if (fieldValue.value == "name"){
// write you business logic
//operatorwidget.selectOptions = ...
//valuewidget.selectOptions = ..
}else{
// write you businese logic ...
}
//*/
operatorwidget.reset();
valuewidget.reset();
};
/*
* Override the API onOperatorInputChange()
* When ever user picks operator value, we can update the value-combo accordingly.
*/
equationeditor.onOperatorInputChange = function(widget){
var fieldwidget = equationeditor.getFieldWidget();
var operatorwidget = equationeditor.getOperatorWidget();
var valuewidget = equationeditor.getValueWidget();
if (this.debug) console.log("customized onOperatorInputChange() " +JSON.stringify(widget.selectedValue));
var fieldValue = fieldwidget.selectedValue;
var operatorValue = operatorwidget.selectedValue;
var operatorObj = metadataUtil.getOperatorObject(operatorValue, "value");
if (operatorObj.type == "boolean"){
var nullFields =[{
"label": "null",
"value": "null"
},
{
"label": "non null",
"value": "non null"
}];
valuewidget.selectOptions = nullFields;
}
valuewidget.reset();
};
/*
* Override the API onValueInputChange()
* When ever user picks operator value, we can update the value-combo accordingly.
*/
equationeditor.onValueInputChange = function(widget){
if (equationeditor.debug) console.log("customized onValueInputChange() " +JSON.stringify(widget.selectedValue));
};
},
debug:true
});
});
</script>
</head>
<body>
<hr><b>This demonstrates equationeditor Widget. <br/> <br/>This widget let you specify equation. <br/> In application, you can control fields, operator and value</b> </hr>
<br/>
<br/>
<div class="ui-widget">
<label>Equation Editor </label>
<br/>
<div id="combobox">
</div>
</div>
</body>
</html>