Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 994 | Rev 996 | 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
     */
993 geraldo 835
    var validatorFormQuestion = $("#form-section").validate({
977 geraldo 836
        ignore: [],
837
        errorClass: 'help-block',
838
        errorElement: 'span',
839
        rules: {
995 geraldo 840
            'section-text': {
977 geraldo 841
                required: true,
842
            },
995 geraldo 843
            'section-value': {
977 geraldo 844
                required: true,
845
                number: true,
846
                min: 1
847
            },
995 geraldo 848
            'section-type': {
977 geraldo 849
                required: true,
850
            },
995 geraldo 851
            'section-max-length': {
977 geraldo 852
                required: true,
853
                digits: true,
854
                min: 0
855
            },
995 geraldo 856
            'section-range': {
977 geraldo 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) {
993 geraldo 883
            if ($('#form-section #section-id').val()) {
977 geraldo 884
                objFormGenerator.editQuestion(
995 geraldo 885
                    $('#form-section #section-section').val(),
993 geraldo 886
                    $('#form-section #section-id').val(),
995 geraldo 887
                    $('#form-section #section-text').val(),
888
                    $('#form-section #section-value').val(),
889
                    $('#form-section #section-type').val(),
890
                    $('#form-section #section-max-length').val(),
891
                    $('#form-section #section-multiline').val(),
892
                    $('#form-section #section-range').val()
977 geraldo 893
                );
894
            } else {
895
                objFormGenerator.addQuestion(
995 geraldo 896
                    $('#form-section #section-section').val(),
897
                    $('#form-section #section-text').val(),
898
                    $('#form-section #section-value').val(),
899
                    $('#form-section #section-type').val(),
900
                    $('#form-section #section-max-length').val(),
901
                    $('#form-section #section-multiline').val(),
902
                    $('#form-section #section-range').val()
977 geraldo 903
                );
904
            }
905
            renderSectionData(objFormGenerator.sections);
993 geraldo 906
            $('#modal-section').modal('hide');
977 geraldo 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
     */
993 geraldo 980
    $('body').on('click', 'button.btn-add-section', function(e) {
977 geraldo 981
        validatorFormQuestion.resetForm();
993 geraldo 982
        $('#form-section #section-id').val('');
995 geraldo 983
        CKEDITOR.instances['section-text'].setData('');
984
        $('#form-section #section-type').val($('#form-section #section-type option:first').val());
985
        $('#form-section #section-max-length').val('0');
986
        $('#form-section #section-max-length').parent().show();
987
        $('#form-section #section-multiline').val('0');
988
        $('#form-section #section-multiline').parent().show();
993 geraldo 989
        $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
990
        $('#modal-section').modal('show');
977 geraldo 991
    });
992
    /**
993
     * Clicked edit question
994
     */
993 geraldo 995
    $('body').on('click', 'button.btn-edit-section', function(e) {
977 geraldo 996
        e.preventDefault();
997
        var slug_section = $(this).data('section');
998
        var slug = $(this).data('question');
999
        var showForm = false;
1000
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1001
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1002
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1003
                    if (slug == objFormGenerator.sections[i].questions[j].slug_question) {
1004
                        validatorFormQuestion.resetForm();
995 geraldo 1005
                        $('#form-section #section-section').val(objFormGenerator.sections[i].slug_section);
993 geraldo 1006
                        $('#form-section #section-id').val(objFormGenerator.sections[i].questions[j].slug_question);
995 geraldo 1007
                        CKEDITOR.instances['section-text'].setData(objFormGenerator.sections[i].questions[j].text);
1008
                        $('#form-section #section-value').val(objFormGenerator.sections[i].questions[j].value);
1009
                        $('#form-section #section-type').val(objFormGenerator.sections[i].questions[j].type);
977 geraldo 1010
                        if (objFormGenerator.sections[i].questions[j].type == 'open') {
995 geraldo 1011
                            $('#form-section #section-max-length').val(objFormGenerator.sections[i].questions[j].maxlength);
1012
                            $('#form-section #section-max-length').parent().show();
1013
                            $('#form-section #section-multiline').val(objFormGenerator.sections[i].questions[j].multiline);
1014
                            $('#form-section #section-multiline').parent().show();
977 geraldo 1015
                        } else {
995 geraldo 1016
                            $('#form-section #section-max-length').val('0');
1017
                            $('#form-section #section-max-length').parent().hide();
1018
                            $('#form-section #section-multiline').val('0');
1019
                            $('#form-section #section-multiline').parent().hide();
977 geraldo 1020
                        }
1021
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-range') {
995 geraldo 1022
                            $('#form-section #section-range').val(objFormGenerator.sections[i].questions[j].range);
1023
                            $('#form-section #section-range').parent().show();
977 geraldo 1024
                        } else {
995 geraldo 1025
                            $('#form-section #section-range').val('10');
1026
                            $('#form-section #section-range').parent().hide();
977 geraldo 1027
                        }
1028
                        showForm = true;
1029
                        break;
1030
                    }
1031
                }
1032
                break;
1033
            }
1034
        }
1035
        if (showForm) {
993 geraldo 1036
            $('#modal-section h4[class="modal-title"]').html('LABEL_EDIT LABEL_SECTION');
1037
            $('#modal-section').modal('show');
977 geraldo 1038
        }
1039
    });
