Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 13335 | Rev 16817 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
7397 eleazar 1
<?php
2
$acl = $this->viewModel()->getRoot()->getVariable('acl');
3
$currentUser = $this->currentUserHelper();
4
 
5
$roleName = $currentUser->getUserTypeId();
6
 
7
$routeAdd = $this->url('organizational-climate/form/add');
8
$routeDatatable = $this->url('organizational-climate/form');
9
$routeDashboard = $this->url('dashboard');
10
 
11
$allowAdd = $acl->isAllowed($roleName, 'organizational-climate/form/add') ? 1 : 0;
12
$allowEdit = $acl->isAllowed($roleName, 'organizational-climate/form/edit') ? 1 : 0;
13
$allowDelete = $acl->isAllowed($roleName, 'organizational-climate/form/delete') ? 1 : 0;
14
 
15
 
16
$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));
17
 
18
 
19
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
20
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
21
 
22
 
23
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
24
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
25
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
26
 
27
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
28
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
29
 
30
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
31
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
32
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
33
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
34
 
35
 
36
$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.min.css'));
37
$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css'));
38
 
39
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/select2.full.min.js'));
40
 
41
$this->inlineScript()->appendFile($this->basePath('plugins/moment/moment-with-locales.min.js'));
42
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css'));
43
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'));
44
 
45
 
46
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
47
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
48
 
49
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
50
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
51
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-input-number/input-number-format.jquery.js'));
52
 
53
// bootbox Alert //
54
$this->inlineScript()->appendFile($this->basePath('plugins/bootbox/bootbox.min.js'));
55
 
56
// JsRender //
57
$this->inlineScript()->appendFile($this->basePath('plugins/jsrender/jsrender.min.js'));
58
 
59
// Page Styles
60
$this->headLink()->appendStylesheet($this->basePath('css/pages/self-evaluation.css'));
61
 
62
$status_active = \LeadersLinked\Model\SurveyForm::STATUS_ACTIVE;
63
$status_inactive = \LeadersLinked\Model\SurveyForm::STATUS_INACTIVE;
64
 
65
$this->inlineScript()->captureStart();
66
echo <<<JS
67
    const classFormGenerator = function() {
68
    this.id = 0,
69
        this.table = '',
70
        this.name = '',
71
        this.text = '',
72
        this.status = 'a',
73
        this.sections = [],
74
        this.clear = function() {
75
            this.sections = [];
76
            this.render();
77
        },
78
        /**
79
         * Render array sections
80
         */
81
        this.renderSection = function(slug_section) {
82
            var s = '';
83
            for (i = 0; i < this.sections.length; i++) {
84
                if (slug_section != this.sections[i].slug_section) {
85
                    continue;
86
                }
87
                for (j = 0; j < this.sections[i].questions.length; j++) {
88
                    this.sections[i].questions[j].position = j;
89
                    if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {
90
                        this.sections[i].questions[j].options.sort(function(a, b) {
91
                            if (a.position > b.position) {
92
                                return 1;
93
                            }
94
                            if (a.position < b.position) {
95
                                return -1;
96
                            }
97
                            return 0;
98
                        });
99
                        for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
100
                            this.sections[i].questions[j].options[k].position = j;
101
                        }
102
                    }
103
                }
104
            }
105
            $('[data-toggle="tooltip"]').tooltip();
106
        },
107
        this.render = function() {
108
            this.sections.sort(function(a, b) {
109
                if (a.position > b.position) {
110
                    return 1;
111
                }
112
                if (a.position < b.position) {
113
                    return -1;
114
                }
115
                return 0;
116
            });
117
            var s = '';
118
            for (i = 0; i < this.sections.length; i++) {
119
                this.sections[i].position = i;
120
                this.sections[i].questions.sort(function(a, b) {
121
                    if (a.position > b.position) {
122
                        return 1;
123
                    }
124
                    if (a.position < b.position) {
125
                        return -1;
126
                    }
127
                    return 0;
128
                });
129
                for (j = 0; j < this.sections[i].questions.length; j++) {
130
                    this.sections[i].questions[j].position = j;
131
                    if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {
132
                        this.sections[i].questions[j].options.sort(function(a, b) {
133
                            if (a.position > b.position) {
134
                                return 1;
135
                            }
136
                            if (a.position < b.position) {
137
                                return -1;
138
                            }
139
                            return 0;
140
                        });
141
                        for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
142
                            this.sections[i].questions[j].options[k].position = j;
143
                        }
144
                    }
145
                }
146
            }
147
            $('[data-toggle="tooltip"]').tooltip();
148
        },
149
        /**
150
         * Add element to section array
151
         */
152
        this.addSection = function(name, text) {
153
            var d = new Date();
154
            var slug = 'section' + d.getTime();
155
            var position = 0;
156
            $.each(this.sections, function(index, section) {
157
                if (position < section.position) {
158
                    position = section.position;
159
                }
160
            });
161
            position++;
162
            var section = {
163
                'slug_section': slug,
164
                'name': name,
165
                'text': text,
166
                'position': position,
167
                'questions': [],
168
                'status': 0
169
            }
170
            this.sections.push(section);
171
        },
172
         /**
173
         * Edit element to section array
174
         */
175
        this.editSection = function(slug, name, text) {
176
            var renderTable = false;
177
            for (i = 0; i < this.sections.length; i++) {
178
                if (slug == this.sections[i].slug_section) {
179
                    this.sections[i].name = name;
180
                    this.sections[i].text = text;
181
                    renderTable = true;
182
                    break;
183
                }
184
            }
185
            if (renderTable) {
186
                this.renderSection(slug);
187
            }
188
        },
189
         /**
190
         * Remove element to section array
191
         */
192
        this.deleteSection = function(slug) {
193
            var renderTable = false;
194
            for (i = 0; i < this.sections.length; i++) {
195
                if (slug == this.sections[i].slug_section) {
196
                    this.sections.splice(i, 1);
197
                    renderTable = true;
198
                    break;
199
                }
200
            }
201
            if (renderTable) {
202
                $('#panel' + slug).remove();
203
            }
204
        },
205
         /**
206
         * Add element to question array
207
         */
208
        this.addQuestion = function(slug_section, text, type, maxlength, multiline, range) {
209
            var d = new Date();
210
            var slug_question = 'question' + d.getTime();
211
            var position = 0;
212
            var renderTable = false;
213
            for (i = 0; i < this.sections.length; i++) {
214
                if (slug_section == this.sections[i].slug_section) {
215
                    $.each(this.sections[i].questions, function(index, question) {
216
                        if (position < question.position) {
217
                            position = question.position;
218
                        }
219
                    });
220
                    position++;
221
                    var question = {
222
                        'slug_section': slug_section,
223
                        'slug_question': slug_question,
224
                        'text': text,
225
                        'type': type,
226
                        'position': position,
227
                        'maxlength': maxlength,
228
                        'multiline': multiline,
229
                        'range': range,
230
                        'options': [],
231
                        'answer': type=='multiple' ? [] : ''
232
                    }
233
                    this.sections[i].questions.push(question);
234
                    renderTable = true;
235
                    break;
236
                }
237
            }
238
            if (renderTable) {
239
                this.renderSection(slug_section);
240
            }
241
        },
242
         /**
243
         * Add element to question array
244
         */
