Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 198 | Rev 200 | 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();
199 geraldo 779
                            instanceName = 'form-text';
780
                            let editor = CKEDITOR.instances[instanceName];
781
                            instanceName = 'form-description';
782
                            CKEDITOR.instances[instanceName].setData('');
198 geraldo 783
                            clearSectionData();
784
 
167 geraldo 785
                        } else {
786
                            $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
787
                        }
788
                    }).fail(function(jqXHR, textStatus, errorThrown) {
789
                        $.fn.showError(textStatus);
790
                    });
791
                    return false;
792
                }
793
            }
794
        }
795
    });
796
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
797
    $("#form-section").on('submit', function() {
798
        for (var instanceName in CKEDITOR.instances) {
799
            CKEDITOR.instances[instanceName].updateElement();
800
        }
801
    })
802
    var validatorFormSection = $("#form-section").validate({
118 steven 803
        ignore: [],
804
        errorClass: 'help-block',
805
        errorElement: 'span',
167 geraldo 806
        rules: {
807
            'section-name': {
808
                required: true,
809
                minlength: 2,
810
                maxlength: 50
811
            },
812
            'section-text': {
813
                required: false,
814
            },
815
            'section-value': {
816
                required: true,
817
                number: true,
818
                min: 1
819
            },
820
        },
821
        highlight: function(element) {
118 steven 822
            $(element).closest('.form-group').addClass('has-error');
823
        },
167 geraldo 824
        unhighlight: function(element) {
118 steven 825
            $(element).closest('.form-group').removeClass('has-error');
826
        },
167 geraldo 827
        errorPlacement: function(error, element) {
118 steven 828
            if (element.attr("data-error-container")) {
829
                error.appendTo(element.attr("data-error-container"));
830
            } else {
831
                error.insertAfter(element);
832
            }
833
        },
834
        invalidHandler: function(form, validator) {
835
            if (!validator.numberOfInvalids())
836
                return;
837
            $('html, body').animate({
838
                scrollTop: $(validator.errorList[0].element).offset().top - 100
839
            }, 1000);
840
        },
167 geraldo 841
        submitHandler: function(form) {
842
            // do other things for a valid form
843
            //form.submit();
844
            var slug = $('#form-section #section-slug').val();
845
            if (slug) {
846
                objFormGenerator.editSection(
847
                    $('#form-section #section-slug').val(),
848
                    $('#form-section #section-name').val(),
849
                    $('#form-section #section-text').val(),
850
                    $('#form-section #section-value').val()
851
                );
852
            } else {
853
                objFormGenerator.addSection(
854
                    $('#form-section #section-name').val(),
855
                    $('#form-section #section-text').val(),
856
                    $('#form-section #section-value').val()
857
                );
858
            }
196 geraldo 859
            renderSectionData(objFormGenerator.sections);
167 geraldo 860
            $('#modal-section').modal('hide');
861
            return false;
862
        }
863
    });
864
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
865
    $("#form-question").on('submit', function() {
866
        for (var instanceName in CKEDITOR.instances) {
867
            CKEDITOR.instances[instanceName].updateElement();
868
        }
869
    })
870
    var validatorFormQuestion = $("#form-question").validate({
118 steven 871
        ignore: [],
872
        errorClass: 'help-block',
873
        errorElement: 'span',
167 geraldo 874
        rules: {
875
            'question-text': {
876
                required: true,
877
            },
878
            'question-value': {
879
                required: true,
880
                number: true,
881
                min: 1
882
            },
883
            'question-type': {
884
                required: true,
885
            },
886
            'question-max-length': {
887
                required: true,
888
                digits: true,
889
                min: 0
890
            },
891
            'question-range': {
892
                required: true,
893
                number: true,
894
                min: 1
895
            },
896
        },
897
        highlight: function(element) {
118 steven 898
            $(element).closest('.form-group').addClass('has-error');
899
        },
167 geraldo 900
        unhighlight: function(element) {
118 steven 901
            $(element).closest('.form-group').removeClass('has-error');
902
        },
167 geraldo 903
        errorPlacement: function(error, element) {
118 steven 904
            if (element.attr("data-error-container")) {
905
                error.appendTo(element.attr("data-error-container"));
906
            } else {
907
                error.insertAfter(element);
908
            }
909
        },
910
        invalidHandler: function(form, validator) {
911
            if (!validator.numberOfInvalids())
912
                return;
913
            $('html, body').animate({
914
                scrollTop: $(validator.errorList[0].element).offset().top - 100
915
            }, 1000);
916
        },
167 geraldo 917
        submitHandler: function(form) {
918
            if ($('#form-question #question-slug').val()) {
919
                objFormGenerator.editQuestion(
920
                    $('#form-question #question-section').val(),
921
                    $('#form-question #question-slug').val(),
922
                    $('#form-question #question-text').val(),
923
                    $('#form-question #question-value').val(),
924
                    $('#form-question #question-type').val(),
925
                    $('#form-question #question-max-length').val(),
926
                    $('#form-question #question-multiline').val(),
927
                    $('#form-question #question-range').val()
928
                );
929
            } else {
930
                objFormGenerator.addQuestion(
931
                    $('#form-question #question-section').val(),
932
                    $('#form-question #question-text').val(),
933
                    $('#form-question #question-value').val(),
934
                    $('#form-question #question-type').val(),
935
                    $('#form-question #question-max-length').val(),
936
                    $('#form-question #question-multiline').val(),
937
                    $('#form-question #question-range').val()
938
                );
939
            }
196 geraldo 940
            renderSectionData(objFormGenerator.sections);
167 geraldo 941
            $('#modal-question').modal('hide');
942
            return false;
943
        }
944
    });