1040
    /**
1041
     * Clicked remove question
1042
     */
993 geraldo 1043
    $('body').on('click', 'button.btn-delete-section', function(e) {
977 geraldo 1044
        e.preventDefault();
1045
        var slug_section = $(this).data('section');
1046
        var slug = $(this).data('question');
1047
        bootbox.confirm({
993 geraldo 1048
            title: "LABEL_DELETE LABEL_SECTION",
1049
            message: "LABEL_SECTION_DELETE",
977 geraldo 1050
            buttons: {
1051
                cancel: {
1052
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1053
                },
1054
                confirm: {
1055
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1056
                }
1057
            },
1058
            callback: function(result) {
1059
                if (result) {
1060
                    objFormGenerator.deleteQuestion(slug_section, slug);
1061
                    renderSectionData(objFormGenerator.sections);
1062
                }
1063
            }
1064
        });
1065
    });
1066
    /**
1067
     * Clicked add new Option
1068
     */
1069
    $('body').on('click', 'button.btn-add-option', function(e) {
1070
        e.preventDefault();
1071
        var slug_section = $(this).data('section');
1072
        var slug_question = $(this).data('question');
1073
        var showForm = false;
1074
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1075
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1076
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1077
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1078
                        validatorFormOption.resetForm();
1079
                        $('#form-option #option-section').val(slug_section);
1080
                        $('#form-option #option-question').val(slug_question);
1081
                        $('#form-option #option-slug').val('');
1082
                        CKEDITOR.instances['option-text'].setData('', function() {
1083
                            editor.focus();
1084
                        });
1085
                        $('#form-option #option-correct').val('0');
1086
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1087
                            $('#form-option #option-correct').parent().hide();
1088
                        } else {
1089
                            $('#form-option #option-correct').parent().show();
1090
                        }
1091
                        if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1092
                            $('#form-option #option-value').val('0');
1093
                            $('#form-option #option-value').parent().show();
1094
                        } else {
1095
                            $('#form-option #option-value').val('1');
1096
                            $('#form-option #option-value').parent().hide();
1097
                        }
1098
                        renderSectionData(objFormGenerator.sections);
1099
                        $('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
1100
                        $('#modal-option').modal('show');
1101
                        return true;
1102
                    }
1103
                }
1104
            }
1105
        }
1106
    });
1107
    /**
1108
     * Clicked edit option
1109
     */
