Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
251 geraldo 1
<?php
2
$acl = $this->viewModel()->getRoot()->getVariable('acl');
3
$currentUser = $this->currentUserHelper();
4
 
5
$roleName = $currentUser->getUserTypeId();
6
 
253 geraldo 7
$routeDatatable = $this->url('self-evaluation/reviews');
251 geraldo 8
$routeDashboard = $this->url('dashboard');
9
 
253 geraldo 10
$allowEdit = $acl->isAllowed($roleName, 'self-evaluation/reviews/edit') ? 1 : 0;
251 geraldo 11
 
12
 
13
$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));
14
 
15
 
16
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
17
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
18
 
19
 
20
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
21
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
22
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
23
 
24
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
25
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
26
 
27
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
28
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
29
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
30
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
31
 
32
 
33
$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.min.css'));
34
$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css'));
35
 
36
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/select2.full.min.js'));
37
 
38
$this->inlineScript()->appendFile($this->basePath('plugins/moment/moment-with-locales.min.js'));
39
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css'));
40
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'));
41
 
42
 
43
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
44
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
45
 
46
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
47
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
48
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-input-number/input-number-format.jquery.js'));
49
// bootbox Alert //
50
$this->inlineScript()->appendFile($this->basePath('plugins/bootbox/bootbox.min.js'));
51
// JsRender //
52
$this->inlineScript()->appendFile($this->basePath('plugins/jsrender/jsrender.min.js'));
53
 
54
 
55
$this->inlineScript()->captureStart();
56
echo <<<JS
57
    const classFormGenerator = function() {
58
    this.id = 0,
59
        this.table = '',
60
        this.name = '',
61
        this.text = '',
62
        this.status = 'a',
63
        this.sections = [],
64
        this.clear = function() {
65
            this.sections = [];
66
            this.render();
67
        },
68
        /**
69
         * Render array sections
70
         */
71
        this.renderSection = function(slug_section) {
72
            var s = '';
73
            for (i = 0; i < this.sections.length; i++) {
74
                if (slug_section != this.sections[i].slug_section) {
75
                    continue;
76
                }
77
                for (j = 0; j < this.sections[i].questions.length; j++) {
78
                    this.sections[i].questions[j].position = j;
79
                    if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {
80
                        this.sections[i].questions[j].options.sort(function(a, b) {
81
                            if (a.position > b.position) {
82
                                return 1;
83
                            }
84
                            if (a.position < b.position) {
85
                                return -1;
86
                            }
87
                            return 0;
88
                        });
89
                        for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
90
                            this.sections[i].questions[j].options[k].position = j;
91
                        }
92
                    }
93
                }
94
            }
95
            $('[data-toggle="tooltip"]').tooltip();
96
        },
97
        this.render = function() {
98
            this.sections.sort(function(a, b) {
99
                if (a.position > b.position) {
100
                    return 1;
101
                }
102
                if (a.position < b.position) {
103
                    return -1;
104
                }
105
                return 0;
106
            });
107
            var s = '';
108
            for (i = 0; i < this.sections.length; i++) {
109
                this.sections[i].position = i;
110
                this.sections[i].questions.sort(function(a, b) {
111
                    if (a.position > b.position) {
112
                        return 1;
113
                    }
114
                    if (a.position < b.position) {
115
                        return -1;
116
                    }
117
                    return 0;
118
                });
119
                for (j = 0; j < this.sections[i].questions.length; j++) {
120
                    this.sections[i].questions[j].position = j;
121
                    if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {
122
                        this.sections[i].questions[j].options.sort(function(a, b) {
123
                            if (a.position > b.position) {
124
                                return 1;
125
                            }
126
                            if (a.position < b.position) {
127
                                return -1;
128
                            }
129
                            return 0;
130
                        });
131
                        for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
132
                            this.sections[i].questions[j].options[k].position = j;
133
                        }
134
                    }
135
                }
136
            }
137
            $('[data-toggle="tooltip"]').tooltip();
138
        },
254 geraldo 139
        /**
140
         * Add element to section array
141
         */
142
        this.addSection = function(name, text, value) {
143
            var d = new Date();
144
            var slug = 'section' + d.getTime();
145
            var position = 0;
146
            $.each(this.sections, function(index, section) {
147
                if (position < section.position) {
148
                    position = section.position;
149
                }
150
            });
151
            position++;
152
            var section = {
153
                'slug_section': slug,
154
                'name': name,
155
                'text': text,
156
                'value': value,
157
                'position': position,
158
                'questions': [],
159
                'status': 0
160
            }
161
            this.sections.push(section);
162
        },