945
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
946
    $("#form-option").on('submit', function() {
947
        for (var instanceName in CKEDITOR.instances) {
948
            CKEDITOR.instances[instanceName].updateElement();
949
        }
950
    })
951
    var validatorFormOption = $("#form-option").validate({
118 steven 952
        ignore: [],
953
        errorClass: 'help-block',
954
        errorElement: 'span',
167 geraldo 955
        rules: {
956
            'option-text': {
957
                required: true,
958
            },
959
            'option-value': {
960
                required: true,
961
                number: true,
962
                min: 1
963
            }
964
        },
965
        highlight: function(element) {
118 steven 966
            $(element).closest('.form-group').addClass('has-error');
967
        },
167 geraldo 968
        unhighlight: function(element) {
118 steven 969
            $(element).closest('.form-group').removeClass('has-error');
970
        },
167 geraldo 971
        errorPlacement: function(error, element) {
118 steven 972
            if (element.attr("data-error-container")) {
973
                error.appendTo(element.attr("data-error-container"));
974
            } else {
975
                error.insertAfter(element);
976
            }
977
        },
978
        invalidHandler: function(form, validator) {
979
            if (!validator.numberOfInvalids())
980
                return;
981
            $('html, body').animate({
982
                scrollTop: $(validator.errorList[0].element).offset().top - 100
983
            }, 1000);
984
        },
167 geraldo 985
        submitHandler: function(form) {
986
            if ($('#form-option #option-slug').val()) {
987
                objFormGenerator.editOption(
988
                    $('#form-option #option-section').val(),
989
                    $('#form-option #option-question').val(),
990
                    $('#form-option #option-slug').val(),
991
                    $('#form-option #option-text').val(),
992
                    $('#form-option #option-correct').val(),
184 geraldo 993
                    $('#form-option #option-value').val()
167 geraldo 994
                );
995
            } else {
996
                objFormGenerator.addOption(
997
                    $('#form-option #option-section').val(),
998
                    $('#form-option #option-question').val(),
999
                    $('#form-option #option-text').val(),
1000
                    $('#form-option #option-correct').val(),
184 geraldo 1001
                    $('#form-option #option-value').val()
167 geraldo 1002
                );
1003
            }
196 geraldo 1004
            renderSectionData(objFormGenerator.sections);
167 geraldo 1005
            $('#modal-option').modal('hide');
1006
            return false;
1007
        }
1008
    });
1009
    $('body').on('click', 'button[id="btn-add-section"]', function(e) {
1010
        e.preventDefault();
1011
        validatorFormSection.resetForm();
1012
        $('#form-section #section-slug').val('');
1013
        $('#form-section #section-name').val('');
1014
        instanceName = 'section-text';
1015
        let editor = CKEDITOR.instances[instanceName];
1016
        editor.setData('', function() {
1017
            editor.focus();
1018
        });
1019
        $('#form-section #section-value').val('0');
1020
        $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
1021
        $('#modal-section').modal('show');
1022
    });
1023
    $('body').on('click', 'button.btn-edit-section', function(e) {
1024
        e.preventDefault();
169 geraldo 1025
        var slug = $(this).data('section');
167 geraldo 1026
        var section;
1027
        var showForm = false;
1028
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1029
            section = objFormGenerator.sections[i];
171 geraldo 1030
            if (slug == section.slug_section) {
167 geraldo 1031
                validatorFormSection.resetForm();
171 geraldo 1032
                $('#form-section #section-slug').val(section.slug_section);
167 geraldo 1033
                $('#form-section #section-name').val(section.name);
1034
                instanceName = 'section-text';
1035
                let editor = CKEDITOR.instances[instanceName];
1036
                editor.setData(section.text, function() {
1037
                    editor.focus();
1038
                });
1039
                $('#form-section #section-value').val(section.value);
1040
                showForm = true;
1041
                break;
1042
            }
1043
        }
1044
        if (showForm) {
1045
            $('#modal-section h4[class="modal-title"]').html('LABEL_EDIT LABEL_SECTION');
1046
            $('#modal-section').modal('show');
1047
        }
1048
    });
