zet-lib 1.5.30 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/lib/Modal.js +85 -30
  2. package/lib/Model.js +118 -2
  3. package/lib/config_generator.js +24 -0
  4. package/lib/generatorApi.js +1328 -0
  5. package/lib/generatorApp.js +1342 -0
  6. package/lib/generatorModel.js +733 -0
  7. package/lib/lang_en.js +115 -0
  8. package/lib/routes/api.js +52 -0
  9. package/lib/routes/index.js +9 -0
  10. package/lib/views/error.ejs +3 -0
  11. package/lib/views/zgenerator/bootstrap3/_form.ejs +24 -0
  12. package/lib/views/zgenerator/bootstrap3/create.ejs +9 -0
  13. package/lib/views/zgenerator/bootstrap3/createjs.ejs +3 -0
  14. package/lib/views/zgenerator/bootstrap3/import.ejs +52 -0
  15. package/lib/views/zgenerator/bootstrap3/importjs.ejs +3 -0
  16. package/lib/views/zgenerator/bootstrap3/index.ejs +29 -0
  17. package/lib/views/zgenerator/bootstrap3/indexcss.ejs +1 -0
  18. package/lib/views/zgenerator/bootstrap3/indexjs.ejs +307 -0
  19. package/lib/views/zgenerator/bootstrap3/update.ejs +8 -0
  20. package/lib/views/zgenerator/bootstrap3/updatejs.ejs +3 -0
  21. package/lib/views/zgenerator/bootstrap3/view.ejs +57 -0
  22. package/lib/views/zgenerator/head.ejs +12 -0
  23. package/lib/views/zgenerator/index.ejs +271 -0
  24. package/lib/views/zgenerator/indexcss.ejs +87 -0
  25. package/lib/views/zgenerator/indexjs.ejs +705 -0
  26. package/lib/views/zgenerator/layout.ejs +198 -0
  27. package/lib/views/zgenerator/manual_basic.ejs +2 -0
  28. package/lib/views/zgenerator/manual_dropdown.ejs +126 -0
  29. package/lib/views/zgenerator/manual_modules.ejs +192 -0
  30. package/lib/views/zgenerator/manual_virtual.ejs +143 -0
  31. package/lib/views/zgenerator/mini.ejs +341 -0
  32. package/lib/views/zgenerator/routerApp.ejs +359 -0
  33. package/lib/views/zgenerator/views/_form.ejs +25 -0
  34. package/lib/views/zgenerator/views/approval.ejs +42 -0
  35. package/lib/views/zgenerator/views/create.ejs +7 -0
  36. package/lib/views/zgenerator/views/createjs.ejs +16 -0
  37. package/lib/views/zgenerator/views/import.ejs +49 -0
  38. package/lib/views/zgenerator/views/importjs.ejs +4 -0
  39. package/lib/views/zgenerator/views/index.ejs +9 -0
  40. package/lib/views/zgenerator/views/indexcss.ejs +2 -0
  41. package/lib/views/zgenerator/views/indexjs.ejs +2 -0
  42. package/lib/views/zgenerator/views/preview.ejs +34 -0
  43. package/lib/views/zgenerator/views/update.ejs +7 -0
  44. package/lib/views/zgenerator/views/updatejs.ejs +16 -0
  45. package/lib/views/zgenerator/views/view.ejs +36 -0
  46. package/lib/zGeneratorRouter.js +46 -22
  47. package/lib/zRoute.js +14 -3
  48. package/package.json +1 -1