251 geraldo 163
         /**
254 geraldo 164
         * Edit element to section array
165
         */
166
        this.editSection = function(slug, name, text, value) {
167
            var renderTable = false;
168
            for (i = 0; i < this.sections.length; i++) {
169
                if (slug == this.sections[i].slug_section) {
170
                    this.sections[i].name = name;
171
                    this.sections[i].text = text;
172
                    this.sections[i].value = value;
173
                    renderTable = true;
174
                    break;
175
                }
176
            }
177
            if (renderTable) {
178
                this.renderSection(slug);
179
            }
180
        },
181
         /**
182
         * Remove element to section array
183
         */
184
        this.deleteSection = function(slug) {
185
            var renderTable = false;
186
            for (i = 0; i < this.sections.length; i++) {
187
                if (slug == this.sections[i].slug_section) {
188
                    this.sections.splice(i, 1);
189
                    renderTable = true;
190
                    break;
191
                }
192
            }
193
            if (renderTable) {
194
                $('#panel' + slug).remove();
195
            }
196
        },
197
         /**
251 geraldo 198
         * Add element to question array
199
         */
254 geraldo 200
        this.addQuestion = function(slug_section, text, value, type, maxlength, multiline, range) {
201
            var d = new Date();
202
            var slug_question = 'question' + d.getTime();
203
            var position = 0;
204
            var renderTable = false;
205
            for (i = 0; i < this.sections.length; i++) {
206
                if (slug_section == this.sections[i].slug_section) {
207
                    $.each(this.sections[i].questions, function(index, question) {
208
                        if (position < question.position) {
209
                            position = question.position;
210
                        }
211
                    });
212
                    position++;
213
                    var question = {
214
                        'slug_section': slug_section,
215
                        'slug_question': slug_question,
216
                        'text': text,
217
                        'value': value,
218
                        'type': type,
219
                        'position': position,
220
                        'maxlength': maxlength,
221
                        'multiline': multiline,
222
                        'range': range,
223
                        'options': [],
224
                        'answer': type=='multiple' ? [] : ''
225
                    }
226
                    this.sections[i].questions.push(question);
227
                    renderTable = true;
228
                    break;
229
                }
230
            }
231
            if (renderTable) {
232
                this.renderSection(slug_section);
233
            }
234
        },
235
         /**
236
         * Add element to question array
237
         */
251 geraldo 238
        this.editQuestion = function(slug_section, slug_question, text, value, type, maxlength, multiline, range) {
239
            var renderTable = false;
240
            for (i = 0; i < this.sections.length; i++) {
241
                if (slug_section == this.sections[i].slug_section) {
242
                    for (j = 0; j < this.sections[i].questions.length; j++) {
243
                        if (slug_question == this.sections[i].questions[j].slug_question) {
244
                            this.sections[i].questions[j].text = text,
245
                                this.sections[i].questions[j].value = value,
246
                                this.sections[i].questions[j].type = type;
247
                            if (type == 'open') {
248
                                this.sections[i].questions[j].maxlength = maxlength;
249
                                this.sections[i].questions[j].multiline = multiline;
250
                                this.sections[i].questions[j].options = [];
251
                            } else {
252
                                this.sections[i].questions[j].maxlength = 0;
253
                                this.sections[i].questions[j].multiline = 0;
254
                            }
255
                            if (type == 'rating-range') {
256
                                this.sections[i].questions[j].range = range;
257
                            } else {
258
                                this.sections[i].questions[j].range = 0;
259
                            }
260
 
261
                            if(type=='multiple'){
262
                                this.sections[i].questions[j].answer = [];
263
                            }else{
264
                                this.sections[i].questions[j].answer = '';
265
                            }
266
 
267
                            renderTable = true;
268
                            break;
269
                        }
270
                    }
271
                }
272
                if (renderTable) {
273
                    break;
274
                }
275
            }
276
            if (renderTable) {
277
                this.renderSection(slug_section);
278
            }
254 geraldo 279
        },
280
        /**
281
         * Remove element to question array
282
         */
283
        this.deleteQuestion = function(slug_section, slug_question) {
284
            var renderTable = false;
285
            for (i = 0; i < this.sections.length; i++) {
286
                if (slug_section == this.sections[i].slug_section) {
287
                    for (j = 0; j < this.sections[i].questions.length; j++) {
288
                        if (slug_question == this.sections[i].questions[j].slug_question) {
289
                            this.sections[i].questions.splice(j, 1);
290
                            renderTable = true;
291
                            break;
292
                        }
293
                    }
294
                }
295
                if (renderTable) {
296
                    break;
297
                }
298
            }
299
            if (renderTable) {
300
                this.renderSection(slug_section);
301
            }
302
        },