1110
    $('body').on('click', 'button.btn-edit-option', function(e) {
1111
        e.preventDefault();
1112
        var slug_section = $(this).data('section');
1113
        var slug_question = $(this).data('question');
1114
        var slug = $(this).data('slug');
1115
        var showForm = false;
1116
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1117
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1118
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1119
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1120
                        for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
1121
                            if (slug == objFormGenerator.sections[i].questions[j].options[k].slug_option) {
1122
                                validatorFormOption.resetForm();
1123
                                $('#form-option #option-section').val(objFormGenerator.sections[i].slug_section);
1124
                                $('#form-option #option-question').val(objFormGenerator.sections[i].questions[j].slug_question);
1125
                                $('#form-option #option-slug').val(objFormGenerator.sections[i].questions[j].options[k].slug_option);
1126
                                CKEDITOR.instances['option-text'].setData(objFormGenerator.sections[i].questions[j].options[k].text,
1127
                                    function() {
1128
                                        editor.focus();
1129
                                    });
1130
                                $('#form-option #option-correct').val(objFormGenerator.sections[i].questions[j].options[k].correct);
1131
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'simple') {
1132
                                    $('#form-option #option-correct').parent().show();
1133
                                } else {
1134
                                    $('#form-option #option-correct').parent().hide();
1135
                                }
1136
                                $('#form-option #option-value').val(objFormGenerator.sections[i].questions[j].options[k].value);
1137
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1138
                                    $('#form-option #option-value').parent().show();
1139
                                } else {
1140
                                    $('#form-option #option-value').parent().hide();
1141
                                }
1142
                                showForm = true;
1143
                                break;
1144
                            }
1145
                        }
1146
                    }
1147
                    if (showForm) {
1148
                        break;
1149
                    }
1150
                }
1151
            }
1152
            if (showForm) {
1153
                break;
1154
            }
1155
        }
1156
        if (showForm) {
1157
            $('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
1158
            $('#modal-option').modal('show');
1159
        }
1160
    });
1161
    /**
1162
     * Clicked remove option
1163
     */
1164
    $('body').on('click', 'button.btn-delete-option', function(e) {
1165
        e.preventDefault();
1166
        var slug_section = $(this).data('section');
1167
        var slug_question = $(this).data('question');
1168
        var slug = $(this).data('slug');
1169
        bootbox.confirm({
1170
            title: "LABEL_DELETE LABEL_OPTION",
993 geraldo 1171
            message: "LABEL_SECTION_DELETE",
977 geraldo 1172
            buttons: {
1173
                cancel: {
1174
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1175
                },
1176
                confirm: {
1177
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1178
                }
1179
            },
1180
            callback: function(result) {
1181
                if (result) {
1182
                    objFormGenerator.deleteOption(slug_section, slug_question, slug);
1183
                    renderSectionData(objFormGenerator.sections);
1184
                }
1185
            }
1186
        });
1187
    })
1188
    /**
1189
     * Clicked new Form
1190
     */
1191
    $('button.btn-add-form').click(function(e) {
1192
        e.preventDefault();
1193
        objFormGenerator.clear();
1194
        objFormGenerator.render();
1195
        validatorForm.resetForm();
1196
        clearSectionData();
1197
        $('#form-main').attr('action', '$routeAdd');
1198
        $('#form-main #form-id').val('0');
1199
        $('#form-main #form-continue').val('0');
1200
        $('#form-main #form-name').val('');
1201
        $('#row-forms').hide();
1202
        $('#row-edit').show();
1203
        $('#form-main #form-name').focus();
1204
    });
1205
    /**
1206
     * Clicked cancel new/edit Form
1207
     */
1208
    $('button.btn-edit-cancel').click(function(e) {
1209
        e.preventDefault();
1210
        $('#row-edit').hide();
1211
        $('#row-forms').show();
1212
    });
1213
    /**
1214
     * Clicked save and continue new Form
1215
     */
1216
    $('button.btn-form-save-continue').click(function(e) {
1217
        e.preventDefault();
1218
        $('#form-main #form-continue').val('1')
1219
        $('#form-main').submit();
1220
    });
1221
    /**
1222
     * Clicked save and close new/edit Form
1223
     */
1224
    $('button.btn-form-save-close').click(function(e) {
1225
        e.preventDefault();
1226
        $('#form-main #form-continue').val('0')
1227
        $('#form-main').submit();
1228
    });
1229
    /**
1230
     * Modal Settings
1231
     */
993 geraldo 1232
    $('#modal-section, #modal-section, #modal-option').modal({
977 geraldo 1233
        backdrop: 'static',
1234
        keyboard: false,
1235
        show: false
1236
    });
1237
    /**
1238
     * Get Question type
1239
     */
1240
    const getQuestionTypeBySlug = (slug_section, slug_question) => {
1241
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1242
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1243
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1244
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1245
                        return objFormGenerator.sections[i].questions[j].type;
1246
                    }
