Proyectos de Subversion LeadersLinked - Backend

Rev

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