Proyectos de Subversion LeadersLinked - Backend

Rev

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