Proyectos de Subversion LeadersLinked - Backend

Rev

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