245
        this.editQuestion = function(slug_section, slug_question, text, type, maxlength, multiline, range) {
246
            var renderTable = false;
247
            for (i = 0; i < this.sections.length; i++) {
248
                if (slug_section == this.sections[i].slug_section) {
249
                    for (j = 0; j < this.sections[i].questions.length; j++) {
250
                        if (slug_question == this.sections[i].questions[j].slug_question) {
251
                            this.sections[i].questions[j].text = text,
252
                                this.sections[i].questions[j].type = type;
253
                            if (type == 'open') {
254
                                this.sections[i].questions[j].maxlength = maxlength;
255
                                this.sections[i].questions[j].multiline = multiline;
256
                                this.sections[i].questions[j].options = [];
257
                            } else {
258
                                this.sections[i].questions[j].maxlength = 0;
259
                                this.sections[i].questions[j].multiline = 0;
260
                            }
261
                            if (type == 'rating-range') {
262
                                this.sections[i].questions[j].range = range;
263
                            } else {
264
                                this.sections[i].questions[j].range = 0;
265
                            }
266
 
267
                            if(type=='multiple'){
268
                                this.sections[i].questions[j].answer = [];
269
                            }else{
270
                                this.sections[i].questions[j].answer = '';
271
                            }
272
 
273
                            renderTable = true;
274
                            break;
275
                        }
276
                    }
277
                }
278
                if (renderTable) {
279
                    break;
280
                }
281
            }
282
            if (renderTable) {
283
                this.renderSection(slug_section);
284
            }
285
        },
286
        /**
287
         * Remove element to question array
288
         */
289
        this.deleteQuestion = function(slug_section, slug_question) {
290
            var renderTable = false;
291
            for (i = 0; i < this.sections.length; i++) {
292
                if (slug_section == this.sections[i].slug_section) {
293
                    for (j = 0; j < this.sections[i].questions.length; j++) {
294
                        if (slug_question == this.sections[i].questions[j].slug_question) {
295
                            this.sections[i].questions.splice(j, 1);
296
                            renderTable = true;
297
                            break;
298
                        }
299
                    }
300
                }
301
                if (renderTable) {
302
                    break;
303
                }
304
            }
305
            if (renderTable) {
306
                this.renderSection(slug_section);
307
            }
308
        },
309
        /**
310
         * Add element to option array
311
         */
312
        this.addOption = function(slug_section, slug_question, text) {
313
            var d = new Date();
314
            var slug_option = 'option' + d.getTime();
315
            var position = 0;
316
            var renderTable = false;
317
            for (i = 0; i < this.sections.length; i++) {
318
                if (slug_section == this.sections[i].slug_section) {
319
                    for (j = 0; j < this.sections[i].questions.length; j++) {
320
                        if (slug_question == this.sections[i].questions[j].slug_question) {
321
                            $.each(this.sections[i].questions[j].options, function(index, option) {
322
                                if (position < option.position) {
323
                                    position = option.position;
324
                                }
325
                            });
326
                            position++;
327
                            var option = {
328
                                'slug_section': slug_section,
329
                                'slug_question': slug_question,
330
                                'slug_option': slug_option,
331
                                'text': text,
332
                                'checked': false
333
                            }
334
                            this.sections[i].questions[j].options.push(option);
335
                            renderTable = true;
336
                            break;
337
                        }
338
                        if (renderTable) {
339
                            break;
340
                        }
341
                    }
342
                }
343
            }
344
            if (renderTable) {
345
                this.renderSection(slug_section);
346
            }
347
        },
348
        /**
349
         * Edit element to option array
350
         */
351
        this.editOption = function(slug_section, slug_question, option_slug, text) {
352
            var renderTable = false;
353
            for (i = 0; i < this.sections.length; i++) {
354
                if (slug_section == this.sections[i].slug_section) {
355
                    for (j = 0; j < this.sections[i].questions.length; j++) {
356
                        if (slug_question == this.sections[i].questions[j].slug_question) {
357
                            for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
358
                                if (option_slug == this.sections[i].questions[j].options[k].slug_option) {
359
                                    this.sections[i].questions[j].options[k].text = text;
360
                                    renderTable = true;
361
                                    break;
362
                                }
363
                            }
364
                        }
365
                        if (renderTable) {
366
                            break;
367
                        }
368
                    }
369
                }
370
                if (renderTable) {
371
                    break;
372
                }
373
            }
374
            if (renderTable) {
375
                this.renderSection(slug_section);
376
            }
377
        },
378
        /**
379
         * Remove element to option array
380
         */
381
        this.deleteOption = function(slug_section, slug_question, option_slug) {
382
            var renderTable = false;
383
            for (i = 0; i < this.sections.length; i++) {
384
                if (slug_section == this.sections[i].slug_section) {
385
                    for (j = 0; j < this.sections[i].questions.length; j++) {
386
                        if (slug_question == this.sections[i].questions[j].slug_question) {
387
                            for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
388
                                if (option_slug == this.sections[i].questions[j].options[k].slug_option) {
389
                                    this.sections[i].questions[j].options.splice(k, 1);
390
                                    renderTable = true;
391
                                    break;
392
                                }
393
                            }
394
                        }
395
                        if (renderTable) {
396
                            break;
397
                        }
398
                    }
399
                }
400
                if (renderTable) {
401
                    break;
402
                }
403
            }
404
            if (renderTable) {
405
                this.renderSection(slug_section);
406
            }
407
        }
408
}
409
 
