Proyectos de Subversion LeadersLinked - Backend

Rev

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

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