Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 264 | Rev 266 | 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
 
261 geraldo 7
$routeAdd = $this->url('self-evaluation/forms/add');
262 geraldo 8
$routeDatatable = $this->url('self-evaluation/reviews');
251 geraldo 9
$routeDashboard = $this->url('dashboard');
10
 
261 geraldo 11
$allowEdit = $acl->isAllowed($roleName, 'self-evaluation/forms/edit') ? 1 : 0;
251 geraldo 12
 
13
 
14
$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));
15
 
16
 
17
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
18
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
19
 
20
 
21
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
22
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
23
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
24
 
25
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
26
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
27
 
28
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
29
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
30
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
31
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
32
 
33
 
34
$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.min.css'));
35
$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css'));
36
 
37
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/select2.full.min.js'));
38
 
39
$this->inlineScript()->appendFile($this->basePath('plugins/moment/moment-with-locales.min.js'));
40
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css'));
41
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'));
42
 
43
 
44
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
45
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
46
 
47
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
48
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
49
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-input-number/input-number-format.jquery.js'));
261 geraldo 50
 
251 geraldo 51
// bootbox Alert //
52
$this->inlineScript()->appendFile($this->basePath('plugins/bootbox/bootbox.min.js'));
261 geraldo 53
 
251 geraldo 54
// JsRender //
55
$this->inlineScript()->appendFile($this->basePath('plugins/jsrender/jsrender.min.js'));
56
 
261 geraldo 57
// Page Styles
58
$this->headLink()->appendStylesheet($this->basePath('css/pages/self-evaluation.css'));
251 geraldo 59
 
261 geraldo 60
$status_active = \LeadersLinked\Model\CompanySelfEvaluationForm::STATUS_ACTIVE;
61
$status_inactive = \LeadersLinked\Model\CompanySelfEvaluationForm::STATUS_INACTIVE;
62
 
63
$lang_es = \LeadersLinked\Model\CompanySelfEvaluationForm::LANGUAGE_SPANISH;
64
$lang_en = \LeadersLinked\Model\CompanySelfEvaluationForm::LANGUAGE_ENGLISH;
65
 
66
 
251 geraldo 67
$this->inlineScript()->captureStart();
68
echo <<<JS
69
    const classFormGenerator = function() {
70
    this.id = 0,
71
        this.table = '',
72
        this.name = '',
73
        this.text = '',
74
        this.status = 'a',
75
        this.sections = [],
76
        this.clear = function() {
77
            this.sections = [];
78
            this.render();
79
        },
80
        /**
81
         * Render array sections
82
         */
83
        this.renderSection = function(slug_section) {
84
            var s = '';
85
            for (i = 0; i < this.sections.length; i++) {
86
                if (slug_section != this.sections[i].slug_section) {
87
                    continue;
88
                }
89
                for (j = 0; j < this.sections[i].questions.length; j++) {
90
                    this.sections[i].questions[j].position = j;
91
                    if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {
92
                        this.sections[i].questions[j].options.sort(function(a, b) {
93
                            if (a.position > b.position) {
94
                                return 1;
95
                            }
96
                            if (a.position < b.position) {
97
                                return -1;
98
                            }
99
                            return 0;
100
                        });
101
                        for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
102
                            this.sections[i].questions[j].options[k].position = j;
103
                        }
104
                    }
105
                }
106
            }
107
            $('[data-toggle="tooltip"]').tooltip();
108
        },
109
        this.render = function() {
110
            this.sections.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
            var s = '';
120
            for (i = 0; i < this.sections.length; i++) {
121
                this.sections[i].position = i;
122
                this.sections[i].questions.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 (j = 0; j < this.sections[i].questions.length; j++) {
132
                    this.sections[i].questions[j].position = j;
133
                    if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {
134
                        this.sections[i].questions[j].options.sort(function(a, b) {
135
                            if (a.position > b.position) {
136
                                return 1;
137
                            }
138
                            if (a.position < b.position) {
139
                                return -1;
140
                            }
141
                            return 0;
142
                        });
143
                        for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
144
                            this.sections[i].questions[j].options[k].position = j;
145
                        }
146
                    }
147
                }
148
            }
149
            $('[data-toggle="tooltip"]').tooltip();
150
        },
264 geraldo 151
 
251 geraldo 152
         /**
153
         * Add element to question array
154
         */