1049
    $('body').on('click', 'button.btn-delete-section', function(e) {
1050
        e.preventDefault();
169 geraldo 1051
        var slug = $(this).data('section');
167 geraldo 1052
        bootbox.confirm({
1053
            title: "LABEL_DELETE LABEL_SECTION",
1054
            message: "LABEL_QUESTION_DELETE",
1055
            buttons: {
1056
                cancel: {
1057
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1058
                },
1059
                confirm: {
1060
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1061
                }
1062
            },
1063
            callback: function(result) {
1064
                if (result) {
1065
                    objFormGenerator.deleteSection(slug);
196 geraldo 1066
                    renderSectionData(objFormGenerator.sections);
167 geraldo 1067
                }
1068
            }
1069
        });
1070
    });
1071
    $('body').on('click', 'button.btn-add-question', function(e) {
1072
        e.preventDefault();
1073
        validatorFormQuestion.resetForm();
169 geraldo 1074
        var slug = $(this).data('section');
167 geraldo 1075
        $('#form-question #question-section').val(slug);
1076
        $('#form-question #question-slug').val('');
1077
        instanceName = 'question-text';
1078
        let editor = CKEDITOR.instances[instanceName];
1079
        editor.setData('', function() {
1080
            editor.focus();
1081
        });
1082
        $('#form-question #question-value').val('0');
1083
        $('#form-question #question-type').val($('#form-question #question-type option:first').val());
1084
        $('#form-question #question-max-length').val('0');
1085
        $('#form-question #question-max-length').parent().show();
1086
        $('#form-question #question-multiline').val('0');
1087
        $('#form-question #question-multiline').parent().show();
1088
        $('#form-question #question-range').val('10');
1089
        $('#form-question #question-range').parent().hide();
1090
        $('#modal-question h4[class="modal-title"]').html('LABEL_ADD LABEL_QUESTION');
1091
        $('#modal-question').modal('show');
1092
    });
1093
    $('body').on('click', 'button.btn-edit-question', function(e) {
1094
        e.preventDefault();
1095
        var slug_section = $(this).data('section');
170 geraldo 1096
        var slug = $(this).data('question');
167 geraldo 1097
        var showForm = false;
1098
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1099
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1100
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1101
                    if (slug == objFormGenerator.sections[i].questions[j].slug_question) {
1102
                        validatorFormQuestion.resetForm();
1103
                        $('#form-question #question-section').val(objFormGenerator.sections[i].slug_section);
1104
                        $('#form-question #question-slug').val(objFormGenerator.sections[i].questions[j].slug_question);
1105
                        instanceName = 'question-text';
1106
                        let editor = CKEDITOR.instances[instanceName];
1107
                        editor.setData(objFormGenerator.sections[i].questions[j].text, function() {
1108
                            editor.focus();
1109
                        });
1110
                        $('#form-question #question-value').val(objFormGenerator.sections[i].questions[j].value);
1111
                        $('#form-question #question-type').val(objFormGenerator.sections[i].questions[j].type);
1112
                        if (objFormGenerator.sections[i].questions[j].type == 'open') {
1113
                            $('#form-question #question-max-length').val(objFormGenerator.sections[i].questions[j].maxlength);
1114
                            $('#form-question #question-max-length').parent().show();
1115
                            $('#form-question #question-multiline').val(objFormGenerator.sections[i].questions[j].multiline);
1116
                            $('#form-question #question-multiline').parent().show();
118 steven 1117
                        } else {
167 geraldo 1118
                            $('#form-question #question-max-length').val('0');
1119
                            $('#form-question #question-max-length').parent().hide();
1120
                            $('#form-question #question-multiline').val('0');
1121
                            $('#form-question #question-multiline').parent().hide();
118 steven 1122
                        }
167 geraldo 1123
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-range') {
1124
                            $('#form-question #question-range').val(objFormGenerator.sections[i].questions[j].range);
1125
                            $('#form-question #question-range').parent().show();
1126
                        } else {
1127
                            $('#form-question #question-range').val('10');
1128
                            $('#form-question #question-range').parent().hide();
1129
                        }
1130
                        showForm = true;
1131
                        break;
1132
                    }
1133
                }
1134
                break;
1135
            }
1136
        }
1137
        if (showForm) {
1138
            $('#modal-question h4[class="modal-title"]').html('LABEL_EDIT LABEL_QUESTION');
1139
            $('#modal-question').modal('show');
1140
        }
1141
    });
