Proyectos de Subversion LeadersLinked - Backend

Rev

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