155
        this.editQuestion = function(slug_section, slug_question, text, value, type, maxlength, multiline, range) {
156
            var renderTable = false;
157
            for (i = 0; i < this.sections.length; i++) {
158
                if (slug_section == this.sections[i].slug_section) {
159
                    for (j = 0; j < this.sections[i].questions.length; j++) {
160
                        if (slug_question == this.sections[i].questions[j].slug_question) {
161
                            this.sections[i].questions[j].text = text,
162
                                this.sections[i].questions[j].value = value,
163
                                this.sections[i].questions[j].type = type;
164
                            if (type == 'open') {
165
                                this.sections[i].questions[j].maxlength = maxlength;
166
                                this.sections[i].questions[j].multiline = multiline;
167
                                this.sections[i].questions[j].options = [];
168
                            } else {
169
                                this.sections[i].questions[j].maxlength = 0;
170
                                this.sections[i].questions[j].multiline = 0;
171
                            }
172
                            if (type == 'rating-range') {
173
                                this.sections[i].questions[j].range = range;
174
                            } else {
175
                                this.sections[i].questions[j].range = 0;
176
                            }
177
 
178
                            if(type=='multiple'){
179
                                this.sections[i].questions[j].answer = [];
180
                            }else{
181
                                this.sections[i].questions[j].answer = '';
182
                            }
183
 
184
                            renderTable = true;
185
                            break;
186
                        }
187
                    }
188
                }
189
                if (renderTable) {
190
                    break;
191
                }
192
            }
193
            if (renderTable) {
194
                this.renderSection(slug_section);
195
            }
254 geraldo 196
        },
264 geraldo 197
 
265 geraldo 198
}}
251 geraldo 199
 
200
function htmlEntities(str) {
201
    return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
202
}
203
jQuery(document).ready(function($) {
204
    var objFormGenerator = new classFormGenerator();
205
    objFormGenerator.render();
206
    var allowEdit = $allowEdit;
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
                    return s;
341
                }
342
            }
343
        ],
344
    });
345
    /**
346
     * Clicked on edit form
347
     */
348
    $('body').on('click', 'button.btn-edit-form', function(e) {
349
        e.preventDefault();
350
        form_id = $(this).data('id')
351
        var action = $(this).data('href');
352
        $.ajax({
353
            'dataType': 'json',
354
            'accept': 'application/json',
355
            'method': 'get',
356
            'url': action,
357
        }).done(function(response) {
358
            if (response['success']) {
359
                validatorForm.resetForm();
360
                $('#form-main').attr('action', action);
361
                $('#form-main #form-id').val(response['data']['id']),
362
                $('#form-main #form-continue').val('0');
363
                $('#form-main #form-name').val(response['data']['name']),
364
 
365
                /*----------Set Ckeditor ------------*/
366
                CKEDITOR.instances['form-description'].setData(response['data']['description']);
367
                CKEDITOR.instances['form-text'].setData(response['data']['text']);
368
 
369
                $('#form-main #form-language').val(response['data']['language']),
370
                $('#form-main #form-status').val(response['data']['status']);
371
 
372
                /*-------------Render Sections -------*/
373
 
374
                objFormGenerator.clear();
375
                objFormGenerator.sections = response['data']['content'] || [];
376
                objFormGenerator.render();
377
                renderSectionData(objFormGenerator.sections);
378
 
254 geraldo 379
                $('#row-forms').hide();
251 geraldo 380
                $('#row-edit').show();
381
                $('#form-main #form-name').focus();
382
 
383
            } else {
384
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
385
            }
386
        }).fail(function(jqXHR, textStatus, errorThrown) {
387
            $.fn.showError(textStatus);
388
        });
389
    });
390
    $(document).on('click', '[data-type="select_all"]', function() {
391
        if ($('input[name="select_all"]:checked').val() == 'all') {
392
            $('[data-type="select"]').prop('checked', true);
393
            $('[data-action="delete"]').removeClass('hide');
394
        } else {
395
            $('[data-type="select"]').prop('checked', false);
396
            $('[data-action="delete"]').addClass('hide');
397
        }
398
    });
399
 
264 geraldo 400
 
251 geraldo 401
 
402
    function currentSelected() {
403
        var selected = [];
404
        $.each($("input[name='select[]']:checked"), function() {
405
            selected.push($(this).val());
406
        });
407
        return selected;
408
    }
