Proyectos de Subversion LeadersLinked - Backend

Rev

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