303
        /**
304
         * Add element to option array
305
         */
306
        this.addOption = function(slug_section, slug_question, text, correct, value) {
307
            var d = new Date();
308
            var slug_option = 'option' + d.getTime();
309
            var position = 0;
310
            var renderTable = false;
311
            for (i = 0; i < this.sections.length; i++) {
312
                if (slug_section == this.sections[i].slug_section) {
313
                    for (j = 0; j < this.sections[i].questions.length; j++) {
314
                        if (slug_question == this.sections[i].questions[j].slug_question) {
315
                            $.each(this.sections[i].questions[j].options, function(index, option) {
316
                                if (position < option.position) {
317
                                    position = option.position;
318
                                }
319
                            });
320
                            position++;
321
                            var option = {
322
                                'slug_section': slug_section,
323
                                'slug_question': slug_question,
324
                                'slug_option': slug_option,
325
                                'text': text,
326
                                'correct': correct,
327
                                'value': value,
328
                                'checked': false
329
                            }
330
                            this.sections[i].questions[j].options.push(option);
331
                            renderTable = true;
332
                            break;
333
                        }
334
                        if (renderTable) {
335
                            break;
336
                        }
337
                    }
338
                }
339
            }
340
            if (renderTable) {
341
                this.renderSection(slug_section);
342
            }
343
        },
344
        /**
345
         * Edit element to option array
346
         */
347
        this.editOption = function(slug_section, slug_question, option_slug, text, correct, value) {
348
            var renderTable = false;
349
            for (i = 0; i < this.sections.length; i++) {
350
                if (slug_section == this.sections[i].slug_section) {
351
                    for (j = 0; j < this.sections[i].questions.length; j++) {
352
                        if (slug_question == this.sections[i].questions[j].slug_question) {
353
                            for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
354
                                if (option_slug == this.sections[i].questions[j].options[k].slug_option) {
355
                                    this.sections[i].questions[j].options[k].text = text;
356
                                    this.sections[i].questions[j].options[k].correct = correct;
357
                                    this.sections[i].questions[j].options[k].value = value;
358
                                    renderTable = true;
359
                                    break;
360
                                }
361
                            }
362
                        }
363
                        if (renderTable) {
364
                            break;
365
                        }
366
                    }
367
                }
368
                if (renderTable) {
369
                    break;
370
                }
371
            }
372
            if (renderTable) {
373
                this.renderSection(slug_section);
374
            }
375
        },
376
        /**
377
         * Remove element to option array
378
         */
379
        this.deleteOption = function(slug_section, slug_question, option_slug) {
380
            var renderTable = false;
381
            for (i = 0; i < this.sections.length; i++) {
382
                if (slug_section == this.sections[i].slug_section) {
383
                    for (j = 0; j < this.sections[i].questions.length; j++) {
384
                        if (slug_question == this.sections[i].questions[j].slug_question) {
385
                            for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
386
                                if (option_slug == this.sections[i].questions[j].options[k].slug_option) {
387
                                    this.sections[i].questions[j].options.splice(k, 1);
388
                                    renderTable = true;
389
                                    break;
390
                                }
391
                            }
392
                        }
393
                        if (renderTable) {
394
                            break;
395
                        }
396
                    }
397
                }
398
                if (renderTable) {
399
                    break;
400
                }
401
            }
402
            if (renderTable) {
403
                this.renderSection(slug_section);
404
            }
251 geraldo 405
        }
406
}
407
 
