Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 196 | Rev 198 | 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
 
115 efrain 59
$status_active = \LeadersLinked\Model\CompanySelfEvaluationForm::STATUS_ACTIVE;
144 geraldo 60
$status_inactive = \LeadersLinked\Model\CompanySelfEvaluationForm::STATUS_INACTIVE;
115 efrain 61
 
144 geraldo 62
$lang_es = \LeadersLinked\Model\CompanySelfEvaluationForm::LANGUAGE_SPANISH;
63
$lang_en = \LeadersLinked\Model\CompanySelfEvaluationForm::LANGUAGE_ENGLISH;
153 geraldo 64
 
167 geraldo 65
 
115 efrain 66
$this->inlineScript()->captureStart();
67
echo <<<JS
167 geraldo 68
    const classFormGenerator = function() {
69
    this.id = 0,
70
        this.table = '',
71
        this.name = '',
72
        this.text = '',
73
        this.status = 'a',
74
        this.sections = [],
75
        this.clear = function() {
76
            this.sections = [];
77
            this.render();
78
        },
171 geraldo 79
        this.renderSection = function(slug_section) {
167 geraldo 80
            var s = '';
81
            for (i = 0; i < this.sections.length; i++) {
171 geraldo 82
                if (slug_section != this.sections[i].slug_section) {
167 geraldo 83
                    continue;
84
                }
85
                for (j = 0; j < this.sections[i].questions.length; j++) {
86
                    this.sections[i].questions[j].position = j;
87
                    if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {
88
                        this.sections[i].questions[j].options.sort(function(a, b) {
89
                            if (a.position > b.position) {
90
                                return 1;
91
                            }
92
                            if (a.position < b.position) {
93
                                return -1;
94
                            }
95
                            return 0;
96
                        });
97
                        for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
98
                            this.sections[i].questions[j].options[k].position = j;
99
                        }
100
                    }
101
                }
102
            }
103
            $('[data-toggle="tooltip"]').tooltip();
104
        },
105
        this.render = function() {
106
            this.sections.sort(function(a, b) {
107
                if (a.position > b.position) {
108
                    return 1;
109
                }
110
                if (a.position < b.position) {
111
                    return -1;
112
                }
113
                return 0;
114
            });
115
            var s = '';
116
            for (i = 0; i < this.sections.length; i++) {
117
                this.sections[i].position = i;
118
                this.sections[i].questions.sort(function(a, b) {
119
                    if (a.position > b.position) {
120
                        return 1;
121
                    }
122
                    if (a.position < b.position) {
123
                        return -1;
124
                    }
125
                    return 0;
126
                });
127
                for (j = 0; j < this.sections[i].questions.length; j++) {
128
                    this.sections[i].questions[j].position = j;
129
                    if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {
130
                        this.sections[i].questions[j].options.sort(function(a, b) {
131
                            if (a.position > b.position) {
132
                                return 1;
133
                            }
134
                            if (a.position < b.position) {
135
                                return -1;
136
                            }
137
                            return 0;
138
                        });
139
                        for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
140
                            this.sections[i].questions[j].options[k].position = j;
141
                        }
142
                    }
143
                }
144
            }
145
            $('[data-toggle="tooltip"]').tooltip();
146
        },
147
        this.addSection = function(name, text, value) {
148
            var d = new Date();
149
            var slug = 'section' + d.getTime();
150
            var position = 0;
151
            $.each(this.sections, function(index, section) {
152
                if (position < section.position) {
153
                    position = section.position;
154
                }
155
            });
156
            position++;
157
            var section = {
158
                'slug_section': slug,
159
                'name': name,
160
                'text': text,
161
                'value': value,
162
                'position': position,
163
                'questions': [],
164
            }
165
            this.sections.push(section);
166
        },
167
        this.editSection = function(slug, name, text, value) {
168
            var renderTable = false;
169
            for (i = 0; i < this.sections.length; i++) {
170
                if (slug == this.sections[i].slug_section) {
171
                    this.sections[i].name = name;
172
                    this.sections[i].text = text;
173
                    this.sections[i].value = value;
174
                    renderTable = true;
175
                    break;
176
                }
177
            }
178
            if (renderTable) {
179
                this.renderSection(slug);
180
            }
181
        },
182
        this.deleteSection = function(slug) {
183
            var renderTable = false;
184
            for (i = 0; i < this.sections.length; i++) {
185
                if (slug == this.sections[i].slug_section) {
186
                    this.sections.splice(i, 1);
187
                    renderTable = true;
188
                    break;
189
                }
190
            }
191
            if (renderTable) {
192
                $('#panel' + slug).remove();
193
            }
194
        },
171 geraldo 195
        this.addQuestion = function(slug_section, text, value, type, maxlength, multiline, range) {
167 geraldo 196
            var d = new Date();
197
            var slug_question = 'question' + d.getTime();
198
            var position = 0;
199
            var renderTable = false;
200
            for (i = 0; i < this.sections.length; i++) {
171 geraldo 201
                if (slug_section == this.sections[i].slug_section) {
167 geraldo 202
                    $.each(this.sections[i].questions, function(index, question) {
203
                        if (position < question.position) {
204
                            position = question.position;
205
                        }
206
                    });
207
                    position++;
208
                    var question = {
171 geraldo 209
                        'slug_section': slug_section,
167 geraldo 210
                        'slug_question': slug_question,
211
                        'text': text,
212
                        'value': value,
213
                        'type': type,
214
                        'position': position,
215
                        'maxlength': maxlength,
216
                        'multiline': multiline,
217
                        'range': range,
218
                        'options': [],
219
                    }
220
                    this.sections[i].questions.push(question);
221
                    renderTable = true;
222
                    break;
223
                }
224
            }
225
            if (renderTable) {
171 geraldo 226
                this.renderSection(slug_section);
167 geraldo 227
            }
228
        },