1142
    $('body').on('click', 'button.btn-delete-question', function(e) {
1143
        e.preventDefault();
1144
        var slug_section = $(this).data('section');
170 geraldo 1145
        var slug = $(this).data('question');
167 geraldo 1146
        bootbox.confirm({
1147
            title: "LABEL_DELETE LABEL_QUESTION",
1148
            message: "LABEL_QUESTION_DELETE",
1149
            buttons: {
1150
                cancel: {
1151
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1152
                },
1153
                confirm: {
1154
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1155
                }
1156
            },
1157
            callback: function(result) {
1158
                if (result) {
1159
                    objFormGenerator.deleteQuestion(slug_section, slug);
196 geraldo 1160
                    renderSectionData(objFormGenerator.sections);
167 geraldo 1161
                }
1162
            }
1163
        });
1164
    });
172 geraldo 1165
 
180 geraldo 1166
     /**
1167
      * Get Question type
1168
      */
181 geraldo 1169
     const getQuestionTypeBySlug = (slug_section, slug_question) => {
180 geraldo 1170
         for (i = 0; i < objFormGenerator.sections.length; i++) {
1171
             if (slug_section == objFormGenerator.sections[i].slug_section) {
1172
                 for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1173
                     if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1174
                         return objFormGenerator.sections[i].questions[j].type;
1175
                     }
1176
                 }
1177
             }
1178
         }
1179
     }
1180
 
1181
     /**
1182
      * Render Sections data
1183
      */
196 geraldo 1184
     const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
180 geraldo 1185
         getType: getQuestionTypeBySlug
1186
     }));
196 geraldo 1187
 
1188
     /**
1189
      * Clear Div Section data
1190
      */
197 geraldo 1191
     const clearSectionData = () => $("#rows").html('');
180 geraldo 1192
 
167 geraldo 1193
    $('body').on('click', 'button.btn-add-option', function(e) {
1194
        e.preventDefault();
1195
        var slug_section = $(this).data('section');
1196
        var slug_question = $(this).data('question');
1197
        var showForm = false;
1198
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1199
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1200
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1201
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1202
                        validatorFormOption.resetForm();
1203
                        $('#form-option #option-section').val(slug_section);
1204
                        $('#form-option #option-question').val(slug_question);
1205
                        $('#form-option #option-slug').val('');
1206
                        instanceName = 'option-text';
1207
                        let editor = CKEDITOR.instances[instanceName];
1208
                        editor.setData('', function() {
1209
                            editor.focus();
1210
                        });
1211
                        $('#form-option #option-correct').val('0');
1212
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1213
                            $('#form-option #option-correct').parent().hide();
1214
                        } else {
1215
                            $('#form-option #option-correct').parent().show();
1216
                        }
1217
                        if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1218
                            $('#form-option #option-value').val('0');
1219
                            $('#form-option #option-value').parent().show();
1220
                        } else {
1221
                            $('#form-option #option-value').val('1');
1222
                            $('#form-option #option-value').parent().hide();
1223
                        }
196 geraldo 1224
                        renderSectionData(objFormGenerator.sections);
167 geraldo 1225
                        showForm = true;
1226
                    }
1227
                }
1228
            }
1229
        }
1230
        if (showForm) {
1231
            $('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
1232
            $('#modal-option').modal('show');
1233
        }
1234
    });
171 geraldo 1235
 
167 geraldo 1236
    $('body').on('click', 'button.btn-edit-option', function(e) {
1237
        e.preventDefault();
1238
        var slug_section = $(this).data('section');
1239
        var slug_question = $(this).data('question');
1240
        var slug = $(this).data('slug');
1241
        var showForm = false;
1242
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1243
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1244
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1245
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1246
                        for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
1247
                            if (slug == objFormGenerator.sections[i].questions[j].options[k].slug_option) {
1248
                                validatorFormOption.resetForm();
1249
                                $('#form-option #option-section').val(objFormGenerator.sections[i].slug_section);
1250
                                $('#form-option #option-question').val(objFormGenerator.sections[i].questions[j].slug_question);
1251
                                $('#form-option #option-slug').val(objFormGenerator.sections[i].questions[j].options[k].slug_option);
1252
                                instanceName = 'option-text';
1253
                                let editor = CKEDITOR.instances[instanceName];
1254
                                editor.setData(objFormGenerator.sections[i].questions[j].options[k].text, function() {
1255
                                    editor.focus();
1256
                                });
1257
                                $('#form-option #option-correct').val(objFormGenerator.sections[i].questions[j].options[k].correct);
1258
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'simple') {
1259
                                    $('#form-option #option-correct').parent().show();
1260
                                } else {
1261
                                    $('#form-option #option-correct').parent().hide();
1262
                                }
1263
                                $('#form-option #option-value').val(objFormGenerator.sections[i].questions[j].options[k].value);
1264
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1265
                                    $('#form-option #option-value').parent().show();
1266
                                } else {
1267
                                    $('#form-option #option-value').parent().hide();
1268
                                }
1269
                                showForm = true;
1270
                                break;
1271
                            }
1272
                        }
1273
                    }
1274
                    if (showForm) {
1275
                        break;
1276
                    }
1277
                }