410
function htmlEntities(str) {
411
    return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
412
}
413
jQuery(document).ready(function($) {
414
    var objFormGenerator = new classFormGenerator();
415
    objFormGenerator.render();
16805 efrain 416
 
417
 
7397 eleazar 418
    var allowEdit = $allowEdit;
419
    var allowDelete = $allowDelete;
420
    /**
421
     * Get rows and set data table
422
     */
423
    var tableForm = $('#gridTable').dataTable({
424
        'processing': true,
425
        'serverSide': true,
426
        'searching': true,
427
        'order': [
428
            [0, 'asc']
429
        ],
430
        'ordering': true,
431
        'ordenable': true,
432
        'responsive': true,
433
        'select': false,
434
        'paging': true,
435
        'pagingType': 'simple_numbers',
436
        'ajax': {
437
            'url': '$routeDatatable',
438
            'type': 'get',
439
            'beforeSend': function(request) {
440
                NProgress.start();
441
            },
442
            'dataFilter': function(response) {
443
                var response = jQuery.parseJSON(response);
444
                var json = {};
445
                json.recordsTotal = 0;
446
                json.recordsFiltered = 0;
447
                json.data = [];
448
                if (response.success) {
449
                    json.recordsTotal = response.data.total;
450
                    json.recordsFiltered = response.data.total;
451
                    json.data = response.data.items;
452
                } else {
453
                    $.fn.showError(response.data)
454
                }
455
                return JSON.stringify(json);
456
            }
457
        },
458
        'language': {
459
            'sProcessing': 'LABEL_DATATABLE_SPROCESSING',
460
            'sLengthMenu': 'LABEL_DATATABLE_SLENGTHMENU',
461
            'sZeroRecords': 'LABEL_DATATABLE_SZERORECORDS',
462
            'sEmptyTable': 'LABEL_DATATABLE_SEMPTYTABLE',
463
            'sInfo': 'LABEL_DATATABLE_SINFO',
464
            'sInfoEmpty': 'LABEL_DATATABLE_SINFOEMPTY',
465
            'sInfoFiltered': 'LABEL_DATATABLE_SINFOFILTERED',
466
            'sInfoPostFix': '',
467
            'sSearch': 'LABEL_DATATABLE_SSEARCH',
468
            'sUrl': '',
469
            'sInfoThousands': ',',
470
            'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
471
            'oPaginate': {
472
                'sFirst': 'LABEL_DATATABLE_SFIRST',
473
                'sLast': 'LABEL_DATATABLE_SLAST',
474
                'sNext': 'LABEL_DATATABLE_SNEXT',
475
                'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
476
            },
477
            'oAria': {
478
                'sSortAscending': ': LABEL_DATATABLE_SSORTASCENDING',
479
                'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
480
            },
481
        },
482
        'drawCallback': function(settings) {
483
            NProgress.done();
484
            $('button.btn-delete').confirmation({
485
                rootSelector: 'button.btn-delete',
486
                title: 'LABEL_ARE_YOU_SURE',
487
                singleton: true,
488
                btnOkLabel: 'LABEL_YES',
489
                btnCancelLabel: 'LABEL_NO',
490
                onConfirm: function(value) {
491
                    action = $(this).data('href');
492
                    NProgress.start();
493
                    $.ajax({
494
                        'dataType': 'json',
495
                        'accept': 'application/json',
496
                        'method': 'post',
497
                        'url': action,
498
                    }).done(function(response) {
499
                        if (response['success']) {
500
                            $.fn.showSuccess(response['data']);
501
                            tableForm.fnDraw();
502
                        } else {
503
                            $.fn.showError(response['data']);
504
                        }
505
                    }).fail(function(jqXHR, textStatus, errorThrown) {
506
                        $.fn.showError(textStatus);
507
                    }).always(function() {
508
                        NProgress.done();
509
                    });
510
                },
511
            });
512
        },
513
        'aoColumns': [{
514
                'mDataProp': 'name'
515
            },
516
            {
517
                'mDataProp': 'status'
518
            },
519
            {
520
                'mDataProp': 'actions'
521
            },
522
        ],
523
        'columnDefs': [{
524
                'targets': 0,
525
                'className': 'text-vertical-middle',
526
            },
527
            {
11220 eleazar 528
                'targets': -2,
7397 eleazar 529
                'orderable': false,
530
                'className': 'text-center',
531
                'render': function(data, type, row) {
11218 eleazar 532
                    checked = data == 'A' ? ' checked="checked" ' : '';
7397 eleazar 533
                    return '<div class="checkbox checkbox-success">' +
534
                        '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
535
                        '<label ></label></div>';
536
                }
537
            },
538
            {
539
                'targets': -1,
540
                'orderable': false,
541
                'render': function(data, type, row) {
542
                    s = '';
543
                    if (allowEdit) {
544
                        s = s + '<button class="btn btn-primary btn-edit-form" data-href="' + data['link_edit'] + '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pencil"></i> LABEL_EDIT </button>&nbsp;';
545
                    }
546
                    if (allowDelete) {
547
                        s = s + '<button class="btn btn-danger btn-delete" data-href="' + data['link_delete'] + '" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-trash"></i> LABEL_DELETE </button>&nbsp;';
548
                    }
549
                    return s;
550
                }
551
            }
552
        ],
553
    });
554
    /**
555
     * Clicked on edit form
556
     */
557
    $('body').on('click', 'button.btn-edit-form', function(e) {
558
        e.preventDefault();
559
        form_id = $(this).data('id')
560
        var action = $(this).data('href');
561
        $.ajax({
562
            'dataType': 'json',
563
            'accept': 'application/json',
564
            'method': 'get',
565
            'url': action,
566
        }).done(function(response) {
567
            if (response['success']) {
568
                validatorForm.resetForm();
569
                $('#form-main').attr('action', action);
570
                $('#form-main #form-id').val(response['data']['id']),
571
                $('#form-main #form-continue').val('0');
572
                $('#form-main #name').val(response['data']['name']),
573
 
574
                /*----------Set Ckeditor ------------*/
575
                CKEDITOR.instances.description.setData(response['data']['description']);
576
                CKEDITOR.instances.text.setData(response['data']['text']);
577
 
578
                $('#form-main #status').val(response['data']['status']);
579
 
580
                /*-------------Render Sections -------*/
581
 
582
                objFormGenerator.clear();
583
                objFormGenerator.sections = response['data']['content'] || [];
584
                objFormGenerator.render();
585
                renderSectionData(objFormGenerator.sections);
586
 
587
                $('#row-forms').hide();
588
                $('#row-edit').show();
589
                $('#form-main #name').focus();
590
 
591
            } else {
592
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
593
            }
594
        }).fail(function(jqXHR, textStatus, errorThrown) {
595
            $.fn.showError(textStatus);
596
        });
597
    });
598
    $(document).on('click', '[data-type="select_all"]', function() {
599
        if ($('input[name="select_all"]:checked').val() == 'all') {
600
            $('[data-type="select"]').prop('checked', true);
601
            $('[data-action="delete"]').removeClass('hide');
602
        } else {
603
            $('[data-type="select"]').prop('checked', false);
604
            $('[data-action="delete"]').addClass('hide');
605
        }
606
    });
607
 
608
    function getLength() {
609
        return $('[data-type="select"]').length;
610
    }
611
 
612
    function currentSelected() {
613
        var selected = [];
614
        $.each($("input[name='select[]']:checked"), function() {
615
            selected.push($(this).val());
616
        });
617
        return selected;
618
    }
619
    $(document).on('change', "input[name='select[]']", function() {
620
        var c = currentSelected();
621
        var cc = getLength();
622
        if (c.length == cc) {
623
            if ($('[data-action="delete"]').hasClass('hide')) {
624
                $('[data-action="delete"]').removeClass('hide');
625
            }
626
            return true;
627
        } else {
628
            $('input[name="select_all"]').prop('checked', false);
629
        }
630
        if (c.length > 0) {
631
            if ($('[data-action="delete"]').hasClass('hide')) {
632
                $('[data-action="delete"]').removeClass('hide');
633
            }
634
        } else {
635
            if (!$('[data-action="delete"]').hasClass('hide')) {
636
                $('[data-action="delete"]').addClass('hide');
637
            }
638
        }
639
    });
640
    var form3 = $('#form_sample_3');
641
    var error3 = $('.alert-danger', form3);
642
    var success3 = $('.alert-success', form3);
643
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
644
    $("#form-main").on('submit', function() {
645
        for (var instanceName in CKEDITOR.instances) {
646
            CKEDITOR.instances[instanceName].updateElement();
647
        }
648
    })
649
    /**
650
     * Validate rules form
651
     */
652
    var validatorForm = $("#form-main").validate({
653
        ignore: [],
654
        errorClass: 'help-block',
655
        errorElement: 'span',
656
        rules: {
657
            'form-name': {
658
                required: true,
659
                minlength: 2,
660
                maxlength: 50
661
            },
662
            'description':{
663
                updateCkeditor:function() {
664
                    CKEDITOR.instances.description.updateElement();
665
                },
666
            },
667
            'text':{
668
                updateCkeditor:function() {
669
                    CKEDITOR.instances.text.updateElement();
670
                },
671
            },
672
            'forrm-status': {
673
                required: true,
674
            },
675
        },
676
        highlight: function(element) {
677
            $(element).closest('.form-group').addClass('has-error');
678
        },
679
        unhighlight: function(element) {
680
            $(element).closest('.form-group').removeClass('has-error');
681
        },
682
        errorPlacement: function(error, element) {
683
            if (element.attr("data-error-container")) {
684
                error.appendTo(element.attr("data-error-container"));
685
            } else {
686
                error.insertAfter(element);
687
            }
688
        },
689
        invalidHandler: function(form, validator) {
690
            if (!validator.numberOfInvalids())
691
                return;
692
            $('html, body').animate({
693
                scrollTop: $(validator.errorList[0].element).offset().top - 100
694
            }, 1000);
695
        },
696
        submitHandler: function(form) {
697
            var error = false;
698
            if (objFormGenerator.sections.length == 0) {
699
                $.fn.showError('ERROR_SECCTIONS');
700
                return false;
701
            } else {
702
                for (i = 0; i < objFormGenerator.sections.length; i++) {
703
                    if (objFormGenerator.sections[i].questions.length == 0) {
704
                        $.fn.showError('ERROR_QUESTIONS'.replace('%s', objFormGenerator.sections[i].name));
705
                        return false;
706
                    }
707
                    for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
708
                        if (objFormGenerator.sections[i].questions[j].type == 'simple' ||
709
                            objFormGenerator.sections[i].questions[j].type == 'multiple' ||
710
                            objFormGenerator.sections[i].questions[j].type == 'rating-open') {
711
                            var questionNumber = j + 1;
712
                            var numberCorrect = 0;
713
                            if (objFormGenerator.sections[i].questions[j].options.length == 0) {
714
                                $.fn.showError('ERROR_OPTIONS'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
715
                                return false;
716
                            }
717
                            var totalOption = 0;
718
                            var maxOption = 0;
719
                        }
720
                    }
721
                }
722
                var formContinue = parseInt($('#form-main #form-continue').val());
723
                var data = {
724
                    'name': $('#form-main #name').val(),
725
                    'description': $('#form-main #description').val(),
726
                    'text': $('#form-main #text').val(),
727
                    'status': $('#form-main #status').val(),
728
                    'content': JSON.stringify(objFormGenerator.sections)
729
                }
730
                $.ajax({
731
                    'dataType': 'json',
732
                    'method': 'post',
733
                    'url': $('#form-main').attr('action'),
734
                    'data': data,
735
                }).done(function(response) {
736
                    if (response['success']) {
737
                        $.fn.showSuccess(response['data']);
738
                        if (formContinue == 1) {
739
                            $('#form-main').attr('action',response['action_edit']);
740
                            $('#form-main #form-id').val(response['id']);
741
                            $('#form-main #form-continue').val(0);
742
                        } else {
743
                            $('#row-edit').hide();
744
                            $('#row-forms').show();
745
                        /*---------- Reset Form -------- */
746
                        $('#form-main')[0].reset();
747
                        /*--------Reset Ckeditor ----------*/
748
                        CKEDITOR.instances.text.setData('');
749
                        CKEDITOR.instances.description.setData('');
750
                        /*--------Reset Sections ----------*/
751
                        clearSectionData();
752
                        /* ------- Refresh Table -----------*/
753
 
754
                        }
755
                        tableForm.fnDraw();
756
                    } else {
757
                        $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
758
                    }
759
                }).fail(function(jqXHR, textStatus, errorThrown) {
760
                    $.fn.showError(textStatus);
761
                });
762
                return false;
763
            }
764
        }
765
    });
766
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
767
    $("#form-section").on('submit', function() {
768
        for (var instanceName in CKEDITOR.instances) {
769
            CKEDITOR.instances[instanceName].updateElement();
770
        }
771
    })
772
    /**
773
     * Validate rules form section
774
     */
775
    var validatorFormSection = $("#form-section").validate({
776
        ignore: [],
777
        errorClass: 'help-block',
778
        errorElement: 'span',
779
        rules: {
780
            'section-name': {
781
                required: true,
782
                minlength: 2,
783
                maxlength: 50
784
            },
785
            'section-text': {
786
                required: false,
787
            },
788
        },
789
        highlight: function(element) {
790
            $(element).closest('.form-group').addClass('has-error');
791
        },
792
        unhighlight: function(element) {
793
            $(element).closest('.form-group').removeClass('has-error');
794
        },
795
        errorPlacement: function(error, element) {
796
            if (element.attr("data-error-container")) {
797
                error.appendTo(element.attr("data-error-container"));
798
            } else {
799
                error.insertAfter(element);
800
            }
801
        },
802
        invalidHandler: function(form, validator) {
803
            if (!validator.numberOfInvalids())
804
                return;
805
            $('html, body').animate({
806
                scrollTop: $(validator.errorList[0].element).offset().top - 100
807
            }, 1000);
808
        },
809
        submitHandler: function(form) {
810
            // do other things for a valid form
811
            //form.submit();
812
            var slug = $('#form-section #section-slug').val();
813
            if (slug) {
814
                objFormGenerator.editSection(
815
                    $('#form-section #section-slug').val(),
816
                    $('#form-section #section-name').val(),
817
                    $('#form-section #section-text').val(),
818
                );
819
            } else {
820
                objFormGenerator.addSection(
821
                    $('#form-section #section-name').val(),
822
                    $('#form-section #section-text').val()
823
                );
824
            }
825
            renderSectionData(objFormGenerator.sections);
826
            $('#modal-section').modal('hide');
827
            return false;
828
        }
829
    });
830
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
831
    $("#form-question").on('submit', function() {
832
        for (var instanceName in CKEDITOR.instances) {
833
            CKEDITOR.instances[instanceName].updateElement();
834
        }
835
    })
836
    /**
837
     * Validate rules form Questions
838
     */
839
    var validatorFormQuestion = $("#form-question").validate({
840
        ignore: [],
841
        errorClass: 'help-block',
842
        errorElement: 'span',
843
        rules: {
844
            'question-text': {
845
                required: true,
846
            },
847
            'question-type': {
848
                required: true,
849
            },
850
            'question-max-length': {
851
                required: true,
852
                digits: true,
853
                min: 0
854
            },
855
            'question-range': {
856
                required: true,
857
                number: true,
858
                min: 1
859
            },
860
        },
861
        highlight: function(element) {
862
            $(element).closest('.form-group').addClass('has-error');
863
        },
864
        unhighlight: function(element) {
865
            $(element).closest('.form-group').removeClass('has-error');
866
        },
867
        errorPlacement: function(error, element) {
868
            if (element.attr("data-error-container")) {
869
                error.appendTo(element.attr("data-error-container"));
870
            } else {
871
                error.insertAfter(element);
872
            }
873
        },
874
        invalidHandler: function(form, validator) {
875
            if (!validator.numberOfInvalids())
876
                return;
877
            $('html, body').animate({
878
                scrollTop: $(validator.errorList[0].element).offset().top - 100
879
            }, 1000);
880
        },
881
        submitHandler: function(form) {
882
            if ($('#form-question #question-slug').val()) {
883
                objFormGenerator.editQuestion(
884
                    $('#form-question #question-section').val(),
885
                    $('#form-question #question-slug').val(),
886
                    $('#form-question #question-text').val(),
887
                    $('#form-question #question-type').val(),
888
                    $('#form-question #question-max-length').val(),
889
                    $('#form-question #question-multiline').val(),
890
                    $('#form-question #question-range').val()
891
                );
892
            } else {
893
                objFormGenerator.addQuestion(
894
                    $('#form-question #question-section').val(),
895
                    $('#form-question #question-text').val(),
896
                    $('#form-question #question-type').val(),
897
                    $('#form-question #question-max-length').val(),
898
                    $('#form-question #question-multiline').val(),
899
                    $('#form-question #question-range').val()
900
                );
901
            }
902
            renderSectionData(objFormGenerator.sections);
903
            $('#modal-question').modal('hide');
904
            return false;
905
        }
906
    });
907
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
908
    $("#form-option").on('submit', function() {
909
        for (var instanceName in CKEDITOR.instances) {
910
            CKEDITOR.instances[instanceName].updateElement();
911
        }
912
    })
913
    /**
914
     * Validate rules form options
915
     */
916
    var validatorFormOption = $("#form-option").validate({
917
        ignore: [],
918
        errorClass: 'help-block',
919
        errorElement: 'span',
920
        rules: {
921
            'option-text': {
922
                required: true,
923
            }
924
 
925
        },
926
        highlight: function(element) {
927
            $(element).closest('.form-group').addClass('has-error');
928
        },
929
        unhighlight: function(element) {
930
            $(element).closest('.form-group').removeClass('has-error');
931
        },
932
        errorPlacement: function(error, element) {
933
            if (element.attr("data-error-container")) {
934
                error.appendTo(element.attr("data-error-container"));
935
            } else {
936
                error.insertAfter(element);
937
            }
938
        },
939
        invalidHandler: function(form, validator) {
940
            if (!validator.numberOfInvalids())
941
                return;
942
            $('html, body').animate({
943
                scrollTop: $(validator.errorList[0].element).offset().top - 100
944
            }, 1000);
945
        },
946
        submitHandler: function(form) {
947
            if ($('#form-option #option-slug').val()) {
948
                objFormGenerator.editOption(
949
                    $('#form-option #option-section').val(),
950
                    $('#form-option #option-question').val(),
951
                    $('#form-option #option-slug').val(),
952
                    $('#form-option #option-text').val()
953
                );
954
            } else {
955
                objFormGenerator.addOption(
956
                    $('#form-option #option-section').val(),
957
                    $('#form-option #option-question').val(),
958
                    $('#form-option #option-text').val()
959
                );
960
            }
961
            renderSectionData(objFormGenerator.sections);
962
            $('#modal-option').modal('hide');
963
            return false;
964
        }
965
    });
966
    /**
967
     * Clicked on add new section
968
     */
969
    $('body').on('click', 'button[id="btn-add-section"]', function(e) {
970
        e.preventDefault();
971
        validatorFormSection.resetForm();
972
        $('#form-section #section-slug').val('');
973
        $('#form-section #section-name').val('');
974
        CKEDITOR.instances['section-text'].setData('');
975
        $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
976
        $('#modal-section').modal('show');
977
    });
978
    /**
979
     * Clicked on edit section
980
     */
981
    $('body').on('click', 'button.btn-edit-section', function(e) {
982
        e.preventDefault();
983
        var slug = $(this).data('section');
984
        var section;
985
        var showForm = false;
986
        for (i = 0; i < objFormGenerator.sections.length; i++) {
987
            section = objFormGenerator.sections[i];
988
            if (slug == section.slug_section) {
989
                validatorFormSection.resetForm();
990
                $('#form-section #section-slug').val(section.slug_section);
991
                $('#form-section #section-name').val(section.name);
992
                CKEDITOR.instances['section-text'].setData(section.text);
993
                showForm = true;
994
                break;
995
            }
996
        }
997
        if (showForm) {
998
            $('#modal-section h4[class="modal-title"]').html('LABEL_EDIT LABEL_SECTION');
999
            $('#modal-section').modal('show');
1000
        }
1001
    });
1002
    /**
1003
     * Clicked on remove section
1004
     */
1005
    $('body').on('click', 'button.btn-delete-section', function(e) {
1006
        e.preventDefault();
1007
        var slug = $(this).data('section');
1008
        bootbox.confirm({
1009
            title: "LABEL_DELETE LABEL_SECTION",
1010
            message: "LABEL_QUESTION_DELETE",
1011
            buttons: {
1012
                cancel: {
1013
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1014
                },
1015
                confirm: {
1016
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1017
                }
1018
            },
1019
            callback: function(result) {
1020
                if (result) {
1021
                    objFormGenerator.deleteSection(slug);
1022
                    renderSectionData(objFormGenerator.sections);
1023
                }
1024
            }
1025
        });
1026
    });
1027
    /**
1028
     * Clicked add new question
1029
     */
1030
    $('body').on('click', 'button.btn-add-question', function(e) {
1031
        e.preventDefault();
1032
        validatorFormQuestion.resetForm();
1033
        var slug = $(this).data('section');
1034
        $('#form-question #question-section').val(slug);
1035
        $('#form-question #question-slug').val('');
1036
        CKEDITOR.instances['question-text'].setData('');
1037
        $('#form-question #question-type').val($('#form-question #question-type option:first').val());
1038
        $('#form-question #question-max-length').val('0');
1039
        $('#form-question #question-max-length').parent().show();
1040
        $('#form-question #question-multiline').val('0');
1041
        $('#form-question #question-multiline').parent().show();
1042
        $('#form-question #question-range').val('10');
1043
        $('#form-question #question-range').parent().hide();
1044
        $('#modal-question h4[class="modal-title"]').html('LABEL_ADD LABEL_QUESTION');
1045
        $('#modal-question').modal('show');
1046
    });
1047
    /**
1048
     * Clicked edit question
1049
     */
1050
    $('body').on('click', 'button.btn-edit-question', function(e) {
1051
        e.preventDefault();
1052
        var slug_section = $(this).data('section');
1053
        var slug = $(this).data('question');
1054
        var showForm = false;
1055
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1056
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1057
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1058
                    if (slug == objFormGenerator.sections[i].questions[j].slug_question) {
1059
                        validatorFormQuestion.resetForm();
1060
                        $('#form-question #question-section').val(objFormGenerator.sections[i].slug_section);
1061
                        $('#form-question #question-slug').val(objFormGenerator.sections[i].questions[j].slug_question);
1062
                        CKEDITOR.instances['question-text'].setData(objFormGenerator.sections[i].questions[j].text);
1063
                        $('#form-question #question-type').val(objFormGenerator.sections[i].questions[j].type);
1064
                        if (objFormGenerator.sections[i].questions[j].type == 'open') {
1065
                            $('#form-question #question-max-length').val(objFormGenerator.sections[i].questions[j].maxlength);
1066
                            $('#form-question #question-max-length').parent().show();
1067
                            $('#form-question #question-multiline').val(objFormGenerator.sections[i].questions[j].multiline);
1068
                            $('#form-question #question-multiline').parent().show();
1069
                        } else {
1070
                            $('#form-question #question-max-length').val('0');
1071
                            $('#form-question #question-max-length').parent().hide();
1072
                            $('#form-question #question-multiline').val('0');
1073
                            $('#form-question #question-multiline').parent().hide();
1074
                        }
1075
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-range') {
1076
                            $('#form-question #question-range').val(objFormGenerator.sections[i].questions[j].range);
1077
                            $('#form-question #question-range').parent().show();
1078
                        } else {
1079
                            $('#form-question #question-range').val('10');
1080
                            $('#form-question #question-range').parent().hide();
1081
                        }
1082
                        showForm = true;
1083
                        break;
1084
                    }
1085
                }
1086
                break;
1087
            }
1088
        }