172 geraldo 229
        this.editQuestion = function(slug_section, slug_question, text, value, type, maxlength, multiline, range) {
167 geraldo 230
            var renderTable = false;
231
            for (i = 0; i < this.sections.length; i++) {
171 geraldo 232
                if (slug_section == this.sections[i].slug_section) {
167 geraldo 233
                    for (j = 0; j < this.sections[i].questions.length; j++) {
172 geraldo 234
                        if (slug_question == this.sections[i].questions[j].slug_question) {
167 geraldo 235
                            this.sections[i].questions[j].text = text,
236
                                this.sections[i].questions[j].value = value,
237
                                this.sections[i].questions[j].type = type;
238
                            if (type == 'open') {
239
                                this.sections[i].questions[j].maxlength = maxlength;
240
                                this.sections[i].questions[j].multiline = multiline;
241
                                this.sections[i].questions[j].options = [];
242
                            } else {
243
                                this.sections[i].questions[j].maxlength = 0;
244
                                this.sections[i].questions[j].multiline = 0;
245
                            }
246
                            if (type == 'rating-range') {
247
                                this.sections[i].questions[j].range = range;
248
                            } else {
249
                                this.sections[i].questions[j].range = 0;
250
                            }
251
                            renderTable = true;
252
                            break;
253
                        }
254
                    }
255
                }
256
                if (renderTable) {
257
                    break;
258
                }
259
            }
260
            if (renderTable) {
171 geraldo 261
                this.renderSection(slug_section);
167 geraldo 262
            }
263
        },
172 geraldo 264
        this.deleteQuestion = function(slug_section, slug_question) {
167 geraldo 265
            var renderTable = false;
266
            for (i = 0; i < this.sections.length; i++) {
171 geraldo 267
                if (slug_section == this.sections[i].slug_section) {
167 geraldo 268
                    for (j = 0; j < this.sections[i].questions.length; j++) {
172 geraldo 269
                        if (slug_question == this.sections[i].questions[j].slug_question) {
167 geraldo 270
                            this.sections[i].questions.splice(j, 1);
271
                            renderTable = true;
272
                            break;
273
                        }
274
                    }
275
                }
276
                if (renderTable) {
277
                    break;
278
                }
279
            }
280
            if (renderTable) {
171 geraldo 281
                this.renderSection(slug_section);
167 geraldo 282
            }
283
        },
183 geraldo 284
        this.addOption = function(slug_section, slug_question, text, correct, value) {
167 geraldo 285
            var d = new Date();
286
            var slug_option = 'option' + d.getTime();
287
            var position = 0;
288
            var renderTable = false;
289
            for (i = 0; i < this.sections.length; i++) {
171 geraldo 290
                if (slug_section == this.sections[i].slug_section) {
167 geraldo 291
                    for (j = 0; j < this.sections[i].questions.length; j++) {
172 geraldo 292
                        if (slug_question == this.sections[i].questions[j].slug_question) {
167 geraldo 293
                            $.each(this.sections[i].questions[j].options, function(index, option) {
294
                                if (position < option.position) {
295
                                    position = option.position;
296
                                }
297
                            });
298
                            position++;
299
                            var option = {
300
                                'slug_section': slug_section,
301
                                'slug_question': slug_question,
302
                                'slug_option': slug_option,
303
                                'text': text,
304
                                'correct': correct,
183 geraldo 305
                                'value': value
167 geraldo 306
                            }
307
                            this.sections[i].questions[j].options.push(option);
308
                            renderTable = true;
309
                            break;
310
                        }
311
                        if (renderTable) {
312
                            break;
313
                        }
314
                    }
315
                }
316
            }
317
            if (renderTable) {
171 geraldo 318
                this.renderSection(slug_section);
167 geraldo 319
            }
320
        },
183 geraldo 321
        this.editOption = function(slug_section, slug_question, option_slug, text, correct, value) {
167 geraldo 322
            var renderTable = false;
323
            for (i = 0; i < this.sections.length; i++) {
171 geraldo 324
                if (slug_section == this.sections[i].slug_section) {
167 geraldo 325
                    for (j = 0; j < this.sections[i].questions.length; j++) {
172 geraldo 326
                        if (slug_question == this.sections[i].questions[j].slug_question) {
167 geraldo 327
                            for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
328
                                if (option_slug == this.sections[i].questions[j].options[k].slug_option) {
329
                                    this.sections[i].questions[j].options[k].text = text;
330
                                    this.sections[i].questions[j].options[k].correct = correct;
331
                                    this.sections[i].questions[j].options[k].value = value;
332
                                    renderTable = true;
333
                                    break;
334
                                }
335
                            }
336
                        }
337
                        if (renderTable) {
338
                            break;
339
                        }
340
                    }
341
                }
342
                if (renderTable) {
343
                    break;
344
                }
345
            }
346
            if (renderTable) {
171 geraldo 347
                this.renderSection(slug_section);
167 geraldo 348
            }
349
        },
172 geraldo 350
        this.deleteOption = function(slug_section, slug_question, option_slug) {
167 geraldo 351
            var renderTable = false;
352
            for (i = 0; i < this.sections.length; i++) {
171 geraldo 353
                if (slug_section == this.sections[i].slug_section) {
167 geraldo 354
                    for (j = 0; j < this.sections[i].questions.length; j++) {
172 geraldo 355
                        if (slug_question == this.sections[i].questions[j].slug_question) {
167 geraldo 356
                            for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
357
                                if (option_slug == this.sections[i].questions[j].options[k].slug_option) {
358
                                    this.sections[i].questions[j].options.splice(k, 1);
359
                                    renderTable = true;
360
                                    break;
361
                                }
362
                            }
363
                        }
364
                        if (renderTable) {
365
                            break;
366
                        }
367
                    }
368
                }
369
                if (renderTable) {
370
                    break;
371
                }
372
            }
373
            if (renderTable) {
171 geraldo 374
                this.renderSection(slug_section);
167 geraldo 375
            }
376
        }
377
}
164 geraldo 378
 
