Proyectos de Subversion LeadersLinked - Backend

Rev

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