Proyectos de Subversion LeadersLinked - Backend

Rev

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

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