167 geraldo 379
function htmlEntities(str) {
380
    return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
381
}
382
jQuery(document).ready(function($) {
383
    var objFormGenerator = new classFormGenerator();
384
    objFormGenerator.render();
385
    var allowEdit = $allowEdit;
386
    var allowDelete = $allowDelete;
387
    var tableForm = $('#gridTable').dataTable({
388
        'processing': true,
389
        'serverSide': true,
390
        'searching': true,
391
        'order': [
392
            [0, 'asc']
393
        ],
394
        'ordering': true,
395
        'ordenable': true,
396
        'responsive': true,
397
        'select': false,
398
        'paging': true,
399
        'pagingType': 'simple_numbers',
400
        'ajax': {
401
            'url': '$routeDatatable',
402
            'type': 'get',
403
            'beforeSend': function(request) {
404
                NProgress.start();
405
            },
406
            'dataFilter': function(response) {
407
                var response = jQuery.parseJSON(response);
408
                var json = {};
409
                json.recordsTotal = 0;
410
                json.recordsFiltered = 0;
411
                json.data = [];
412
                if (response.success) {
413
                    json.recordsTotal = response.data.total;
414
                    json.recordsFiltered = response.data.total;
415
                    json.data = response.data.items;
416
                } else {
417
                    $.fn.showError(response.data)
418
                }
419
                return JSON.stringify(json);
420
            }
421
        },
422
        'language': {
423
            'sProcessing': 'LABEL_DATATABLE_SPROCESSING',
424
            'sLengthMenu': 'LABEL_DATATABLE_SLENGTHMENU',
425
            'sZeroRecords': 'LABEL_DATATABLE_SZERORECORDS',
426
            'sEmptyTable': 'LABEL_DATATABLE_SEMPTYTABLE',
427
            'sInfo': 'LABEL_DATATABLE_SINFO',
428
            'sInfoEmpty': 'LABEL_DATATABLE_SINFOEMPTY',
429
            'sInfoFiltered': 'LABEL_DATATABLE_SINFOFILTERED',
430
            'sInfoPostFix': '',
431
            'sSearch': 'LABEL_DATATABLE_SSEARCH',
432
            'sUrl': '',
433
            'sInfoThousands': ',',
434
            'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
435
            'oPaginate': {
436
                'sFirst': 'LABEL_DATATABLE_SFIRST',
437
                'sLast': 'LABEL_DATATABLE_SLAST',
438
                'sNext': 'LABEL_DATATABLE_SNEXT',
439
                'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
440
            },
441
            'oAria': {
442
                'sSortAscending': ': LABEL_DATATABLE_SSORTASCENDING',
443
                'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
444
            },
445
        },
446
        'drawCallback': function(settings) {
447
            NProgress.done();
448
            $('button.btn-delete').confirmation({
449
                rootSelector: 'button.btn-delete',
450
                title: 'LABEL_ARE_YOU_SURE',
451
                singleton: true,
452
                btnOkLabel: 'LABEL_YES',
453
                btnCancelLabel: 'LABEL_NO',
454
                onConfirm: function(value) {
455
                    action = $(this).data('href');
456
                    NProgress.start();
457
                    $.ajax({
458
                        'dataType': 'json',
459
                        'accept': 'application/json',
460
                        'method': 'post',
461
                        'url': action,
462
                    }).done(function(response) {
463
                        if (response['success']) {
464
                            $.fn.showSuccess(response['data']);
196 geraldo 465
                            tableForm.fnDraw();
167 geraldo 466
                        } else {
467
                            $.fn.showError(response['data']);
468
                        }
469
                    }).fail(function(jqXHR, textStatus, errorThrown) {
470
                        $.fn.showError(textStatus);
471
                    }).always(function() {
472
                        NProgress.done();
473
                    });
474
                },
475
            });
476
        },
477
        'aoColumns': [{
478
                'mDataProp': 'name'
479
            },
480
            {
481
                'mDataProp': 'language'
482
            },
483
            {
484
                'mDataProp': 'status'
485
            },
486
            {
487
                'mDataProp': 'actions'
488
            },
489
        ],
490
        'columnDefs': [{
491
                'targets': 0,
492
                'className': 'text-vertical-middle',
493
            },
494
            {
495
                'targets': 1,
496
                'className': 'text-vertical-middle',
497
            },
498
            {
499
                'targets': -2,
500
                'orderable': false,
501
                'className': 'text-center',
502
                'render': function(data, type, row) {
503
                    checked = data == 'a' ? ' checked="checked" ' : '';
504
                    return '<div class="checkbox checkbox-success">' +
505
                        '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
506
                        '<label ></label></div>';
507
                }
508
            },
509
            {
510
                'targets': -1,
511
                'orderable': false,
512
                'render': function(data, type, row) {
513
                    s = '';
514
                    if (allowEdit) {
515
                        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;';
516
                    }
517
                    if (allowDelete) {
518
                        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;';
519
                    }
520
                    return s;
521
                }
522
            }
523
        ],
118 steven 524
    });
187 efrain 525
 
167 geraldo 526
    $('body').on('click', 'button.btn-edit-form', function(e) {
527
        e.preventDefault();
528
        form_id = $(this).data('id')
529
        var action = $(this).data('href');
530
        $.ajax({
531
            'dataType': 'json',
532
            'accept': 'application/json',
533
            'method': 'get',
534
            'url': action,
535
        }).done(function(response) {
536
            if (response['success']) {
537
                validatorForm.resetForm();
192 efrain 538
                $('#form-main #form-id').val(response['data']['id']),
167 geraldo 539
                    $('#form-main #form-continue').val('0');
194 efrain 540
                $('#form-main #form-name').val(response['data']['name']),
167 geraldo 541
                    instanceName = 'form-description';
542
                let editor = CKEDITOR.instances[instanceName];
192 efrain 543
                editor.setData(response['data']['description'], function() {
167 geraldo 544
                    editor.focus();
545
                });
546
                instanceName = 'form-text';
192 efrain 547
                CKEDITOR.instances[instanceName].setData(response['data']['text']);
548
                $('#form-main #form-language').val(response['data']['language']),
549
                    $('#form-main #form-status').val(response['data']['status']);
167 geraldo 550
                objFormGenerator.clear();
192 efrain 551
                objFormGenerator.sections = response['data']['content'] || [];
167 geraldo 552
                objFormGenerator.render();
196 geraldo 553
                renderSectionData(objFormGenerator.sections);
167 geraldo 554
                $('#row-forms').hide();
555
                $('#row-edit').show();
556
                $('#form-main #form-name').focus();
557
            } else {
558
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
559
            }
560
        }).fail(function(jqXHR, textStatus, errorThrown) {
561
            $.fn.showError(textStatus);
562
        });
563
    });
564
    $(document).on('click', '[data-type="select_all"]', function() {
565
        if ($('input[name="select_all"]:checked').val() == 'all') {
566
            $('[data-type="select"]').prop('checked', true);
567
            $('[data-action="delete"]').removeClass('hide');
568
        } else {
569
            $('[data-type="select"]').prop('checked', false);
570
            $('[data-action="delete"]').addClass('hide');
571
        }
572
    });
118 steven 573
 
167 geraldo 574
    function getLength() {
575
        return $('[data-type="select"]').length;
576
    }
118 steven 577
 
167 geraldo 578
    function currentSelected() {
579
        var selected = [];
580
        $.each($("input[name='select[]']:checked"), function() {
581
            selected.push($(this).val());
582
        });
583
        return selected;
584
    }
585
    $(document).on('change', "input[name='select[]']", function() {
586
        var c = currentSelected();
587
        var cc = getLength();
588
        if (c.length == cc) {
589
            if ($('[data-action="delete"]').hasClass('hide')) {
590
                $('[data-action="delete"]').removeClass('hide');
591
            }
592
            return true;
593
        } else {
594
            $('input[name="select_all"]').prop('checked', false);
595
        }
596
        if (c.length > 0) {
597
            if ($('[data-action="delete"]').hasClass('hide')) {
598
                $('[data-action="delete"]').removeClass('hide');
599
            }
600
        } else {
601
            if (!$('[data-action="delete"]').hasClass('hide')) {
602
                $('[data-action="delete"]').addClass('hide');
603
            }
604
        }
118 steven 605
    });
167 geraldo 606
    var form3 = $('#form_sample_3');
607
    var error3 = $('.alert-danger', form3);
608
    var success3 = $('.alert-success', form3);
609
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
610
    $("#form-main").on('submit', function() {
611
        for (var instanceName in CKEDITOR.instances) {
612
            CKEDITOR.instances[instanceName].updateElement();
613
        }
614
    })
615
    var validatorForm = $("#form-main").validate({
118 steven 616
        ignore: [],
617
        errorClass: 'help-block',
618
        errorElement: 'span',
167 geraldo 619
        rules: {
620
            'form-name': {
621
                required: true,
622
                minlength: 2,
623
                maxlength: 50
624
            },
625
            'form-description': {
626
                required: true,
627
            },
628
            'form-text': {
629
                required: true,
630
            },
631
            'form-language': {
632
                required: true,
633
            },
634
            'forrm-status': {
635
                required: true,
636
            },
637
        },
638
        highlight: function(element) {
118 steven 639
            $(element).closest('.form-group').addClass('has-error');
640
        },
167 geraldo 641
        unhighlight: function(element) {
118 steven 642
            $(element).closest('.form-group').removeClass('has-error');
643
        },
167 geraldo 644
        errorPlacement: function(error, element) {
118 steven 645
            if (element.attr("data-error-container")) {
646
                error.appendTo(element.attr("data-error-container"));
647
            } else {
648
                error.insertAfter(element);
649
            }
650
        },
651
        invalidHandler: function(form, validator) {
652
            if (!validator.numberOfInvalids())
653
                return;
654
            $('html, body').animate({
655
                scrollTop: $(validator.errorList[0].element).offset().top - 100
656
            }, 1000);
657
        },
167 geraldo 658
        submitHandler: function(form) {
659
            var error = false;
660
            if (objFormGenerator.sections.length == 0) {
661
                $.fn.showError('ERROR_SECCTIONS');
662
                error = true;
663
            } else {
664
                for (i = 0; i < objFormGenerator.sections.length; i++) {
665
                    if (objFormGenerator.sections[i].questions.length == 0) {
666
                        $.fn.showError('ERROR_QUESTIONS'.replace('%s', objFormGenerator.sections[i].name));
667
                        break;
668
                    }
669
                    var valueSection = parseInt(objFormGenerator.sections[i].value);
670
                    var totalValueQuestion = 0;
671
                    for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
672
                        valueQuestion = parseInt(objFormGenerator.sections[i].questions[j].value);
673
                        totalValueQuestion = totalValueQuestion + valueQuestion;
674
                        if (objFormGenerator.sections[i].questions[j].type == 'simple' ||
675
                            objFormGenerator.sections[i].questions[j].type == 'multiple' ||
676
                            objFormGenerator.sections[i].questions[j].type == 'rating-open') {
677
                            var questionNumber = j + 1;
678
                            var numberCorrect = 0;
679
                            if (objFormGenerator.sections[i].questions[j].options.length == 0) {
680
                                $.fn.showError('ERROR_OPTIONS'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
681
                                error = true;
682
                                return false;
683
                                break;
684
                            }
685
                            var totalOption = 0;
686
                            var maxOption = 0;
687
                            for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
688
                                if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
689
                                    if (objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
690
                                        numberCorrect++;
691
                                    }
692
                                }
693
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' && objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
694
                                    totalOption = totalOption + parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
695
                                }
696
                                if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
697
                                    if (parseInt(objFormGenerator.sections[i].questions[j].options[k].value) > maxOption) {
698
                                        maxOption = parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
699
                                    }
700
                                }
701
                            }
702
                            if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
703
                                if (numberCorrect == 0) {
704
                                    $.fn.showError('ERROR_OPTIONS_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
705
                                    error = true;
706
                                    return false;
707
                                    break;
708
                                }
709
                                if (objFormGenerator.sections[i].questions[j].type == 'simple' && numberCorrect > 1) {
710
                                    $.fn.showError('ERROR_OPTIONS_DUPLICATE_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 == 'multiple' && numberCorrect == 1) {
716
                                    $.fn.showError('ERROR_OPTIONS_ONE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
717
                                    error = true;
718
                                    return false;
719
                                    break;
720
                                }
721
                            }
722
                            if (objFormGenerator.sections[i].questions[j].type == 'multiple' && totalOption > valueQuestion) {
723
                                $.fn.showError('ERROR_OPTIONS_SUM_VALUES'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
724
                                error = true;
725
                                return false;
726
                                break;
727
                            }
728
                            if (objFormGenerator.sections[i].questions[j].type == 'rating-open' && maxOption > valueQuestion) {
729
                                $.fn.showError('ERROR_OPTIONS_MAX_OPTION'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
730
                                error = true;
731
                                return false;
732
                                break;
733
                            }
734
                        }
735
                    }
736
                    if (valueSection != totalValueQuestion) {
737
                        $.fn.showError('ERROR_VALUE_SECTIONS'.replace('%s', objFormGenerator.sections[i].name));
738
                        error = true;
739
                        return false;
740
                        break;
741
                    }
742
                }
743
                if (error) {
744
                    return false;
745
                } else {
746
                    var formId = parseInt($('#form-main #form-id').val());
747
                    var formContinue = parseInt($('#form-main #form-continue').val());
748
                    var data = {
749
                        'id': formId,
750
                        'name': $('#form-main #form-name').val(),
751
                        'description': $('#form-main #form-description').val(),
752
                        'text': $('#form-main #form-text').val(),
753
                        'language': $('#form-main #form-language').val(),
754
                        'status': $('#form-main #form-status').val(),
187 efrain 755
                        'content': JSON.stringify(objFormGenerator.sections)
167 geraldo 756
                    }
757
                    $.ajax({
758
                        'dataType': 'json',
759
                        'method': 'post',
760
                        'url': '$routeAdd',
761
                        'data': data,
762
                    }).done(function(response) {
763
                        if (response['success']) {
196 geraldo 764
                            $.fn.showSuccess(response['data']);
167 geraldo 765
                            if (formContinue == 1) {
766
                                $('#form-main #form-id').val(response['form-id']);
767
                                $('#form-main #form-continue').val(0);
768
                            } else {
769
                                $('#row-edit').hide();
770
                                $('#row-forms').show();
771
                            }
772
                            tableForm.fnDraw();
773
                        } else {
774
                            $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
775
                        }
776
                    }).fail(function(jqXHR, textStatus, errorThrown) {
777
                        $.fn.showError(textStatus);
778
                    });
779
                    return false;
780
                }
781
            }
782
        }
783
    });
784
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
785
    $("#form-section").on('submit', function() {
786
        for (var instanceName in CKEDITOR.instances) {
787
            CKEDITOR.instances[instanceName].updateElement();
788
        }
789
    })
790
    var validatorFormSection = $("#form-section").validate({
118 steven 791
        ignore: [],
792
        errorClass: 'help-block',
793
        errorElement: 'span',
167 geraldo 794
        rules: {
795
            'section-name': {
796
                required: true,
797
                minlength: 2,
798
                maxlength: 50
799
            },
800
            'section-text': {
801
                required: false,
802
            },
803
            'section-value': {
804
                required: true,
805
                number: true,
806
                min: 1
807
            },
808
        },
809
        highlight: function(element) {
118 steven 810
            $(element).closest('.form-group').addClass('has-error');
811
        },
167 geraldo 812
        unhighlight: function(element) {
118 steven 813
            $(element).closest('.form-group').removeClass('has-error');
814
        },
167 geraldo 815
        errorPlacement: function(error, element) {
118 steven 816
            if (element.attr("data-error-container")) {
817
                error.appendTo(element.attr("data-error-container"));
818
            } else {
819
                error.insertAfter(element);
820
            }
821
        },
822
        invalidHandler: function(form, validator) {
823
            if (!validator.numberOfInvalids())
824
                return;
825
            $('html, body').animate({
826
                scrollTop: $(validator.errorList[0].element).offset().top - 100
827
            }, 1000);
828
        },
167 geraldo 829
        submitHandler: function(form) {
830
            // do other things for a valid form
831
            //form.submit();
832
            var slug = $('#form-section #section-slug').val();
833
            if (slug) {
834
                objFormGenerator.editSection(
835
                    $('#form-section #section-slug').val(),
836
                    $('#form-section #section-name').val(),
837
                    $('#form-section #section-text').val(),
838
                    $('#form-section #section-value').val()
839
                );
840
            } else {
841
                objFormGenerator.addSection(
842
                    $('#form-section #section-name').val(),
843
                    $('#form-section #section-text').val(),
844
                    $('#form-section #section-value').val()
845
                );
846
            }
196 geraldo 847
            renderSectionData(objFormGenerator.sections);
167 geraldo 848
            $('#modal-section').modal('hide');
849
            return false;
850
        }
851
    });
852
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
853
    $("#form-question").on('submit', function() {
854
        for (var instanceName in CKEDITOR.instances) {
855
            CKEDITOR.instances[instanceName].updateElement();
856
        }
857
    })
858
    var validatorFormQuestion = $("#form-question").validate({
118 steven 859
        ignore: [],
860
        errorClass: 'help-block',
861
        errorElement: 'span',
167 geraldo 862
        rules: {
863
            'question-text': {
864
                required: true,
865
            },
866
            'question-value': {
867
                required: true,
868
                number: true,
869
                min: 1
870
            },
871
            'question-type': {
872
                required: true,
873
            },
874
            'question-max-length': {
875
                required: true,
876
                digits: true,
877
                min: 0
878
            },
879
            'question-range': {
880
                required: true,
881
                number: true,
882
                min: 1
883
            },
884
        },
885
        highlight: function(element) {
118 steven 886
            $(element).closest('.form-group').addClass('has-error');
887
        },
167 geraldo 888
        unhighlight: function(element) {
118 steven 889
            $(element).closest('.form-group').removeClass('has-error');
890
        },
167 geraldo 891
        errorPlacement: function(error, element) {
118 steven 892
            if (element.attr("data-error-container")) {
893
                error.appendTo(element.attr("data-error-container"));
894
            } else {
895
                error.insertAfter(element);
896
            }
897
        },
898
        invalidHandler: function(form, validator) {
899
            if (!validator.numberOfInvalids())
900
                return;
901
            $('html, body').animate({
902
                scrollTop: $(validator.errorList[0].element).offset().top - 100
903
            }, 1000);
904
        },
167 geraldo 905
        submitHandler: function(form) {
906
            if ($('#form-question #question-slug').val()) {
907
                objFormGenerator.editQuestion(
908
                    $('#form-question #question-section').val(),
909
                    $('#form-question #question-slug').val(),
910
                    $('#form-question #question-text').val(),
911
                    $('#form-question #question-value').val(),
912
                    $('#form-question #question-type').val(),
913
                    $('#form-question #question-max-length').val(),
914
                    $('#form-question #question-multiline').val(),
915
                    $('#form-question #question-range').val()
916
                );
917
            } else {
918
                objFormGenerator.addQuestion(
919
                    $('#form-question #question-section').val(),
920
                    $('#form-question #question-text').val(),
921
                    $('#form-question #question-value').val(),
922
                    $('#form-question #question-type').val(),
923
                    $('#form-question #question-max-length').val(),
924
                    $('#form-question #question-multiline').val(),
925
                    $('#form-question #question-range').val()
926
                );
927
            }
196 geraldo 928
            renderSectionData(objFormGenerator.sections);
167 geraldo 929
            $('#modal-question').modal('hide');
930
            return false;
931
        }
932
    });
933
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
934
    $("#form-option").on('submit', function() {
935
        for (var instanceName in CKEDITOR.instances) {
936
            CKEDITOR.instances[instanceName].updateElement();
937
        }
938
    })
939
    var validatorFormOption = $("#form-option").validate({
118 steven 940
        ignore: [],
941
        errorClass: 'help-block',
942
        errorElement: 'span',
167 geraldo 943
        rules: {
944
            'option-text': {
945
                required: true,
946
            },
947
            'option-value': {
948
                required: true,
949
                number: true,
950
                min: 1
951
            }
952
        },
953
        highlight: function(element) {
118 steven 954
            $(element).closest('.form-group').addClass('has-error');
955
        },
167 geraldo 956
        unhighlight: function(element) {
118 steven 957
            $(element).closest('.form-group').removeClass('has-error');
958
        },
167 geraldo 959
        errorPlacement: function(error, element) {
118 steven 960
            if (element.attr("data-error-container")) {
961
                error.appendTo(element.attr("data-error-container"));
962
            } else {
963
                error.insertAfter(element);
964
            }
965
        },
966
        invalidHandler: function(form, validator) {
967
            if (!validator.numberOfInvalids())
968
                return;
969
            $('html, body').animate({
970
                scrollTop: $(validator.errorList[0].element).offset().top - 100
971
            }, 1000);
972
        },
167 geraldo 973
        submitHandler: function(form) {
974
            if ($('#form-option #option-slug').val()) {
975
                objFormGenerator.editOption(
976
                    $('#form-option #option-section').val(),
977
                    $('#form-option #option-question').val(),
978
                    $('#form-option #option-slug').val(),
979
                    $('#form-option #option-text').val(),
980
                    $('#form-option #option-correct').val(),
184 geraldo 981
                    $('#form-option #option-value').val()
167 geraldo 982
                );
983
            } else {
984
                objFormGenerator.addOption(
985
                    $('#form-option #option-section').val(),
986
                    $('#form-option #option-question').val(),
987
                    $('#form-option #option-text').val(),
988
                    $('#form-option #option-correct').val(),
184 geraldo 989
                    $('#form-option #option-value').val()
167 geraldo 990
                );
991
            }
196 geraldo 992
            renderSectionData(objFormGenerator.sections);
167 geraldo 993
            $('#modal-option').modal('hide');
994
            return false;
995
        }
996
    });
997
    $('body').on('click', 'button[id="btn-add-section"]', function(e) {
998
        e.preventDefault();
999
        validatorFormSection.resetForm();
1000
        $('#form-section #section-slug').val('');
1001
        $('#form-section #section-name').val('');
1002
        instanceName = 'section-text';
1003
        let editor = CKEDITOR.instances[instanceName];
1004
        editor.setData('', function() {
1005
            editor.focus();
1006
        });
1007
        $('#form-section #section-value').val('0');
1008
        $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
1009
        $('#modal-section').modal('show');
1010
    });
1011
    $('body').on('click', 'button.btn-edit-section', function(e) {
1012
        e.preventDefault();
169 geraldo 1013
        var slug = $(this).data('section');
167 geraldo 1014
        var section;
1015
        var showForm = false;
1016
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1017
            section = objFormGenerator.sections[i];
171 geraldo 1018
            if (slug == section.slug_section) {
167 geraldo 1019
                validatorFormSection.resetForm();
171 geraldo 1020
                $('#form-section #section-slug').val(section.slug_section);
167 geraldo 1021
                $('#form-section #section-name').val(section.name);
1022
                instanceName = 'section-text';
1023
                let editor = CKEDITOR.instances[instanceName];
1024
                editor.setData(section.text, function() {
1025
                    editor.focus();
1026
                });
1027
                $('#form-section #section-value').val(section.value);
1028
                showForm = true;
1029
                break;
1030
            }
1031
        }
1032
        if (showForm) {
1033
            $('#modal-section h4[class="modal-title"]').html('LABEL_EDIT LABEL_SECTION');
1034
            $('#modal-section').modal('show');
1035
        }
1036
    });
1037
    $('body').on('click', 'button.btn-delete-section', function(e) {
1038
        e.preventDefault();
169 geraldo 1039
        var slug = $(this).data('section');
167 geraldo 1040
        bootbox.confirm({
1041
            title: "LABEL_DELETE LABEL_SECTION",
1042
            message: "LABEL_QUESTION_DELETE",
1043
            buttons: {
1044
                cancel: {
1045
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1046
                },
1047
                confirm: {
1048
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1049
                }
1050
            },
1051
            callback: function(result) {
1052
                if (result) {
1053
                    objFormGenerator.deleteSection(slug);
196 geraldo 1054
                    renderSectionData(objFormGenerator.sections);
167 geraldo 1055
                }
1056
            }
1057
        });
1058
    });
1059
    $('body').on('click', 'button.btn-add-question', function(e) {
1060
        e.preventDefault();
1061
        validatorFormQuestion.resetForm();
169 geraldo 1062
        var slug = $(this).data('section');
167 geraldo 1063
        $('#form-question #question-section').val(slug);
1064
        $('#form-question #question-slug').val('');
1065
        instanceName = 'question-text';
1066
        let editor = CKEDITOR.instances[instanceName];
1067
        editor.setData('', function() {
1068
            editor.focus();
1069
        });
1070
        $('#form-question #question-value').val('0');
1071
        $('#form-question #question-type').val($('#form-question #question-type option:first').val());
1072
        $('#form-question #question-max-length').val('0');
1073
        $('#form-question #question-max-length').parent().show();
1074
        $('#form-question #question-multiline').val('0');
1075
        $('#form-question #question-multiline').parent().show();
1076
        $('#form-question #question-range').val('10');
1077
        $('#form-question #question-range').parent().hide();
1078
        $('#modal-question h4[class="modal-title"]').html('LABEL_ADD LABEL_QUESTION');
1079
        $('#modal-question').modal('show');
1080
    });
1081
    $('body').on('click', 'button.btn-edit-question', function(e) {
1082
        e.preventDefault();
1083
        var slug_section = $(this).data('section');
170 geraldo 1084
        var slug = $(this).data('question');
167 geraldo 1085
        var showForm = false;
1086
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1087
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1088
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1089
                    if (slug == objFormGenerator.sections[i].questions[j].slug_question) {
1090
                        validatorFormQuestion.resetForm();
1091
                        $('#form-question #question-section').val(objFormGenerator.sections[i].slug_section);
1092
                        $('#form-question #question-slug').val(objFormGenerator.sections[i].questions[j].slug_question);
1093
                        instanceName = 'question-text';
1094
                        let editor = CKEDITOR.instances[instanceName];
1095
                        editor.setData(objFormGenerator.sections[i].questions[j].text, function() {
1096
                            editor.focus();
1097
                        });
1098
                        $('#form-question #question-value').val(objFormGenerator.sections[i].questions[j].value);
1099
                        $('#form-question #question-type').val(objFormGenerator.sections[i].questions[j].type);
1100
                        if (objFormGenerator.sections[i].questions[j].type == 'open') {
1101
                            $('#form-question #question-max-length').val(objFormGenerator.sections[i].questions[j].maxlength);
1102
                            $('#form-question #question-max-length').parent().show();
1103
                            $('#form-question #question-multiline').val(objFormGenerator.sections[i].questions[j].multiline);
1104
                            $('#form-question #question-multiline').parent().show();
118 steven 1105
                        } else {
167 geraldo 1106
                            $('#form-question #question-max-length').val('0');
1107
                            $('#form-question #question-max-length').parent().hide();
1108
                            $('#form-question #question-multiline').val('0');
1109
                            $('#form-question #question-multiline').parent().hide();
118 steven 1110
                        }
167 geraldo 1111
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-range') {
1112
                            $('#form-question #question-range').val(objFormGenerator.sections[i].questions[j].range);
1113
                            $('#form-question #question-range').parent().show();
1114
                        } else {
1115
                            $('#form-question #question-range').val('10');
1116
                            $('#form-question #question-range').parent().hide();
1117
                        }
1118
                        showForm = true;
1119
                        break;
1120
                    }
1121
                }
1122
                break;
1123
            }