1089
        if (showForm) {
1090
            $('#modal-question h4[class="modal-title"]').html('LABEL_EDIT LABEL_QUESTION');
1091
            $('#modal-question').modal('show');
1092
        }
1093
    });
1094
    /**
1095
     * Clicked remove question
1096
     */
1097
    $('body').on('click', 'button.btn-delete-question', function(e) {
1098
        e.preventDefault();
1099
        var slug_section = $(this).data('section');
1100
        var slug = $(this).data('question');
1101
        bootbox.confirm({
1102
            title: "LABEL_DELETE LABEL_QUESTION",
1103
            message: "LABEL_QUESTION_DELETE",
1104
            buttons: {
1105
                cancel: {
1106
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1107
                },
1108
                confirm: {
1109
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1110
                }
1111
            },
1112
            callback: function(result) {
1113
                if (result) {
1114
                    objFormGenerator.deleteQuestion(slug_section, slug);
1115
                    renderSectionData(objFormGenerator.sections);
1116
                }
1117
            }
1118
        });
1119
    });
1120
    /**
1121
     * Clicked add new Option
1122
     */
1123
    $('body').on('click', 'button.btn-add-option', function(e) {
1124
        e.preventDefault();
1125
        var slug_section = $(this).data('section');
1126
        var slug_question = $(this).data('question');
1127
        var showForm = false;
1128
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1129
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1130
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1131
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1132
                        validatorFormOption.resetForm();
1133
                        $('#form-option #option-section').val(slug_section);
1134
                        $('#form-option #option-question').val(slug_question);
1135
                        $('#form-option #option-slug').val('');
1136
                        CKEDITOR.instances['option-text'].setData('', function() {
1137
                            editor.focus();
1138
                        });
1139
 
1140
                        renderSectionData(objFormGenerator.sections);
1141
                        $('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
1142
                        $('#modal-option').modal('show');
1143
                        return true;
1144
                    }
1145
                }
1146
            }
