Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 366 | Rev 368 | 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
 
306 geraldo 60
 
307 geraldo 61
$pending = \LeadersLinked\Model\CompanySelfEvaluationTest::STATUS_PENDING;
308 geraldo 62
$review = \LeadersLinked\Model\CompanySelfEvaluationTest::STATUS_REVIEW;
307 geraldo 63
$completed = \LeadersLinked\Model\CompanySelfEvaluationTest::STATUS_COMPLETED;
306 geraldo 64
 
251 geraldo 65
$this->inlineScript()->captureStart();
66
echo <<<JS
339 geraldo 67
const classFormGenerator = function() {
251 geraldo 68
    this.id = 0,
69
        this.table = '',
70
        this.name = '',
71
        this.text = '',
72
        this.status = 'a',
73
        this.sections = [],
74
        this.clear = function() {
75
            this.sections = [];
76
            this.render();
77
        },
78
        /**
79
         * Render array sections
80
         */
81
        this.renderSection = function(slug_section) {
82
            var s = '';
83
            for (i = 0; i < this.sections.length; i++) {
84
                if (slug_section != this.sections[i].slug_section) {
85
                    continue;
86
                }
87
                for (j = 0; j < this.sections[i].questions.length; j++) {
88
                    this.sections[i].questions[j].position = j;
89
                    if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {
90
                        this.sections[i].questions[j].options.sort(function(a, b) {
91
                            if (a.position > b.position) {
92
                                return 1;
93
                            }
94
                            if (a.position < b.position) {
95
                                return -1;
96
                            }
97
                            return 0;
98
                        });
99
                        for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
100
                            this.sections[i].questions[j].options[k].position = j;
101
                        }
102
                    }
103
                }
104
            }
105
            $('[data-toggle="tooltip"]').tooltip();
106
        },
107
        this.render = function() {
108
            this.sections.sort(function(a, b) {
109
                if (a.position > b.position) {
110
                    return 1;
111
                }
112
                if (a.position < b.position) {
113
                    return -1;
114
                }
115
                return 0;
116
            });
117
            var s = '';
118
            for (i = 0; i < this.sections.length; i++) {
119
                this.sections[i].position = i;
120
                this.sections[i].questions.sort(function(a, b) {
121
                    if (a.position > b.position) {
122
                        return 1;
123
                    }
124
                    if (a.position < b.position) {
125
                        return -1;
126
                    }
127
                    return 0;
128
                });
129
                for (j = 0; j < this.sections[i].questions.length; j++) {
130
                    this.sections[i].questions[j].position = j;
131
                    if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {
132
                        this.sections[i].questions[j].options.sort(function(a, b) {
133
                            if (a.position > b.position) {
134
                                return 1;
135
                            }
136
                            if (a.position < b.position) {
137
                                return -1;
138
                            }
139
                            return 0;
140
                        });
141
                        for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
142
                            this.sections[i].questions[j].options[k].position = j;
143
                        }
144
                    }
145
                }
146
            }
147
            $('[data-toggle="tooltip"]').tooltip();
266 geraldo 148
        };
352 geraldo 149
    /**
150
     * Add element to question array
151
     */
152
    this.editQuestion = function(slug_section, slug_question, status) {
153
        var renderTable = false;
154
        for (i = 0; i < this.sections.length; i++) {
155
            if (slug_section == this.sections[i].slug_section) {
156
                for (j = 0; j < this.sections[i].questions.length; j++) {
157
                    if (slug_question == this.sections[i].questions[j].slug_question) {
158
                        this.sections[i].questions[j].status = status;
159
                        console.log(this.sections[i].questions[j]);
160
                        renderTable = true;
161
                        break;
345 geraldo 162
                    }
163
                }
164
            }
165
            if (renderTable) {
352 geraldo 166
                break;
345 geraldo 167
            }
352 geraldo 168
        }
169
        if (renderTable) {
170
            this.renderSection(slug_section);
171
        }
172
    };
