Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 292 | Rev 294 | 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',
293 geraldo 273
                'className': 'text-vertical-middle',
251 geraldo 274
            },
275
            {
276
                'targets': -1,
277
                'orderable': false,
278
                'render': function(data, type, row) {
279
                    s = '';
280
                    if (allowEdit) {
293 geraldo 281
                        s = s + '<button class="btn btn-primary btn-edit-form" data-href="' + data + '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pencil"></i> LABEL_EDIT </button>&nbsp;';
251 geraldo 282
                    }
283
                    return s;
284
                }
285
            }
286
        ],
287
    });
288
    /**
289
     * Clicked on edit form
290
     */
291
    $('body').on('click', 'button.btn-edit-form', function(e) {
292
        e.preventDefault();
293
        form_id = $(this).data('id')
294
        var action = $(this).data('href');
295
        $.ajax({
296
            'dataType': 'json',
297
            'accept': 'application/json',
298
            'method': 'get',
299
            'url': action,
300
        }).done(function(response) {
301
            if (response['success']) {
302
                validatorForm.resetForm();
303
                $('#form-main').attr('action', action);
304
                $('#form-main #form-id').val(response['data']['id']),
305
                $('#form-main #form-continue').val('0');
306
                $('#form-main #form-name').val(response['data']['name']),
307
 
308
                /*----------Set Ckeditor ------------*/
309
                CKEDITOR.instances['form-description'].setData(response['data']['description']);
310
                CKEDITOR.instances['form-text'].setData(response['data']['text']);
311
 
312
                $('#form-main #form-language').val(response['data']['language']),
313
                $('#form-main #form-status').val(response['data']['status']);
314
 
315
                /*-------------Render Sections -------*/
316
 
317
                objFormGenerator.clear();
318
                objFormGenerator.sections = response['data']['content'] || [];
319
                objFormGenerator.render();
320
                renderSectionData(objFormGenerator.sections);
321
 
254 geraldo 322
                $('#row-forms').hide();
251 geraldo 323
                $('#row-edit').show();
324
                $('#form-main #form-name').focus();
325
 
326
            } else {
327
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
328
            }
329
        }).fail(function(jqXHR, textStatus, errorThrown) {
330
            $.fn.showError(textStatus);
331
        });
332
    });
333
    $(document).on('click', '[data-type="select_all"]', function() {
334
        if ($('input[name="select_all"]:checked').val() == 'all') {
335
            $('[data-type="select"]').prop('checked', true);
336
            $('[data-action="delete"]').removeClass('hide');
337
        } else {
338
            $('[data-type="select"]').prop('checked', false);
339
            $('[data-action="delete"]').addClass('hide');
340
        }
341
    });
342
 
264 geraldo 343
 
251 geraldo 344
 
345
    function currentSelected() {
346
        var selected = [];
347
        $.each($("input[name='select[]']:checked"), function() {
348
            selected.push($(this).val());
349
        });
350
        return selected;
351
    }
352
    $(document).on('change', "input[name='select[]']", function() {
353
        var c = currentSelected();
354
        var cc = getLength();
355
        if (c.length == cc) {
356
            if ($('[data-action="delete"]').hasClass('hide')) {
357
                $('[data-action="delete"]').removeClass('hide');
358
            }
359
            return true;
360
        } else {
361
            $('input[name="select_all"]').prop('checked', false);
362
        }
363
        if (c.length > 0) {
364
            if ($('[data-action="delete"]').hasClass('hide')) {
365
                $('[data-action="delete"]').removeClass('hide');
366
            }
367
        } else {
368
            if (!$('[data-action="delete"]').hasClass('hide')) {
369
                $('[data-action="delete"]').addClass('hide');
370
            }
371
        }
372
    });
373
    var form3 = $('#form_sample_3');
374
    var error3 = $('.alert-danger', form3);
375
    var success3 = $('.alert-success', form3);
376
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
377
    $("#form-main").on('submit', function() {
378
        for (var instanceName in CKEDITOR.instances) {
379
            CKEDITOR.instances[instanceName].updateElement();
380
        }
381
    })
382
    /**
383
     * Validate rules form
384
     */
