Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 181 | Rev 184 | 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(),
173 geraldo 1075
                    $('#form-option #option-value').val(),
1076
                    $('#form-option #question-type').val(),
167 geraldo 1077
                );
1078
            } else {
1079
                objFormGenerator.addOption(
1080
                    $('#form-option #option-section').val(),
1081
                    $('#form-option #option-question').val(),
1082
                    $('#form-option #option-text').val(),
1083
                    $('#form-option #option-correct').val(),
173 geraldo 1084
                    $('#form-option #option-value').val(),
1085
                    $('#form-option #question-type').val(),
167 geraldo 1086
                );
1087
            }
1088
            renderData(objFormGenerator.sections);
1089
            $('#modal-option').modal('hide');
1090
            return false;
1091
        }
1092
    });
1093
    $('body').on('click', 'button[id="btn-add-section"]', function(e) {
1094
        e.preventDefault();
1095
        validatorFormSection.resetForm();
1096
        $('#form-section #section-slug').val('');
1097
        $('#form-section #section-name').val('');
1098
        instanceName = 'section-text';
1099
        let editor = CKEDITOR.instances[instanceName];
1100
        editor.setData('', function() {
1101
            editor.focus();
1102
        });
1103
        $('#form-section #section-value').val('0');
1104
        $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
1105
        $('#modal-section').modal('show');
1106
    });
1107
    $('body').on('click', 'button.btn-edit-section', function(e) {
1108
        e.preventDefault();
169 geraldo 1109
        var slug = $(this).data('section');
167 geraldo 1110
        var section;
1111
        var showForm = false;
1112
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1113
            section = objFormGenerator.sections[i];
171 geraldo 1114
            if (slug == section.slug_section) {
167 geraldo 1115
                validatorFormSection.resetForm();
171 geraldo 1116
                $('#form-section #section-slug').val(section.slug_section);
167 geraldo 1117
                $('#form-section #section-name').val(section.name);
1118
                instanceName = 'section-text';
1119
                let editor = CKEDITOR.instances[instanceName];
1120
                editor.setData(section.text, function() {
1121
                    editor.focus();
1122
                });
1123
                $('#form-section #section-value').val(section.value);
1124
                showForm = true;
1125
                break;
1126
            }
1127
        }
1128
        if (showForm) {
1129
            $('#modal-section h4[class="modal-title"]').html('LABEL_EDIT LABEL_SECTION');
1130
            $('#modal-section').modal('show');
1131
        }
1132
    });
1133
    $('body').on('click', 'button.btn-delete-section', function(e) {
1134
        e.preventDefault();
169 geraldo 1135
        var slug = $(this).data('section');
167 geraldo 1136
        bootbox.confirm({
1137
            title: "LABEL_DELETE LABEL_SECTION",
1138
            message: "LABEL_QUESTION_DELETE",
1139
            buttons: {
1140
                cancel: {
1141
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1142
                },
1143
                confirm: {
1144
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1145
                }
1146
            },
1147
            callback: function(result) {
1148
                if (result) {
1149
                    objFormGenerator.deleteSection(slug);
1150
                    renderData(objFormGenerator.sections);
1151
                }
1152
            }
1153
        });
1154
    });
1155
    $('body').on('click', 'button.btn-add-question', function(e) {
1156
        e.preventDefault();
1157
        validatorFormQuestion.resetForm();
169 geraldo 1158
        var slug = $(this).data('section');
167 geraldo 1159
        $('#form-question #question-section').val(slug);
1160
        $('#form-question #question-slug').val('');
1161
        instanceName = 'question-text';
1162
        let editor = CKEDITOR.instances[instanceName];
1163
        editor.setData('', function() {
1164
            editor.focus();
1165
        });
1166
        $('#form-question #question-value').val('0');
1167
        $('#form-question #question-type').val($('#form-question #question-type option:first').val());
1168
        $('#form-question #question-max-length').val('0');
1169
        $('#form-question #question-max-length').parent().show();
1170
        $('#form-question #question-multiline').val('0');
1171
        $('#form-question #question-multiline').parent().show();
1172
        $('#form-question #question-range').val('10');
1173
        $('#form-question #question-range').parent().hide();
1174
        $('#modal-question h4[class="modal-title"]').html('LABEL_ADD LABEL_QUESTION');
1175
        $('#modal-question').modal('show');
1176
    });