1124
        }
1125
        if (showForm) {
1126
            $('#modal-question h4[class="modal-title"]').html('LABEL_EDIT LABEL_QUESTION');
1127
            $('#modal-question').modal('show');
1128
        }
1129
    });
1130
    $('body').on('click', 'button.btn-delete-question', function(e) {
1131
        e.preventDefault();
1132
        var slug_section = $(this).data('section');
170 geraldo 1133
        var slug = $(this).data('question');
167 geraldo 1134
        bootbox.confirm({
1135
            title: "LABEL_DELETE LABEL_QUESTION",
1136
            message: "LABEL_QUESTION_DELETE",
1137
            buttons: {
1138
                cancel: {
1139
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1140
                },
1141
                confirm: {
1142
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1143
                }
1144
            },
1145
            callback: function(result) {
1146
                if (result) {
1147
                    objFormGenerator.deleteQuestion(slug_section, slug);
196 geraldo 1148
                    renderSectionData(objFormGenerator.sections);
167 geraldo 1149
                }
1150
            }
1151
        });
1152
    });
172 geraldo 1153
 
180 geraldo 1154
     /**
1155
      * Get Question type
1156
      */
181 geraldo 1157
     const getQuestionTypeBySlug = (slug_section, slug_question) => {
180 geraldo 1158
         for (i = 0; i < objFormGenerator.sections.length; i++) {
1159
             if (slug_section == objFormGenerator.sections[i].slug_section) {
1160
                 for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1161
                     if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1162
                         return objFormGenerator.sections[i].questions[j].type;
1163
                     }
1164
                 }
1165
             }