1247
                }
1248
            }
1249
        }
1250
    }
1251
    /**
1252
     * Remove Html Tags
1253
     */
1254
    const removeTags = (str) => str.toString().replace( /(<([^>]+)>)/ig, '')
1255
    /**
1256
     * Render Sections data
1257
     */
1258
    const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
1259
        getType: getQuestionTypeBySlug,
1260
        removeTags: removeTags
1261
    }));
1262
 
1263
 
1264
    /**
1265
     * Clear Div Section data
1266
     */
1267
    const clearSectionData = () => $("#rows").html('');
1268
    /**
1269
     * Clicked refresh button
1270
     */
1271
    $('button.btn-refresh').click(function(e) {
1272
        tableForm.fnDraw();
1273
    });
1274
 
1275
});
1276
JS;
1277
$this->inlineScript()->captureEnd();
1278
?>
1279
 
1280
<!-- Content Header (Page header) -->
1281
<section class="content-header">
1282
    <div class="container-fluid">
1283
        <div class="row mb-2">
1284
            <div class="col-sm-12">
984 geraldo 1285
                <h1>LABEL_PERFORMANCE_EVALUATION</h1>
977 geraldo 1286
            </div>
1287
        </div>
1288
    </div>
1289
    <!-- /.container-fluid -->
1290
</section>
1291
<section class="content">
1292
    <div class="container-fluid" id="row-forms">
1293
        <div class="row">
1294
            <div class="col-12">
1295
                <div class="card">
1296
                    <div class="card-body">
1297
                        <table id="gridTable" class="table   table-hover">
1298
                            <thead>
1299
                                <tr>
990 geraldo 1300
                                    <th>LABEL_NAME</th>
1301
                                    <th>LABEL_LANGUAGE</th>
1302
                                    <th>LABEL_ACTIVE</th>
977 geraldo 1303
                                    <th>LABEL_ACTIONS</th>
1304
                                </tr>
1305
                            </thead>
1306
                            <tbody></tbody>
1307
                        </table>
1308
                    </div>
1309
                    <div class="card-footer clearfix">
1310
                        <div style="float:right;">
1311
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
1312
                            <?php if ($allowAdd) : ?>
1313
                                <button type="button" class="btn btn-primary btn-add-form"><i class="fa fa-plus"></i> LABEL_ADD </button>
1314
                            <?php endif; ?>
1315
                        </div>
1316
                    </div>
1317
                </div>
1318
            </div>
1319
        </div>
1320
    </div>
1321
 
1322
    <!-- Create/Edit Form -->
1323
 
1324
    <div class="row" id="row-edit" style="display: none">
1325
        <div class="col-xs-12 col-md-12">
1326
            <form action="#" name="form-main" id="form-main">
1327
                <input type="hidden" name="form-id" id="form-id" value="0" />
1328
                <input type="hidden" name="form-continue" id="form-continue" value="0" />
990 geraldo 1329
                <div class="form-group">
1330
                    <label for="form-name">LABEL_FIRST_NAME</label>
1331
                    <input type="text" name="form-name" id="form-name" class="form-control" maxlength="50" />
1332
                </div>
977 geraldo 1333
                <div class="row">
1334
                    <div class="col-xs-12 col-md-12 text-right">
994 geraldo 1335
                        <button type="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>
977 geraldo 1336
                    </div>
1337
                </div>
1338
                <br />
1339
                <div class="row">
1340
                    <div class="col-xs-12 col-md-12">
1341
                        <div class="panel-group" id="rows"></div>
1342
                    </div>
1343
                </div>
1344
                <div class="form-group">
1345
                    <button type="submit" form="form-main" class="btn btn-info btn-form-save-continue">LABEL_SAVE & LABEL_CONTINUE</button>
1346
                    <button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE & LABEL_CLOSE</button>
1347
                    <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
1348
                </div>
1349
            </form>
1350
        </div>
1351
    </div>
1352
 
1353
    <!-- Create/Edit Form-->
1354
 
990 geraldo 1355
 
977 geraldo 1356
 
1357
    <!-- Question Modal -->
1358
 
993 geraldo 1359
    <div  id="modal-section" class="modal" tabindex="-1" role="dialog">