1177
    $('body').on('click', 'button.btn-edit-question', function(e) {
1178
        e.preventDefault();
1179
        var slug_section = $(this).data('section');
170 geraldo 1180
        var slug = $(this).data('question');
167 geraldo 1181
        var showForm = false;
1182
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1183
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1184
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1185
                    if (slug == objFormGenerator.sections[i].questions[j].slug_question) {
1186
                        validatorFormQuestion.resetForm();
1187
                        $('#form-question #question-section').val(objFormGenerator.sections[i].slug_section);
1188
                        $('#form-question #question-slug').val(objFormGenerator.sections[i].questions[j].slug_question);
1189
                        instanceName = 'question-text';
1190
                        let editor = CKEDITOR.instances[instanceName];
1191
                        editor.setData(objFormGenerator.sections[i].questions[j].text, function() {
1192
                            editor.focus();
1193
                        });
1194
                        $('#form-question #question-value').val(objFormGenerator.sections[i].questions[j].value);
1195
                        $('#form-question #question-type').val(objFormGenerator.sections[i].questions[j].type);
1196
                        if (objFormGenerator.sections[i].questions[j].type == 'open') {
1197
                            $('#form-question #question-max-length').val(objFormGenerator.sections[i].questions[j].maxlength);
1198
                            $('#form-question #question-max-length').parent().show();
1199
                            $('#form-question #question-multiline').val(objFormGenerator.sections[i].questions[j].multiline);
1200
                            $('#form-question #question-multiline').parent().show();
118 steven 1201
                        } else {
167 geraldo 1202
                            $('#form-question #question-max-length').val('0');
1203
                            $('#form-question #question-max-length').parent().hide();
1204
                            $('#form-question #question-multiline').val('0');
1205
                            $('#form-question #question-multiline').parent().hide();
118 steven 1206
                        }
167 geraldo 1207
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-range') {
1208
                            $('#form-question #question-range').val(objFormGenerator.sections[i].questions[j].range);
1209
                            $('#form-question #question-range').parent().show();
1210
                        } else {
1211
                            $('#form-question #question-range').val('10');
1212
                            $('#form-question #question-range').parent().hide();
1213
                        }
1214
                        showForm = true;
1215
                        break;
1216
                    }
1217
                }
1218
                break;
1219
            }
1220
        }
1221
        if (showForm) {
1222
            $('#modal-question h4[class="modal-title"]').html('LABEL_EDIT LABEL_QUESTION');
1223
            $('#modal-question').modal('show');
1224
        }
1225
    });
1226
    $('body').on('click', 'button.btn-delete-question', function(e) {
1227
        e.preventDefault();
1228
        var slug_section = $(this).data('section');
170 geraldo 1229
        var slug = $(this).data('question');
167 geraldo 1230
        bootbox.confirm({
1231
            title: "LABEL_DELETE LABEL_QUESTION",
1232
            message: "LABEL_QUESTION_DELETE",
1233
            buttons: {
1234
                cancel: {
1235
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1236
                },
1237
                confirm: {
1238
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1239
                }
1240
            },
1241
            callback: function(result) {
1242
                if (result) {
1243
                    objFormGenerator.deleteQuestion(slug_section, slug);
1244
                    renderData(objFormGenerator.sections);
1245
                }
1246
            }
1247
        });
1248
    });
172 geraldo 1249
 
180 geraldo 1250
     /**
1251
      * Get Question type
1252
      */
181 geraldo 1253
     const getQuestionTypeBySlug = (slug_section, slug_question) => {
180 geraldo 1254
         for (i = 0; i < objFormGenerator.sections.length; i++) {
1255
             if (slug_section == objFormGenerator.sections[i].slug_section) {
1256
                 for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1257
                     if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1258
                         return objFormGenerator.sections[i].questions[j].type;
1259
                     }
1260
                 }
1261
             }