409
    $(document).on('change', "input[name='select[]']", function() {
410
        var c = currentSelected();
411
        var cc = getLength();
412
        if (c.length == cc) {
413
            if ($('[data-action="delete"]').hasClass('hide')) {
414
                $('[data-action="delete"]').removeClass('hide');
415
            }
416
            return true;
417
        } else {
418
            $('input[name="select_all"]').prop('checked', false);
419
        }
420
        if (c.length > 0) {
421
            if ($('[data-action="delete"]').hasClass('hide')) {
422
                $('[data-action="delete"]').removeClass('hide');
423
            }
424
        } else {
425
            if (!$('[data-action="delete"]').hasClass('hide')) {
426
                $('[data-action="delete"]').addClass('hide');
427
            }
428
        }
429
    });
430
    var form3 = $('#form_sample_3');
431
    var error3 = $('.alert-danger', form3);
432
    var success3 = $('.alert-success', form3);
433
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
434
    $("#form-main").on('submit', function() {
435
        for (var instanceName in CKEDITOR.instances) {
436
            CKEDITOR.instances[instanceName].updateElement();
437
        }
438
    })
439
    /**
440
     * Validate rules form
441
     */
442
    var validatorForm = $("#form-main").validate({
443
        ignore: [],
444
        errorClass: 'help-block',
445
        errorElement: 'span',
446
        rules: {
447
            'form-name': {
448
                required: true,
449
                minlength: 2,
450
                maxlength: 50
451
            },
452
            'form-description': {
453
                required: true,
454
            },
455
            'form-text': {
456
                required: true,
457
            },
458
            'form-language': {
459
                required: true,
460
            },
461
            'forrm-status': {
462
                required: true,
463
            },
464
        },
465
        highlight: function(element) {
466
            $(element).closest('.form-group').addClass('has-error');
467
        },
468
        unhighlight: function(element) {
469
            $(element).closest('.form-group').removeClass('has-error');
470
        },
471
        errorPlacement: function(error, element) {
472
            if (element.attr("data-error-container")) {
473
                error.appendTo(element.attr("data-error-container"));
474
            } else {
475
                error.insertAfter(element);
476
            }
477
        },
478
        invalidHandler: function(form, validator) {
479
            if (!validator.numberOfInvalids())
480
                return;
481
            $('html, body').animate({
482
                scrollTop: $(validator.errorList[0].element).offset().top - 100
483
            }, 1000);
484
        },
485
        submitHandler: function(form) {
486
            var error = false;
487
            if (objFormGenerator.sections.length == 0) {
488
                $.fn.showError('ERROR_SECCTIONS');
489
                return false;
490
            } else {
491
                for (i = 0; i < objFormGenerator.sections.length; i++) {
492
                    if (objFormGenerator.sections[i].questions.length == 0) {
493
                        $.fn.showError('ERROR_QUESTIONS'.replace('%s', objFormGenerator.sections[i].name));
494
                        return false;
495
                    }
496
                    var valueSection = parseInt(objFormGenerator.sections[i].value);
497
                    var totalValueQuestion = 0;
498
                    for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
499
                        valueQuestion = parseInt(objFormGenerator.sections[i].questions[j].value);
500
                        totalValueQuestion = totalValueQuestion + valueQuestion;
501
                        if (objFormGenerator.sections[i].questions[j].type == 'simple' ||
502
                            objFormGenerator.sections[i].questions[j].type == 'multiple' ||
503
                            objFormGenerator.sections[i].questions[j].type == 'rating-open') {
504
                            var questionNumber = j + 1;
505
                            var numberCorrect = 0;
506
                            if (objFormGenerator.sections[i].questions[j].options.length == 0) {
507
                                $.fn.showError('ERROR_OPTIONS'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
508
                                return false;
509
                            }
510
                            var totalOption = 0;
511
                            var maxOption = 0;
512
                            for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
513
                                if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
514
                                    if (objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
515
                                        numberCorrect++;
516
                                    }
517
                                }
518
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' && objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
519
                                    totalOption = totalOption + parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
520
                                }
521
                                if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
522
                                    if (parseInt(objFormGenerator.sections[i].questions[j].options[k].value) > maxOption) {
523
                                        maxOption = parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
524
                                    }
525
                                }
526
                            }
527
                            if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
528
                                if (numberCorrect == 0) {
529
                                    $.fn.showError('ERROR_OPTIONS_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
530
                                    return false;
531
                                }
532
                                if (
533
                                    objFormGenerator.sections[i].questions[j].type == 'simple' && numberCorrect > 1) {
534
                                    $.fn.showError('ERROR_OPTIONS_DUPLICATE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
535
                                    return false;
536
                                }
537
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' && numberCorrect == 1) {
538
                                    $.fn.showError('ERROR_OPTIONS_ONE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
539
                                    return false;
540
                                }
541
                            }
542
                            if (objFormGenerator.sections[i].questions[j].type == 'multiple' && totalOption != valueQuestion) {
543
                                $.fn.showError('ERROR_OPTIONS_SUM_VALUES'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
544
                                return false;
545
                            }
546
                            if (objFormGenerator.sections[i].questions[j].type == 'rating-open' && maxOption > valueQuestion) {
547
                                $.fn.showError('ERROR_OPTIONS_MAX_OPTION'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
548
                                return false;
549
                            }
550
                        }
551
                    }
552
                    if (valueSection != totalValueQuestion) {
553
                        $.fn.showError('ERROR_VALUE_SECTIONS'.replace('%s', objFormGenerator.sections[i].name));
554
                        return false;
555
                    }
556
                }
557
                var formId = parseInt($('#form-main #form-id').val());
558
                var formContinue = parseInt($('#form-main #form-continue').val());
559
                var data = {
560
                    'id': formId,
561
                    'name': $('#form-main #form-name').val(),
562
                    'description': $('#form-main #form-description').val(),
563
                    'text': $('#form-main #form-text').val(),
564
                    'language': $('#form-main #form-language').val(),
565
                    'status': $('#form-main #form-status').val(),
566
                    'content': JSON.stringify(objFormGenerator.sections)
567
                }
568
                $.ajax({
569
                    'dataType': 'json',
570
                    'method': 'post',
571
                    'url': $('#form-main').attr('action'),
572
                    'data': data,
573
                }).done(function(response) {
574
                    if (response['success']) {
575
                        $.fn.showSuccess(response['data']);
576
                        if (formContinue == 1) {
577
                            $('#form-main').attr('action',response['action_edit']);
578
                            $('#form-main #form-id').val(response['id']);
579
                            $('#form-main #form-continue').val(0);
580
                        } else {
581
                            $('#row-edit').hide();
254 geraldo 582
                            $('#row-forms').show();
251 geraldo 583
                        /*---------- Reset Form -------- */
584
                        $('#form-main')[0].reset();
585
                        /*--------Reset Ckeditor ----------*/
586
                        CKEDITOR.instances['form-text'].setData('');
587
                        CKEDITOR.instances['form-description'].setData('');
588
                        /*--------Reset Sections ----------*/
589
                        clearSectionData();
590
                        /* ------- Refresh Table -----------*/
591
 
592
                        }
593
                        tableForm.fnDraw();
594
                    } else {
595
                        $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
596
                    }
597
                }).fail(function(jqXHR, textStatus, errorThrown) {
598
                    $.fn.showError(textStatus);
599
                });
600
                return false;
601
            }
602
        }
603
    });