385
    var validatorForm = $("#form-main").validate({
386
        ignore: [],
387
        errorClass: 'help-block',
388
        errorElement: 'span',
389
        rules: {
390
            'form-name': {
391
                required: true,
392
                minlength: 2,
393
                maxlength: 50
394
            },
395
            'form-description': {
396
                required: true,
397
            },
398
            'form-text': {
399
                required: true,
400
            },
401
            'form-language': {
402
                required: true,
403
            },
404
            'forrm-status': {
405
                required: true,
406
            },
407
        },
408
        highlight: function(element) {
409
            $(element).closest('.form-group').addClass('has-error');
410
        },
411
        unhighlight: function(element) {
412
            $(element).closest('.form-group').removeClass('has-error');
413
        },
414
        errorPlacement: function(error, element) {
415
            if (element.attr("data-error-container")) {
416
                error.appendTo(element.attr("data-error-container"));
417
            } else {
418
                error.insertAfter(element);
419
            }
420
        },
421
        invalidHandler: function(form, validator) {
422
            if (!validator.numberOfInvalids())
423
                return;
424
            $('html, body').animate({
425
                scrollTop: $(validator.errorList[0].element).offset().top - 100
426
            }, 1000);
427
        },
428
        submitHandler: function(form) {
429
            var error = false;
430
            if (objFormGenerator.sections.length == 0) {
431
                $.fn.showError('ERROR_SECCTIONS');
432
                return false;
433
            } else {
434
                for (i = 0; i < objFormGenerator.sections.length; i++) {
435
                    if (objFormGenerator.sections[i].questions.length == 0) {
436
                        $.fn.showError('ERROR_QUESTIONS'.replace('%s', objFormGenerator.sections[i].name));
437
                        return false;
438
                    }
439
                    var valueSection = parseInt(objFormGenerator.sections[i].value);
440
                    var totalValueQuestion = 0;
441
                    for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
442
                        valueQuestion = parseInt(objFormGenerator.sections[i].questions[j].value);
443
                        totalValueQuestion = totalValueQuestion + valueQuestion;
444
                        if (objFormGenerator.sections[i].questions[j].type == 'simple' ||
445
                            objFormGenerator.sections[i].questions[j].type == 'multiple' ||
446
                            objFormGenerator.sections[i].questions[j].type == 'rating-open') {
447
                            var questionNumber = j + 1;
448
                            var numberCorrect = 0;
449
                            if (objFormGenerator.sections[i].questions[j].options.length == 0) {
450
                                $.fn.showError('ERROR_OPTIONS'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
451
                                return false;
452
                            }
453
                            var totalOption = 0;
454
                            var maxOption = 0;
455
                            for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
456
                                if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
457
                                    if (objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
458
                                        numberCorrect++;
459
                                    }
460
                                }
461
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' && objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
462
                                    totalOption = totalOption + parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
463
                                }
464
                                if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
465
                                    if (parseInt(objFormGenerator.sections[i].questions[j].options[k].value) > maxOption) {
466
                                        maxOption = parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
467
                                    }
468
                                }
469
                            }
470
                            if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
471
                                if (numberCorrect == 0) {
472
                                    $.fn.showError('ERROR_OPTIONS_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
473
                                    return false;
474
                                }
475
                                if (
476
                                    objFormGenerator.sections[i].questions[j].type == 'simple' && numberCorrect > 1) {
477
                                    $.fn.showError('ERROR_OPTIONS_DUPLICATE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
478
                                    return false;
479
                                }
480
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' && numberCorrect == 1) {
481
                                    $.fn.showError('ERROR_OPTIONS_ONE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
482
                                    return false;
483
                                }
484
                            }
485
                            if (objFormGenerator.sections[i].questions[j].type == 'multiple' && totalOption != valueQuestion) {
486
                                $.fn.showError('ERROR_OPTIONS_SUM_VALUES'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
487
                                return false;
488
                            }
489
                            if (objFormGenerator.sections[i].questions[j].type == 'rating-open' && maxOption > valueQuestion) {
490
                                $.fn.showError('ERROR_OPTIONS_MAX_OPTION'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
491
                                return false;
492
                            }
493
                        }
494
                    }
495
                    if (valueSection != totalValueQuestion) {
496
                        $.fn.showError('ERROR_VALUE_SECTIONS'.replace('%s', objFormGenerator.sections[i].name));
497
                        return false;
498
                    }
499
                }
500
                var formId = parseInt($('#form-main #form-id').val());
501
                var formContinue = parseInt($('#form-main #form-continue').val());
502
                var data = {
503
                    'id': formId,
504
                    'name': $('#form-main #form-name').val(),
505
                    'description': $('#form-main #form-description').val(),
506
                    'text': $('#form-main #form-text').val(),
507
                    'language': $('#form-main #form-language').val(),
508
                    'status': $('#form-main #form-status').val(),
509
                    'content': JSON.stringify(objFormGenerator.sections)
510
                }
511
                $.ajax({
512
                    'dataType': 'json',
513
                    'method': 'post',
514
                    'url': $('#form-main').attr('action'),
515
                    'data': data,
516
                }).done(function(response) {
517
                    if (response['success']) {
518
                        $.fn.showSuccess(response['data']);
519
                        if (formContinue == 1) {
520
                            $('#form-main').attr('action',response['action_edit']);
521
                            $('#form-main #form-id').val(response['id']);
522
                            $('#form-main #form-continue').val(0);
523
                        } else {
524
                            $('#row-edit').hide();
254 geraldo 525
                            $('#row-forms').show();
251 geraldo 526
                        /*---------- Reset Form -------- */
527
                        $('#form-main')[0].reset();
528
                        /*--------Reset Ckeditor ----------*/
529
                        CKEDITOR.instances['form-text'].setData('');
530
                        CKEDITOR.instances['form-description'].setData('');
531
                        /*--------Reset Sections ----------*/
532
                        clearSectionData();
533
                        /* ------- Refresh Table -----------*/
534
 
535
                        }
536
                        tableForm.fnDraw();
537
                    } else {
538
                        $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
539
                    }
540
                }).fail(function(jqXHR, textStatus, errorThrown) {
541
                    $.fn.showError(textStatus);
542
                });
543
                return false;
544
            }
545
        }
546
    });