339 geraldo 173
}
251 geraldo 174
jQuery(document).ready(function($) {
175
    var objFormGenerator = new classFormGenerator();
176
    objFormGenerator.render();
177
    var allowEdit = $allowEdit;
178
    /**
179
     * Get rows and set data table
180
     */
181
    var tableForm = $('#gridTable').dataTable({
182
        'processing': true,
183
        'serverSide': true,
184
        'searching': true,
185
        'order': [
186
            [0, 'asc']
187
        ],
188
        'ordering': true,
189
        'ordenable': true,
190
        'responsive': true,
191
        'select': false,
192
        'paging': true,
193
        'pagingType': 'simple_numbers',
194
        'ajax': {
195
            'url': '$routeDatatable',
196
            'type': 'get',
197
            'beforeSend': function(request) {
198
                NProgress.start();
199
            },
200
            'dataFilter': function(response) {
201
                var response = jQuery.parseJSON(response);
202
                var json = {};
203
                json.recordsTotal = 0;
204
                json.recordsFiltered = 0;
205
                json.data = [];
206
                if (response.success) {
207
                    json.recordsTotal = response.data.total;
208
                    json.recordsFiltered = response.data.total;
209
                    json.data = response.data.items;
210
                } else {
211
                    $.fn.showError(response.data)
212
                }
213
                return JSON.stringify(json);
214
            }
215
        },
216
        'language': {
217
            'sProcessing': 'LABEL_DATATABLE_SPROCESSING',
218
            'sLengthMenu': 'LABEL_DATATABLE_SLENGTHMENU',
219
            'sZeroRecords': 'LABEL_DATATABLE_SZERORECORDS',
220
            'sEmptyTable': 'LABEL_DATATABLE_SEMPTYTABLE',
221
            'sInfo': 'LABEL_DATATABLE_SINFO',
222
            'sInfoEmpty': 'LABEL_DATATABLE_SINFOEMPTY',
223
            'sInfoFiltered': 'LABEL_DATATABLE_SINFOFILTERED',
224
            'sInfoPostFix': '',
225
            'sSearch': 'LABEL_DATATABLE_SSEARCH',
226
            'sUrl': '',
227
            'sInfoThousands': ',',
228
            'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
229
            'oPaginate': {
230
                'sFirst': 'LABEL_DATATABLE_SFIRST',
231
                'sLast': 'LABEL_DATATABLE_SLAST',
232
                'sNext': 'LABEL_DATATABLE_SNEXT',
233
                'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
234
            },
235
            'oAria': {
236
                'sSortAscending': ': LABEL_DATATABLE_SSORTASCENDING',
237
                'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
238
            },
239
        },
240
        'drawCallback': function(settings) {
241
            NProgress.done();
242
            $('button.btn-delete').confirmation({
243
                rootSelector: 'button.btn-delete',
244
                title: 'LABEL_ARE_YOU_SURE',
245
                singleton: true,
246
                btnOkLabel: 'LABEL_YES',
247
                btnCancelLabel: 'LABEL_NO',
248
                onConfirm: function(value) {
249
                    action = $(this).data('href');
250
                    NProgress.start();
251
                    $.ajax({
252
                        'dataType': 'json',
253
                        'accept': 'application/json',
254
                        'method': 'post',
255
                        'url': action,
256
                    }).done(function(response) {
257
                        if (response['success']) {
258
                            $.fn.showSuccess(response['data']);
259
                            tableForm.fnDraw();
260
                        } else {
261
                            $.fn.showError(response['data']);
262
                        }
263
                    }).fail(function(jqXHR, textStatus, errorThrown) {
264
                        $.fn.showError(textStatus);
265
                    }).always(function() {
266
                        NProgress.done();
267
                    });
268
                },
269
            });
270
        },
339 geraldo 271
        'aoColumns': [{
294 geraldo 272
                'mDataProp': 'user'
339 geraldo 273
            }, {
251 geraldo 274
                'mDataProp': 'name'
275
            },
276
            {
277
                'mDataProp': 'language'
278
            },
279
            {
280
                'mDataProp': 'status'
281
            },
282
            {
294 geraldo 283
                'mDataProp': 'link_edit'
251 geraldo 284
            },
285
        ],
339 geraldo 286
        'columnDefs': [{
251 geraldo 287
                'targets': 0,
288
                'className': 'text-vertical-middle',
339 geraldo 289
            }, {
294 geraldo 290
                'targets': 1,
291
                'className': 'text-vertical-middle',
251 geraldo 292
            },
293
            {
294 geraldo 294
                'targets': -1,
251 geraldo 295
                'className': 'text-vertical-middle',
296
            },
297
            {
292 geraldo 298
                'targets': -2,
299
                'orderable': false,
300
                'className': 'text-center',
293 geraldo 301
                'className': 'text-vertical-middle',
251 geraldo 302
            },
303
            {
304
                'targets': -1,
305
                'orderable': false,
306
                'render': function(data, type, row) {
307
                    s = '';
308
                    if (allowEdit) {
293 geraldo 309
                        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 310
                    }
311
                    return s;
312
                }
313
            }
314
        ],
315
    });
316
    /**
317
     * Clicked on edit form
318
     */
319
    $('body').on('click', 'button.btn-edit-form', function(e) {
320
        e.preventDefault();
321
        form_id = $(this).data('id')
322
        var action = $(this).data('href');
323
        $.ajax({
324
            'dataType': 'json',
325
            'accept': 'application/json',
326
            'method': 'get',
327
            'url': action,
328
        }).done(function(response) {
329
            if (response['success']) {
330
                $('#form-main').attr('action', action);
331
                $('#form-main #form-id').val(response['data']['id']),
366 geraldo 332
                $('#name').html(response['data']['name']);
333
                $('#form-status').val(response['data']['status']);
316 geraldo 334
                $('#text').html(response['data']['text']);
335
                $('#user').html(response['data']['user']);
251 geraldo 336
                /*-------------Render Sections -------*/
337
                objFormGenerator.clear();
338
                objFormGenerator.sections = response['data']['content'] || [];
339
                objFormGenerator.render();
340
                renderSectionData(objFormGenerator.sections);
254 geraldo 341
                $('#row-forms').hide();
251 geraldo 342
                $('#row-edit').show();
343
            } else {
344
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
345
            }
346
        }).fail(function(jqXHR, textStatus, errorThrown) {
347
            $.fn.showError(textStatus);
348
        });
349
    });
351 geraldo 350
    $('button.btn-form-save-close').click(function(e) {
352 geraldo 351
        var formContinue = parseInt($('#form-main #form-continue').val());
352
        var data = {
353
            'status': $('#form-main #form-status').val(),
354
            'content': JSON.stringify(objFormGenerator.sections)
355
        }
356
        $.ajax({
357
            'dataType': 'json',
358
            'method': 'post',
359
            'url': $('#form-main').attr('action'),
360
            'data': data,
361
        }).done(function(response) {
362
            if (response['success']) {
363
                $.fn.showSuccess(response['data']);
364
                $('#row-edit').hide();
365
                $('#row-forms').show();
366
                /*---------- Reset Form -------- */
367
                $('#form-main')[0].reset();
368
                /*--------Reset Sections ----------*/
369
                clearSectionData();
370
                /* ------- Refresh Table -----------*/
371
                tableForm.fnDraw();
372
            } else {
373
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
374
            }
375
        }).fail(function(jqXHR, textStatus, errorThrown) {
376
            $.fn.showError(textStatus);
377
        });
378
        return false;
351 geraldo 379
    });
251 geraldo 380
    /**
381
     * Clicked cancel new/edit Form
382
     */
383
    $('button.btn-edit-cancel').click(function(e) {
384
        e.preventDefault();
385
        $('#row-edit').hide();
254 geraldo 386
        $('#row-forms').show();
251 geraldo 387
    });
388
    /**
339 geraldo 389
     * Get Answers
390
     */
391
    const getAnswer = (type, options, answer) => {
392
        if (type == 'open' || type == 'rating-range') {
328 geraldo 393
            return answer;
251 geraldo 394
        }
339 geraldo 395
        if (type == 'multiple') {
352 geraldo 396
            let opt = '';
339 geraldo 397
            opt += removeTags(options.filter((opt) => answer.includes(opt.slug_option))[0].text) + ' ';
332 geraldo 398
            return opt;
330 geraldo 399
        }
338 geraldo 400
        return removeTags(options.filter((opt) => opt.slug_option == answer)[0].text);
251 geraldo 401
    }
402
    /**
341 geraldo 403
     * Get Status
404
     */
344 geraldo 405
    const getStatus = (options, answer) => options.filter((opt) => (opt.slug_option == answer || answer.includes(opt.slug_option)) &&
352 geraldo 406
        opt.correct == 1) ? 'LABEL_CORRECT' : 'LABEL_FAIL'
341 geraldo 407
    /**
251 geraldo 408
     * Remove Html Tags
409
     */
339 geraldo 410
    const removeTags = (str) => str.toString().replace(/(<([^>]+)>)/ig, '')
251 geraldo 411
    /**
412
     * Render Sections data
413
     */
414
    const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
323 geraldo 415
        removeTags: removeTags,
341 geraldo 416
        getAnswer: getAnswer,
345 geraldo 417
        getStatus: getStatus,
418
        editQuestion: objFormGenerator.editQuestion
251 geraldo 419
    }));