264 geraldo 604
 
251 geraldo 605
    /**
606
     * Clicked cancel new/edit Form
607
     */
608
    $('button.btn-edit-cancel').click(function(e) {
609
        e.preventDefault();
610
        $('#row-edit').hide();
254 geraldo 611
        $('#row-forms').show();
251 geraldo 612
    });
613
    /**
614
     * Clicked save and continue new Form
615
     */
616
    $('button.btn-form-save-continue').click(function(e) {
617
        e.preventDefault();
618
        $('#form-main #form-continue').val('1')
619
        $('#form-main').submit();
620
    });
621
    /**
622
     * Clicked save and close new/edit Form
623
     */
624
    $('button.btn-form-save-close').click(function(e) {
625
        e.preventDefault();
626
        $('#form-main #form-continue').val('0')
627
        $('#form-main').submit();
628
    });
629
    /**
630
     * Modal Settings
631
     */
632
    $('#modal-section, #modal-question, #modal-option').modal({
633
        backdrop: 'static',
634
        keyboard: false,
635
        show: false
636
    });
637
    /**
638
     * Get Question type
639
     */
640
    const getQuestionTypeBySlug = (slug_section, slug_question) => {
641
        for (i = 0; i < objFormGenerator.sections.length; i++) {
642
            if (slug_section == objFormGenerator.sections[i].slug_section) {
643
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
644
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
645
                        return objFormGenerator.sections[i].questions[j].type;
646
                    }
647
                }
648
            }