408
function htmlEntities(str) {
409
    return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
410
}
411
jQuery(document).ready(function($) {
412
    var objFormGenerator = new classFormGenerator();
413
    objFormGenerator.render();
414
    var allowEdit = $allowEdit;
415
    var allowDelete = $allowDelete;
416
    /**
417
     * Get rows and set data table
418
     */
419
    var tableForm = $('#gridTable').dataTable({
420
        'processing': true,
421
        'serverSide': true,
422
        'searching': true,
423
        'order': [
424
            [0, 'asc']
425
        ],
426
        'ordering': true,
427
        'ordenable': true,
428
        'responsive': true,
429
        'select': false,
430
        'paging': true,
431
        'pagingType': 'simple_numbers',
432
        'ajax': {
433
            'url': '$routeDatatable',
434
            'type': 'get',
435
            'beforeSend': function(request) {
436
                NProgress.start();
437
            },
438
            'dataFilter': function(response) {
439
                var response = jQuery.parseJSON(response);
440
                var json = {};
441
                json.recordsTotal = 0;
442
                json.recordsFiltered = 0;
443
                json.data = [];
444
                if (response.success) {
445
                    json.recordsTotal = response.data.total;
446
                    json.recordsFiltered = response.data.total;
447
                    json.data = response.data.items;
448
                } else {
449
                    $.fn.showError(response.data)
450
                }
451
                return JSON.stringify(json);
452
            }
453
        },
454
        'language': {
455
            'sProcessing': 'LABEL_DATATABLE_SPROCESSING',
456
            'sLengthMenu': 'LABEL_DATATABLE_SLENGTHMENU',
457
            'sZeroRecords': 'LABEL_DATATABLE_SZERORECORDS',
458
            'sEmptyTable': 'LABEL_DATATABLE_SEMPTYTABLE',
459
            'sInfo': 'LABEL_DATATABLE_SINFO',
460
            'sInfoEmpty': 'LABEL_DATATABLE_SINFOEMPTY',
461
            'sInfoFiltered': 'LABEL_DATATABLE_SINFOFILTERED',
462
            'sInfoPostFix': '',
463
            'sSearch': 'LABEL_DATATABLE_SSEARCH',
464
            'sUrl': '',
465
            'sInfoThousands': ',',
466
            'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
467
            'oPaginate': {
468
                'sFirst': 'LABEL_DATATABLE_SFIRST',
469
                'sLast': 'LABEL_DATATABLE_SLAST',
470
                'sNext': 'LABEL_DATATABLE_SNEXT',
471
                'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
472
            },
473
            'oAria': {
474
                'sSortAscending': ': LABEL_DATATABLE_SSORTASCENDING',
475
                'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
476
            },
477
        },
478
        'drawCallback': function(settings) {
479
            NProgress.done();
480
            $('button.btn-delete').confirmation({
481
                rootSelector: 'button.btn-delete',
482
                title: 'LABEL_ARE_YOU_SURE',
483
                singleton: true,
484
                btnOkLabel: 'LABEL_YES',
485
                btnCancelLabel: 'LABEL_NO',
486
                onConfirm: function(value) {
487
                    action = $(this).data('href');
488
                    NProgress.start();
489
                    $.ajax({
490
                        'dataType': 'json',
491
                        'accept': 'application/json',
492
                        'method': 'post',
493
                        'url': action,
494
                    }).done(function(response) {
495
                        if (response['success']) {
496
                            $.fn.showSuccess(response['data']);
497
                            tableForm.fnDraw();
498
                        } else {
499
                            $.fn.showError(response['data']);
500
                        }
501
                    }).fail(function(jqXHR, textStatus, errorThrown) {
502
                        $.fn.showError(textStatus);
503
                    }).always(function() {
504
                        NProgress.done();
505
                    });
506
                },
507
            });
508
        },
509
        'aoColumns': [{
510
                'mDataProp': 'name'
511
            },
512
            {
513
                'mDataProp': 'language'
514
            },
515
            {
516
                'mDataProp': 'status'
517
            },
518
            {
519
                'mDataProp': 'actions'
520
            },
521
        ],
522
        'columnDefs': [{
523
                'targets': 0,
524
                'className': 'text-vertical-middle',
525
            },
526
            {
527
                'targets': 1,
528
                'className': 'text-vertical-middle',
529
            },
530
            {
531
                'targets': -2,
532
                'orderable': false,
533
                'className': 'text-center',
534
                'render': function(data, type, row) {
535
                    checked = data == 'a' ? ' checked="checked" ' : '';
536
                    return '<div class="checkbox checkbox-success">' +
537
                        '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
538
                        '<label ></label></div>';
539
                }
540
            },
541
            {
542
                'targets': -1,
543
                'orderable': false,
544
                'render': function(data, type, row) {
545
                    s = '';
546
                    if (allowEdit) {
547
                        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;';
548
                    }
549
                    if (allowDelete) {
550
                        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;';
551
                    }
552
                    return s;
553
                }
554
            }
555
        ],
556
    });
557
    /**
558
     * Clicked on edit form
559
     */
560
    $('body').on('click', 'button.btn-edit-form', function(e) {
561
        e.preventDefault();
562
        form_id = $(this).data('id')
563
        var action = $(this).data('href');
564
        $.ajax({
565
            'dataType': 'json',
566
            'accept': 'application/json',
567
            'method': 'get',
568
            'url': action,
569
        }).done(function(response) {
570
            if (response['success']) {
571
                validatorForm.resetForm();
572
                $('#form-main').attr('action', action);
573
                $('#form-main #form-id').val(response['data']['id']),
574
                $('#form-main #form-continue').val('0');
575
                $('#form-main #form-name').val(response['data']['name']),
576
 
577
                /*----------Set Ckeditor ------------*/
578
                CKEDITOR.instances['form-description'].setData(response['data']['description']);
579
                CKEDITOR.instances['form-text'].setData(response['data']['text']);
580
 
581
                $('#form-main #form-language').val(response['data']['language']),
582
                $('#form-main #form-status').val(response['data']['status']);
583
 
584
                /*-------------Render Sections -------*/
585
 
586
                objFormGenerator.clear();
587
                objFormGenerator.sections = response['data']['content'] || [];
588
                objFormGenerator.render();
589
                renderSectionData(objFormGenerator.sections);
590
 
254 geraldo 591
                $('#row-forms').hide();
251 geraldo 592
                $('#row-edit').show();
593
                $('#form-main #form-name').focus();
594
 
595
            } else {
596
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
597
            }
598
        }).fail(function(jqXHR, textStatus, errorThrown) {
599
            $.fn.showError(textStatus);
600
        });
601
    });
602
    $(document).on('click', '[data-type="select_all"]', function() {
603
        if ($('input[name="select_all"]:checked').val() == 'all') {
604
            $('[data-type="select"]').prop('checked', true);
605
            $('[data-action="delete"]').removeClass('hide');
606
        } else {
607
            $('[data-type="select"]').prop('checked', false);
608
            $('[data-action="delete"]').addClass('hide');
609
        }
610
    });
611
 
612
    function getLength() {
613
        return $('[data-type="select"]').length;
614
    }
615
 
616
    function currentSelected() {
617
        var selected = [];
618
        $.each($("input[name='select[]']:checked"), function() {
619
            selected.push($(this).val());
620
        });
621
        return selected;
622
    }
623
    $(document).on('change', "input[name='select[]']", function() {
624
        var c = currentSelected();
625
        var cc = getLength();
626
        if (c.length == cc) {
627
            if ($('[data-action="delete"]').hasClass('hide')) {
628
                $('[data-action="delete"]').removeClass('hide');
629
            }
630
            return true;
631
        } else {
632
            $('input[name="select_all"]').prop('checked', false);
633
        }
634
        if (c.length > 0) {
635
            if ($('[data-action="delete"]').hasClass('hide')) {
636
                $('[data-action="delete"]').removeClass('hide');
637
            }
638
        } else {
639
            if (!$('[data-action="delete"]').hasClass('hide')) {
640
                $('[data-action="delete"]').addClass('hide');
641
            }
642
        }
643
    });
644
    var form3 = $('#form_sample_3');
645
    var error3 = $('.alert-danger', form3);
646
    var success3 = $('.alert-success', form3);
647
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
648
    $("#form-main").on('submit', function() {
649
        for (var instanceName in CKEDITOR.instances) {
650
            CKEDITOR.instances[instanceName].updateElement();
651
        }
652
    })
653
    /**
654
     * Validate rules form
655
     */
656
    var validatorForm = $("#form-main").validate({
657
        ignore: [],
658
        errorClass: 'help-block',
659
        errorElement: 'span',
660
        rules: {
661
            'form-name': {
662
                required: true,
663
                minlength: 2,
664
                maxlength: 50
665
            },
666
            'form-description': {
667
                required: true,
668
            },
669
            'form-text': {
670
                required: true,
671
            },
672
            'form-language': {
673
                required: true,
674
            },
675
            'forrm-status': {
676
                required: true,
677
            },
678
        },
679
        highlight: function(element) {
680
            $(element).closest('.form-group').addClass('has-error');
681
        },
682
        unhighlight: function(element) {
683
            $(element).closest('.form-group').removeClass('has-error');
684
        },
685
        errorPlacement: function(error, element) {
686
            if (element.attr("data-error-container")) {
687
                error.appendTo(element.attr("data-error-container"));
688
            } else {
689
                error.insertAfter(element);
690
            }
691
        },
692
        invalidHandler: function(form, validator) {
693
            if (!validator.numberOfInvalids())
694
                return;
695
            $('html, body').animate({
696
                scrollTop: $(validator.errorList[0].element).offset().top - 100
697
            }, 1000);
698
        },
699
        submitHandler: function(form) {
700
            var error = false;
701
            if (objFormGenerator.sections.length == 0) {
702
                $.fn.showError('ERROR_SECCTIONS');
703
                return false;
704
            } else {
705
                for (i = 0; i < objFormGenerator.sections.length; i++) {
706
                    if (objFormGenerator.sections[i].questions.length == 0) {
707
                        $.fn.showError('ERROR_QUESTIONS'.replace('%s', objFormGenerator.sections[i].name));
708
                        return false;
709
                    }
710
                    var valueSection = parseInt(objFormGenerator.sections[i].value);
711
                    var totalValueQuestion = 0;
712
                    for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
713
                        valueQuestion = parseInt(objFormGenerator.sections[i].questions[j].value);
714
                        totalValueQuestion = totalValueQuestion + valueQuestion;
715
                        if (objFormGenerator.sections[i].questions[j].type == 'simple' ||
716
                            objFormGenerator.sections[i].questions[j].type == 'multiple' ||
717
                            objFormGenerator.sections[i].questions[j].type == 'rating-open') {
718
                            var questionNumber = j + 1;
719
                            var numberCorrect = 0;
720
                            if (objFormGenerator.sections[i].questions[j].options.length == 0) {
721
                                $.fn.showError('ERROR_OPTIONS'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
722
                                return false;
723
                            }
724
                            var totalOption = 0;
725
                            var maxOption = 0;
726
                            for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
727
                                if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
728
                                    if (objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
729
                                        numberCorrect++;
730
                                    }
731
                                }
732
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' && objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
733
                                    totalOption = totalOption + parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
734
                                }
735
                                if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
736
                                    if (parseInt(objFormGenerator.sections[i].questions[j].options[k].value) > maxOption) {
737
                                        maxOption = parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
738
                                    }
739
                                }
740
                            }
741
                            if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
742
                                if (numberCorrect == 0) {
743
                                    $.fn.showError('ERROR_OPTIONS_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
744
                                    return false;
745
                                }
746
                                if (
747
                                    objFormGenerator.sections[i].questions[j].type == 'simple' && numberCorrect > 1) {
748
                                    $.fn.showError('ERROR_OPTIONS_DUPLICATE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
749
                                    return false;
750
                                }
751
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' && numberCorrect == 1) {
752
                                    $.fn.showError('ERROR_OPTIONS_ONE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
753
                                    return false;
754
                                }
755
                            }
756
                            if (objFormGenerator.sections[i].questions[j].type == 'multiple' && totalOption != valueQuestion) {
757
                                $.fn.showError('ERROR_OPTIONS_SUM_VALUES'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
758
                                return false;
759
                            }
760
                            if (objFormGenerator.sections[i].questions[j].type == 'rating-open' && maxOption > valueQuestion) {
761
                                $.fn.showError('ERROR_OPTIONS_MAX_OPTION'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
762
                                return false;
763
                            }
764
                        }
765
                    }
766
                    if (valueSection != totalValueQuestion) {
767
                        $.fn.showError('ERROR_VALUE_SECTIONS'.replace('%s', objFormGenerator.sections[i].name));
768
                        return false;
769
                    }
770
                }
771
                var formId = parseInt($('#form-main #form-id').val());
772
                var formContinue = parseInt($('#form-main #form-continue').val());
773
                var data = {
774
                    'id': formId,
775
                    'name': $('#form-main #form-name').val(),
776
                    'description': $('#form-main #form-description').val(),
777
                    'text': $('#form-main #form-text').val(),
778
                    'language': $('#form-main #form-language').val(),
779
                    'status': $('#form-main #form-status').val(),
780
                    'content': JSON.stringify(objFormGenerator.sections)
781
                }
782
                $.ajax({
783
                    'dataType': 'json',
784
                    'method': 'post',
785
                    'url': $('#form-main').attr('action'),
786
                    'data': data,
787
                }).done(function(response) {
788
                    if (response['success']) {
789
                        $.fn.showSuccess(response['data']);
790
                        if (formContinue == 1) {
791
                            $('#form-main').attr('action',response['action_edit']);
792
                            $('#form-main #form-id').val(response['id']);
793
                            $('#form-main #form-continue').val(0);
794
                        } else {
795
                            $('#row-edit').hide();
254 geraldo 796
                            $('#row-forms').show();
251 geraldo 797
                        /*---------- Reset Form -------- */
798
                        $('#form-main')[0].reset();
799
                        /*--------Reset Ckeditor ----------*/
800
                        CKEDITOR.instances['form-text'].setData('');
801
                        CKEDITOR.instances['form-description'].setData('');
802
                        /*--------Reset Sections ----------*/
803
                        clearSectionData();
804
                        /* ------- Refresh Table -----------*/
805
 
806
                        }
807
                        tableForm.fnDraw();
808
                    } else {
809
                        $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
810
                    }
811
                }).fail(function(jqXHR, textStatus, errorThrown) {
812
                    $.fn.showError(textStatus);
813
                });
814
                return false;
815
            }
816
        }
817
    });
257 geraldo 818
 
819
 
251 geraldo 820
    /**
821
     * Clicked cancel new/edit Form
822
     */
823
    $('button.btn-edit-cancel').click(function(e) {
824
        e.preventDefault();
825
        $('#row-edit').hide();
254 geraldo 826
        $('#row-forms').show();
251 geraldo 827
    });
828
    /**
829
     * Clicked save and continue new Form
830
     */
831
    $('button.btn-form-save-continue').click(function(e) {
832
        e.preventDefault();
833
        $('#form-main #form-continue').val('1')
834
        $('#form-main').submit();
835
    });
836
    /**
837
     * Clicked save and close new/edit Form
838
     */
839
    $('button.btn-form-save-close').click(function(e) {
840
        e.preventDefault();
841
        $('#form-main #form-continue').val('0')
842
        $('#form-main').submit();
843
    });
844
    /**
845
     * Modal Settings
846
     */
847
    $('#modal-section, #modal-question, #modal-option').modal({
848
        backdrop: 'static',
849
        keyboard: false,
850
        show: false
851
    });
852
    /**
853
     * Get Question type
854
     */
855
    const getQuestionTypeBySlug = (slug_section, slug_question) => {
856
        for (i = 0; i < objFormGenerator.sections.length; i++) {
857
            if (slug_section == objFormGenerator.sections[i].slug_section) {
858
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
859
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
860
                        return objFormGenerator.sections[i].questions[j].type;
861
                    }
862
                }
863
            }
864
        }