264 geraldo 547
 
251 geraldo 548
    /**
549
     * Clicked cancel new/edit Form
550
     */
551
    $('button.btn-edit-cancel').click(function(e) {
552
        e.preventDefault();
553
        $('#row-edit').hide();
254 geraldo 554
        $('#row-forms').show();
251 geraldo 555
    });
556
    /**
557
     * Clicked save and continue new Form
558
     */
559
    $('button.btn-form-save-continue').click(function(e) {
560
        e.preventDefault();
561
        $('#form-main #form-continue').val('1')
562
        $('#form-main').submit();
563
    });
564
    /**
565
     * Clicked save and close new/edit Form
566
     */
567
    $('button.btn-form-save-close').click(function(e) {
568
        e.preventDefault();
569
        $('#form-main #form-continue').val('0')
570
        $('#form-main').submit();
571
    });
572
    /**
573
     * Modal Settings
574
     */
575
    $('#modal-section, #modal-question, #modal-option').modal({
576
        backdrop: 'static',
577
        keyboard: false,
578
        show: false
579
    });
580
    /**
581
     * Get Question type
582
     */
583
    const getQuestionTypeBySlug = (slug_section, slug_question) => {
584
        for (i = 0; i < objFormGenerator.sections.length; i++) {
585
            if (slug_section == objFormGenerator.sections[i].slug_section) {
586
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
587
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
588
                        return objFormGenerator.sections[i].questions[j].type;
589
                    }
590
                }
591
            }
592
        }
593
    }
594
    /**
595
     * Remove Html Tags
596
     */
597
    const removeTags = (str) => str.toString().replace( /(<([^>]+)>)/ig, '')
598
    /**
599
     * Render Sections data
600
     */
601
    const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
602
        getType: getQuestionTypeBySlug,
603
        removeTags: removeTags
604
    }));
605
 
606
 
607
    /**
608
     * Clear Div Section data
609
     */
610
    const clearSectionData = () => $("#rows").html('');
