Proyectos de Subversion LeadersLinked - Backend

Rev

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