1147
        }
1148
    });
1149
    /**
1150
     * Clicked edit option
1151
     */
1152
    $('body').on('click', 'button.btn-edit-option', function(e) {
1153
        e.preventDefault();
1154
        var slug_section = $(this).data('section');
1155
        var slug_question = $(this).data('question');
1156
        var slug = $(this).data('slug');
1157
        var showForm = false;
1158
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1159
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1160
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1161
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1162
                        for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
1163
                            if (slug == objFormGenerator.sections[i].questions[j].options[k].slug_option) {
1164
                                validatorFormOption.resetForm();
1165
                                $('#form-option #option-section').val(objFormGenerator.sections[i].slug_section);
1166
                                $('#form-option #option-question').val(objFormGenerator.sections[i].questions[j].slug_question);
1167
                                $('#form-option #option-slug').val(objFormGenerator.sections[i].questions[j].options[k].slug_option);
1168
                                CKEDITOR.instances['option-text'].setData(objFormGenerator.sections[i].questions[j].options[k].text,
1169
                                    function() {
1170
                                        editor.focus();
1171
                                    });
1172
                                showForm = true;
1173
                                break;
1174
                            }
1175
                        }
1176
                    }
1177
                    if (showForm) {
1178
                        break;
1179
                    }
1180
                }