611
    /**
612
     * Clicked refresh button
613
     */
614
    $('button.btn-refresh').click(function(e) {
615
        tableForm.fnDraw();
616
    });
617
 
618
});
619
JS;
620
$this->inlineScript()->captureEnd();
621
?>
622
 
623
<!-- Content Header (Page header) -->
624
<section class="content-header">
625
    <div class="container-fluid">
626
        <div class="row mb-2">
627
            <div class="col-sm-12">
264 geraldo 628
                <h1>LABEL_REVIEWS</h1>
251 geraldo 629
            </div>
630
        </div>
631
    </div>
632
    <!-- /.container-fluid -->
633
</section>
634
<section class="content">
254 geraldo 635
    <div class="container-fluid" id="row-forms">
251 geraldo 636
        <div class="row">
637
            <div class="col-12">
638
                <div class="card">
639
                    <div class="card-body">
640
                        <table id="gridTable" class="table   table-hover">
641
                            <thead>
642
                                <tr>
643
                                    <th>LABEL_NAME</th>
644
                                    <th>LABEL_LANGUAGE</th>
261 geraldo 645
                                    <th>LABEL_ACTIVE</th>
251 geraldo 646
                                    <th>LABEL_ACTIONS</th>
647
                                </tr>
648
                            </thead>
649
                            <tbody></tbody>
650
                        </table>
651
                    </div>
652
                    <div class="card-footer clearfix">
653
                        <div style="float:right;">
654
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
655
                        </div>
656
                    </div>
657
                </div>
658
            </div>
659
        </div>
660
    </div>
661
 
662
    <!-- Create/Edit Form -->
663
 
664
    <div class="row" id="row-edit" style="display: none">
665
        <div class="col-xs-12 col-md-12">
666
            <form action="#" name="form-main" id="form-main">
261 geraldo 667
                <input type="hidden" name="form-id" id="form-id" value="0" />
668
                <input type="hidden" name="form-continue" id="form-continue" value="0" />
251 geraldo 669
                <div class="form-group">
261 geraldo 670
                    <label for="form-name">LABEL_FIRST_NAME</label>
671
                    <input type="text" name="form-name" id="form-name" class="form-control" maxlength="50" />
672
                </div>
673
                <div class="form-group">
674
                    <label for="form-description">LABEL_DESCRIPTION</label>
675
                    <!--  ckeditor -->
676
                    <textarea  name="form-description" id="form-description" rows="5" class="ckeditor form-control"></textarea>
677
                </div>
678
                <div class="form-group">
679
                    <label for="form-text">LABEL_TEXT</label>
680
                    <!--  ckeditor -->
681
                    <textarea  name="form-text" id="form-text" rows="5" class="ckeditor form-control"></textarea>
682
                </div>
683
                <div class="form-group">
684
                    <label for="form-language">LABEL_LANGUAGES</label>
685
                    <select name="form-language" id="form-language" class="form-control">
686
                        <option value="<?php echo $lang_en; ?>">LABEL_ENGLISH</option>
687
                        <option value="<?php echo $lang_es; ?>">LABEL_SPANISH</option>
688
                    </select>
689
                </div>
690
                <div class="form-group">
691
                    <label for="form-status">LABEL_STATUS</label>
692
                    <select name="form-status" id="form-status" class="form-control">
693
                        <option value="<?php echo $status_inactive; ?>">LABEL_INACTIVE</option>
694
                        <option value="<?php echo $status_active; ?>">LABEL_ACTIVE</option>
695
                    </select>
696
                </div>
697
                <br/>
698
                <div class="row">
699
                    <div class="col-xs-12 col-md-12 text-right">
700
                        <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>
701
                    </div>
702
                </div>
703
                <br />
704
                <div class="row">
705
                    <div class="col-xs-12 col-md-12">
706
                        <div class="panel-group" id="rows"></div>
707
                    </div>
708
                </div>
709
                <div class="form-group">
251 geraldo 710
                    <button type="submit" form="form-main" class="btn btn-info btn-form-save-continue">LABEL_SAVE & LABEL_CONTINUE</button>
711
                    <button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE & LABEL_CLOSE</button>