1262
         }
1263
     }
1264
 
1265
     /**
1266
      * Render Sections data
1267
      */
1268
     const renderData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
1269
         getType: getQuestionTypeBySlug
1270
     }));
1271
 
167 geraldo 1272
    $('body').on('click', 'button.btn-add-option', function(e) {
1273
        e.preventDefault();
1274
        var slug_section = $(this).data('section');
1275
        var slug_question = $(this).data('question');
1276
        var showForm = false;
1277
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1278
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1279
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1280
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1281
                        validatorFormOption.resetForm();
1282
                        $('#form-option #option-section').val(slug_section);
1283
                        $('#form-option #option-question').val(slug_question);
1284
                        $('#form-option #option-slug').val('');
1285
                        instanceName = 'option-text';
1286
                        let editor = CKEDITOR.instances[instanceName];
1287
                        editor.setData('', function() {
1288
                            editor.focus();
1289
                        });
1290
                        $('#form-option #option-correct').val('0');
1291
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1292
                            $('#form-option #option-correct').parent().hide();
1293
                        } else {
1294
                            $('#form-option #option-correct').parent().show();
1295
                        }
1296
                        if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1297
                            $('#form-option #option-value').val('0');
1298
                            $('#form-option #option-value').parent().show();
1299
                        } else {
1300
                            $('#form-option #option-value').val('1');
1301
                            $('#form-option #option-value').parent().hide();
1302
                        }
1303
                        renderData(objFormGenerator.sections);
1304
                        showForm = true;
1305
                    }
1306
                }
1307
            }
1308
        }
1309
        if (showForm) {
1310
            $('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
1311
            $('#modal-option').modal('show');
1312
        }
1313
    });
171 geraldo 1314
 
167 geraldo 1315
    $('body').on('click', 'button.btn-edit-option', function(e) {
1316
        e.preventDefault();
1317
        var slug_section = $(this).data('section');
1318
        var slug_question = $(this).data('question');
1319
        var slug = $(this).data('slug');
1320
        var showForm = false;
1321
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1322
            if (slug_section == objFormGenerator.sections[i].slug_section) {
1323
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
1324
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
1325
                        for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
1326
                            if (slug == objFormGenerator.sections[i].questions[j].options[k].slug_option) {
1327
                                validatorFormOption.resetForm();
1328
                                $('#form-option #option-section').val(objFormGenerator.sections[i].slug_section);
1329
                                $('#form-option #option-question').val(objFormGenerator.sections[i].questions[j].slug_question);
1330
                                $('#form-option #option-slug').val(objFormGenerator.sections[i].questions[j].options[k].slug_option);
1331
                                instanceName = 'option-text';
1332
                                let editor = CKEDITOR.instances[instanceName];
1333
                                editor.setData(objFormGenerator.sections[i].questions[j].options[k].text, function() {
1334
                                    editor.focus();
1335
                                });
1336
                                $('#form-option #option-correct').val(objFormGenerator.sections[i].questions[j].options[k].correct);
1337
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'simple') {
1338
                                    $('#form-option #option-correct').parent().show();
1339
                                } else {
1340
                                    $('#form-option #option-correct').parent().hide();
1341
                                }
1342
                                $('#form-option #option-value').val(objFormGenerator.sections[i].questions[j].options[k].value);
1343
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
1344
                                    $('#form-option #option-value').parent().show();
1345
                                } else {
1346
                                    $('#form-option #option-value').parent().hide();
1347
                                }
1348
                                showForm = true;
1349
                                break;
1350
                            }
1351
                        }
1352
                    }
1353
                    if (showForm) {
1354
                        break;
1355
                    }
1356
                }
1357
            }
1358
            if (showForm) {
1359
                break;
1360
            }
1361
        }
1362
        if (showForm) {
1363
            $('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
1364
            $('#modal-option').modal('show');
1365
        }
1366
    });