977 geraldo 1360
        <div class="modal-dialog modal-lg" role="document">
993 geraldo 1361
            <form action="#" name="form-section" id="form-section">
995 geraldo 1362
                <input type="hidden" name="section-section" id="section-section" />
993 geraldo 1363
                <input type="hidden" name="section-id" id="section-id" />
977 geraldo 1364
                <div class="modal-content">
1365
                    <div class="modal-header">
993 geraldo 1366
                        <h4 class="modal-title">LABEL_ADD LABEL_SECTION</h4>
977 geraldo 1367
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1368
                            <span aria-hidden="true">&times;</span>
1369
                        </button>
1370
                    </div>
1371
                    <div class="modal-body">
1372
                        <div class="form-group">
995 geraldo 1373
                            <label for="section-text">LABEL_TEXT</label>
977 geraldo 1374
                            <!--  ckeditor -->
995 geraldo 1375
                            <textarea  name="section-text" id="section-text" rows="5" class="ckeditor form-control"></textarea>
977 geraldo 1376
                        </div>
1377
                        <div class="form-group">
995 geraldo 1378
                            <label for="section-value">LABEL_VALUE</label>
1379
                            <input type="text" name="section-value" id="section-value"  class="form-control" />
990 geraldo 1380
                        </div>
1381
                        <div class="form-group">
995 geraldo 1382
                            <label for="section-type">LABEL_TYPE</label>
1383
                            <select name="section-type" id="section-type" class="form-control">
977 geraldo 1384
                                <option value="open">LABEL_OPEN</option>
1385
                                <option value="simple">Simple</option>
1386
                                <option value="multiple">Multiple</option>
1387
                            </select>
1388
                        </div>
1389
                        <div class="form-group">
995 geraldo 1390
                            <label for="section-max-length">LABEL_MAXLENGTH</label>
1391
                            <input type="text" name="section-max-length" id="section-max-length"  class="form-control" />
977 geraldo 1392
                        </div>
1393
                        <div class="form-group">
995 geraldo 1394
                            <label for="section-multiline">LABEL_MULTI_LINE</label>
1395
                            <select name="section-multiline" id="section-multiline" class="form-control">
977 geraldo 1396
                                <option value="1">LABEL_YES</option>
1397
                                <option value="0">LABEL_NOT</option>
1398
                            </select>
1399
                        </div>
1400
                    </div>
1401
                    <div class="modal-footer">
1402
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
1403
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1404
                    </div>
1405
                </div>
1406
            </form>
1407
        </div>
1408
    </div>
1409
 
1410
    <!-- End Modal Question -->
1411
 
1412
    <!-- Modal Options -->
1413
 
1414
    <div  id="modal-option" class="modal" tabindex="-1" role="dialog">
1415
        <div class="modal-dialog modal-lg" role="document">
1416
            <form action="#" name="form-option" id="form-option">
1417
                <input type="hidden" name="option-section" id="option-section" value="" />
1418
                <input type="hidden" name="option-question" id="option-question" value="" />
1419
                <input type="hidden" name="option-slug" id="option-slug" value="" />
1420
                <div class="modal-content">
1421
                    <div class="modal-header">
1422
                        <h4 class="modal-title">LABEL_OPTION</h4>
1423
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1424
                            <span aria-hidden="true">&times;</span>
1425
                        </button>
1426
                    </div>
1427
                    <div class="modal-body">
1428
                        <div class="form-group">
1429
                            <label for="option-text">LABEL_TEXT</label>
1430
                            <!--  ckeditor -->
1431
                            <textarea  name="option-text" id="option-text" rows="5" class="ckeditor form-control"></textarea>
1432
                        </div>
1433
                    </div>
1434
                    <div class="modal-footer">
1435
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
1436
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1437
                    </div>
1438
                </div>
1439
            </form>
1440
        </div>
1441
    </div>
1442
 
1443
    <!-- End Modal Options -->
1444
 
1445
    <!---Template Sections --->
1446
    <script id="sectionTemplate" type="text/x-jsrender">
1447
    <div class="panel panel-default" id="panel-{{:slug_section}}">
1448
        <div class="panel-heading">
1449
            <h4 class="panel-title">