420
    /**
421
     * Clear Div Section data
422
     */
423
    const clearSectionData = () => $("#rows").html('');
424
    /**
425
     * Clicked refresh button
426
     */
427
    $('button.btn-refresh').click(function(e) {
428
        tableForm.fnDraw();
429
    });
430
});
431
JS;
432
$this->inlineScript()->captureEnd();
433
?>
434
 
435
<!-- Content Header (Page header) -->
436
<section class="content-header">
437
    <div class="container-fluid">
438
        <div class="row mb-2">
439
            <div class="col-sm-12">
264 geraldo 440
                <h1>LABEL_REVIEWS</h1>
251 geraldo 441
            </div>
442
        </div>
443
    </div>
444
    <!-- /.container-fluid -->
445
</section>
314 geraldo 446
<section class="content" style="padding: 13px;">
254 geraldo 447
    <div class="container-fluid" id="row-forms">
251 geraldo 448
        <div class="row">
449
            <div class="col-12">
450
                <div class="card">
451
                    <div class="card-body">
452
                        <table id="gridTable" class="table   table-hover">
453
                            <thead>
454
                                <tr>
294 geraldo 455
                                <th>LABEL_USER</th>
251 geraldo 456
                                    <th>LABEL_NAME</th>
457
                                    <th>LABEL_LANGUAGE</th>