865
    }
866
    /**
867
     * Remove Html Tags
868
     */
869
    const removeTags = (str) => str.toString().replace( /(<([^>]+)>)/ig, '')
870
    /**
871
     * Render Sections data
872
     */
873
    const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
874
        getType: getQuestionTypeBySlug,
875
        removeTags: removeTags
876
    }));
877
 
878
 
879
    /**
880
     * Clear Div Section data
881
     */
882
    const clearSectionData = () => $("#rows").html('');
883
    /**
884
     * Clicked refresh button
885
     */
886
    $('button.btn-refresh').click(function(e) {
887
        tableForm.fnDraw();
888
    });
889
 
890
});
891
JS;
892
$this->inlineScript()->captureEnd();
893
?>
894
 
895
<!-- Content Header (Page header) -->
896
<section class="content-header">
897
    <div class="container-fluid">
898
        <div class="row mb-2">
899
            <div class="col-sm-12">
254 geraldo 900
                <h1>LABEL_SELF_EVALUATION_FORMS</h1>
251 geraldo 901
            </div>
902
        </div>
903
    </div>
904
    <!-- /.container-fluid -->
905
</section>
906
<section class="content">
254 geraldo 907
    <div class="container-fluid" id="row-forms">
251 geraldo 908
        <div class="row">