1181
            }
1182
            if (showForm) {
1183
                break;
1184
            }
1185
        }
1186
        if (showForm) {
1187
            $('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
1188
            $('#modal-option').modal('show');
1189
        }
1190
    });
1191
    /**
1192
     * Clicked remove option
1193
     */
1194
    $('body').on('click', 'button.btn-delete-option', function(e) {
1195
        e.preventDefault();
1196
        var slug_section = $(this).data('section');
1197
        var slug_question = $(this).data('question');
1198
        var slug = $(this).data('slug');
1199
        bootbox.confirm({
1200
            title: "LABEL_DELETE LABEL_OPTION",
1201
            message: "LABEL_QUESTION_DELETE",
1202
            buttons: {
1203
                cancel: {
1204
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1205
                },
1206
                confirm: {
1207
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1208
                }
1209
            },
1210
            callback: function(result) {
1211
                if (result) {
1212
                    objFormGenerator.deleteOption(slug_section, slug_question, slug);
1213
                    renderSectionData(objFormGenerator.sections);
1214
                }
1215
            }
1216
        });
1217
    })
1218
 
1219
    /**
1220
     * Format input number (Form Question)
1221
     */
1222
    $('#form-question #question-max-length').inputNumberFormat({
1223
        'decimal': 0
1224
    });
1225
    /**
1226
     * Detect when updating question status and hide/Show options
1227
     */
1228
    $('#form-question #question-type').change(function(e) {
1229
        e.preventDefault();
1230
        if ($('#form-question #question-type').val() == 'open') {
1231
            $('#form-question #question-max-length').parent().show();
1232
            $('#form-question #question-multiline').parent().show();
1233
        } else {
1234
            $('#form-question #question-max-length').val('0');
1235
            $('#form-question #question-max-length').parent().hide();
1236
            $('#form-question #question-multiline').val('0');
1237
            $('#form-question #question-multiline').parent().hide();
1238
        }
1239
        $('#form-question #question-range').val('10');
1240
        if ($('#form-question #question-type').val() == 'rating-range') {
1241
            $('#form-question #question-range').parent().show();
1242
        } else {
1243
            $('#form-question #question-range').parent().hide();
1244
        }
1245
    });
1246
    /**
1247
     * Clicked new Form
1248
     */
1249
    $('button.btn-add-form').click(function(e) {
1250
        e.preventDefault();
1251
        objFormGenerator.clear();
1252
        objFormGenerator.render();
1253
        validatorForm.resetForm();
1254
        clearSectionData();
1255
        $('#form-main').attr('action', '$routeAdd');
1256
        $('#form-main #form-continue').val('0');
1257
        $('#form-main #name').val('');
1258
        $('#form-main #status').val('$status_inactive');
1259
        CKEDITOR.instances.text.setData('');
1260
        CKEDITOR.instances.description.setData('');
1261
        $('#row-forms').hide();
1262
        $('#row-edit').show();
1263
        $('#form-main #name').focus();
1264
    });
1265
    /**
1266
     * Clicked cancel new/edit Form
1267
     */
1268
    $('button.btn-edit-cancel').click(function(e) {
1269
        e.preventDefault();
1270
        $('#row-edit').hide();
1271
        $('#row-forms').show();
1272
    });
1273
    /**
1274
     * Clicked save and continue new Form
1275
     */
1276
    $('button.btn-form-save-continue').click(function(e) {
1277
        e.preventDefault();
1278
        $('#form-main #form-continue').val('1')
1279
        $('#form-main').submit();
1280
    });
1281
    /**
1282
     * Clicked save and close new/edit Form
1283
     */
1284
    $('button.btn-form-save-close').click(function(e) {
1285
        e.preventDefault();
1286
        $('#form-main #form-continue').val('0')
1287
        $('#form-main').submit();
1288
    });
1289
    /**
1290
     * Modal Settings
1291
     */
1292
    $('#modal-section, #modal-question, #modal-option').modal({
1293
        backdrop: 'static',
1294
        keyboard: false,
1295
        show: false
1296
    });
1297
    /**
1298
     * Get Question type
1299
     */
1300
    const getQuestionTypeBySlug = (slug_section, slug_question) => {
1301
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1302
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1303
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1304
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1305
                        return objFormGenerator.sections[i].questions[j].type;
1306
                    }
1307
                }
1308
            }
1309
        }
1310
    }
1311
    /**
1312
     * Remove Html Tags
1313
     */
1314
    const removeTags = (str) => str.toString().replace( /(<([^>]+)>)/ig, '')
1315
    /**
1316
     * Render Sections data
1317
     */
1318
    const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
1319
        getType: getQuestionTypeBySlug,
1320
        removeTags: removeTags
1321
    }));
1322
 
1323
 
1324
    /**
1325
     * Clear Div Section data
1326
     */
1327
    const clearSectionData = () => $("#rows").html('');
1328
    /**
1329
     * Clicked refresh button
1330
     */
1331
    $('button.btn-refresh').click(function(e) {
1332
        tableForm.fnDraw();
1333
    });
1334
 