1450
                <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:slug_section}}" href="#collapse-{{:slug_section}}">
1451
                    <span class="section-name{{:slug_section}}">
1452
                        {{:name}}
1453
                    </span>
1454
                </a>
1455
            </h4>
1456
        </div>
1457
        <div id="collapse-{{:slug_section}}" class="panel-collapse in collapse show">
1458
            <div class="panel-body">
1459
                <div class="table-responsive">
1460
                    <table class="table table-bordered">
1461
                        <thead>
1462
                            <tr>
1463
                                <th style="width: 10%;">LABEL_ELEMENT</th>
1464
                                <th style="width: 50%;">LABEL_TEXT</th>
1465
                                <th style="width: 10%;">LABEL_VALUE</th>
1466
                                <th style="width: 10%;">LABEL_TYPE</th>
1467
                                <th style="width: 20%;">LABEL_ACTIONS</th>
1468
                            </tr>
1469
                        </thead>
1470
                        <tbody>
1471
                            <tr class="tr-section">
1472
                                <td class="text-left">LABEL_SECTION</td>
1473
                                <td class="text-left">{{:name}}</td>
1474
                                <td>{{:value}}</td>
1475
                                <td></td>
1476
                                <td>
1477
                                    <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>
1478
                                    <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>
993 geraldo 1479
                                    <button class="btn btn-default btn-add-question" data-section="{{:slug_section}}" data-toggle="tooltip"  data-original-title="LABEL_ADD  LABEL_SECTION"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_ADD  LABEL_SECTION </button>
977 geraldo 1480
                                </td>
1481
                            </tr>
1482
                            {{for questions}}
1483
                            <tr class="tr-question">
993 geraldo 1484
                                <td class="text-left">--LABEL_SECTION</td>
977 geraldo 1485
                                <td class="text-left">
1486
                                    {{:~removeTags(text)}}
1487
                                </td>
1488
                                <td><font color="red">{{:value}}</font></td>
1489
                                <td class="text-capitalize">
1490
                                    {{if type == 'open'}} LABEL_OPEN {{/if}}
1491
                                    {{if type == 'simple'}} Simple {{/if}}
1492
                                    {{if type == 'multiple'}} Multiple {{/if}}
1493
                                    {{if type == 'rating-open'}} LABEL_RATING_OPEN {{/if}}
1494
                                    {{if type == 'rating-range'}} LABEL_RATING_RANGE {{/if}}
1495
                                </td>
1496
                                <td>
993 geraldo 1497
                                    <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_SECTION"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_SECTION</button>
1498
                                    <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_SECTION"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_SECTION</button>
977 geraldo 1499
 
1500
                                    {{if type == 'simple' || type == 'rating-open' || type=='multiple' }}
1501
                                    <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>
1502
                                    {{/if}}
1503
 
1504
                                </td>
1505
                            </tr>
1506
                            {{for options}}
1507
                            <tr class="tr-option">
1508
                                <td class="text-left">---LABEL_OPTION</td>
1509
                                <td class="text-left">
1510
                                    {{:~removeTags(text)}}
1511
                                </td>
1512
                                <td>
1513
 
1514
                                    {{if ~getType( slug_section, slug_question) == 'multiple' || ~getType( slug_section, slug_question) == 'rating-open'  }}
1515
                                    {{:value}}
1516
                                    {{/if}}
1517
                                </td>
1518
                                <td class="text-left">
1519
                                    {{if ~getType( slug_section, slug_question) != 'rating-open'}}
1520
                                    {{if correct == 1}}
1521
                                    <font color="green">LABEL_CORRECT</font>
1522
                                    {{/if}}
1523
                                    {{if correct == 0}}
1524
                                    <font color="red">LABEL_FAIL</font>
1525
                                    {{/if}}
1526
                                    {{/if}}
1527
                                </td>
1528
                                <td>
1529
                                    <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>
1530
                                    <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>
1531
                                </td>
1532
                            </tr>
1533
                            {{/for}}
1534
                            {{/for}}
1535
                        </tbody>
1536
                    </table>
1537
                </div>
1538
            </div>
1539
        </div>
1540
    </div>
1541
    </script>
1542
 
1543
    <!-- End Template Sections-->
1544
 
1545
</section>