649
        }
650
    }
651
    /**
652
     * Remove Html Tags
653
     */
654
    const removeTags = (str) => str.toString().replace( /(<([^>]+)>)/ig, '')
655
    /**
656
     * Render Sections data
657
     */
658
    const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
659
        getType: getQuestionTypeBySlug,
660
        removeTags: removeTags
661
    }));
662
 
663
 
664
    /**
665
     * Clear Div Section data
666
     */
667
    const clearSectionData = () => $("#rows").html('');
668
    /**
669
     * Clicked refresh button
670
     */
671
    $('button.btn-refresh').click(function(e) {
672
        tableForm.fnDraw();
673
    });
674
 
675
});
676
JS;
677
$this->inlineScript()->captureEnd();
678
?>
679
 
680
<!-- Content Header (Page header) -->
681
<section class="content-header">
682
    <div class="container-fluid">
683
        <div class="row mb-2">
684
            <div class="col-sm-12">
264 geraldo 685
                <h1>LABEL_REVIEWS</h1>
251 geraldo 686
            </div>
687
        </div>
688
    </div>
689
    <!-- /.container-fluid -->
690
</section>
691
<section class="content">
254 geraldo 692
    <div class="container-fluid" id="row-forms">
251 geraldo 693
        <div class="row">
694
            <div class="col-12">
695
                <div class="card">
696
                    <div class="card-body">
697
                        <table id="gridTable" class="table   table-hover">
698
                            <thead>
699
                                <tr>
700
                                    <th>LABEL_NAME</th>
701
                                    <th>LABEL_LANGUAGE</th>
261 geraldo 702
                                    <th>LABEL_ACTIVE</th>
251 geraldo 703
                                    <th>LABEL_ACTIONS</th>
704
                                </tr>
705
                            </thead>
706
                            <tbody></tbody>
707
                        </table>
708
                    </div>
709
                    <div class="card-footer clearfix">
710
                        <div style="float:right;">
711
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
712
                        </div>
713
                    </div>
714
                </div>
715
            </div>
716
        </div>
717
    </div>
718
 
719
    <!-- Create/Edit Form -->
720
 
721
    <div class="row" id="row-edit" style="display: none">
722
        <div class="col-xs-12 col-md-12">
723
            <form action="#" name="form-main" id="form-main">
261 geraldo 724
                <input type="hidden" name="form-id" id="form-id" value="0" />
725
                <input type="hidden" name="form-continue" id="form-continue" value="0" />
251 geraldo 726
                <div class="form-group">
261 geraldo 727
                    <label for="form-name">LABEL_FIRST_NAME</label>
728
                    <input type="text" name="form-name" id="form-name" class="form-control" maxlength="50" />
729
                </div>
730
                <div class="form-group">
731
                    <label for="form-description">LABEL_DESCRIPTION</label>
732
                    <!--  ckeditor -->
733
                    <textarea  name="form-description" id="form-description" rows="5" class="ckeditor form-control"></textarea>
734
                </div>
735
                <div class="form-group">
736
                    <label for="form-text">LABEL_TEXT</label>
737
                    <!--  ckeditor -->
738
                    <textarea  name="form-text" id="form-text" rows="5" class="ckeditor form-control"></textarea>
739
                </div>
740
                <div class="form-group">
741
                    <label for="form-language">LABEL_LANGUAGES</label>
742
                    <select name="form-language" id="form-language" class="form-control">
743
                        <option value="<?php echo $lang_en; ?>">LABEL_ENGLISH</option>
744
                        <option value="<?php echo $lang_es; ?>">LABEL_SPANISH</option>
745
                    </select>
746
                </div>
747
                <div class="form-group">
748
                    <label for="form-status">LABEL_STATUS</label>
749
                    <select name="form-status" id="form-status" class="form-control">
750
                        <option value="<?php echo $status_inactive; ?>">LABEL_INACTIVE</option>
751
                        <option value="<?php echo $status_active; ?>">LABEL_ACTIVE</option>
752
                    </select>
753
                </div>
754
                <br/>
755
                <div class="row">
756
                    <div class="col-xs-12 col-md-12 text-right">
757
                        <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>
758
                    </div>
759
                </div>
760
                <br />
761
                <div class="row">
762
                    <div class="col-xs-12 col-md-12">
763
                        <div class="panel-group" id="rows"></div>
764
                    </div>