11214 stevensc 1335
    CKEDITOR.replace('description', {
16805 efrain 1336
                                toolbar: [
1337
                                        { name: 'editing', items: ['Scayt'] },
1338
                                        { name: 'links', items: ['Link', 'Unlink'] },
1339
                                        { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'] },
1340
                                        { name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', 'RemoveFormat'] },
1341
                                        '/',
1342
                                        { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },
1343
                                        { name: 'styles', items: ['Styles', 'Format'] },
1344
                                        { name: 'tools', items: ['Maximize'] }
1345
                                ],
1346
                                removePlugins: 'elementspath,Anchor',
1347
                                heigth: 100
1348
                        });
11214 stevensc 1349
    CKEDITOR.replace('text', {
16805 efrain 1350
                                toolbar: [
1351
                                        { name: 'editing', items: ['Scayt'] },
1352
                                        { name: 'links', items: ['Link', 'Unlink'] },
1353
                                        { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'] },
1354
                                        { name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', 'RemoveFormat'] },
1355
                                        '/',
1356
                                        { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },
1357
                                        { name: 'styles', items: ['Styles', 'Format'] },
1358
                                        { name: 'tools', items: ['Maximize'] }
1359
                                ],
1360
                                removePlugins: 'elementspath,Anchor',
1361
                                heigth: 100
1362
                        });
7397 eleazar 1363
 
1364
});
1365
JS;
1366
$this->inlineScript()->captureEnd();
16805 efrain 1367
?>
12475 stevensc 1368
 
16805 efrain 1369
<!-- Content Header (Page header) -->
1370
<section class="content-header">
1371
    <div class="container-fluid">
1372
        <div class="row mb-2">
1373
            <div class="col-sm-12">
1374
                <h1>LABEL_SELF_EVALUATION_FORMS</h1>
1375
            </div>
1376
        </div>
1377
    </div>
1378
    <!-- /.container-fluid -->
1379
</section>
1380
<section class="content">
1381
    <div class="container-fluid" id="row-forms">
1382
        <div class="row">
1383
            <div class="col-12">
1384
                <div class="card">
1385
                    <div class="card-body">
1386
                        <table id="gridTable" class="table   table-hover">
1387
                            <thead>
1388
                                <tr>
1389
                                    <th>LABEL_NAME</th>
1390
                                    <th>LABEL_ACTIVE</th>
1391
                                    <th>LABEL_ACTIONS</th>
1392
                                </tr>
1393
                            </thead>
1394
                            <tbody></tbody>
1395
                        </table>
1396
                    </div>
1397
                    <div class="card-footer clearfix">
1398
                        <div style="float:right;">
1399
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
1400
                            <?php if ($allowAdd) : ?>
1401
                                <button type="button" class="btn btn-primary btn-add-form"><i class="fa fa-plus"></i> LABEL_ADD </button>
1402
                            <?php endif; ?>
1403
                        </div>
1404
                    </div>
1405
                </div>
1406
            </div>
1407
        </div>
1408
    </div>
12475 stevensc 1409
 
16805 efrain 1410
    <!-- Create/Edit Form -->
7397 eleazar 1411
 
16805 efrain 1412
    <div class="row" id="row-edit" style="display: none">
1413
        <div class="col-xs-12 col-md-12">
1414
            <form action="#" name="form-main" id="form-main">
1415
                <input type="hidden" name="form-id" id="form-id" value="0" />
1416
                <input type="hidden" name="form-continue" id="form-continue" value="0" />
1417
                <?php
1418
                //$form = $this->formAdd;
1419
                $form->setAttributes([
1420
                    'method' => 'post',
1421
                    'name' => 'form-main',
1422
                    'action' => $routeAdd,
1423
                    'id' => 'form-main'
1424
                ]);
1425
                $form->prepare();
1426
                echo $this->form()->openTag($form);
1427
                ?>
1428
                <div class="form-group">
1429
                    <?php
1430
                    $element = $form->get('name');
1431
                    $element->setOptions(['label' => 'LABEL_FIRST_NAME']);
1432
                    $element->setAttributes(['class' => 'form-control']);
1433
                    echo $this->formLabel($element);
1434
                    echo $this->formText($element);
1435
                    ?>
1436
                </div>
1437
                <div class="form-group">
1438
                    <?php
1439
                    $element = $form->get('description');
1440
                    $element->setOptions(['label' => 'LABEL_DESCRIPTION']);
1441
                    $element->setAttributes(['class' => 'form-control']);
1442
                    echo $this->formLabel($element);
1443
                    echo $this->formTextArea($element);
1444
                    ?>
1445
                </div>
1446
                <div class="form-group">
1447
                    <?php
1448
                    $element = $form->get('text');
1449
                    $element->setOptions(['label' => 'LABEL_TEXT']);
1450
                    $element->setAttributes(['class' => 'form-control']);
1451
                    echo $this->formLabel($element);
1452
                    echo $this->formTextArea($element);
1453
                    ?>
1454
                </div>
1455
                <div class="form-group">
1456
                    <?php
1457
                    $element = $form->get('status');
1458
                    $element->setAttributes(['class' => 'form-control']);
1459
                    $element->setOptions(['label' => 'LABEL_STATUS']);
1460
                    echo $this->formLabel($element);
1461
                    echo $this->formSelect($element);
1462
                    ?>
1463
                </div>
1464
                <br />
1465
                <div class="row">
1466
                    <div class="col-xs-12 col-md-12 text-right">
1467
                        <button class="btn btn-primary" id="btn-add-section" data-toggle="tooltip" title="LABEL_ADD LABEL_SECTION"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_ADD LABEL_SECTION</button>
1468
                    </div>
1469
                </div>
1470
                <br />
1471
                <div class="row">
1472
                    <div class="col-xs-12 col-md-12">
1473
                        <div class="panel-group" id="rows"></div>
1474
                    </div>
1475
                </div>
1476
                <div class="form-group">
1477
                    <button type="submit" form="form-main" class="btn btn-info btn-form-save-continue">LABEL_SAVE & LABEL_CONTINUE</button>
1478
                    <button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE & LABEL_CLOSE</button>
1479
                    <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
1480
                </div>
1481
            </form>
1482
        </div>
1483
    </div>
1484
 
1485
    <!-- Create/Edit Form-->
1486
 
1487
    <!-- Section Modal -->
1488
    <div id="modal-section" class="modal" tabindex="-1" role="dialog">
1489
        <div class="modal-dialog modal-lg" role="document">
1490
            <form action="#" name="form-section" id="form-section">
1491
                <input type="hidden" name="section-slug" id="section-slug" value="" />
1492
                <div class="modal-content">
1493
                    <div class="modal-header">
1494
                        <h4 class="modal-title">LABEL_ADD LABEL_SECTION</h4>
1495
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1496
                            <span aria-hidden="true">&times;</span>
1497
                        </button>
1498
                    </div>
1499
                    <div class="modal-body">
1500
                        <div class="form-group">
1501
                            <label for="section-name">LABEL_FIRST_NAME</label>
1502
                            <input type="text" name="section-name" id="section-name" class="form-control" maxlength="50" value="" />
1503
                        </div>
1504
                        <div class="form-group">
1505
                            <label for="section-text">LABEL_TEXT</label>
1506
                            <!--  ckeditor -->
1507
                            <textarea name="section-text" id="section-text" rows="5" class="ckeditor form-control"></textarea>
1508
                        </div>
1509
                    </div>
1510
                    <div class="modal-footer">
1511
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
1512
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1513
                    </div>
1514
                </div>
1515
            </form>
1516
        </div>
1517
    </div>
1518
    <!-- End Modal Section -->
1519
 
1520
    <!-- Question Modal -->
1521
 
1522
    <div id="modal-question" class="modal" tabindex="-1" role="dialog">
1523
        <div class="modal-dialog modal-lg" role="document">
1524
            <form action="#" name="form-question" id="form-question">
1525
                <input type="hidden" name="question-section" id="question-section" />
1526
                <input type="hidden" name="question-slug" id="question-slug" />
1527
                <div class="modal-content">
1528
                    <div class="modal-header">
1529
                        <h4 class="modal-title">LABEL_ADD LABEL_QUESTION</h4>
1530
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1531
                            <span aria-hidden="true">&times;</span>
1532
                        </button>
1533
                    </div>
1534
                    <div class="modal-body">
1535
                        <div class="form-group">
1536
                            <label for="question-text">LABEL_TEXT</label>
1537
                            <!--  ckeditor -->
1538
                            <textarea name="question-text" id="question-text" rows="5" class="ckeditor form-control"></textarea>
1539
                        </div>
1540
                        <div class="form-group">
1541
                            <label for="question-type">LABEL_TYPE</label>
1542
                            <select name="question-type" id="question-type" class="form-control">
1543
                                <option value="open">LABEL_OPEN</option>
1544
                                <option value="simple">Simple</option>
1545
                                <option value="multiple">Multiple</option>
1546
 
1547
                            </select>
1548
                        </div>
1549
                        <div class="form-group">
1550
                            <label for="question-max-length">LABEL_MAXLENGTH</label>
1551
                            <input type="text" name="question-max-length" id="question-max-length" class="form-control" />
1552
                        </div>
1553
                        <div class="form-group">
1554
                            <label for="question-multiline">LABEL_MULTI_LINE</label>
1555
                            <select name="question-multiline" id="question-multiline" class="form-control">
1556
                                <option value="1">LABEL_YES</option>
1557
                                <option value="0">LABEL_NOT</option>
1558
                            </select>
1559
                        </div>
1560
                        <div class="form-group">
1561
                            <label for="question-range">LABEL_RANGE</label>
1562
                            <select name="question-range" id="question-range" class="form-control">
1563
                                <option value="10">1-10</option>
1564
                                <option value="6">1-6</option>
1565
                                <option value="5">1-5</option>
1566
                            </select>
1567
                        </div>
1568
                    </div>
1569
                    <div class="modal-footer">
1570
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
1571
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1572
                    </div>
1573
                </div>
1574
            </form>
1575
        </div>
1576
    </div>
1577
 
1578
    <!-- End Modal Question -->
1579
 
1580
    <!-- Modal Options -->
1581
 
1582
    <div id="modal-option" class="modal" tabindex="-1" role="dialog">
1583
        <div class="modal-dialog modal-lg" role="document">
1584
            <form action="#" name="form-option" id="form-option">
1585
                <input type="hidden" name="option-section" id="option-section" value="" />
1586
                <input type="hidden" name="option-question" id="option-question" value="" />
1587
                <input type="hidden" name="option-slug" id="option-slug" value="" />
1588
                <div class="modal-content">
1589
                    <div class="modal-header">
1590
                        <h4 class="modal-title">LABEL_OPTION</h4>
1591
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1592
                            <span aria-hidden="true">&times;</span>
1593
                        </button>
1594
                    </div>
1595
                    <div class="modal-body">
1596
                        <div class="form-group">
1597
                            <label for="option-text">LABEL_TEXT</label>
1598
                            <!--  ckeditor -->
1599
                            <textarea name="option-text" id="option-text" rows="5" class="ckeditor form-control"></textarea>
1600
                        </div>
1601
                    </div>
1602
                    <div class="modal-footer">
1603
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
1604
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1605
                    </div>
1606
                </div>
1607
            </form>
1608
        </div>
1609
    </div>
1610
 
1611
    <!-- End Modal Options -->
1612
 
1613
    <!---Template Sections --->
1614
    <script id="sectionTemplate" type="text/x-jsrender">
1615
        <div class="panel panel-default" id="panel-{{:slug_section}}">
1616
        <div class="panel-heading">
1617
            <h4 class="panel-title">
1618
                <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:slug_section}}" href="#collapse-{{:slug_section}}">
