zet-lib 1.3.39 → 1.3.41

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