-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbehaivor.js
570 lines (463 loc) · 19.2 KB
/
behaivor.js
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
/* Behaivor for tabs - Listeners */
let options = [];
let elements_table_added = [];
//Listener: When the user change the value of the tab_name input
$("#tab_name").on('input', function () {
let tab = $("#tab_name").val();
console.log("on");
if (tab.length > 0) {
$("#addTab").attr("disabled", false);
}
else {
$("#addTab").attr("disabled", true);
}
});
//Listener: When the user click on the button addTab
$("#addTab").click(function () {
let tab = $("#tab_name").val();
addTab(tab);
$("#tab_name").val("");
$("#addTab").attr("disabled", true);
fillTabs();
unlockPanels();
updateEditorCode();
});
//Fill all tabs for select panels
function fillTabs() {
let tabs = getAllTabs();
$("#tab_selected").html("");
$("#tab_selected_element").html("");
for (let tab of tabs) {
$("#tab_selected").append("<option value=" + tab.location + ">" + tab.name + "</option>");
$("#tab_selected_element").append("<option value=" + tab.location + ">" + tab.name + "</option>");
}
}
function unlockPanels() {
$("#panel_name").attr("disabled", false);
$("#tab_selected").attr("disabled", false);
$("#panel_type").attr("disabled", false);
}
//Listener: When the user change the value of the panel_name input
$("#panel_name").on('input', function () {
let panel = $("#panel_name").val();
console.log("on");
let tab = $("#tab_selected option:selected").val();
if (panel.length > 0 && tab != undefined) {
$("#addPanel").attr("disabled", false);
}
else {
$("#addPanel").attr("disabled", true);
}
});
//Listener: When the user click on the button addPanel
$("#addPanel").click(function () {
let panel = $("#panel_name").val();
let tab = $("#tab_selected option:selected").val();
let type = $("#panel_type option:selected").val();
addPanel(tab, panel, type);
$("#panel_name").val("");
$("#addPanel").attr("disabled", true);
allPanels();
unlockElements();
updateEditorCode();
});
//Fill all panels by tab_id
function allPanels() {
let tab_id = $("#tab_selected_element option:selected").val();
let panels = getAllPanels(tab_id);
$("#panel_selected_element").html("");
$("#panel_selected_element").attr("disabled", false);
for (let panel of panels) {
$("#panel_selected_element").append("<option value=" + panel.id + ">" + panel.name + "</option>");
}
}
//Listener when the option selected change
$("#tab_selected_element").change(function () {
console.log("tab changed");
let tab = $("#tab_selected_element option:selected").val();
allPanels(tab);
});
//Fill all the element
function fillAllElements() {
let elements = [
{ "name": "DatePicker", "value": "date" },
{ "name": "DateTimePicker", "value": "datetime" },
{ "name": "TimePicker", "value": "time" },
{ "name": "WeekPicker", "value": "week" },
{ "name": "MonthPicker", "value": "month" },
{ "name": "Text", "value": "text" },
{ "name": "TextArea", "value": "textArea" },
{ "name": "Number", "value": "number" },
{ "name": "Radio Buttons - Single Selection", "value": "radio" },
{ "name": "Checkbox - Multiple Selections", "value": "checkbox" },
{ "name": "Select - Single Selection", "value": "select" },
{ "name": "MultiSelect - Multiple Selections", "value": "multiselect" },
{ "name": "List - Single Selection", "value": "list" },
{ "name": "Image 1 Label", "value": "image1Label" },
{ "name": "Image 2 Labels", "value": "image2Labels" },
{ "name": "Table", "value": "table" }
];
for (let element of elements) {
$("#element_selected").append("<option value=" + element.value + ">" + element.name + "</option>");
}
}
function displayElements() {
fillAllElements();
changeOptionsForElement();
}
displayElements();
//Listen when the element option selected change
$("#element_selected").change(function () {
changeOptionsForElement();
});
function changeOptionsForElement() {
let element = $("#element_selected option:selected").val();
$("#element_config").html("");
let fields;
switch (element) {
case "date": case "datetime": case "time": case "week": case "month":
fields = showDateFields();
for (let field of fields) {
$("#element_config").append(field.element_html);
}
break;
case "number":
fields = showNumberFields();
for (let field of fields) {
$("#element_config").append(field.element_html);
}
break;
case "text": case "textArea":
fields = showTextFields();
for (let field of fields) {
$("#element_config").append(field.element_html);
}
break;
case "radio": case "checkbox": case "select": case "multiselect":
fields = showSelectionsFields();
options = [];
for (let field of fields) {
$("#element_config").append(field.element_html);
}
$("#options_type").change(function () {
let option_selected = $("#options_type option:selected").val();
switch (option_selected) {
case "Custom":
$("#opName").attr("disabled", false);
$("#opValue").attr("disabled", false);
break;
}
});
$("#AddOp").click(function () {
let option_selected = $("#options_type option:selected").val();
switch (option_selected) {
case "Si,No":
options.push({ "label": "Si", "value": "Si" });
options.push({ "label": "No", "value": "No" });
showOptions();
break;
case "Si,No,N/A":
options.push({ "label": "Si", "value": "Si" });
options.push({ "label": "No", "value": "No" });
options.push({ "label": "N/A", "value": "N/A" });
showOptions();
break;
case "Bueno,Malo,Regular,N/A":
options.push({ "label": "Bueno", "value": "Bueno" });
options.push({ "label": "Malo", "value": "Malo" });
options.push({ "label": "Regular", "value": "Regular" });
options.push({ "label": "N/A", "value": "N/A" });
showOptions();
break;
case "Rural,Urbano":
options.push({ "label": "Rural", "value": "Rural" });
options.push({ "label": "Urbano", "value": "Urbano" });
showOptions();
break;
case "Custom":
let opName = $("#opName").val();
let opValue = $("#opValue").val();
options.push({ "label": opName, "value": opValue });
showOptions();
break;
}
$("#addElement").attr("disabled", false);
});
break;
case "list":
options = [];
fields = showListFields();
for (let field of fields) {
$("#element_config").append(field.element_html);
}
showFieldsforOptions();
break;
case "table":
fields = showTableFields();
for (let field of fields) {
$("#element_config").append(field.element_html);
}
showTableElementSelected();
$("#table_element").change(function () {
showTableElementSelected();
});
break;
case "image1Label":
fields = showImage1LabelFields();
for (let field of fields) {
$("#element_config").append(field.element_html);
}
break;
case "image2Labels":
fields = showImage2LabelFields();
for (let field of fields) {
$("#element_config").append(field.element_html);
}
break;
}
}
showMenu();
function showMenu() {
$("#show_tabs_form").hide();
$("#show_element_form").hide();
$("#show_editor_code").hide();
$("#show_tabs_form_action").click(function () {
$("#show_tabs_form").show();
$("#show_element_form").hide();
$("#show_editor_code").hide();
});
$("#show_element_form_action").click(function () {
let tree_created = checkTree();
if (tree_created) {
$("#treeNotFound").hide();
$("#confElement").show();
}
else {
$("#treeNotFound").show();
$("#confElement").hide();
}
$("#show_tabs_form").hide();
$("#show_element_form").show();
$("#show_editor_code").hide();
});
$("#show_editor_code_action").click(function () {
$("#show_tabs_form").hide();
$("#show_element_form").hide();
$("#show_editor_code").show();
});
}
function unlockElements() {
$("#tab_selected_element").attr("disabled", false);
$("#panel_selected_element").attr("disabled", false);
$("#element_selected").attr("disabled", false);
}
/* Listener for the element_name */
$("#element_name").on('input', function () {
console.log("name edited");
let element = $("#element_name").val();
let tab = $("#panel_selected_element option:selected").val()
if (element.length > 0 && tab != undefined) {
$("#addElement").attr("disabled", false);
}
else {
$("#addElement").attr("disabled", true);
}
});
$("#addElement").click(function () {
let tab_id = $("#tab_selected_element option:selected").val();
let panel_id = $("#panel_selected_element option:selected").val();
let element = $("#element_selected option:selected").val();
let element_name = $("#element_name").val();
let size_sm = $("#element_size_small option:selected").val();
let size_md = $("#element_size_medium option:selected").val();
let size_lg = $("#element_size_lg option:selected").val();
let autofocus = $("#element_autofocus").is(":checked");
let required = $("#element_required").is(":checked");
let disabled = $("#element_disabled").is(":checked");
let readOnly = $("#element_readOnly").is(":checked");
addElement(tab_id, panel_id, element, element_name, size_sm, size_md, size_lg, autofocus, required, disabled, readOnly);
updateEditorCode();
$("#element_name").val("");
options =[];
elements_table_added = [];
showTableElementsAdded();
});
function updateEditorCode() {
editor.setValue("" + JSON.stringify(getCodePreview(), null, '\t'));
$("#templateNavTabs").html("");
$("#templateTabsPanel").html("");
executeEngine(codePreview);
}
/* Start Listening opName && opValue */
$("#opName, #opValue").on("input", function () {
let opName = $("#opName").val();
let opValue = $("#opValue").val();
if (opName.length > 0 & opValue.length > 0) {
$("#AddOp").attr("disabled", false);
}
else {
$("#AddOp").attr("disabled", true);
}
});
function showOptions() {
$("#listOpts").html("");
if(options.length > 0){
for (let opt of options) {
$("#listOpts").append("<li class='list-group-item'><b>Nombre:</b> " + opt.label + " - <b>Valor:</b> " + opt.value + "<br><!--<button class='btn btn-danger btn-sm pull-rigth'><span class='fa fa-trash-o'></span>Eliminar</button>--></li>");
}
}
else{
$("#listOpts").append("<li class='list-group-item'>No existe elementos agregados</li>");
}
}
menuEditor();
function menuEditor() {
$("#edit_content_editor").click(function () {
editor.setReadOnly(false);
$("#save_content_editor").attr("disabled", false);
});
$("#save_content_editor").click(function () {
editor.setReadOnly(true);
let codePreviewCache = codePreview;
try {
codePreview = JSON.parse(editor.getValue());
launchModal("Se ha agregado el codigo correctamente");
unlockPanels();
unlockElements();
fillTabs();
allPanels();
} catch (error) {
codePreview = codePreviewCache;
launchErrorModal(error);
}
updateEditorCode();
$("#save_content_editor").attr("disabled", true);
});
$("#download_content_editor").click(function () {
launchJSONmodal();
});
}
function showTableElementSelected() {
let table_element = $("#table_element option:selected").val();
let number_elements = [{ "element_html": "<div class=col-md-6><label class=control-label>Mínimo Numero</label><input class=form-control id=minNumber type=number></div>" },
{ "element_html": " <div class=col-md-6><label class=control-label>Máximo Numero</label><input class=form-control id=maxNumber type=number></div>" }
];
let text_elements = [{ "element_html": "<div class=col-md-6><label class=control-label>Max Length</label><input class=form-control id=maxLength type=number></div>" }];
let list_elements = [{ "element_html": "<div class=col-md-6><label class=control-label>Crear Opciones</label><select class=form-control id=options_type><option value=Si,No>Si - No<option value=Si,No,N/A>Si - No - N/A<option value=Bueno,Malo,Regular,N/A>Bueno - Malo - Regular - N/A<option value=Rural,Urbano>Rural - Urbano<option value=Custom>Otra</select><br><input class=form-control disabled id=opName placeholder='Nombre Opción'><br><input class=form-control disabled id=opValue placeholder='Valor de la Opción'> <button class='btn btn-primary'id=AddOp>Agregar Opción</button></div>" },
{ "element_html": "<div class=col-md-6><label class=control-label>Opciones Creadas</label><div><ul class=list-group id=listOpts><li class=list-group-item>No existe elementos agregados</ul></div></div>" }
];
$("#table_element_selected").html("");
options = [];
showOptions();
showTableElementsAdded();
switch (table_element) {
case "number":
for (let element of number_elements) {
$("#table_element_selected").append(element.element_html);
}
break;
case "text":
for (let element of text_elements) {
$("#table_element_selected").append(element.element_html);
}
break;
case "list":
for (let element of list_elements) {
$("#table_element_selected").append(element.element_html);
}
showFieldsforOptions();
break;
}
$("#btnAddEleTable").off("click");
$("#btnAddEleTable").click(function () {
let element = $("#table_element option:selected").val();
let element_name = $("#table_ele_name").val();
let size_sm = $("#element_size_small option:selected").val();
let size_md = $("#element_size_medium option:selected").val();
let size_lg = $("#element_size_lg option:selected").val();
let autofocus = $("#element_autofocus").is(":checked");
let required = $("#element_required").is(":checked");
let disabled = $("#element_disabled").is(":checked");
let readOnly = $("#element_readOnly").is(":checked");
elements_table_added.push(addElementTable( element, element_name, size_sm, size_md, size_lg, autofocus, required, disabled, readOnly));
showTableElementsAdded();
options=[];
showOptions();
$("#table_ele_name").val("");
switch(element){
case "number":
$("#minNumber").val("");
$("#maxNumber").val("");
break;
case"text":
$("#maxLength").val("");
break;
case"list":
$("#opName").val("");
$("#opValue").val("");
break;
}
});
}
function showFieldsforOptions() {
$("#options_type").change(function () {
let option_selected = $("#options_type option:selected").val();
switch (option_selected) {
case "Custom":
$("#opName").attr("disabled", false);
$("#opValue").attr("disabled", false);
break;
}
});
$("#AddOp").click(function () {
let option_selected = $("#options_type option:selected").val();
switch (option_selected) {
case "Si,No":
options.push({ "label": "Si", "value": "Si" });
options.push({ "label": "No", "value": "No" });
showOptions();
break;
case "Si,No,N/A":
options.push({ "label": "Si", "value": "Si" });
options.push({ "label": "No", "value": "No" });
options.push({ "label": "N/A", "value": "N/A" });
showOptions();
break;
case "Bueno,Malo,Regular,N/A":
options.push({ "label": "Bueno", "value": "Bueno" });
options.push({ "label": "Malo", "value": "Malo" });
options.push({ "label": "Regular", "value": "Regular" });
options.push({ "label": "N/A", "value": "N/A" });
showOptions();
break;
case "Rural,Urbano":
options.push({ "label": "Rural", "value": "Rural" });
options.push({ "label": "Urbano", "value": "Urbano" });
showOptions();
break;
case "Custom":
let opName = $("#opName").val();
let opValue = $("#opValue").val();
options.push({ "label": opName, "value": opValue });
showOptions();
break;
}
$("#addElement").attr("disabled", false);
});
}
function showTableElementsAdded(){
$("#table_elements_added").html("");
for(let element of elements_table_added){
switch(element.type){
case "text": case "number":
$("#table_elements_added").append("<li class='list-group-item'><b>Nombre:</b> " + element.label.value + " - <b> Type :</b> " + element.type + "<br><!--<button class='btn btn-danger btn-sm pull-rigth'><span class='fa fa-trash-o'></span>Eliminar</button>--></li>");
break;
case "list":
let listOptions = "";
for (let options of element.options){
listOptions += "<li> <b>Label:</b>"+options.label + " - <b> Valor: </b>"+ options.value + "</li>";
}
$("#table_elements_added").append("<li class='list-group-item'><b>Nombre:</b> " + element.label.value + " - <b> Type :</b> " + element.type + "<br> <ul> "+ listOptions + "<ul><br><!--<button class='btn btn-danger btn-sm pull-rigth'><span class='fa fa-trash-o'></span>Eliminar</button>--></li>");
}
}
}