1166
         }
1167
     }
1168
 
1169
     /**
1170
      * Render Sections data
1171
      */
196 geraldo 1172
     const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
180 geraldo 1173
         getType: getQuestionTypeBySlug
1174
     }));
196 geraldo 1175
 
1176
     /**
1177
      * Clear Div Section data
1178
      */
197 geraldo 1179
     const clearSectionData = () => $("#rows").html('');
180 geraldo 1180
 
167 geraldo 1181
    $('body').on('click', 'button.btn-add-option', function(e) {
1182
        e.preventDefault();
1183
        var slug_section = $(this).data('section');
1184
        var slug_question = $(this).data('question');
1185
        var showForm = false;
1186
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1187
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1188
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1189
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1190
                        validatorFormOption.resetForm();
1191
                        $('#form-option #option-section').val(slug_section);
1192
                        $('#form-option #option-question').val(slug_question);
1193
                        $('#form-option #option-slug').val('');
1194
                        instanceName = 'option-text';
1195
                        let editor = CKEDITOR.instances[instanceName];
1196
                        editor.setData('', function() {
1197
                            editor.focus();
1198
                        });
1199
                        $('#form-option #option-correct').val('0');
1200
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1201
                            $('#form-option #option-correct').parent().hide();
1202
                        } else {
1203
                            $('#form-option #option-correct').parent().show();
1204
                        }
1205
                        if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1206
                            $('#form-option #option-value').val('0');
1207
                            $('#form-option #option-value').parent().show();
1208
                        } else {
1209
                            $('#form-option #option-value').val('1');
1210
                            $('#form-option #option-value').parent().hide();
1211
                        }