909
            <div class="col-12">
910
                <div class="card">
911
                    <div class="card-body">
912
                        <table id="gridTable" class="table   table-hover">
913
                            <thead>
914
                                <tr>
915
                                    <th>LABEL_NAME</th>
916
                                    <th>LABEL_LANGUAGE</th>
254 geraldo 917
                                    <th>LABEL_ACTIVE</th>
251 geraldo 918
                                    <th>LABEL_ACTIONS</th>
919
                                </tr>
920
                            </thead>
921
                            <tbody></tbody>
922
                        </table>
923
                    </div>
924
                    <div class="card-footer clearfix">
925
                        <div style="float:right;">
926
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
927
                        </div>
928
                    </div>
929
                </div>
930
            </div>
931
        </div>
932
    </div>
933
 
934
    <!-- Create/Edit Form -->
935
 
936
    <div class="row" id="row-edit" style="display: none">
937
        <div class="col-xs-12 col-md-12">
938
            <form action="#" name="form-main" id="form-main">
256 geraldo 939
 
251 geraldo 940
                <div class="form-group">
941
                    <button type="submit" form="form-main" class="btn btn-info btn-form-save-continue">LABEL_SAVE & LABEL_CONTINUE</button>
942
                    <button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE & LABEL_CLOSE</button>
