Proyectos de Subversion LeadersLinked - Backend

Rev

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

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