1367
    $('body').on('click', 'button.btn-delete-option', function(e) {
1368
        e.preventDefault();
1369
        var slug_section = $(this).data('section');
1370
        var slug_question = $(this).data('question');
1371
        var slug = $(this).data('slug');
1372
        bootbox.confirm({
1373
            title: "LABEL_DELETE LABEL_OPTION",
1374
            message: "LABEL_QUESTION_DELETE",
1375
            buttons: {
1376
                cancel: {
1377
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
1378
                },
1379
                confirm: {
1380
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
1381
                }
1382
            },
1383
            callback: function(result) {
1384
                if (result) {
1385
                    objFormGenerator.deleteOption(slug_section, slug_question, slug);
1386
                    renderData(objFormGenerator.sections);
1387
                }
1388
            }
1389
        });
1390
    })
1391
    $('#form-section #section-value').inputNumberFormat({
1392
        'decimal': 2
1393
    });
1394
    $('#form-question #question-value').inputNumberFormat({
1395
        'decimal': 2
1396
    });
1397
    $('#form-question #question-max-length').inputNumberFormat({
1398
        'decimal': 0
1399
    });
1400
    $('#form-option #option-value').inputNumberFormat({
1401
        'decimal': 2
1402
    });
1403
    $('#form-question #question-type').change(function(e) {
1404
        e.preventDefault();
1405
        if ($('#form-question #question-type').val() == 'open') {
1406
            $('#form-question #question-max-length').parent().show();
1407
            $('#form-question #question-multiline').parent().show();
1408
        } else {
1409
            $('#form-question #question-max-length').val('0');
1410
            $('#form-question #question-max-length').parent().hide();
1411
            $('#form-question #question-multiline').val('0');
1412
            $('#form-question #question-multiline').parent().hide();
1413
        }
1414
        $('#form-question #question-range').val('10');
1415
        if ($('#form-question #question-type').val() == 'rating-range') {
1416
            $('#form-question #question-range').parent().show();
1417
        } else {
1418
            $('#form-question #question-range').parent().hide();
1419
        }
1420
    });
1421
    $('button.btn-add-form').click(function(e) {
1422
        e.preventDefault();
1423
        objFormGenerator.clear();
1424
        objFormGenerator.render();
1425
        validatorForm.resetForm();
1426
        $('#form-main #form-id').val('0');
1427
        $('#form-main #form-continue').val('0');
1428
        $('#form-main #form-name').val('');
1429
        instanceName = 'form-text';
1430
        let editor = CKEDITOR.instances[instanceName];
1431
        editor.setData('', function() {
1432
            editor.focus();
1433
        });
1434
        instanceName = 'form-description';
1435
        CKEDITOR.instances[instanceName].setData('');
1436
        $('#form-main #form-language').val('$lang_es'),
1437
            $('#form-main #form-status').val('$status_inactive');
1438
        $('#row-forms').hide();
1439
        $('#row-edit').show();
1440
        $('#form-main #form-name').focus();
1441
    });
1442
    $('button.btn-edit-cancel').click(function(e) {
1443
        e.preventDefault();
1444
        $('#row-edit').hide();
1445
        $('#row-forms').show();
1446
    });
1447
    $('button.btn-form-save-continue').click(function(e) {
1448
        e.preventDefault();
1449
        $('#form-main #form-continue').val('1')
1450
        $('#form-main').submit();
1451
    });
1452
    $('button.btn-form-save-close').click(function(e) {
1453
        e.preventDefault();
1454
        $('#form-main #form-continue').val('0')
1455
        $('#form-main').submit();
1456
    });
1457
    $('#modal-section, #modal-question, #modal-option').modal({
1458
        backdrop: 'static',
1459
        keyboard: false,
1460
        show: false
1461
    });
1462
});
118 steven 1463
JS;
115 efrain 1464
$this->inlineScript()->captureEnd();
1465
?>
118 steven 1466
 
121 steven 1467
<style type="text/css">
135 geraldo 1468
    tbody input[type="checkbox"]{
1469
        margin-left: 14px;
1470
    }
