Proyectos de Subversion LeadersLinked - Backend

Rev

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