Proyectos de Subversion LeadersLinked - Backend

Rev

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

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