765
                </div>
766
                <div class="form-group">
251 geraldo 767
                    <button type="submit" form="form-main" class="btn btn-info btn-form-save-continue">LABEL_SAVE & LABEL_CONTINUE</button>
768
                    <button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE & LABEL_CLOSE</button>
769
                    <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
770
                </div>
771
            </form>
772
        </div>
773
    </div>
774
 
261 geraldo 775
    <!-- Create/Edit Form-->
251 geraldo 776
 
264 geraldo 777
 
261 geraldo 778
 
251 geraldo 779
    <!---Template Sections --->
780
    <script id="sectionTemplate" type="text/x-jsrender">
781
    <div class="panel panel-default" id="panel-{{:slug_section}}">
782
        <div class="panel-heading">
783
            <h4 class="panel-title">
784
                <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:slug_section}}" href="#collapse-{{:slug_section}}">
785
                    <span class="section-name{{:slug_section}}">
786
                        {{:name}}
787
                    </span>
788
                </a>
789
            </h4>
790
        </div>
791
        <div id="collapse-{{:slug_section}}" class="panel-collapse in collapse show">
792
            <div class="panel-body">
793
                <div class="table-responsive">
794
                    <table class="table table-bordered">
795
                        <thead>
796
                            <tr>
797
                                <th style="width: 10%;">LABEL_ELEMENT</th>
798
                                <th style="width: 50%;">LABEL_TEXT</th>
799
                                <th style="width: 10%;">LABEL_VALUE</th>
800
                                <th style="width: 10%;">LABEL_TYPE</th>
801
                                <th style="width: 20%;">LABEL_ACTIONS</th>
802
                            </tr>
803
                        </thead>
804
                        <tbody>
805
                            <tr class="tr-section">
806
                                <td class="text-left">LABEL_SECTION</td>
807
                                <td class="text-left">{{:name}}</td>
808
                                <td>{{:value}}</td>
809
                                <td></td>
810
                                <td>
811
                                    <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>
812
                                    <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>
813
                                    <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>
814
                                </td>
815
                            </tr>
816
                            {{for questions}}
817
                            <tr class="tr-question">
818
                                <td class="text-left">--LABEL_QUESTION</td>
819
                                <td class="text-left">
820
                                    {{:~removeTags(text)}}
821
                                </td>
822
                                <td><font color="red">{{:value}}</font></td>
823
                                <td class="text-capitalize">
824
                                    {{if type == 'open'}} LABEL_OPEN {{/if}}
825
                                    {{if type == 'simple'}} Simple {{/if}}
826
                                    {{if type == 'multiple'}} Multiple {{/if}}
827
                                    {{if type == 'rating-open'}} LABEL_RATING_OPEN {{/if}}
828
                                    {{if type == 'rating-range'}} LABEL_RATING_RANGE {{/if}}
829
                                </td>
830
                                <td>
831
                                    <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>
832
                                    <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>
833
 
834
                                    {{if type == 'simple' || type == 'rating-open' || type=='multiple' }}
835
                                    <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>
836
                                    {{/if}}
837
 
838
                                </td>
839
                            </tr>
840
                            {{for options}}
841
                            <tr class="tr-option">
842
                                <td class="text-left">---LABEL_OPTION</td>
843
                                <td class="text-left">
844
                                    {{:~removeTags(text)}}
845
                                </td>
846
                                <td>
847
 
848
                                    {{if ~getType( slug_section, slug_question) == 'multiple' || ~getType( slug_section, slug_question) == 'rating-open'  }}
849
                                    {{:value}}
850
                                    {{/if}}
851
                                </td>
852
                                <td class="text-left">
853
                                    {{if ~getType( slug_section, slug_question) != 'rating-open'}}
854
                                    {{if correct == 1}}
855
                                    <font color="green">LABEL_CORRECT</font>
856
                                    {{/if}}
857
                                    {{if correct == 0}}
858
                                    <font color="red">LABEL_FAIL</font>
859
                                    {{/if}}
860
                                    {{/if}}
861
                                </td>
862
                                <td>
863
                                    <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>
864
                                    <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>
865
                                </td>
866
                            </tr>
867
                            {{/for}}
868
                            {{/for}}
869
                        </tbody>
870
                    </table>
871
                </div>
872
            </div>
873
        </div>
874
    </div>
875
    </script>
876
 
877
    <!-- End Template Sections-->
878
 
879
</section>