Proyectos de Subversion LeadersLinked - Backend

Rev

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

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