943
                    <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
944
                </div>
945
            </form>
946
        </div>
947
    </div>
948
 
256 geraldo 949
 
251 geraldo 950
 
951
    <!---Template Sections --->
952
    <script id="sectionTemplate" type="text/x-jsrender">
953
    <div class="panel panel-default" id="panel-{{:slug_section}}">
954
        <div class="panel-heading">
955
            <h4 class="panel-title">
956
                <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:slug_section}}" href="#collapse-{{:slug_section}}">
957
                    <span class="section-name{{:slug_section}}">
958
                        {{:name}}
959
                    </span>
960
                </a>
961
            </h4>
962
        </div>
963
        <div id="collapse-{{:slug_section}}" class="panel-collapse in collapse show">
964
            <div class="panel-body">
965
                <div class="table-responsive">
966
                    <table class="table table-bordered">
967
                        <thead>
968
                            <tr>
969
                                <th style="width: 10%;">LABEL_ELEMENT</th>
970
                                <th style="width: 50%;">LABEL_TEXT</th>
971
                                <th style="width: 10%;">LABEL_VALUE</th>
972
                                <th style="width: 10%;">LABEL_TYPE</th>
973
                                <th style="width: 20%;">LABEL_ACTIONS</th>
974
                            </tr>
975
                        </thead>
