zet-lib 1.3.43 → 1.4.1

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.
@@ -0,0 +1,851 @@
1
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.15.0/ace.js"></script>
2
+ <script>
3
+ var others = {}
4
+ var query = '';
5
+ var container_time = ''
6
+ //end container
7
+ var editor_router = ace.edit('router')
8
+ editor_router.getSession().setMode('ace/mode/javascript')
9
+
10
+ var editor_index_ejs = ace.edit('index_ejs')
11
+ editor_index_ejs.getSession().setMode('ace/mode/ejs')
12
+ //editor_index_ejs.setValue(datas.index_ejs);
13
+
14
+ var editor_indexcss_ejs = ace.edit('indexcss_ejs')
15
+ editor_indexcss_ejs.getSession().setMode('ace/mode/ejs')
16
+ //editor_indexcss_ejs.setValue(datas.indexcss_ejs);
17
+
18
+ var editor_indexjs_ejs = ace.edit('indexjs_ejs')
19
+ editor_indexjs_ejs.getSession().setMode('ace/mode/ejs')
20
+ //editor_indexjs_ejs.setValue(datas.indexjs_ejs);
21
+
22
+ var editor_view_ejs = ace.edit('view_ejs')
23
+ editor_view_ejs.getSession().setMode('ace/mode/ejs')
24
+ //editor_view_ejs.setValue(datas.view_ejs);
25
+ </script>
26
+
27
+ <script>
28
+ var datas = {}
29
+ var loadForm = function () {
30
+ ajaxPost(
31
+ '/<%- routeName%>/load-form',
32
+ {
33
+ table: $('#table').val(),
34
+ },
35
+ function (html) {
36
+ var obj = html.data
37
+ editor_router.setValue(obj.router)
38
+ editor_index_ejs.setValue(obj.index_ejs)
39
+ editor_indexcss_ejs.setValue(obj.indexcss_ejs)
40
+ editor_indexjs_ejs.setValue(obj.indexjs_ejs)
41
+ editor_view_ejs.setValue(obj.view_ejs)
42
+ queries = obj.queries
43
+ $("#query").val(queries.sql)
44
+ const fields = queries.fields || []
45
+ setTimeout(function () {
46
+ fields.map((item) => {
47
+ $('input[name="joins_checks___'+item+'"]').prop("checked", true)
48
+ })
49
+ },2000)
50
+ }
51
+ )
52
+ }
53
+
54
+ function toName(str, separator) {
55
+ if (str && str.length) {
56
+ separator = separator || '_'
57
+ str = str.trim()
58
+ return str.replace(/\s+/g, separator).toLowerCase()
59
+ }
60
+ }
61
+
62
+ function click_setting(elem) {
63
+ var name = elem.data('name'),
64
+ label = elem.data('label'),
65
+ table = $('#table').val(),
66
+ caption = elem.data('type')
67
+ $('#modal_setting_label').html(`Setting ${label} <span class="badge bg-primary text-dark">${caption}</span>`)
68
+ $('#body_content').html('Loading...')
69
+ $('body').find('#delete_field').attr('data-name', name)
70
+ ajaxPost(
71
+ '/<%- routeName%>/setting_field',
72
+ {
73
+ name: name,
74
+ table: table,
75
+ },
76
+ function (html) {
77
+ $('#body_content').html(html)
78
+ let val = 'id'
79
+ if ($('#relation_table').length) {
80
+ dropdownRelations('relation_table', 'relation_name', 'relation_concat', $('#relation_table').data('value'), $('#relation_name').data('value'), $('#relation_concat').data('value'))
81
+ }
82
+ if ($('#dragdrop_table').length) {
83
+ dropdownRelations('dragdrop_table', 'dragdrop_name', 'dragdrop_concat', $('#dragdrop_table').data('value'), $('#dragdrop_name').data('value'), $('#dragdrop_concat').data('value'))
84
+ }
85
+ if ($('#typeahead_table').length) {
86
+ val = $('body').find('#typeahead_concat').attr('value')
87
+ dropdownRelations('typeahead_table', 'typeahead_name', 'typeahead_concat', $('#typeahead_table').data('value'), $('#typeahead_name').data('value'), val)
88
+ }
89
+ if ($('#table_table').length) {
90
+ dropdownRelations('table_table', 'relation_name', '', $('#table_table').data('value'))
91
+ }
92
+ if ($('#multi_line_editor_table').length) {
93
+ dropdownRelations('multi_line_editor_table', 'relation_name', '', $('#multi_line_editor_table').data('value'))
94
+ $('.editor').froalaEditor({ height: 400 })
95
+ var samp = $('<samp></samp>')
96
+ var text = `<p><h3>List Fields :</h3></p>`
97
+ text += getFieldsFromTable($('#multi_line_editor_table').val(), name)
98
+ $('#multi_line_editor_table').closest('div').append(samp)
99
+ samp.html(text)
100
+
101
+ $('#multi_line_editor_table').on('change', function () {
102
+ var text = `<p><h3>List Fields :</h3></p>`
103
+ text += getFieldsFromTable($(this).val(), name)
104
+ samp.html(text)
105
+ })
106
+ }
107
+ if ($('#dropdown_multi_table').length) {
108
+ dropdownRelations('dropdown_multi_table', 'dropdown_multi_name', '', $('#dropdown_multi_table').data('value'), $('#dropdown_multi_name').data('value'))
109
+ }
110
+ }
111
+ )
112
+ $('#modal_setting').modal('show')
113
+ }
114
+
115
+ function dropdownRelations(elemTable, elemField, elemConcat, value, fieldValue, concatValue) {
116
+ elemTable = elemTable || 'relationtable'
117
+ elemField = elemField || 'relationfield'
118
+ elemConcat = elemConcat || 'relationconcat'
119
+ value = value || ''
120
+ fieldValue = fieldValue || ''
121
+ concatValue = concatValue || 'id'
122
+
123
+ let html = ''
124
+ let elementTable = $('body').find('#' + elemTable)
125
+ if (!elementTable.length) {
126
+ return
127
+ }
128
+ let tableHtml = ''
129
+ for (let key in ZFIELDS) {
130
+ let selected = value == key ? ' selected ' : ''
131
+ tableHtml += `<option value="${key}" ${selected}>${ZFIELDS[key].name}</option>`
132
+ }
133
+ elementTable.html(tableHtml)
134
+ let currentRelation = elementTable.val()
135
+ let elementField = $('body').find('#' + elemField)
136
+ //var concatValue = "id";
137
+ for (let key in ZFIELDS[currentRelation].labels) {
138
+ let selected = fieldValue == key ? ' selected ' : ''
139
+ //concatValue = fieldValue == key ? key : "id";
140
+ html += `<option value="${key}" ${selected}>${ZFIELDS[currentRelation].labels[key]}</option>`
141
+ }
142
+ elementField.html(html)
143
+ $('#' + elemConcat).val(concatValue)
144
+ $('#' + elemConcat).attr('value', concatValue)
145
+ }
146
+
147
+ function getFieldsFromTable(table, name) {
148
+ let html = `<ul class="list-group">`
149
+ let nots = ['id', 'company_id', 'created_by', 'created_at', 'updated_by', 'updated_at']
150
+ for (let key in ZFIELDS[table].labels) {
151
+ if (nots.indexOf(key) <= -1) {
152
+ 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>`
153
+ }
154
+ }
155
+ html += `</ul>`
156
+ return html
157
+ }
158
+
159
+ //on checked
160
+ function checked_join($this){
161
+ let nameel = $($this).attr("name");
162
+ let name = nameel.replace("joins_checks___","").split(".")
163
+ if($($this).is(":checked")){
164
+ toastr.success(`${name[1]} successfully add`)
165
+ let value = $("#joins___"+name[0]+"___"+name[1]).val()
166
+ var li = `<li id="li${name[0]}_wtf_${name[1]}">
167
+ <div class="input-group">
168
+ <div class="input-group-prepend">
169
+ <span class="input-group-text modal_setting" data-type="Text" data-name="${name[0]}_wtf_${name[1]}" data-label="${value}"><i class="fa fa-cog text-info modal_setting" data-type="Text" data-label="${value}"></i> </span>
170
+ <span class="input-group-text can-copy" data-name="${name[0]}_wtf_${name[1]}" title="click to copy"><i class="fa fa-copy"></i></span>
171
+ <span class="input-group-text">${name[0]}_wtf_${name[1]}</span>
172
+ <input type="text" class="form-control" data-name="${name[0]}_wtf_${name[1]}" name="${name[0]}_wtf_${name[1]}" value="${value}">
173
+ <input type="hidden" name="LEFT" value="${name[0]}_wtf_${name[1]}">
174
+ </div>
175
+ </div><br></li>`
176
+ $(".mydragable").eq(0).append(li)
177
+ setQuery(nameel,1)
178
+ } else {
179
+ toastr.error(`${name[1]} successfully remove`)
180
+ $("#li"+name[0]+"_wtf_"+name[1]).remove();
181
+ setQuery(nameel,-1)
182
+ }
183
+ }
184
+
185
+ $(function () {
186
+ let counter = $('.divtabs').length || 1
187
+ function selectTable(table) {
188
+ if (!table) return false
189
+ ajaxPost('/<%- routeName%>/fields', { table , queries}, function (json) {
190
+ $('#divfields').show()
191
+ $('.card-script').show()
192
+ $('#results').hide()
193
+ $('#contentfields').html(json.html)
194
+ $('#tabs').html(json.tabview)
195
+ $('#divtablist').html(json.tabBox)
196
+ counter = json.count
197
+ $('ol.mydragable').sortable({
198
+ group: 'mydragable',
199
+ nested: false,
200
+ //pullPlaceholder: false,
201
+ isValidTarget: function ($item, container) {
202
+ if ($item.hasClass('add-container')) {
203
+ return false
204
+ } else if ($item.hasClass('icon-trash')) {
205
+ return false
206
+ } else {
207
+ return true
208
+ }
209
+ },
210
+ onMousedown: function ($item, _super, event) {
211
+ if ($(event.target).is('i')) {
212
+ let elem = $(event.target)
213
+ //console.log(elem.attr("class"))
214
+ if (elem.hasClass('modal_setting')) {
215
+ click_setting(elem)
216
+ }
217
+ return false
218
+ }
219
+ return true
220
+ },
221
+ onDrop: function ($item, container, _super) {
222
+ //class container-nav
223
+ let time = new Date().getTime()
224
+ let $itemclass = $item.attr('class')
225
+ let getidname = $item.parents().attr('id') || ''
226
+ let iname = $item.find('input[type=text]').attr('data-name')
227
+ let containertype = $item.parents().data('name')
228
+ let newname = getidname ? iname + '___' + getidname : iname
229
+ let leftright = $item.find('input[type=hidden]').attr('name')
230
+ //container-box
231
+ if ($itemclass.indexOf('container-nav') > -1) {
232
+ let parentId = $item.parents().parents()
233
+ $item.find('input[type=text]').attr('name', newname)
234
+ $item.find('input[type=hidden]').attr('name', containertype)
235
+ } else {
236
+ $item.find('input[type=text]').attr('name', newname)
237
+ $item.find('input[type=hidden]').attr('name', containertype)
238
+ }
239
+ _super($item, container)
240
+ },
241
+ })
242
+
243
+ //tab draggable
244
+ $('ul.sortable-list').sortable()
245
+ //end tab draggable
246
+ loadForm()
247
+ })
248
+ }
249
+
250
+ function nextDragged() {
251
+ setTimeout(() => {
252
+ ajaxPost(
253
+ '/<%- routeName%>/tab-draggable',
254
+ {
255
+ tabs: $('.sortable-list')
256
+ .find('input[name="tabs[]"]')
257
+ .each((index, elm) => $(elm).val()),
258
+ },
259
+ () => location.href
260
+ )
261
+ }, 1000)
262
+ }
263
+
264
+ function buildOneRow(columncount) {
265
+ let html = ``
266
+ let time = new Date().getTime()
267
+ let col_md = `col-md-${12 / columncount}`
268
+ let container_time = `container_${time}`
269
+ html += `<li class="container-nav"><i class="fa fa-arrows icon-float"></i><div class="row mt-1 mb-1">`
270
+ for (let i = 1; i <= columncount; i++) {
271
+ html += `<div class="${col_md}" style="background-color: rgba(0,0,0,.03)" ><ol class="divboxlittle container-box"><li><i data-container="${container_time}" data-id="${i}" data-split="${columncount}" data-column="ONE_COLUMN" class="fa fa-plus-circle fa-2x add-container text-success"></i></li></ol> </div>`
272
+ }
273
+ html += `</div></li>`
274
+ return html
275
+ }
276
+
277
+ $('#modal-container-save').on('click', function () {
278
+ let columncount = $('#column-count').val()
279
+ let html = buildOneRow(columncount)
280
+ let length = $('ol').length
281
+ $('ol')
282
+ .eq(length - 1)
283
+ .append(html)
284
+ $('.btn-modal-container-close').click()
285
+ })
286
+
287
+ $('body').on('click', '.add-container', function () {
288
+ parentContainer = $(this).closest('ol')
289
+ let options = ''
290
+ let ols = $('ol.mydragable > li')
291
+ let myObj = {}
292
+ ols.each(function () {
293
+ let span = $(this).find('div').find('div').find('span')
294
+ let name = span.data('name')
295
+ if (name) {
296
+ myObj[name] = $(this)
297
+ }
298
+ })
299
+ for (let key in myObj) {
300
+ options += `<option value="${key}">${key}</option>`
301
+ }
302
+ fieldsObjectInput = myObj
303
+ $('#container-select').html(options)
304
+ $('#modal_container_into').modal('show')
305
+ })
306
+
307
+ $('#moveintocontainer').on('click', function () {
308
+ let myval = $('#container-select').val()
309
+ if (myval) {
310
+ let myelement = fieldsObjectInput[myval]
311
+ myelement.find('input[type=hidden]').attr('name', 'ONE_COLUMN')
312
+ myelement.appendTo(parentContainer)
313
+ }
314
+ $('.btncontainer-close').click()
315
+ setTimeout(function () {
316
+ saveContainer()
317
+ }, 2000)
318
+ })
319
+
320
+ $('#table').on('change', function () {
321
+ location.href = '/<%- routeName%>?view=' + $(this).val()
322
+ loadForm()
323
+ })
324
+
325
+ $('#generate').on('click', function () {
326
+ ajaxPost(
327
+ '/<%- routeName%>',
328
+ {
329
+ table: $('#table').val(),
330
+ route: $('#route').val(),
331
+ },
332
+ function (data) {
333
+ if (data.status == 0) {
334
+ $('#results').hide()
335
+ toastr.error(data.message, data.title)
336
+ } else {
337
+ $('#results').show()
338
+ toastr.success(data.title, data.message)
339
+ $('#resultsbody').html(data.datas)
340
+ }
341
+ $('#divfields').hide()
342
+ }
343
+ )
344
+ })
345
+
346
+ $('#add').on('click', function () {
347
+ var tabname = $('#tabname')
348
+ var tabsvalue = $('#tabsvalue')
349
+ if (tabname.val() == '') {
350
+ alert('tab name is empty!')
351
+ return false
352
+ }
353
+ $('#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>")
354
+ tabname.val('')
355
+ $('#savetab').click()
356
+ counter++
357
+ })
358
+
359
+ $('#savetab').on('click', function () {
360
+ ajaxPost('/<%- routeName%>/tabs', $('#formgenerator').serializeArray(), function (data) {
361
+ if (data.status == 1) location.href = ''
362
+ else alert(data.title)
363
+ })
364
+ })
365
+
366
+ function saveFields() {
367
+ ajaxPost(
368
+ '/<%- routeName%>/save_and_generate',
369
+ {
370
+ details: $('#formfields').serializeArray(),
371
+ table: $('#route').val(),
372
+ router: editor_router.getValue(),
373
+ index_ejs: editor_index_ejs.getValue(),
374
+ indexcss_ejs: editor_indexcss_ejs.getValue(),
375
+ indexjs_ejs: editor_indexjs_ejs.getValue(),
376
+ view_ejs: editor_view_ejs.getValue(),
377
+ queries:queries,
378
+ },
379
+ function (data) {
380
+ if (data.status == 0) {
381
+ toastr.error(data.message, data.title)
382
+ } else {
383
+ toastr.success(data.title, data.message)
384
+ }
385
+ }
386
+ )
387
+ }
388
+ $('#save').on('click', function () {
389
+ saveFields()
390
+ })
391
+ $('#save_script').on('click', function () {
392
+ saveFields()
393
+ })
394
+ $('.btn-reset').on('click', function () {
395
+ if (window.confirm('Reset to factory settings ?')) {
396
+ ajaxPost(
397
+ '/<%- routeName%>/reset',
398
+ {
399
+ table: $('#table').val(),
400
+ },
401
+ function (data) {
402
+ if (data.status == 0) {
403
+ toastr.error(data.message, data.title)
404
+ } else {
405
+ toastr.success(data.title, data.message)
406
+ location.href = ''
407
+ }
408
+ }
409
+ )
410
+ }
411
+ })
412
+
413
+ selectTable($('#table').val())
414
+ function changeUrl(title, url) {
415
+ var origin = window.location.origin
416
+ if (typeof history.pushState != 'undefined') {
417
+ var obj = { Title: title, Url: origin + '/<%- routeName%>?table=' + url }
418
+ window.history.pushState(obj, obj.Title, obj.Url)
419
+ } else {
420
+ alert('Browser does not support HTML5.')
421
+ }
422
+ }
423
+
424
+ $('#modal-table').on('change', function () {
425
+ $('#modal-route').val(toName($(this).val()))
426
+ })
427
+ $('#modal-table').on('input', function () {
428
+ $('#modal-route').val(toName($(this).val()))
429
+ })
430
+ $('#delete_module').on('click', function () {
431
+ if (window.confirm('sure to delete ?')) {
432
+ ajaxDelete('/<%- routeName%>/delete-table', { table: $('#table').val() }, function (data) {
433
+ toastrForm(data)
434
+ if (data.status == 1) {
435
+ location.href = '/<%- routeName%>'
436
+ }
437
+ })
438
+ }
439
+ })
440
+
441
+ $('#modal-save').on('click', function () {
442
+ let reservedWord = ['order', 'left', 'right', 'by', 'zrole', 'role', 'zuser', 'zcompany_access']
443
+ let moduleName = $('#modal-table').val()
444
+ moduleName = moduleName.toLowerCase()
445
+ let arrModules = reservedWord.filter((item) => item == moduleName)
446
+ if (arrModules.length) {
447
+ toastrForm({
448
+ status: 0,
449
+ title: 'Error Module Name reserved',
450
+ message: 'Please change your module name',
451
+ })
452
+ return false
453
+ }
454
+ ajaxPost('/<%- routeName%>/addview', { name: $('#modal-table').val(), route: $('#modal-route').val() }, function (data) {
455
+ toastrForm(data)
456
+ if (data.status == 1) {
457
+ location.href = '/<%- routeName%>?view=' + $('#modal-route').val()
458
+ }
459
+ })
460
+ })
461
+
462
+ $('#modal-add').on('click', function () {
463
+ let others = fixContainer()
464
+ ajaxPost(
465
+ '/<%- routeName%>/add_field',
466
+ {
467
+ table: $('#table').val(),
468
+ name: $('#modal_name').val(),
469
+ type: $('#modal_type').val(),
470
+ position: $('#modal_position').val(),
471
+ relationtable: $('#relationtable').val(),
472
+ relationfield: $('#relationfield').val(),
473
+ relationconcat: $('#relationconcat').val(),
474
+ relationfields: $('#relationfields').val(),
475
+ others: JSON.stringify(others),
476
+ },
477
+ function (data) {
478
+ $(this).show()
479
+ toastrForm(data)
480
+ if (data.status == 1) {
481
+ var type = $('#modal_type').val()
482
+ location.href = ''
483
+ }
484
+ }
485
+ )
486
+ })
487
+
488
+ $('body').on('click', '.modal_setting', function () {
489
+ click_setting($(this))
490
+ })
491
+
492
+ $('body').on('click', '.select-plus', function () {
493
+ let name = $(this).data('name')
494
+ let item = $(this).data('item')
495
+ let num = $('.group-select').length || 0
496
+ html = `<div class="input-group group-select"><div class="input-group-prepend">
497
+ <input type="number" class="form-control cvalue" placeholder="Value" name="${name}[${item}][${num}][value]">
498
+ <input type="text" class="form-control clabel" placeholder="Label" name="${name}[${item}][${num}][label]">
499
+ <span class="input-group-text trash-select" data-name="${name}" data-item="${item}"><i class="fa fa-trash text-danger"></i> </span>
500
+ </div></div>`
501
+ $('.divselect').append(html)
502
+ })
503
+
504
+ $('body').on('click', '.trash-select', function () {
505
+ let name = $(this).data('name')
506
+ let item = $(this).data('item')
507
+ $(this).closest('.group-select').remove()
508
+ $('.group-select').each(function (index, value) {
509
+ $(this)
510
+ .closest('div')
511
+ .find('input.cvalue')
512
+ .attr('name', name + '[' + item + '][' + index + '][value]')
513
+ $(this)
514
+ .closest('div')
515
+ .find('input.clabel')
516
+ .attr('name', name + '[' + item + '][' + index + '][label]')
517
+ })
518
+ })
519
+
520
+ $('body').on('click', '#modal-setting-save', function () {
521
+ let datas = $('#modal-setting-form').serializeArray()
522
+ ajaxPost('/<%- routeName%>/save_setting?table=' + $('#table').val(), datas, function (data) {
523
+ toastrForm(data)
524
+ if (data.status == 1) {
525
+ $('#modal_setting').modal('hide')
526
+ }
527
+ })
528
+ })
529
+
530
+ $('body').on('change', '#modal_type', function () {
531
+ if ($(this).val() == 'relation') {
532
+ $('.divrelation').show()
533
+ $('.divrelationfield').show()
534
+ $('.divconcat').show()
535
+ $('.divfield').hide()
536
+ dropdownRelations()
537
+ } else if ($(this).val() == 'table') {
538
+ $('.divrelation').show()
539
+ $('.divrelationfield').hide()
540
+ $('.divconcat').hide()
541
+ $('.divfield').hide()
542
+ dropdownRelations()
543
+ } else if ($(this).val() == 'multi_line_editor') {
544
+ $('.divrelation').show()
545
+ $('.divrelationfield').hide()
546
+ $('.divconcat').hide()
547
+ $('.divfield').hide()
548
+ dropdownRelations()
549
+ } else if ($(this).val() == 'dropdown_multi') {
550
+ $('.divrelation').show()
551
+ $('.divrelationfield').show()
552
+ $('.divconcat').show()
553
+ $('.divfield').hide()
554
+ dropdownRelations()
555
+ } else if ($(this).val() == 'dropdown_chain') {
556
+ $('.divrelation').show()
557
+ $('.divrelationfield').show()
558
+ $('.divconcat').show()
559
+ $('.divfield').show()
560
+ dropdownRelations()
561
+ } else if ($(this).val() == 'typeahead') {
562
+ $('.divrelation').show()
563
+ $('.divrelationfield').show()
564
+ $('.divconcat').show()
565
+ $('.divfield').hide()
566
+ dropdownRelations()
567
+ } else if ($(this).val() == 'dragdrop') {
568
+ $('.divrelation').show()
569
+ $('.divrelationfield').show()
570
+ $('.divconcat').show()
571
+ $('.divfield').hide()
572
+ dropdownRelations()
573
+ } else {
574
+ $('.divrelation').hide()
575
+ $('.divconcat').hide()
576
+ $('.divfield').hide()
577
+ }
578
+ })
579
+
580
+ $('body').on('click', '#delete_field', function () {
581
+ let name = $(this).data('name')
582
+ if (window.confirm('sure delete ? ')) {
583
+ $("#li"+name).remove();
584
+ $("input[name='joins_checks___"+name.replace("_wtf_",".")+"']").prop("checked", false);
585
+ $(".close").click();
586
+ }
587
+ })
588
+
589
+ $('body').on('click', '#modal-tab-save', function () {
590
+ ajaxPost(
591
+ '/<%- routeName%>/tab_rename',
592
+ {
593
+ id: $(this).data('id'),
594
+ name: $('body').find('#edittab').val(),
595
+ table: $('#table').val(),
596
+ },
597
+ function (data) {
598
+ toastrForm(data)
599
+ if (data.status == 1) {
600
+ location.href = ''
601
+ }
602
+ }
603
+ )
604
+ })
605
+
606
+ $('body').on('change', '#relationtable', function () {
607
+ dropdownRelations('relationtable', 'relationfield', 'relationconcat', $(this).val(), '', 'CONCAT(' + $('body').find('#relationfield').val() + ')')
608
+ })
609
+
610
+ $('body').on('change', '#relation_table', function () {
611
+ dropdownRelations('relation_table', 'relation_name', 'relation_concat', $(this).val(), '', 'CONCAT(' + $('body').find('#relation_field').val() + ')')
612
+ })
613
+
614
+ $(document).on('change', '#dragdrop_table', function () {
615
+ dropdownRelations('dragdrop_table', 'dragdrop_name', 'dragdrop_concat', $(this).val(), '', 'CONCAT(' + $('body').find('#relation_field').val() + ')')
616
+ })
617
+
618
+ $('body').on('change', '#relation_name', function () {
619
+ $('#relation_concat').val('CONCAT(' + $(this).val() + ')')
620
+ })
621
+
622
+ $('body').on('change', '#dragdrop_name', function () {
623
+ $('#dragdrop_concat').val('CONCAT(' + $(this).val() + ')')
624
+ })
625
+
626
+ $('body').on('change', '#typeahead_table', function () {
627
+ dropdownRelations('typeahead_table', 'typeahead_name', 'typeahead_concat', $(this).val())
628
+ })
629
+ $('body').on('change', '#dropdown_multi_table', function () {
630
+ dropdownRelations('dropdown_multi_table', 'dropdown_multi_name', 'dropdown_multi_concat', $(this).val())
631
+ })
632
+ $('body').on('change', '#multi_line_editor_table', function () {
633
+ dropdownRelations('multi_line_editor_table', 'multi_line_editor_name', 'multi_line_editor_concat', $(this).val())
634
+ })
635
+ $('body').on('change', '#dropdown_chain_table', function () {
636
+ dropdownRelations('dropdown_chain_table', 'dropdown_chain_name', 'dropdown_chain_concat', $(this).val())
637
+ })
638
+
639
+ $('body').on('change', '#relationfield', function () {
640
+ $('#relationconcat').val('CONCAT(' + $(this).val() + ')')
641
+ })
642
+ $('body').on('change', '#relationname', function () {
643
+ $('#relation_concat').val('CONCAT(' + $(this).val() + ')')
644
+ })
645
+ $('body').on('change', '#typeahead_name', function () {
646
+ $('#typeahead_concat').val('CONCAT(' + $(this).val() + ')')
647
+ })
648
+ $('body').on('change', '#dropdown_multi_name', function () {
649
+ $('#dropdown_multi_concat').val('CONCAT(' + $(this).val() + ')')
650
+ })
651
+ $('body').on('change', '#dropdown_chain_name', function () {
652
+ $('#dropdown_chain_concat').val('CONCAT(' + $(this).val() + ')')
653
+ })
654
+
655
+ $('.export-file').on('click', function (e) {
656
+ e.preventDefault()
657
+ let table = $('#route').val()
658
+ ajaxPost(
659
+ '/<%- routeName%>/export',
660
+ {
661
+ table: table,
662
+ },
663
+ function (data) {
664
+ toastrForm(data)
665
+ if (data.status == 1) {
666
+ location.href = `/zdownload/zgenerator/${table}`
667
+ }
668
+ }
669
+ )
670
+ })
671
+
672
+ $('#submit-import').on('click', function () {
673
+ $('#modal-form-file').submit()
674
+ })
675
+ submitForm('modal-form-file', '', '', function (data) {
676
+ toastrForm(data)
677
+ if (data.status == 1) {
678
+ setTimeout(function () {
679
+ location.href = `?table=${data.table}`
680
+ }, 1000)
681
+ }
682
+ })
683
+ })
684
+
685
+ function fixContainer() {
686
+ let length = $('.container-nav').length
687
+ let obj = {}
688
+ let getId = ''
689
+ if (length) {
690
+ $ols = $('ol.mydragable')
691
+ $ols.each(function () {
692
+ getId = $ols.attr('id') ? $ols.attr('id') : ''
693
+ let name = $(this).data('name')
694
+ if (!Object.prototype.hasOwnProperty.call(obj, name)) {
695
+ obj[name] = []
696
+ }
697
+ let lis = $(this).children('li')
698
+ lis.each(function () {
699
+ let className = $(this).attr('class') ? $(this).attr('class') : ''
700
+ //console.log(`className ${className}`)
701
+ if (className == 'container-nav') {
702
+ let parent_container = $(this).parent('ol.mydragable')
703
+ let parent_container_id = parent_container.attr('id') || ''
704
+ let parent_container_name = parent_container.data('name') || ''
705
+ let child_container = $(this)
706
+ child_container.attr('data-name', parent_container.data('name')).attr('id', parent_container.attr('id'))
707
+ let arr = []
708
+ let $containerboxs = $(this).find('.container-box')
709
+ let $containerboxsLength = $containerboxs.length
710
+ for (let i = 0; i < $containerboxsLength; i++) {
711
+ //console.log(`$containerboxsLength ${i}`)
712
+ let item = []
713
+ let $lis = $containerboxs.eq(i).find('li')
714
+ let $lisLength = $lis.length
715
+ for (let x = 1; x < $lisLength; x++) {
716
+ let $name = ''
717
+ if (parent_container_id) {
718
+ let getname = $lis.eq(x).find('input[type=hidden]').val()
719
+ $name = `${getname}___${parent_container_id}`
720
+ //fixed in tab
721
+ $lis.eq(x).find('input[type=text]').attr('name', $name)
722
+ $lis.eq(x).find('input[type=hidden]').attr('name', name)
723
+ } else {
724
+ $name = $lis.eq(x).find('input[type=text]').attr('data-name')
725
+ $lis.eq(x).find('input[type=text]').attr('name', $name)
726
+ $lis.eq(x).find('input[type=hidden]').attr('name', name)
727
+ }
728
+ item.push($name)
729
+ }
730
+ arr.push(item)
731
+ }
732
+ obj[name].push(arr)
733
+ } else {
734
+ obj[name].push($(this).find('input[type=text]').attr('name'))
735
+ }
736
+ })
737
+ })
738
+ }
739
+ others = obj
740
+ return obj
741
+ }
742
+ </script>
743
+
744
+ <script>
745
+ $(function () {
746
+ $('.layout21').on('click', function (e) {
747
+ e.preventDefault()
748
+ if (sorting == '[2,1]') {
749
+ } else {
750
+ let table = $('#table').val()
751
+ ajaxPost(
752
+ '/<%- routeName%>/sorting',
753
+ {
754
+ table: table,
755
+ sorting: '[2,1]',
756
+ },
757
+ function (dt) {
758
+ location.href = ''
759
+ }
760
+ )
761
+ }
762
+ })
763
+
764
+ $('.layout12').on('click', function (e) {
765
+ e.preventDefault()
766
+ if (sorting == '[1,2]') {
767
+ } else {
768
+ let table = $('#table').val()
769
+ ajaxPost(
770
+ '/<%- routeName%>/sorting',
771
+ {
772
+ table: table,
773
+ sorting: '[1,2]',
774
+ },
775
+ function (dt) {
776
+ location.href = ''
777
+ }
778
+ )
779
+ }
780
+ })
781
+
782
+ $("#modal-joins-save").on("click", function (e) {
783
+ let table_join = $('#select_module_joins').val();
784
+ let table = $('#table').val()
785
+ if (table == table_join) {
786
+ toastr.error("Your selected module is equal with current module");
787
+ return;
788
+ }
789
+ ajaxPost(
790
+ '/<%- routeName%>/joins',
791
+ {
792
+ table_join: table_join,
793
+ table: table,
794
+ },
795
+ function (dt) {
796
+ toastrForm(dt);
797
+ if (dt.status == 1) {
798
+ $("#joinlist").html(dt.html);
799
+ $("#closejoin").click();
800
+ }
801
+ }
802
+ )
803
+ })
804
+ loadJoins();
805
+ })
806
+
807
+ function loadJoins() {
808
+ ajaxPost(
809
+ '/<%- routeName%>/load-joins',
810
+ {
811
+ table: $('#table').val(),
812
+ },
813
+ function (dt) {
814
+ if (dt.status == 1) {
815
+ $("#joinlist").html(dt.html);
816
+ }
817
+ }
818
+ )
819
+ }
820
+
821
+ function removeJoins(table_join) {
822
+ if (window.confirm('Sure to delete ?')) {
823
+ ajaxPost(
824
+ '/<%- routeName %>/remove-joins',
825
+ {
826
+ table: $('#table').val(),
827
+ table_join: table_join
828
+ },
829
+ function (dt) {
830
+ location.reload();
831
+ }
832
+ )
833
+ }
834
+ }
835
+
836
+ function setQuery(name,type){
837
+ ajaxPost(
838
+ '/<%- routeName %>/set-query',
839
+ {
840
+ name:name,
841
+ type:type,
842
+ queries:queries
843
+ },
844
+ function (dt) {
845
+ query = dt.sql;
846
+ queries = dt;
847
+ $("#query").val(dt.sql)
848
+ }
849
+ )
850
+ }
851
+ </script>