@@ -0,0 +1,705 @@
1
+ <!-- set to localStorage -->
2
+ <script>
3
+ localStorage.setItem('datas', <%- JSON.stringify(JSON.stringify(datas,null,2)) %>);
4
+ var datas = JSON.parse(localStorage.getItem("datas"));
5
+ </script>
6
+ <!-- Modal -->
7
+ <div class="modal fade" id="add_table" tabindex="-1" aria-labelledby="add_table" aria-hidden="true">
8
+ <div class="modal-dialog">
9
+ <div class="modal-content">
10
+ <div class="modal-header">
11
+ <h5 class="modal-title" id="exampleModalLabel">Add Table</h5>
12
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i> </button>
13
+ </div>
14
+ <div class="modal-body">
15
+ <form id="modal-form" method="post" action="/generator">
16
+ <div class="form-group">
17
+ <label for="table">Module Name</label>
18
+ <input type="text" class="form-control" id="modal-table" name="table"/>
19
+ </div>
20
+
21
+ <div class="form-group">
22
+ <label for="route">Route</label>
23
+ <input type="text" class="form-control" id="modal-route" name="route"/>
24
+ </div>
25
+ </form>
26
+ </div>
27
+ <div class="modal-footer">
28
+ <button type="button" class="btn btn-secondary" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
29
+ <button type="button" id="modal-save" class="btn btn-primary"><i class="fa fa-paper-plane"></i> Save</button>
30
+ </div>
31
+ </div>
32
+ </div>
33
+ </div>
34
+
35
+
36
+ <div class="modal fade" id="modal_add_field" tabindex="-1" aria-labelledby="add_table" aria-hidden="true">
37
+ <div class="modal-dialog">
38
+ <div class="modal-content">
39
+ <div class="modal-header">
40
+ <h5 class="modal-title" >Add Field</h5>
41
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i> </button>
42
+ </div>
43
+ <div class="modal-body">
44
+
45
+ <form id="modal-form" method="post" action="/<%- routeName%>">
46
+ <div class="form-group">
47
+ <label for="table">Name</label>
48
+ <div class="input-group">
49
+ <div class="input-group-prepend">
50
+ <select id="modal_position" class="form-control">
51
+ <option value="LEFT">Left</option>
52
+ <option value="RIGHT">Right</option>
53
+ <option value="ONE_COLUMN">One Column</option>
54
+ </select>
55
+ </div>
56
+ <input type="text" class="form-control" id="modal_name" placeholder="Field Name" name="name"/>
57
+ </div>
58
+ </div>
59
+
60
+ <div class="form-group">
61
+ <label for="route">Type</label>
62
+ <select class="form-control" id="modal_type">
63
+ <% for(var key in selects){%>
64
+ <option value="<%- key%>"><%- selects[key]%></option>
65
+ <%}%>
66
+ </select>
67
+ </div>
68
+
69
+ <div class="row divrelation" style="display:none">
70
+ <div class="col-md-6">
71
+ <div class="form-group">
72
+ <label for="route">Module Name</label>
73
+ <select class="form-control" id="relationtable"></select>
74
+ </div>
75
+ </div>
76
+
77
+ <div class="col-md-6 divrelationfield">
78
+ <div class="form-group ">
79
+ <label for="route">Label</label>
80
+ <select class="form-control" id="relationfield"></select>
81
+ </div>
82
+ </div>
83
+
84
+ <div class="col-md-12 divconcat">
85
+ <div class="form-group ">
86
+ <label for="route">Concat</label>
87
+ <input type="text" class="form-control" id="relationconcat" placeholder='CONCAT(fullname, " (email) : ", email)' >
88
+ </div>
89
+ </div>
90
+
91
+ </div>
92
+ </form>
93
+
94
+ </div>
95
+ <div class="modal-footer">
96
+ <button type="button" class="btn btn-secondary" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
97
+ <button type="button" id="modal-add" class="btn btn-primary"><i class="fa fa-plus"></i> Add</button>
98
+ </div>
99
+ </div>
100
+ </div>
101
+ </div>
102
+
103
+
104
+ <div class="modal fade" id="modal_setting" tabindex="-1" aria-labelledby="modal_setting" aria-hidden="true">
105
+ <div class="modal-dialog">
106
+ <div class="modal-content">
107
+ <div class="modal-header">
108
+ <h5 class="modal-title" id="modal_setting_label">Setting</h5>
109
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i> </button>
110
+ </div>
111
+ <div class="modal-body">
112
+ <form id="modal-setting-form" method="post" action="/<%- routeName%>/save_setting">
113
+ <div id="body_content"></div>
114
+ </form>
115
+ </div>
116
+ <div class="modal-footer">
117
+ <button class="btn btn-danger text-white" id="delete_field" type="button"><i class="fa fa-trash"></i> Delete</button>
118
+ <button type="button" class="btn btn-secondary" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
119
+ <button type="button" id="modal-setting-save" class="btn btn-primary"><i class="fa fa-paper-plane"></i> Save</button>
120
+ </div>
121
+ </div>
122
+ </div>
123
+ </div>
124
+
125
+
126
+
127
+ <div class="modal fade" id="modal_tab" tabindex="-1" aria-labelledby="modal_setting" aria-hidden="true">
128
+ <div class="modal-dialog">
129
+ <div class="modal-content">
130
+ <div class="modal-header">
131
+ <h5 class="modal-title" id="modal_setting_label">Tab</h5>
132
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i> </button>
133
+ </div>
134
+ <div class="modal-body">
135
+ <form>
136
+ <input type="text" id="edittab" class="form-control">
137
+ </form>
138
+ </div>
139
+ <div class="modal-footer">
140
+ <button type="button" class="btn btn-secondary" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
141
+ <button type="button" id="modal-tab-save" class="btn btn-primary"><i class="fa fa-paper-plane"></i> Save</button>
142
+ </div>
143
+ </div>
144
+ </div>
145
+ </div>
146
+
147
+
148
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ace.js"></script>
149
+ <script>
150
+ var editor_hardcode_grid = ace.edit("hardcode_grid");
151
+ editor_hardcode_grid.getSession().setMode("ace/mode/javascript");
152
+ var editor_router = ace.edit("router");
153
+ editor_router.getSession().setMode("ace/mode/javascript");
154
+
155
+ var editor_index_ejs = ace.edit("index_ejs");
156
+ editor_index_ejs.getSession().setMode("ace/mode/ejs");
157
+ //editor_index_ejs.setValue(datas.index_ejs);
158
+
159
+ var editor_indexcss_ejs = ace.edit("indexcss_ejs");
160
+ editor_indexcss_ejs.getSession().setMode("ace/mode/ejs");
161
+ //editor_indexcss_ejs.setValue(datas.indexcss_ejs);
162
+
163
+ var editor_indexjs_ejs = ace.edit("indexjs_ejs");
164
+ editor_indexjs_ejs.getSession().setMode("ace/mode/ejs");
165
+ //editor_indexjs_ejs.setValue(datas.indexjs_ejs);
166
+
167
+ var editor_form_ejs = ace.edit("form_ejs");
168
+ editor_form_ejs.getSession().setMode("ace/mode/ejs");
169
+ //editor_form_ejs.setValue(datas.form_ejs);
170
+
171
+ var editor_create_ejs = ace.edit("create_ejs");
172
+ editor_create_ejs.getSession().setMode("ace/mode/ejs");
173
+ //editor_create_ejs.setValue(datas.create_ejs);
174
+
175
+ var editor_createjs_ejs = ace.edit("createjs_ejs");
176
+ editor_createjs_ejs.getSession().setMode("ace/mode/ejs");
177
+ //editor_createjs_ejs.setValue(datas.createjs_ejs);
178
+
179
+ var editor_update_ejs = ace.edit("update_ejs");
180
+ editor_update_ejs.getSession().setMode("ace/mode/ejs");
181
+ //editor_update_ejs.setValue(datas.update_ejs);
182
+
183
+ var editor_updatejs_ejs = ace.edit("updatejs_ejs");
184
+ editor_updatejs_ejs.getSession().setMode("ace/mode/ejs");
185
+ //editor_updatejs_ejs.setValue(datas.updatejs_ejs);
186
+
187
+ var editor_import_ejs = ace.edit("import_ejs");
188
+ editor_import_ejs.getSession().setMode("ace/mode/ejs");
189
+ //editor_import_ejs.setValue(datas.import_ejs);
190
+
191
+ var editor_importjs_ejs = ace.edit("importjs_ejs");
192
+ editor_importjs_ejs.getSession().setMode("ace/mode/ejs");
193
+ //editor_importjs_ejs.setValue(datas.importjs_ejs);
194
+
195
+ var editor_view_ejs = ace.edit("view_ejs");
196
+ editor_view_ejs.getSession().setMode("ace/mode/ejs");
197
+ //editor_view_ejs.setValue(datas.view_ejs);
198
+
199
+ </script>
200
+
201
+ <script>
202
+ var loadForm = function(){
203
+ ajaxPost("/<%- routeName%>/load-form",{
204
+ table : $("#table").val()
205
+ }, function (html) {
206
+ var obj = html.data;
207
+ editor_index_ejs.setValue(obj.index_ejs);
208
+ editor_indexcss_ejs.setValue(obj.indexcss_ejs);
209
+ editor_indexjs_ejs.setValue(obj.indexjs_ejs);
210
+ editor_form_ejs.setValue(obj.form_ejs);
211
+ editor_create_ejs.setValue(obj.create_ejs);
212
+ editor_createjs_ejs.setValue(obj.createjs_ejs);
213
+ editor_update_ejs.setValue(obj.update_ejs);
214
+ editor_updatejs_ejs.setValue(obj.updatejs_ejs);
215
+ editor_import_ejs.setValue(obj.import_ejs);
216
+ editor_importjs_ejs.setValue(obj.importjs_ejs);
217
+ editor_view_ejs.setValue(obj.view_ejs);
218
+ });
219
+ }
220
+
221
+
222
+ function toName(str, separator) {
223
+ if(str && str.length) {
224
+ separator = separator || "_";
225
+ str = str.trim();
226
+ return str.replace(/\s+/g, separator).toLowerCase();
227
+ }
228
+ }
229
+
230
+ function click_setting(elem) {
231
+ var name = elem.data("name"),
232
+ label = elem.data("label"),
233
+ table = $("#table").val(),
234
+ caption = elem.data("type");
235
+ $("#modal_setting_label").html(`Setting ${label} <span class="badge bg-primary text-dark">${caption}</span>`);
236
+ $("#body_content").html("Loading...");
237
+ $("body").find("#delete_field").attr("data-name", name);
238
+
239
+ ajaxPost("/<%- routeName%>/setting_field",{
240
+ name : name,
241
+ table : table
242
+ }, function (html) {
243
+ $("#body_content").html(html);
244
+ if($("#relation_table").length) {
245
+ dropdownRelations("relation_table", "relation_name", "relation_concat",$("#relation_table").data("value"),$("#relation_name").data("value"), $("#relation_concat").data("value"));
246
+ }
247
+ if($("#typeahead_table").length) {
248
+ dropdownRelations("typeahead_table", "typeahead_name", "typeahead_concat",$("#typeahead_table").data("value"),$("#typeahead_name").data("value"), $("#relation_concat").data("value"));
249
+ }
250
+ if($("#table_table").length) {
251
+ dropdownRelations("table_table", "relation_name","",$("#table_table").data("value"));
252
+ }
253
+ if($("#multi_line_editor_table").length) {
254
+ dropdownRelations("multi_line_editor_table", "relation_name","",$("#multi_line_editor_table").data("value"));
255
+ $(".editor").froalaEditor({height: 400});
256
+ var samp = $("<samp></samp>");
257
+ var text = `<p><h3>List Fields :</h3></p>`;
258
+ text += getFieldsFromTable($("#multi_line_editor_table").val(), name);
259
+ $("#multi_line_editor_table").closest("div").append(samp);
260
+ samp.html(text);
261
+
262
+ $("#multi_line_editor_table").on("change", function () {
263
+ var text = `<p><h3>List Fields :</h3></p>`;
264
+ text += getFieldsFromTable($(this).val(), name);
265
+ samp.html(text);
266
+ });
267
+ }
268
+ if($("#dropdown_multi_table").length) {
269
+ dropdownRelations("dropdown_multi_table", "dropdown_multi_name","",$("#dropdown_multi_table").data("value"),$("#dropdown_multi_name").data("value"));
270
+ }
271
+ });
272
+
273
+ $("#modal_setting").modal("show");
274
+ }
275
+
276
+ function dropdownRelations(elemTable, elemField, elemConcat, value, fieldValue, concatValue) {
277
+ elemTable = elemTable || "relationtable";
278
+ elemField = elemField || "relationfield";
279
+ elemConcat = elemConcat || "relationconcat";
280
+
281
+ value = value || "";
282
+ fieldValue = fieldValue || "";
283
+ concatValue = concatValue || "id";
284
+
285
+ let html = '';
286
+ var elementTable = $("body").find("#"+elemTable);
287
+ if(!elementTable.length){
288
+ return;
289
+ }
290
+
291
+ let tableHtml = '';
292
+ for(var key in ZFIELDS) {
293
+ var selected = value == key ? " selected " : "";
294
+ tableHtml += `<option value="${key}" ${selected}>${ZFIELDS[key].name}</option>`;
295
+ }
296
+ elementTable.html(tableHtml);
297
+ var currentRelation = elementTable.val();
298
+ var elementField = $("body").find("#"+elemField);
299
+ //var concatValue = "id";
300
+ for(var key in ZFIELDS[currentRelation].labels) {
301
+ var selected = fieldValue == key ? " selected " : "";
302
+ //concatValue = fieldValue == key ? key : "id";
303
+ html += `<option value="${key}" ${selected}>${ZFIELDS[currentRelation].labels[key]}</option>`;
304
+ }
305
+ elementField.html(html);
306
+ $("#"+elemConcat).val(concatValue);
307
+ }
308
+
309
+
310
+ function getFieldsFromTable(table, name) {
311
+ var html =`<ul class="list-group">`;
312
+ var nots = ["id","company_id","created_by","created_at","updated_by","updated_at"];
313
+ for(var key in ZFIELDS[table].labels) {
314
+ if(nots.indexOf(key) <= -1) {
315
+ html += `<li class="list-group-item"><button onclick="copyToClipboard('[[[${key}_${name}]]]');" type="button" class="btn-copy-code btn btn-outline-grey btn-sm px-2 waves-effect" title="Copy Text" ><i class="fa fa-copy mr-1"></i> ${key} </button> <input type="text" name="${name}[fields][${key}_${name}]" value="${ZFIELDS[table].labels[key]}"></li>`;
316
+ }
317
+ }
318
+
319
+ html += `</ul>`
320
+ return html;
321
+ }
322
+
323
+
324
+ $(function () {
325
+ var counter = $(".divtabs").length || 1;
326
+ function selectTable(table) {
327
+ if (!table) return false;
328
+ ajaxPost('/<%- routeName%>/fields',{table: table}, function (json) {
329
+ $("#divfields").show();
330
+ $(".card-script").show();
331
+ $("#results").hide();
332
+ $("#contentfields").html(json.html);
333
+ $("#tabs").html(json.tabview);
334
+ $("#divtablist").html(json.tabBox)
335
+ counter = json.count;
336
+ $("ol.mydragable").sortable({
337
+ group: 'mydragable',
338
+ isValidTarget: function ($item, container) {
339
+ return true;
340
+ },
341
+ /* onDrag: function ($item, position, _super, event) {
342
+ console.log(event.target.nodeName);
343
+ console.log(event.target);
344
+ if($(event.target).is("i")) {
345
+ var elem = $(event.target);
346
+ console.log(elem.attr("class"))
347
+ if(elem.hasClass("modal_setting")) {
348
+ alert("ada");
349
+ }
350
+
351
+ _super($item, container);
352
+ return false;
353
+ }
354
+ },*/
355
+ onMousedown: function ($item, _super, event) {
356
+ /* console.log(event.target.nodeName);
357
+ console.log(event.target);*/
358
+ if($(event.target).is("i")) {
359
+ var elem = $(event.target);
360
+ //console.log(elem.attr("class"))
361
+ if(elem.hasClass("modal_setting")) {
362
+ click_setting(elem);
363
+ }
364
+ return false;
365
+ }
366
+
367
+ return true;
368
+ },
369
+ onDrop: function ($item, container, _super) {
370
+ var getidname = $item.parents().attr('id') || "";
371
+ var iname = $item.find('input[type=text]').attr('data-name');
372
+ var containertype = $item.parents().data('name');
373
+ var newname = getidname ? iname + "___" + getidname : iname;
374
+ var leftright = $item.find('input[type=hidden]').attr('name');
375
+ $item.find('input[type=text]').attr('name', newname);
376
+ $item.find('input[type=hidden]').attr('name', containertype);
377
+
378
+ _super($item, container);
379
+ }
380
+ });
381
+ loadForm();
382
+ });
383
+ }
384
+
385
+ $("#table").on("change", function () {
386
+ location.href = '/<%- routeName%>?table=' + $(this).val();
387
+ loadForm();
388
+ });
389
+
390
+ $("#generate").on("click", function () {
391
+ ajaxPost('/<%- routeName%>', {
392
+ table: $("#table").val(),
393
+ route: $("#route").val()
394
+ }, function (data) {
395
+ if (data.status == 0) {
396
+ $("#results").hide();
397
+ toastr.error(data.message, data.title);
398
+ } else {
399
+ $("#results").show();
400
+ toastr.success(data.title, data.message);
401
+ $("#resultsbody").html(data.datas);
402
+ }
403
+ $("#divfields").hide();
404
+ });
405
+ });
406
+
407
+ $("#add").on("click", function () {
408
+ var tabname = $("#tabname");
409
+ var tabsvalue = $("#tabsvalue");
410
+ if (tabname.val() == "") {
411
+ alert("tab name is empty!");
412
+ return false;
413
+ }
414
+ $("#tabs").append("<div class='divtabs'> " + counter + ". " + tabname.val() + " <input type='hidden' name='tabs[]' value='" + tabname.val() + "' /> <button type='button' onclick='$(this).parent().remove();' class='trashtab'><i class='fas fa-trash'></i> </button></div><br>");
415
+ tabname.val("");
416
+ counter++;
417
+ });
418
+
419
+ $("#savetab").on("click", function () {
420
+ ajaxPost('/<%- routeName%>/tabs',$("#formgenerator").serializeArray(), function (data) {
421
+ if (data.status == 1)
422
+ location.href = ''
423
+ else
424
+ alert(data.title);
425
+ });
426
+ });
427
+
428
+ function saveFields() {
429
+ ajaxPost("/<%- routeName%>/save_fields",{
430
+ details: $("#formfields").serializeArray(),
431
+ table: $("#table").val(),
432
+ hardcode_grid : editor_hardcode_grid.getValue(),
433
+ router : editor_router.getValue(),
434
+ index_ejs : editor_index_ejs.getValue(),
435
+ indexcss_ejs : editor_indexcss_ejs.getValue(),
436
+ indexjs_ejs : editor_indexjs_ejs.getValue(),
437
+ form_ejs : editor_form_ejs.getValue(),
438
+ create_ejs : editor_create_ejs.getValue(),
439
+ createjs_ejs : editor_createjs_ejs.getValue(),
440
+ update_ejs : editor_update_ejs.getValue(),
441
+ updatejs_ejs : editor_updatejs_ejs.getValue(),
442
+ import_ejs : editor_import_ejs.getValue(),
443
+ importjs_ejs : editor_importjs_ejs.getValue(),
444
+ view_ejs : editor_view_ejs.getValue(),
445
+
446
+ }, function (data) {
447
+ if (data.status == 0) {
448
+ toastr.error(data.message, data.title);
449
+ } else {
450
+ toastr.success(data.title, data.message);
451
+ }
452
+ });
453
+ }
454
+
455
+ $("#save").on("click", function () {
456
+ saveFields();
457
+ });
458
+
459
+ $("#save_script").on("click", function () {
460
+ saveFields();
461
+ });
462
+
463
+ $(".btn-reset").on("click", function () {
464
+ if(window.confirm("Reset ?")) {
465
+ ajaxPost("/<%- routeName%>/reset", {
466
+ table: $("#table").val(),
467
+ }, function (data) {
468
+ if (data.status == 0) {
469
+ toastr.error(data.message, data.title);
470
+ } else {
471
+ toastr.success(data.title, data.message);
472
+ location.href = '';
473
+ }
474
+ });
475
+ }
476
+ })
477
+
478
+ selectTable($("#table").val());
479
+
480
+ function changeUrl(title, url) {
481
+ var origin = window.location.origin;
482
+ if (typeof (history.pushState) != "undefined") {
483
+ var obj = {Title: title, Url: origin + '/<%- routeName%>?table=' + url};
484
+ window.history.pushState(obj, obj.Title, obj.Url);
485
+ } else {
486
+ alert("Browser does not support HTML5.");
487
+ }
488
+ }
489
+
490
+ $("#modal-table").on("change", function () {
491
+ $("#modal-route").val(toName($(this).val()));
492
+ });
493
+
494
+ $('#modal-table').on('input', function() {
495
+ $("#modal-route").val(toName($(this).val()));
496
+ });
497
+
498
+ $("#delete_module").on("click", function () {
499
+ if(window.confirm("sure to delete ?")) {
500
+ ajaxDelete("/<%- routeName%>/delete-table",{table:$("#table").val()}, function (data) {
501
+ toastrForm(data);
502
+ if(data.status == 1) {
503
+ location.href = '/<%- routeName%>';
504
+ }
505
+ });
506
+ }
507
+ });
508
+
509
+ $("#modal-save").on("click", function () {
510
+ var reservedWord = ['order','left','right','by'];
511
+ var moduleName = $("#modal-table").val();
512
+ moduleName = moduleName.toLowerCase();
513
+ var arrModules = reservedWord.filter((item) => item == moduleName);
514
+ if(arrModules.length) {
515
+ toastrForm({
516
+ status : 0,
517
+ title: "Error Module Name reserved",
518
+ message: "Please change your module name"
519
+ })
520
+ return false;
521
+ }
522
+ ajaxPost("/<%- routeName%>",{name:$("#modal-table").val(),route:$("#modal-route").val()}, function (data) {
523
+ toastrForm(data);
524
+ if(data.status == 1) {
525
+ location.href = '/<%- routeName%>?table=' + $("#modal-route").val();
526
+ }
527
+ });
528
+ });
529
+
530
+ $("#modal-add").on("click", function () {
531
+ //$(this).hide();
532
+ ajaxPost("/<%- routeName%>/add_field",{
533
+ table:$("#table").val(),
534
+ name:$("#modal_name").val(),
535
+ type:$("#modal_type").val(),
536
+ position:$("#modal_position").val(),
537
+ relationtable:$("#relationtable").val(),
538
+ relationfield:$("#relationfield").val(),
539
+ relationconcat:$("#relationconcat").val(),
540
+ relationfields:$("#relationfields").val(),
541
+
542
+ }, function (data) {
543
+ $(this).show();
544
+ toastrForm(data);
545
+ if(data.status == 1) {
546
+ var type = $("#modal_type").val();
547
+ location.href = '';
548
+ }
549
+ });
550
+ });
551
+
552
+
553
+ $("body").on("click",".modal_setting", function () {
554
+ click_setting($(this));
555
+ });
556
+
557
+ $("body").on("click",".select-plus", function () {
558
+ var name = $(this).data("name");
559
+ var item = $(this).data("item");
560
+ var num = $(".group-select").length || 0;
561
+ html = `<div class="input-group group-select"><div class="input-group-prepend">
562
+ <input type="number" class="form-control cvalue" placeholder="Value" name="${name}[${item}][${num}][value]">
563
+ <input type="text" class="form-control clabel" placeholder="Label" name="${name}[${item}][${num}][label]">
564
+ <span class="input-group-text trash-select" data-name="${name}" data-item="${item}"><i class="fa fa-trash text-danger"></i> </span>
565
+ </div></div>`;
566
+
567
+ $(".divselect").append(html);
568
+ });
569
+
570
+ $("body").on("click",".trash-select", function () {
571
+ var name = $(this).data("name");
572
+ var item = $(this).data("item");
573
+ $(this).closest(".group-select").remove();
574
+ $(".group-select").each(function (index, value) {
575
+ $(this).closest("div").find("input.cvalue").attr("name",name+"["+item+"]["+index+"][value]");
576
+ $(this).closest("div").find("input.clabel").attr("name",name+"["+item+"]["+index+"][label]");
577
+ });
578
+ });
579
+
580
+ $("body").on("click","#modal-setting-save", function () {
581
+ var datas = $('#modal-setting-form').serializeArray();
582
+ ajaxPost("/<%- routeName%>/save_setting?table="+$("#table").val(), datas, function (data) {
583
+ toastrForm(data);
584
+ if(data.status == 1) {
585
+ $('#modal_setting').modal('hide');
586
+ }
587
+ });
588
+ });
589
+
590
+ $("body").on("change","#modal_type", function () {
591
+ if($(this).val() == "relation") {
592
+ $(".divrelation").show();
593
+ $(".divrelationfield").show();
594
+ $(".divconcat").show();
595
+ $(".divfield").hide();
596
+ dropdownRelations();
597
+ } else if($(this).val() == "table"){
598
+ $(".divrelation").show();
599
+ $(".divrelationfield").hide();
600
+ $(".divconcat").hide();
601
+ $(".divfield").hide();
602
+ dropdownRelations();
603
+ } else if($(this).val() == "multi_line_editor"){
604
+ $(".divrelation").show();
605
+ $(".divrelationfield").hide();
606
+ $(".divconcat").hide();
607
+ $(".divfield").hide();
608
+ dropdownRelations();
609
+ } else if($(this).val() == "dropdown_multi"){
610
+ $(".divrelation").show();
611
+ $(".divrelationfield").show();
612
+ $(".divconcat").show();
613
+ $(".divfield").hide();
614
+ dropdownRelations();
615
+ } else if($(this).val() == "dropdown_chain"){
616
+ $(".divrelation").show();
617
+ $(".divrelationfield").show();
618
+ $(".divconcat").show();
619
+ $(".divfield").show();
620
+ dropdownRelations();
621
+ } else if($(this).val() == "typeahead"){
622
+ $(".divrelation").show();
623
+ $(".divrelationfield").show();
624
+ $(".divconcat").show();
625
+ $(".divfield").hide();
626
+ dropdownRelations();
627
+ } else {
628
+ $(".divrelation").hide();
629
+ $(".divconcat").hide();
630
+ $(".divfield").hide();
631
+ }
632
+ });
633
+
634
+ $("body").on("click","#delete_field", function () {
635
+ var name = $(this).data("name");
636
+ if(window.confirm("sure delete ? ")) {
637
+ ajaxDelete("/<%- routeName%>/delete_field", {name:name, table:$("#table").val()}, function (data) {
638
+ toastrForm(data);
639
+ if(data.status ==1){
640
+ location.href = '';
641
+ }
642
+ });
643
+ }
644
+ });
645
+
646
+ $("body").on("click",".edittab", function () {
647
+ $("body").find("#edittab").val($(this).data("name"));
648
+ $("body").find("#modal-tab-save").attr("data-id", $(this).data("id"));
649
+ });
650
+
651
+ $("body").on("click", "#modal-tab-save", function () {
652
+ ajaxPost("/<%- routeName%>/tab_rename",{
653
+ id:$(this).data("id"),
654
+ name:$("body").find("#edittab").val(),
655
+ table : $("#table").val()
656
+ } , function (data) {
657
+ toastrForm(data);
658
+ if(data.status == 1) {
659
+ location.href = '';
660
+ }
661
+ });
662
+ });
663
+
664
+ $("body").on("change","#relationtable", function () {
665
+ dropdownRelations("relationtable","relationfield","relationconcat",$(this).val(),"", "CONCAT("+$("body").find("#relationfield").val()+")");
666
+ });
667
+
668
+ $("body").on("change","#relation_table", function () {
669
+ dropdownRelations("relation_table","relation_name","relation_concat",$(this).val(),"", "CONCAT("+$("body").find("#relation_field").val()+")");
670
+ });
671
+
672
+ $("body").on("change","#relation_name", function () {
673
+ $("#relation_concat").val("CONCAT("+$(this).val()+")");
674
+ });
675
+
676
+ $("body").on("change","#typeahead_table", function () {
677
+ dropdownRelations("typeahead_table","typeahead_name","typeahead_concat",$(this).val());
678
+ });
679
+ $("body").on("change","#dropdown_multi_table", function () {
680
+ dropdownRelations("dropdown_multi_table","dropdown_multi_name","dropdown_multi_concat",$(this).val());
681
+ });
682
+ $("body").on("change","#multi_line_editor_table", function () {
683
+ dropdownRelations("multi_line_editor_table","multi_line_editor_name","multi_line_editor_concat",$(this).val());
684
+ });
685
+ $("body").on("change","#dropdown_chain_table", function () {
686
+ dropdownRelations("dropdown_chain_table","dropdown_chain_name","dropdown_chain_concat",$(this).val());
687
+ });
688
+
689
+ $("body").on("change","#relationfield", function(){
690
+ $("#relationconcat").val("CONCAT("+$(this).val()+")");
691
+ });
692
+ $("body").on("change","#relationname", function(){
693
+ $("#relation_concat").val("CONCAT("+$(this).val()+")");
694
+ });
695
+ $("body").on("change","#typeahead_name", function(){
696
+ $("#typeahead_concat").val("CONCAT("+$(this).val()+")");
697
+ });
698
+ $("body").on("change","#dropdown_multi_name", function(){
699
+ $("#dropdown_multi_concat").val("CONCAT("+$(this).val()+")");
700
+ });
701
+ $("body").on("change","#dropdown_chain_name", function(){
702
+ $("#dropdown_chain_concat").val("CONCAT("+$(this).val()+")");
703
+ });
704
+ });
705
+ </script>