Proyectos de Subversion LeadersLinked - Backend

Rev

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