1278
            }
1279
            if (showForm) {
1280
                break;
1281
            }
1282
        }
1283
        if (showForm) {
1284
            $('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
1285
            $('#modal-option').modal('show');
1286
        }
1287
    });
1288
    $('body').on('click', 'button.btn-delete-option', function(e) {
1289
        e.preventDefault();
1290
        var slug_section = $(this).data('section');
1291
        var slug_question = $(this).data('question');
1292
        var slug = $(this).data('slug');
1293
        bootbox.confirm({
1294
            title: "LABEL_DELETE LABEL_OPTION",
1295
            message: "LABEL_QUESTION_DELETE",
1296
            buttons: {
1297
                cancel: {
1298
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1299
                },
1300
                confirm: {
1301
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1302
                }
1303
            },
1304
            callback: function(result) {
1305
                if (result) {
1306
                    objFormGenerator.deleteOption(slug_section, slug_question, slug);
196 geraldo 1307
                    renderSectionData(objFormGenerator.sections);
167 geraldo 1308
                }
1309
            }
1310
        });
1311
    })
1312
    $('#form-section #section-value').inputNumberFormat({
1313
        'decimal': 2
1314
    });
1315
    $('#form-question #question-value').inputNumberFormat({
1316
        'decimal': 2
1317
    });
1318
    $('#form-question #question-max-length').inputNumberFormat({
1319
        'decimal': 0
1320
    });
1321
    $('#form-option #option-value').inputNumberFormat({
1322
        'decimal': 2
1323
    });
1324
    $('#form-question #question-type').change(function(e) {
1325
        e.preventDefault();
1326
        if ($('#form-question #question-type').val() == 'open') {
1327
            $('#form-question #question-max-length').parent().show();
1328
            $('#form-question #question-multiline').parent().show();
1329
        } else {
1330
            $('#form-question #question-max-length').val('0');
1331
            $('#form-question #question-max-length').parent().hide();
1332
            $('#form-question #question-multiline').val('0');
1333
            $('#form-question #question-multiline').parent().hide();
1334
        }
1335
        $('#form-question #question-range').val('10');
1336
        if ($('#form-question #question-type').val() == 'rating-range') {
1337
            $('#form-question #question-range').parent().show();
1338
        } else {
1339
            $('#form-question #question-range').parent().hide();
1340
        }
1341
    });
1342
    $('button.btn-add-form').click(function(e) {
1343
        e.preventDefault();
1344
        objFormGenerator.clear();
1345
        objFormGenerator.render();
1346
        validatorForm.resetForm();
196 geraldo 1347
        clearSectionData();
167 geraldo 1348
        $('#form-main #form-id').val('0');
1349
        $('#form-main #form-continue').val('0');
1350
        $('#form-main #form-name').val('');
1351
        instanceName = 'form-text';
1352
        let editor = CKEDITOR.instances[instanceName];
1353
        instanceName = 'form-description';
1354
        CKEDITOR.instances[instanceName].setData('');
1355
        $('#form-main #form-language').val('$lang_es'),
1356
            $('#form-main #form-status').val('$status_inactive');
1357
        $('#row-forms').hide();
1358
        $('#row-edit').show();
1359
        $('#form-main #form-name').focus();
1360
    });
1361
    $('button.btn-edit-cancel').click(function(e) {
1362
        e.preventDefault();
1363
        $('#row-edit').hide();
1364
        $('#row-forms').show();
1365
    });
1366
    $('button.btn-form-save-continue').click(function(e) {
1367
        e.preventDefault();
1368
        $('#form-main #form-continue').val('1')
1369
        $('#form-main').submit();
1370
    });
1371
    $('button.btn-form-save-close').click(function(e) {
1372
        e.preventDefault();
1373
        $('#form-main #form-continue').val('0')
1374
        $('#form-main').submit();
1375
    });
1376
    $('#modal-section, #modal-question, #modal-option').modal({
1377
        backdrop: 'static',
1378
        keyboard: false,
1379
        show: false
1380
    });
1381
});
118 steven 1382
JS;
115 efrain 1383
$this->inlineScript()->captureEnd();
1384
?>
118 steven 1385
 
115 efrain 1386
<!-- Content Header (Page header) -->
1387
<section class="content-header">
135 geraldo 1388
    <div class="container-fluid">
1389
        <div class="row mb-2">
1390
            <div class="col-sm-12">
1391
                <h1>LABEL_SELF_EVALUATION_FORMS</h1>
1392
            </div>
1393
        </div>
145 geraldo 1394
    </div>
1395
    <!-- /.container-fluid -->
115 efrain 1396
</section>
1397
<section class="content">
135 geraldo 1398
    <div class="container-fluid" id="row-forms">
1399
        <div class="row">
1400
            <div class="col-12">
145 geraldo 1401
                <div class="card">
135 geraldo 1402
                    <div class="card-body">
