Proyectos de Subversion LeadersLinked - Backend

Rev

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