294 geraldo 458
                                    <th>LABEL_STATUS</th>
251 geraldo 459
                                    <th>LABEL_ACTIONS</th>
460
                                </tr>
461
                            </thead>
462
                            <tbody></tbody>
463
                        </table>
464
                    </div>
465
                    <div class="card-footer clearfix">
466
                        <div style="float:right;">
467
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
468
                        </div>
469
                    </div>
470
                </div>
471
            </div>
472
        </div>
473
    </div>
474
 
475
    <!-- Create/Edit Form -->
476
 
477
    <div class="row" id="row-edit" style="display: none">
478
        <div class="col-xs-12 col-md-12">
479
            <form action="#" name="form-main" id="form-main">
480
                <div class="form-group">
318 geraldo 481
                <label for="form-status">LABEL_USER:</label>
317 geraldo 482
                <div id="user"></div>
483
                </div>
484
                <div class="form-group">
318 geraldo 485
                <label for="form-status">LABEL_FORM:</label>
317 geraldo 486
                <div id="name"></div>
487
                </div>
488
                <div class="form-group">
318 geraldo 489
                <label for="form-status">LABEL_DESCRIPTION:</label>
317 geraldo 490
                <div id="text"></div>
491
                </div>
492
                <div class="form-group">
318 geraldo 493
                    <label for="form-status">LABEL_STATUS:</label>
261 geraldo 494
                    <select name="form-status" id="form-status" class="form-control">
306 geraldo 495
                        <option value="<?php echo $pending; ?>">LABEL_PENDING</option>
496
                        <option value="<?php echo $review; ?>">LABEL_REVIEW</option>
497
                        <option value="<?php echo $completed; ?>">LABEL_COMPLETED</option>
261 geraldo 498
                    </select>
303 geraldo 499
                </div>
261 geraldo 500
                <div class="row">
501
                    <div class="col-xs-12 col-md-12">
502
                        <div class="panel-group" id="rows"></div>
503
                    </div>
504
                </div>
505
                <div class="form-group">
319 geraldo 506
                    <button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE</button>
251 geraldo 507
                    <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
508
                </div>
509
            </form>
510
        </div>
511
    </div>
512
 
261 geraldo 513
    <!-- Create/Edit Form-->
251 geraldo 514
 
264 geraldo 515
 
261 geraldo 516
 
251 geraldo 517
    <!---Template Sections --->
518
    <script id="sectionTemplate" type="text/x-jsrender">
519
    <div class="panel panel-default" id="panel-{{:slug_section}}">
520
        <div class="panel-heading">
521
            <h4 class="panel-title">
522
                <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:slug_section}}" href="#collapse-{{:slug_section}}">
523
                    <span class="section-name{{:slug_section}}">
524
                        {{:name}}
525
                    </span>
526
                </a>
527
            </h4>
528
        </div>
529
        <div id="collapse-{{:slug_section}}" class="panel-collapse in collapse show">
530
            <div class="panel-body">
531
                <div class="table-responsive">
310 geraldo 532
                {{for questions}}
251 geraldo 533
                    <table class="table table-bordered">
534
                        <thead>
535
                            <tr>
367 geraldo 536
                                <th style="width: 40%;">LABEL_QUESTION</th>
537
                                <th style="width: 40%;">LABEL_ANSWER</th>
538
                                <th style="width: 20%;">LABEL_ACTION</th>
312 geraldo 539
 
251 geraldo 540
                            </tr>
541
                        </thead>
542
                        <tbody>
543
                            <tr class="tr-question">
303 geraldo 544
                                <td class="text-left">{{:~removeTags(text)}} </td>
367 geraldo 545
                                <td>{{:~getAnswer(type,options,answer)}}</td>
339 geraldo 546
                                <td>
340 geraldo 547
 
548
                                {{if type == 'simple'  || type=='multiple' }}
341 geraldo 549
 
550
                                {{:~getStatus( options,answer)}}
551
 
340 geraldo 552
                                {{/if}}
553
 
367 geraldo 554
 
339 geraldo 555
 
556
                                </td>
251 geraldo 557
                            </tr>
558
                        </tbody>
559
                    </table>
310 geraldo 560
 
561
                    {{/for}}
251 geraldo 562
                </div>
563
            </div>
564
        </div>
565
    </div>
566
    </script>
567
 
568
    <!-- End Template Sections-->
569
 
570
</section>