153 geraldo 1403
                        <table id="gridTable" class="table   table-hover">
1404
                            <thead>
1405
                                <tr>
1406
                                    <th>LABEL_NAME</th>
1407
                                    <th>LABEL_LANGUAGE</th>
1408
                                    <th>LABEL_ACTIVE</th>
1409
                                    <th>LABEL_ACTIONS</th>
1410
                                </tr>
1411
                            </thead>
155 geraldo 1412
                            <tbody></tbody>
153 geraldo 1413
                        </table>
135 geraldo 1414
                    </div>
1415
                    <div class="card-footer clearfix">
1416
                        <div style="float:right;">
1417
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
1418
                            <?php if ($allowAdd) : ?>
1419
                                <button type="button" class="btn btn-primary btn-add-form"><i class="fa fa-plus"></i> LABEL_ADD </button>
1420
                            <?php endif; ?>
1421
                        </div>
1422
                    </div>
1423
                </div>
145 geraldo 1424
            </div>
1425
        </div>
135 geraldo 1426
    </div>
154 geraldo 1427
 
155 geraldo 1428
    <!-- Create/Edit Form -->
174 geraldo 1429
 
1430
    <div class="row" id="row-edit" style="display: none">
1431
        <div class="col-xs-12 col-md-12">
1432
            <form action="#" name="form-main" id="form-main">
1433
                <input type="hidden" name="form-id" id="form-id" value="0" />
1434
                <input type="hidden" name="form-continue" id="form-continue" value="0" />
1435
                <div class="form-group">
1436
                    <label for="form-name">LABEL_FIRST_NAME</label>
1437
                    <input type="text" name="form-name" id="form-name" class="form-control" maxlength="50" />
1438
                </div>
1439
                <div class="form-group">
1440
                    <label for="form-description">LABEL_DESCRIPTION</label>
1441
                    <!--  ckeditor -->
1442
                    <textarea  name="form-description" id="form-description" rows="5" class="ckeditor form-control"></textarea>
1443
                </div>
1444
                <div class="form-group">
1445
                    <label for="form-text">LABEL_TEXT</label>
1446
                    <!--  ckeditor -->
1447
                    <textarea  name="form-text" id="form-text" rows="5" class="ckeditor form-control"></textarea>
1448
                </div>
1449
                <div class="form-group">
1450
                    <label for="form-language">LABEL_LANGUAGES</label>
1451
                    <select name="form-language" id="form-language" class="form-control">
176 geraldo 1452
                        <option value="<?php echo $lang_en; ?>">LABEL_ENGLISH</option>
1453
                        <option value="<?php echo $lang_es; ?>">LABEL_SPANISH</option>
174 geraldo 1454
                    </select>
1455
                </div>
1456
                <div class="form-group">
1457
                    <label for="form-status">LABEL_STATUS</label>
1458
                    <select name="form-status" id="form-status" class="form-control">
176 geraldo 1459
                        <option value="<?php echo $status_inactive; ?>">LABEL_INACTIVE</option>
1460
                        <option value="<?php echo $status_active; ?>">LABEL_ACTIVE</option>
174 geraldo 1461
                    </select>
1462
                </div>
1463
                <br/>
1464
                <div class="row">
1465
                    <div class="col-xs-12 col-md-12 text-right">
1466
                        <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>
1467
                    </div>
1468
                </div>
1469
                <br />
1470
                <div class="row">
1471
                    <div class="col-xs-12 col-md-12">
1472
                        <div class="panel-group" id="rows"></div>
1473
                    </div>
1474
                </div>
1475
                <div class="form-group">
1476
                    <button type="submit" form="form-main" class="btn btn-info btn-form-save-continue">LABEL_SAVE & LABEL_CONTINUE</button>
1477
                    <button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE & LABEL_CLOSE</button>
1478
                    <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
1479
                </div>
1480
            </form>
1481
        </div>
1482
    </div>
1483
 
155 geraldo 1484
    <!-- Create/Edit Form-->
154 geraldo 1485
 
135 geraldo 1486
    <!-- Section Modal -->
174 geraldo 1487
    <div  id="modal-section" class="modal" tabindex="-1" role="dialog">
1488
        <div class="modal-dialog modal-lg" role="document">
1489
            <form action="#" name="form-section" id="form-section">
1490
                <input type="hidden" name="section-slug" id="section-slug" value="" />
1491
                <div class="modal-content">
1492
                    <div class="modal-header">
1493
                        <h4 class="modal-title">LABEL_ADD LABEL_SECTION</h4>
1494
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1495
                            <span aria-hidden="true">&times;</span>
1496
                        </button>
1497
                    </div>
1498
                    <div class="modal-body">
1499
                        <div class="form-group">
1500
                            <label for="section-name">LABEL_FIRST_NAME</label>
1501
                            <input type="text" name="section-name" id="section-name" class="form-control" maxlength="50" value="" />