1471
    .panel-heading .accordion-toggle:after {
1472
        /* symbol for "opening" panels */
1473
        display: inline-block;
1474
        font: normal normal normal 14px/1 FontAwesome;
1475
        font-size: inherit;
1476
        content: "\f077" ;
1477
        float: right;        /* adjust as needed */
1478
        color: grey;         /* adjust as needed */
1479
        text-rendering: auto;
1480
        -webkit-font-smoothing: antialiased;
1481
    }
1482
    .panel-heading .accordion-toggle.collapsed:after {
1483
        /* symbol for "collapsed" panels */
1484
        content: "\f078";    /* adjust as needed, taken from bootstrap.css */
1485
    }
121 steven 1486
</style>
115 efrain 1487
<!-- Content Header (Page header) -->
1488
<section class="content-header">
135 geraldo 1489
    <div class="container-fluid">
1490
        <div class="row mb-2">
1491
            <div class="col-sm-12">
1492
                <h1>LABEL_SELF_EVALUATION_FORMS</h1>
1493
            </div>
1494
        </div>
145 geraldo 1495
    </div>
1496
    <!-- /.container-fluid -->
115 efrain 1497
</section>
1498
<section class="content">
135 geraldo 1499
    <div class="container-fluid" id="row-forms">
1500
        <div class="row">
1501
            <div class="col-12">
145 geraldo 1502
                <div class="card">
135 geraldo 1503
                    <div class="card-body">
153 geraldo 1504
                        <table id="gridTable" class="table   table-hover">
1505
                            <thead>
1506
                                <tr>
1507
                                    <th>LABEL_NAME</th>
1508
                                    <th>LABEL_LANGUAGE</th>
1509
                                    <th>LABEL_ACTIVE</th>
1510
                                    <th>LABEL_ACTIONS</th>
1511
                                </tr>
1512
                            </thead>
155 geraldo 1513
                            <tbody></tbody>
153 geraldo 1514
                        </table>
135 geraldo 1515
                    </div>
1516
                    <div class="card-footer clearfix">
1517
                        <div style="float:right;">
1518
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
1519
                            <?php if ($allowAdd) : ?>
1520
                                <button type="button" class="btn btn-primary btn-add-form"><i class="fa fa-plus"></i> LABEL_ADD </button>
1521
                            <?php endif; ?>
1522
                        </div>
1523
                    </div>
1524
                </div>
145 geraldo 1525
            </div>
1526
        </div>
135 geraldo 1527
    </div>
154 geraldo 1528
 
155 geraldo 1529
    <!-- Create/Edit Form -->
174 geraldo 1530
 
1531
    <div class="row" id="row-edit" style="display: none">
1532
        <div class="col-xs-12 col-md-12">
1533
            <form action="#" name="form-main" id="form-main">
1534
                <input type="hidden" name="form-id" id="form-id" value="0" />
1535
                <input type="hidden" name="form-continue" id="form-continue" value="0" />
1536
                <div class="form-group">
1537
                    <label for="form-name">LABEL_FIRST_NAME</label>
1538
                    <input type="text" name="form-name" id="form-name" class="form-control" maxlength="50" />
1539
                </div>
1540
                <div class="form-group">
1541
                    <label for="form-description">LABEL_DESCRIPTION</label>
1542
                    <!--  ckeditor -->
1543
                    <textarea  name="form-description" id="form-description" rows="5" class="ckeditor form-control"></textarea>
1544
                </div>
1545
                <div class="form-group">
1546
                    <label for="form-text">LABEL_TEXT</label>
1547
                    <!--  ckeditor -->
1548
                    <textarea  name="form-text" id="form-text" rows="5" class="ckeditor form-control"></textarea>
1549
                </div>
1550
                <div class="form-group">
1551
                    <label for="form-language">LABEL_LANGUAGES</label>
1552
                    <select name="form-language" id="form-language" class="form-control">
176 geraldo 1553
                        <option value="<?php echo $lang_en; ?>">LABEL_ENGLISH</option>
