Proyectos de Subversion LeadersLinked - Backend

Rev

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