1502
                        </div>
1503
                        <div class="form-group">
1504
                            <label for="section-text">LABEL_TEXT</label>
1505
                            <!--  ckeditor -->
1506
                            <textarea  name="section-text" id="section-text" rows="5" class="ckeditor form-control"></textarea>
1507
                        </div>
1508
                        <div class="form-group">
1509
                            <label for="section-value">LABEL_VALUE</label>
1510
                            <input type="text" name="section-value" id="section-value"  class="form-control" value="0" />
1511
                        </div>
1512
                    </div>
1513
                    <div class="modal-footer">
1514
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
1515
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1516
                    </div>
1517
                </div>
1518
            </form>
1519
        </div>
1520
    </div>
135 geraldo 1521
    <!-- End Modal Section -->
153 geraldo 1522
 
135 geraldo 1523
    <!-- Question Modal -->
156 geraldo 1524
 
174 geraldo 1525
    <div  id="modal-question" class="modal" tabindex="-1" role="dialog">
1526
        <div class="modal-dialog modal-lg" role="document">
1527
            <form action="#" name="form-question" id="form-question">
1528
                <input type="hidden" name="question-section" id="question-section" />
1529
                <input type="hidden" name="question-slug" id="question-slug" />
1530
                <div class="modal-content">
1531
                    <div class="modal-header">
1532
                        <h4 class="modal-title">LABEL_ADD LABEL_QUESTION</h4>
1533
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1534
                            <span aria-hidden="true">&times;</span>
1535
                        </button>
1536
                    </div>
1537
                    <div class="modal-body">
1538
                        <div class="form-group">
1539
                            <label for="question-text">LABEL_TEXT</label>
1540
                            <!--  ckeditor -->
1541
                            <textarea  name="question-text" id="question-text" rows="5" class="ckeditor form-control"></textarea>
1542
                        </div>
1543
                        <div class="form-group">
1544
                            <label for="question-value">LABEL_VALUE</label>
1545
                            <input type="text" name="question-value" id="question-value"  class="form-control" />
1546
                        </div>
1547
                        <div class="form-group">
1548
                            <label for="question-type">LABEL_TYPE</label>
1549
                            <select name="question-type" id="question-type" class="form-control">
1550
                                <option value="open">LABEL_OPEN</option>
1551
                                <option value="simple">Simple</option>
1552
                                <option value="multiple">Multiple</option>
1553
                                <option value="rating-open">LABEL_RATING_OPEN</option>
1554
                                <option value="rating-range">LABEL_RATING_RANGE</option>
1555
                            </select>
1556
                        </div>
1557
                        <div class="form-group">
1558
                            <label for="question-max-length">LABEL_MAXLENGTH</label>
1559
                            <input type="text" name="question-max-length" id="question-max-length"  class="form-control" />
1560
                        </div>
1561
                        <div class="form-group">
1562
                            <label for="question-multiline">LABEL_MULTI_LINE</label>
1563
                            <select name="question-multiline" id="question-multiline" class="form-control">
1564
                                <option value="1">LABEL_YES</option>
1565
                                <option value="0">LABEL_NOT</option>
1566
                            </select>
1567
                        </div>
1568
                        <div class="form-group">
1569
                            <label for="question-range">LABEL_RANGE</label>
1570
                            <select name="question-range" id="question-range" class="form-control">
1571
                                <option value="10">1-10</option>
1572
                                <option value="6">1-6</option>
1573
                                <option value="5">1-5</option>
1574
                            </select>
1575
                        </div>
1576
                    </div>
1577
                    <div class="modal-footer">
1578
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
1579
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1580
                    </div>
1581
                </div>
1582
            </form>
1583
        </div>
1584
    </div>
156 geraldo 1585
 
167 geraldo 1586
    <!-- End Modal Question -->
153 geraldo 1587
 
1588
    <!-- Modal Options -->
156 geraldo 1589
 
174 geraldo 1590
    <div  id="modal-option" class="modal" tabindex="-1" role="dialog">
1591
        <div class="modal-dialog modal-lg" role="document">
1592
            <form action="#" name="form-option" id="form-option">
1593
                <input type="hidden" name="option-section" id="option-section" value="" />
1594
                <input type="hidden" name="option-question" id="option-question" value="" />
1595
                <input type="hidden" name="option-slug" id="option-slug" value="" />
1596
                <div class="modal-content">
1597
                    <div class="modal-header">
1598
                        <h4 class="modal-title">LABEL_OPTION</h4>
1599
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1600
                            <span aria-hidden="true">&times;</span>
1601
                        </button>
1602
                    </div>
1603
                    <div class="modal-body">
1604
                        <div class="form-group">
1605
                            <label for="option-text">LABEL_TEXT</label>
1606
                            <!--  ckeditor -->