1554
                        <option value="<?php echo $lang_es; ?>">LABEL_SPANISH</option>
174 geraldo 1555
                    </select>
1556
                </div>
1557
                <div class="form-group">
1558
                    <label for="form-status">LABEL_STATUS</label>
1559
                    <select name="form-status" id="form-status" class="form-control">
176 geraldo 1560
                        <option value="<?php echo $status_inactive; ?>">LABEL_INACTIVE</option>
1561
                        <option value="<?php echo $status_active; ?>">LABEL_ACTIVE</option>
174 geraldo 1562
                    </select>
1563
                </div>
1564
                <br/>
1565
                <div class="row">
1566
                    <div class="col-xs-12 col-md-12 text-right">
1567
                        <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>
1568
                    </div>
1569
                </div>
1570
                <br />
1571
                <div class="row">
1572
                    <div class="col-xs-12 col-md-12">
1573
                        <div class="panel-group" id="rows"></div>
1574
                    </div>
1575
                </div>
1576
                <div class="form-group">
1577
                    <button type="submit" form="form-main" class="btn btn-info btn-form-save-continue">LABEL_SAVE & LABEL_CONTINUE</button>
1578
                    <button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE & LABEL_CLOSE</button>
1579
                    <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
1580
                </div>
1581
            </form>
1582
        </div>
1583
    </div>
1584
 
155 geraldo 1585
    <!-- Create/Edit Form-->
154 geraldo 1586
 
135 geraldo 1587
    <!-- Section Modal -->
174 geraldo 1588
    <div  id="modal-section" class="modal" tabindex="-1" role="dialog">
1589
        <div class="modal-dialog modal-lg" role="document">
1590
            <form action="#" name="form-section" id="form-section">
1591
                <input type="hidden" name="section-slug" id="section-slug" value="" />
1592
                <div class="modal-content">
1593
                    <div class="modal-header">
1594
                        <h4 class="modal-title">LABEL_ADD LABEL_SECTION</h4>
1595
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1596
                            <span aria-hidden="true">&times;</span>
1597
                        </button>
1598
                    </div>
1599
                    <div class="modal-body">
1600
                        <div class="form-group">
1601
                            <label for="section-name">LABEL_FIRST_NAME</label>
1602
                            <input type="text" name="section-name" id="section-name" class="form-control" maxlength="50" value="" />
1603
                        </div>
1604
                        <div class="form-group">
1605
                            <label for="section-text">LABEL_TEXT</label>
1606
                            <!--  ckeditor -->
1607
                            <textarea  name="section-text" id="section-text" rows="5" class="ckeditor form-control"></textarea>
1608
                        </div>
1609
                        <div class="form-group">
1610
                            <label for="section-value">LABEL_VALUE</label>
1611
                            <input type="text" name="section-value" id="section-value"  class="form-control" value="0" />
1612
                        </div>
1613
                    </div>
1614
                    <div class="modal-footer">
1615
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
1616
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1617
                    </div>
1618
                </div>
1619
            </form>
1620
        </div>
1621
    </div>
135 geraldo 1622
    <!-- End Modal Section -->
153 geraldo 1623
 
135 geraldo 1624
    <!-- Question Modal -->
156 geraldo 1625
 
174 geraldo 1626
    <div  id="modal-question" class="modal" tabindex="-1" role="dialog">
1627
        <div class="modal-dialog modal-lg" role="document">
1628
            <form action="#" name="form-question" id="form-question">
1629
                <input type="hidden" name="question-section" id="question-section" />
1630
                <input type="hidden" name="question-slug" id="question-slug" />
1631
                <div class="modal-content">
1632
                    <div class="modal-header">
1633
                        <h4 class="modal-title">LABEL_ADD LABEL_QUESTION</h4>
1634
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1635
                            <span aria-hidden="true">&times;</span>
1636
                        </button>
1637
                    </div>
1638
                    <div class="modal-body">
1639
                        <div class="form-group">
1640
                            <label for="question-text">LABEL_TEXT</label>