1619
                    <span class="section-name{{:slug_section}}">
1620
                        {{:name}}
1621
                    </span>
1622
                </a>
1623
            </h4>
1624
        </div>
1625
        <div id="collapse-{{:slug_section}}" class="panel-collapse in collapse show">
1626
            <div class="panel-body">
1627
                <div class="table-responsive">
1628
                    <table class="table table-bordered">
1629
                        <thead>
1630
                            <tr>
1631
                                <th style="width: 10%;">LABEL_ELEMENT</th>
1632
                                <th style="width: 50%;">LABEL_TEXT</th>
1633
                                <th style="width: 10%;">LABEL_TYPE</th>
1634
                                <th style="width: 20%;">LABEL_ACTIONS</th>
1635
                            </tr>
1636
                        </thead>
1637
                        <tbody>
1638
                            <tr class="tr-section">
1639
                                <td class="text-left">LABEL_SECTION</td>
1640
                                <td class="text-left">{{:name}}</td>
1641
                                <td></td>
1642
                                <td>
1643
                                    <button class="btn btn-default btn-edit-section" data-section="{{:slug_section}}" data-toggle="tooltip"  data-original-title="LABEL_EDIT LABEL_SECTION"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_SECTION </button>
1644
                                    <button class="btn btn-default btn-delete-section" data-section="{{:slug_section}}" data-toggle="tooltip"  data-original-title="LABEL_DELETE LABEL_SECTION"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_SECTION </button>
1645
                                    <button class="btn btn-default btn-add-question" data-section="{{:slug_section}}" data-toggle="tooltip"  data-original-title="LABEL_ADD  LABEL_QUESTION"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_ADD  LABEL_QUESTION </button>
1646
                                </td>
1647
                            </tr>
1648
                            {{for questions}}
1649
                            <tr class="tr-question">
1650
                                <td class="text-left">--LABEL_QUESTION</td>
1651
                                <td class="text-left">
1652
                                    {{:~removeTags(text)}}
1653
                                </td>
1654
                                <td class="text-capitalize">
1655
                                    {{if type == 'open'}} LABEL_OPEN {{/if}}
1656
                                    {{if type == 'simple'}} Simple {{/if}}
1657
                                    {{if type == 'multiple'}} Multiple {{/if}}
1658
                                </td>
1659
                                <td>
1660
                                    <button class="btn btn-default btn-edit-question" data-section="{{:slug_section}}" data-question="{{:slug_question}}" data-toggle="tooltip"  data-original-title="LABEL_EDIT LABEL_QUESTION"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_QUESTION</button>
1661
                                    <button class="btn btn-default btn-delete-question" data-section="{{:slug_section}}" data-question="{{:slug_question}}" data-toggle="tooltip"  data-original-title="LABEL_DELETE LABEL_QUESTION"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_QUESTION</button>
1662
 
1663
                                    {{if type == 'simple' || type == 'rating-open' || type=='multiple' }}
1664
                                    <button class="btn btn-default btn-add-option" data-section="{{:slug_section}}" data-question="{{:slug_question}}" data-toggle="tooltip"  data-original-title="LABEL_ADD  LABEL_OPTION"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_ADD  LABEL_OPTION</button>
1665
                                    {{/if}}
1666
 
1667
                                </td>
1668
                            </tr>
1669
                            {{for options}}
1670
                            <tr class="tr-option">
1671
                                <td class="text-left">---LABEL_OPTION</td>
1672
                                <td class="text-left">
1673
                                    {{:~removeTags(text)}}
1674
                                </td>
1675
                                <td>
1676
 
1677
                                    {{if ~getType( slug_section, slug_question) == 'multiple' || ~getType( slug_section, slug_question) == 'rating-open'  }}
1678
                                    {{/if}}
1679
                                </td>
1680
                                <td>
1681
                                    <button class="btn btn-default btn-edit-option" data-section="{{:slug_section}}" data-question="{{:slug_question}}" data-slug="{{:slug_option}}" data-toggle="tooltip"  data-original-title="LABEL_EDIT LABEL_OPTION"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_OPTION</button>
1682
                                    <button class="btn btn-default btn-delete-option" data-section="{{:slug_section}}" data-question="{{:slug_question}}" data-slug="{{:slug_option}}" data-toggle="tooltip"  data-original-title="LABEL_DELETE LABEL_OPTION"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_OPTION</button>
1683
                                </td>
1684
                            </tr>
1685
                            {{/for}}
1686
                            {{/for}}
1687
                        </tbody>
1688
                    </table>
1689
                </div>
1690
            </div>
1691
        </div>
1692
    </div>
1693
    </script>
1694
 
1695
    <!-- End Template Sections-->
1696
 
1697
</section>