196 geraldo 1212
                        renderSectionData(objFormGenerator.sections);
167 geraldo 1213
                        showForm = true;
1214
                    }
1215
                }
1216
            }
1217
        }
1218
        if (showForm) {
1219
            $('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
1220
            $('#modal-option').modal('show');
1221
        }
1222
    });
171 geraldo 1223
 
167 geraldo 1224
    $('body').on('click', 'button.btn-edit-option', function(e) {
1225
        e.preventDefault();
1226
        var slug_section = $(this).data('section');
1227
        var slug_question = $(this).data('question');
1228
        var slug = $(this).data('slug');
1229
        var showForm = false;
1230
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1231
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1232
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1233
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1234
                        for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
1235
                            if (slug == objFormGenerator.sections[i].questions[j].options[k].slug_option) {
1236
                                validatorFormOption.resetForm();
1237
                                $('#form-option #option-section').val(objFormGenerator.sections[i].slug_section);
1238
                                $('#form-option #option-question').val(objFormGenerator.sections[i].questions[j].slug_question);
1239
                                $('#form-option #option-slug').val(objFormGenerator.sections[i].questions[j].options[k].slug_option);
1240
                                instanceName = 'option-text';
1241
                                let editor = CKEDITOR.instances[instanceName];
1242
                                editor.setData(objFormGenerator.sections[i].questions[j].options[k].text, function() {
1243
                                    editor.focus();
1244
                                });
1245
                                $('#form-option #option-correct').val(objFormGenerator.sections[i].questions[j].options[k].correct);
1246
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'simple') {
1247
                                    $('#form-option #option-correct').parent().show();
1248
                                } else {
1249
                                    $('#form-option #option-correct').parent().hide();
1250
                                }
1251
                                $('#form-option #option-value').val(objFormGenerator.sections[i].questions[j].options[k].value);
1252
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1253
                                    $('#form-option #option-value').parent().show();
1254
                                } else {
1255
                                    $('#form-option #option-value').parent().hide();
1256
                                }
1257
                                showForm = true;
1258
                                break;
1259
                            }