1641
                            <!--  ckeditor -->
1642
                            <textarea  name="question-text" id="question-text" rows="5" class="ckeditor form-control"></textarea>
1643
                        </div>
1644
                        <div class="form-group">
1645
                            <label for="question-value">LABEL_VALUE</label>
1646
                            <input type="text" name="question-value" id="question-value"  class="form-control" />
1647
                        </div>
1648
                        <div class="form-group">
1649
                            <label for="question-type">LABEL_TYPE</label>
1650
                            <select name="question-type" id="question-type" class="form-control">
1651
                                <option value="open">LABEL_OPEN</option>
1652
                                <option value="simple">Simple</option>
1653
                                <option value="multiple">Multiple</option>
1654
                                <option value="rating-open">LABEL_RATING_OPEN</option>
1655
                                <option value="rating-range">LABEL_RATING_RANGE</option>
1656
                            </select>
1657
                        </div>
1658
                        <div class="form-group">
1659
                            <label for="question-max-length">LABEL_MAXLENGTH</label>
1660
                            <input type="text" name="question-max-length" id="question-max-length"  class="form-control" />
1661
                        </div>
1662
                        <div class="form-group">
1663
                            <label for="question-multiline">LABEL_MULTI_LINE</label>
1664
                            <select name="question-multiline" id="question-multiline" class="form-control">
1665
                                <option value="1">LABEL_YES</option>
1666
                                <option value="0">LABEL_NOT</option>
1667
                            </select>
1668
                        </div>
1669
                        <div class="form-group">
1670
                            <label for="question-range">LABEL_RANGE</label>
1671
                            <select name="question-range" id="question-range" class="form-control">
1672
                                <option value="10">1-10</option>
1673
                                <option value="6">1-6</option>
1674
                                <option value="5">1-5</option>
1675
                            </select>
1676
                        </div>
1677
                    </div>
1678
                    <div class="modal-footer">
1679
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
1680
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1681
                    </div>
1682
                </div>
1683
            </form>
1684
        </div>
1685
    </div>
156 geraldo 1686
 
167 geraldo 1687
    <!-- End Modal Question -->
153 geraldo 1688
 
1689
    <!-- Modal Options -->
156 geraldo 1690
 
174 geraldo 1691
    <div  id="modal-option" class="modal" tabindex="-1" role="dialog">
1692
        <div class="modal-dialog modal-lg" role="document">
1693
            <form action="#" name="form-option" id="form-option">
1694
                <input type="hidden" name="option-section" id="option-section" value="" />
1695
                <input type="hidden" name="option-question" id="option-question" value="" />
1696
                <input type="hidden" name="option-slug" id="option-slug" value="" />
1697
                <div class="modal-content">
1698
                    <div class="modal-header">
1699
                        <h4 class="modal-title">LABEL_OPTION</h4>
1700
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1701
                            <span aria-hidden="true">&times;</span>
1702
                        </button>
1703
                    </div>
1704
                    <div class="modal-body">
1705
                        <div class="form-group">
1706
                            <label for="option-text">LABEL_TEXT</label>
1707
                            <!--  ckeditor -->
1708
                            <textarea  name="option-text" id="option-text" rows="5" class="ckeditor form-control"></textarea>
1709
                        </div>
1710
                        <div class="form-group">
1711
                            <label for="option-correct">LABEL_ANSWER_CORRECT</label>
1712
                            <select name="option-correct" id="option-correct" class="form-control">
1713
                                <option value="1">LABEL_YES</option>
1714
                                <option value="0">LABEL_NOT</option>
1715
                            </select>
1716
                        </div>
1717
                        <div class="form-group">
1718
                            <label for="option-value">LABEL_VALUE</label>
1719
                            <input type="text" name="option-value" id="option-value" class="form-control" />
1720
                        </div>
1721
                    </div>
1722
                    <div class="modal-footer">
1723
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
1724
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1725
                    </div>
1726
                </div>
1727
            </form>
1728
        </div>
1729
    </div>
1730
 