1607
                            <textarea  name="option-text" id="option-text" rows="5" class="ckeditor form-control"></textarea>
1608
                        </div>
1609
                        <div class="form-group">
1610
                            <label for="option-correct">LABEL_ANSWER_CORRECT</label>
1611
                            <select name="option-correct" id="option-correct" class="form-control">
1612
                                <option value="1">LABEL_YES</option>
1613
                                <option value="0">LABEL_NOT</option>
1614
                            </select>
1615
                        </div>
1616
                        <div class="form-group">
1617
                            <label for="option-value">LABEL_VALUE</label>
1618
                            <input type="text" name="option-value" id="option-value" class="form-control" />
1619
                        </div>
1620
                    </div>
1621
                    <div class="modal-footer">
1622
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
1623
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1624
                    </div>
1625
                </div>
1626
            </form>
1627
        </div>
1628
    </div>
1629
 
135 geraldo 1630
    <!-- End Modal Options -->
153 geraldo 1631
 
180 geraldo 1632
    <!---Template Sections --->
1633
    <script id="sectionTemplate" type="text/x-jsrender">
1634
    <div class="panel panel-default" id="panel-{{:slug_section}}">
1635
        <div class="panel-heading">
1636
            <h4 class="panel-title">
1637
                <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:slug_section}}" href="#collapse-{{:slug_section}}">
1638
                    <span class="section-name{{:slug_section}}">
1639
                        {{:name}}
1640
                    </span>
1641
                </a>
1642
            </h4>
1643
        </div>
1644
        <div id="collapse-{{:slug_section}}" class="panel-collapse in collapse show">
1645
            <div class="panel-body">
1646
                <div class="table-responsive">
1647
                    <table class="table table-bordered">
1648
                        <thead>
1649
                            <tr>
1650
                                <th>LABEL_ELEMENT</th>
1651
                                <th>LABEL_TEXT</th>
1652
                                <th>LABEL_VALUE</th>
1653
                                <th>LABEL_TYPE</th>
1654
                                <th>LABEL_ACTIONS</th>
1655
                            </tr>
1656
                        </thead>
1657
                        <tbody>
1658
                            <tr class="tr-section">
1659
                                <td class="text-left">LABEL_SECTION</td>
1660
                                <td class="text-left">{{:name}}</td>
1661
                                <td>{{:value}}</td>
1662
                                <td></td>
1663
                                <td>
1664
                                    <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>
1665
                                    <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>
1666
                                    <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>
1667
                                </td>
1668
                            </tr>
1669
                            {{for questions}}
1670
                            <tr class="tr-question">
1671
                                <td class="text-left">--LABEL_QUESTION</td>
1672
                                <td class="text-left">
1673
                                    {{:text}}
1674
                                </td>
1675
                                <td><font color="red">{{:value}}</font></td>
1676
                                <td class="text-capitalize">
1677
                                    {{if type == 'open'}} LABEL_OPEN {{/if}}
1678
                                    {{if type == 'simple'}} Simple {{/if}}
1679
                                    {{if type == 'multiple'}} Multiple {{/if}}
1680
                                    {{if type == 'rating-open'}} LABEL_RATING_OPEN {{/if}}
1681
                                    {{if type == 'rating-range'}} LABEL_RATING_RANGE {{/if}}
1682
                                </td>
1683
                                <td>
1684
                                    <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>
1685
                                    <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>
1686
                                    <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>
1687
                                </td>
1688
                            </tr>
1689
                            {{for options}}
1690
                            <tr class="tr-option">
1691
                                <td class="text-left">---LABEL_OPTION</td>
1692
                                <td class="text-left">
1693
                                    {{:text}}
1694
                                </td>
1695
                                <td>
153 geraldo 1696
 
186 geraldo 1697
                                    {{if ~getType( slug_section, slug_question) == 'multiple' || ~getType( slug_section, slug_question) == 'rating-open'  }}
1698
                                    {{:value}}
1699
                                    {{/if}}
180 geraldo 1700
                                </td>
1701
                                <td class="text-left">
186 geraldo 1702
                                    {{if ~getType( slug_section, slug_question) != rating-open'}}
1703
                                    {{if correct == 1}}
1704
                                    <font color="green">LABEL_CORRECT</font>
1705
                                    {{/if}}
1706
                                    {{if correct == 0}}
1707
                                    <font color="red">LABEL_FAIL</font>
1708
                                    {{/if}}
1709
                                    {{/if}}
180 geraldo 1710
                                </td>
1711
                                <td>
1712
                                    <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>
1713
                                    <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>
1714
                                </td>
1715
                            </tr>
1716
                            {{/for}}
1717
                            {{/for}}
1718
                        </tbody>
1719
                    </table>
1720
                </div>
1721
            </div>
1722
        </div>
1723
    </div>
1724
    </script>
1725
 
1726
    <!-- End Template Sections-->
1727
 
119 steven 1728
</section>