1260
                        }
1261
                    }
1262
                    if (showForm) {
1263
                        break;
1264
                    }
1265
                }
1266
            }
1267
            if (showForm) {
1268
                break;
1269
            }
1270
        }
1271
        if (showForm) {
1272
            $('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
1273
            $('#modal-option').modal('show');
1274
        }
1275
    });
1276
    $('body').on('click', 'button.btn-delete-option', function(e) {
1277
        e.preventDefault();
1278
        var slug_section = $(this).data('section');
1279
        var slug_question = $(this).data('question');
1280
        var slug = $(this).data('slug');
1281
        bootbox.confirm({
1282
            title: "LABEL_DELETE LABEL_OPTION",
1283
            message: "LABEL_QUESTION_DELETE",
1284
            buttons: {
1285
                cancel: {
1286
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1287
                },
1288
                confirm: {
1289
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1290
                }
1291
            },
1292
            callback: function(result) {
1293
                if (result) {
1294
                    objFormGenerator.deleteOption(slug_section, slug_question, slug);
196 geraldo 1295
                    renderSectionData(objFormGenerator.sections);
167 geraldo 1296
                }
1297
            }
1298
        });
1299
    })
1300
    $('#form-section #section-value').inputNumberFormat({
1301
        'decimal': 2
1302
    });