712
                    <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
713
                </div>
714
            </form>
715
        </div>
716
    </div>
717
 
261 geraldo 718
    <!-- Create/Edit Form-->
251 geraldo 719
 
264 geraldo 720
 
261 geraldo 721
 
251 geraldo 722
    <!---Template Sections --->
723
    <script id="sectionTemplate" type="text/x-jsrender">
724
    <div class="panel panel-default" id="panel-{{:slug_section}}">
725
        <div class="panel-heading">
726
            <h4 class="panel-title">
727
                <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:slug_section}}" href="#collapse-{{:slug_section}}">
728
                    <span class="section-name{{:slug_section}}">
729
                        {{:name}}
730
                    </span>
731
                </a>
732
            </h4>
733
        </div>
734
        <div id="collapse-{{:slug_section}}" class="panel-collapse in collapse show">
735
            <div class="panel-body">
736
                <div class="table-responsive">
737
                    <table class="table table-bordered">
738
                        <thead>
739
                            <tr>
740
                                <th style="width: 10%;">LABEL_ELEMENT</th>
741
                                <th style="width: 50%;">LABEL_TEXT</th>
742
                                <th style="width: 10%;">LABEL_VALUE</th>
743
                                <th style="width: 10%;">LABEL_TYPE</th>
744
                                <th style="width: 20%;">LABEL_ACTIONS</th>
745
                            </tr>
746
                        </thead>
747
                        <tbody>
748
                            <tr class="tr-section">
749
                                <td class="text-left">LABEL_SECTION</td>
750
                                <td class="text-left">{{:name}}</td>
751
                                <td>{{:value}}</td>
752
                                <td></td>
753
                                <td>
754
                                    <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>
755
                                    <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>
756
                                    <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>
757
                                </td>
758
                            </tr>
759
                            {{for questions}}
760
                            <tr class="tr-question">
761
                                <td class="text-left">--LABEL_QUESTION</td>
762
                                <td class="text-left">
763
                                    {{:~removeTags(text)}}
764
                                </td>
765
                                <td><font color="red">{{:value}}</font></td>
766
                                <td class="text-capitalize">
767
                                    {{if type == 'open'}} LABEL_OPEN {{/if}}
768
                                    {{if type == 'simple'}} Simple {{/if}}
769
                                    {{if type == 'multiple'}} Multiple {{/if}}
770
                                    {{if type == 'rating-open'}} LABEL_RATING_OPEN {{/if}}
771
                                    {{if type == 'rating-range'}} LABEL_RATING_RANGE {{/if}}
772
                                </td>
773
                                <td>
774
                                    <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>
775
                                    <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>
776
 
777
                                    {{if type == 'simple' || type == 'rating-open' || type=='multiple' }}
778
                                    <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>
779
                                    {{/if}}
780
 
781
                                </td>
782
                            </tr>
783
                            {{for options}}
784
                            <tr class="tr-option">
785
                                <td class="text-left">---LABEL_OPTION</td>
786
                                <td class="text-left">
787
                                    {{:~removeTags(text)}}
788
                                </td>
789
                                <td>
790
 
791
                                    {{if ~getType( slug_section, slug_question) == 'multiple' || ~getType( slug_section, slug_question) == 'rating-open'  }}
792
                                    {{:value}}
793
                                    {{/if}}
794
                                </td>
795
                                <td class="text-left">
796
                                    {{if ~getType( slug_section, slug_question) != 'rating-open'}}
797
                                    {{if correct == 1}}
798
                                    <font color="green">LABEL_CORRECT</font>
799
                                    {{/if}}
800
                                    {{if correct == 0}}
801
                                    <font color="red">LABEL_FAIL</font>
802
                                    {{/if}}
803
                                    {{/if}}
804
                                </td>
805
                                <td>
806
                                    <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>
807
                                    <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>
808
                                </td>
809
                            </tr>
810
                            {{/for}}
811
                            {{/for}}
812
                        </tbody>
813
                    </table>
814
                </div>
815
            </div>
816
        </div>
817
    </div>
818
    </script>
819
 
820
    <!-- End Template Sections-->
821
 
822
</section>