Proyectos de Subversion LeadersLinked - Backend

Rev

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