Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 205 | Rev 207 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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