Proyectos de Subversion LeadersLinked - Backend

Rev

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