Proyectos de Subversion LeadersLinked - Backend

Rev

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