1303
    $('#form-question #question-value').inputNumberFormat({
1304
        'decimal': 2
1305
    });
1306
    $('#form-question #question-max-length').inputNumberFormat({
1307
        'decimal': 0
1308
    });
1309
    $('#form-option #option-value').inputNumberFormat({
1310
        'decimal': 2
1311
    });
1312
    $('#form-question #question-type').change(function(e) {
1313
        e.preventDefault();
1314
        if ($('#form-question #question-type').val() == 'open') {
1315
            $('#form-question #question-max-length').parent().show();
1316
            $('#form-question #question-multiline').parent().show();
1317
        } else {
1318
            $('#form-question #question-max-length').val('0');
1319
            $('#form-question #question-max-length').parent().hide();
1320
            $('#form-question #question-multiline').val('0');
1321
            $('#form-question #question-multiline').parent().hide();
1322
        }
1323
        $('#form-question #question-range').val('10');
1324
        if ($('#form-question #question-type').val() == 'rating-range') {
1325
            $('#form-question #question-range').parent().show();
1326
        } else {
1327
            $('#form-question #question-range').parent().hide();
1328
        }
1329
    });
1330
    $('button.btn-add-form').click(function(e) {
1331
        e.preventDefault();
1332
        objFormGenerator.clear();
1333
        objFormGenerator.render();
1334
        validatorForm.resetForm();
196 geraldo 1335
        clearSectionData();
167 geraldo 1336
        $('#form-main #form-id').val('0');
1337
        $('#form-main #form-continue').val('0');
1338
        $('#form-main #form-name').val('');
1339
        instanceName = 'form-text';
1340
        let editor = CKEDITOR.instances[instanceName];
1341
        editor.setData('', function() {
1342
            editor.focus();
1343
        });
1344
        instanceName = 'form-description';
1345
        CKEDITOR.instances[instanceName].setData('');
1346
        $('#form-main #form-language').val('$lang_es'),
1347
            $('#form-main #form-status').val('$status_inactive');
1348
        $('#row-forms').hide();
1349
        $('#row-edit').show();
1350
        $('#form-main #form-name').focus();
1351
    });
1352
    $('button.btn-edit-cancel').click(function(e) {
1353
        e.preventDefault();
1354
        $('#row-edit').hide();
1355
        $('#row-forms').show();
1356
    });
1357
    $('button.btn-form-save-continue').click(function(e) {
1358
        e.preventDefault();
1359
        $('#form-main #form-continue').val('1')
1360
        $('#form-main').submit();
1361
    });
1362
    $('button.btn-form-save-close').click(function(e) {
1363
        e.preventDefault();
1364
        $('#form-main #form-continue').val('0')
1365
        $('#form-main').submit();
1366
    });
1367
    $('#modal-section, #modal-question, #modal-option').modal({
1368
        backdrop: 'static',
1369
        keyboard: false,
1370
        show: false
1371
    });
1372
});
118 steven 1373
JS;
115 efrain 1374
$this->inlineScript()->captureEnd();
1375
?>
118 steven 1376
 
121 steven 1377
<style type="text/css">
135 geraldo 1378
    tbody input[type="checkbox"]{
1379
        margin-left: 14px;
1380
    }
1381
    .panel-heading .accordion-toggle:after {
1382
        /* symbol for "opening" panels */
1383
        display: inline-block;
1384
        font: normal normal normal 14px/1 FontAwesome;
1385
        font-size: inherit;
1386
        content: "\f077" ;
1387
        float: right;        /* adjust as needed */
1388
        color: grey;         /* adjust as needed */
1389
        text-rendering: auto;
1390
        -webkit-font-smoothing: antialiased;
1391
    }
1392
    .panel-heading .accordion-toggle.collapsed:after {
1393
        /* symbol for "collapsed" panels */
1394
        content: "\f078";    /* adjust as needed, taken from bootstrap.css */
1395
    }
121 steven 1396
</style>
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>