976
                        <tbody>
977
                            <tr class="tr-section">
978
                                <td class="text-left">LABEL_SECTION</td>
979
                                <td class="text-left">{{:name}}</td>
980
                                <td>{{:value}}</td>
981
                                <td></td>
982
                                <td>
983
                                    <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>
984
                                    <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>
985
                                    <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>
986
                                </td>
987
                            </tr>
988
                            {{for questions}}
989
                            <tr class="tr-question">
990
                                <td class="text-left">--LABEL_QUESTION</td>
991
                                <td class="text-left">
992
                                    {{:~removeTags(text)}}
993
                                </td>
994
                                <td><font color="red">{{:value}}</font></td>
995
                                <td class="text-capitalize">
996
                                    {{if type == 'open'}} LABEL_OPEN {{/if}}
997
                                    {{if type == 'simple'}} Simple {{/if}}
998
                                    {{if type == 'multiple'}} Multiple {{/if}}
999
                                    {{if type == 'rating-open'}} LABEL_RATING_OPEN {{/if}}
1000
                                    {{if type == 'rating-range'}} LABEL_RATING_RANGE {{/if}}
1001
                                </td>
1002
                                <td>
1003
                                    <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>
1004
                                    <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>
1005
 
1006
                                    {{if type == 'simple' || type == 'rating-open' || type=='multiple' }}
1007
                                    <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>
1008
                                    {{/if}}
1009
 
1010
                                </td>
1011
                            </tr>
1012
                            {{for options}}
1013
                            <tr class="tr-option">
1014
                                <td class="text-left">---LABEL_OPTION</td>
1015
                                <td class="text-left">
1016
                                    {{:~removeTags(text)}}
1017
                                </td>
1018
                                <td>
1019
 
1020
                                    {{if ~getType( slug_section, slug_question) == 'multiple' || ~getType( slug_section, slug_question) == 'rating-open'  }}
1021
                                    {{:value}}
1022
                                    {{/if}}
1023
                                </td>
1024
                                <td class="text-left">
1025
                                    {{if ~getType( slug_section, slug_question) != 'rating-open'}}
1026
                                    {{if correct == 1}}
1027
                                    <font color="green">LABEL_CORRECT</font>
1028
                                    {{/if}}
1029
                                    {{if correct == 0}}
1030
                                    <font color="red">LABEL_FAIL</font>
1031
                                    {{/if}}
1032
                                    {{/if}}
1033
                                </td>
1034
                                <td>
1035
                                    <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>
1036
                                    <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>
1037
                                </td>
1038
                            </tr>
1039
                            {{/for}}
1040
                            {{/for}}
1041
                        </tbody>
1042
                    </table>
1043
                </div>
1044
            </div>
1045
        </div>
1046
    </div>
1047
    </script>
1048
 
1049
    <!-- End Template Sections-->
1050
 
1051
</section>