135 geraldo 1731
    <!-- End Modal Options -->
153 geraldo 1732
 
180 geraldo 1733
    <!---Template Sections --->
1734
    <script id="sectionTemplate" type="text/x-jsrender">
1735
    <div class="panel panel-default" id="panel-{{:slug_section}}">
1736
        <div class="panel-heading">
1737
            <h4 class="panel-title">
1738
                <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:slug_section}}" href="#collapse-{{:slug_section}}">
1739
                    <span class="section-name{{:slug_section}}">
1740
                        {{:name}}
1741
                    </span>
1742
                </a>
1743
            </h4>
1744
        </div>
1745
        <div id="collapse-{{:slug_section}}" class="panel-collapse in collapse show">
1746
            <div class="panel-body">
1747
                <div class="table-responsive">
1748
                    <table class="table table-bordered">
1749
                        <thead>
1750
                            <tr>
1751
                                <th>LABEL_ELEMENT</th>
1752
                                <th>LABEL_TEXT</th>
1753
                                <th>LABEL_VALUE</th>
1754
                                <th>LABEL_TYPE</th>
1755
                                <th>LABEL_ACTIONS</th>
1756
                            </tr>
1757
                        </thead>
1758
                        <tbody>
1759
                            <tr class="tr-section">
1760
                                <td class="text-left">LABEL_SECTION</td>
1761
                                <td class="text-left">{{:name}}</td>
1762
                                <td>{{:value}}</td>
1763
                                <td></td>
1764
                                <td>
1765
                                    <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>
1766
                                    <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>
1767
                                    <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>
1768
                                </td>
1769
                            </tr>
1770
                            {{for questions}}
1771
                            <tr class="tr-question">
1772
                                <td class="text-left">--LABEL_QUESTION</td>
1773
                                <td class="text-left">
1774
                                    {{:text}}
1775
                                </td>
1776
                                <td><font color="red">{{:value}}</font></td>
1777
                                <td class="text-capitalize">
1778
                                    {{if type == 'open'}} LABEL_OPEN {{/if}}
1779
                                    {{if type == 'simple'}} Simple {{/if}}
1780
                                    {{if type == 'multiple'}} Multiple {{/if}}
1781
                                    {{if type == 'rating-open'}} LABEL_RATING_OPEN {{/if}}
1782
                                    {{if type == 'rating-range'}} LABEL_RATING_RANGE {{/if}}
1783
                                </td>
1784
                                <td>
1785
                                    <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>
1786
                                    <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>
1787
                                    <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>
1788
                                </td>
1789
                            </tr>
1790
                            {{for options}}
1791
                            <tr class="tr-option">
1792
                                <td class="text-left">---LABEL_OPTION</td>
1793
                                <td class="text-left">
1794
                                    {{:text}}
1795
                                </td>
1796
                                <td>
153 geraldo 1797
 
183 geraldo 1798
                                    {{if getType( slug_section, slug_question) == 'multiple' || getType( slug_section, slug_question) == 'rating-open'  }}
180 geraldo 1799
                                    {{:value}}
1800
                                    {{/if}}
1801
                                </td>
1802
                                <td class="text-left">
183 geraldo 1803
                                    {{if getType( slug_section, slug_question) != rating-open'}}
180 geraldo 1804
                                    {{if correct == 1}}
1805
                                    <font color="green">LABEL_CORRECT</font>
1806
                                    {{/if}}
1807
                                    {{if correct == 0}}
1808
                                    <font color="red">LABEL_FAIL</font>
1809
                                    {{/if}}
1810
                                    {{/if}}
1811
                                </td>
1812
                                <td>
1813
                                    <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>
1814
                                    <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>
1815
                                </td>
1816
                            </tr>
1817
                            {{/for}}
1818
                            {{/for}}
1819
                        </tbody>
1820
                    </table>
1821
                </div>
1822
            </div>
1823
        </div>
1824
    </div>
1825
    </script>
1826
 
1827
    <!-- End Template Sections-->
1828
 
119 steven 1829
</section>