Proyectos de Subversion LeadersLinked - Backend

Rev

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

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