Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15443 | Rev 16822 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
15443 efrain 1
<?php
2
$t = strtotime("+3 days");
3
$startDate = date('d/m/Y', $t);
4
 
5
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
6
$currentUser    = $this->currentUserHelper();
7
$roleName       = $currentUser->getUserTypeId();
8
 
9
$routeDatatable = $this->url('performance-evaluation/evaluations');
10
$routeAdd = $this->url('performance-evaluation/evaluations/add');
11
 
12
$allowAdd = $acl->isAllowed($roleName, 'performance-evaluation/evaluations/add') ? 1 : 0;
13
$allowDelete = $acl->isAllowed($roleName, 'performance-evaluation/evaluations/delete') ? 1 : 0;
14
$allowReport =  $acl->isAllowed($roleName, 'performance-evaluation/evaluations/report') ? 1 : 0;
15
 
16
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
17
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
18
 
19
 
20
$this->inlineScript()->appendFile($this->basePath('plugins/bootbox/bootbox.min.js'));
21
 
22
 
23
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
24
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
25
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
26
 
27
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
28
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
29
 
30
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
31
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
32
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
33
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
34
 
35
 
36
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
37
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
38
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
39
 
40
$this->inlineScript()->appendFile($this->basePath('plugins/moment/moment-with-locales.min.js'));
41
//$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css'));
42
//$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'));
43
 
44
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-datepicker/js/bootstrap-datepicker.js'));
45
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-datepicker/js/bootstrap-datepicker.es.js'));
46
 
47
 
48
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-datepicker/css/bootstrap-datepicker.css'));
49
 
50
$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.min.css'));
51
$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css'));
52
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/select2.min.js'));
53
 
54
// JsRender //
55
$this->inlineScript()->appendFile($this->basePath('plugins/jsrender/jsrender.min.js'));
56
 
57
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
58
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
59
 
60
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
61
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
62
 
63
 
64
$this->inlineScript()->captureStart();
65
echo <<<JS
66
 
67
 
68
jQuery( document ).ready(function( $ ) {
69
 
70
    var allowAdd = $allowAdd;
71
    var allowDelete = $allowDelete
72
    var allowReport = $allowReport
73
 
74
    $.validator.setDefaults({
75
        debug: true,
76
        highlight: function(element) {
77
            $(element).addClass('is-invalid');
78
        },
79
        unhighlight: function(element) {
80
            $(element).removeClass('is-invalid');
81
        },
82
        errorElement: 'span',
83
        errorClass: 'error invalid-feedback',
84
        errorPlacement: function(error, element) {
85
            if(element.parent('.form-group').length) {
86
                error.insertAfter(element);
87
            } else if(element.parent('.toggle').length) {
88
                error.insertAfter(element.parent().parent());
89
            } else {
90
                error.insertAfter(element.parent());
91
            }
92
        }
93
    });
94
 
95
 
96
 
97
    $.fn.showFormErrorValidator = function(fieldname, errors) {
98
        var field = $(fieldname);
99
        if(field) {
100
            $(field).addClass('form-group-has-error');
101
 
102
            var error = $('<div id="' + fieldname +'-error" class="form-group-invalid-feedback">' + errors + '</div>');
103
            if(field.parent('.form-group').length) {
104
                error.insertAfter(field.parent());
105
            } else {
106
                error.insertAfter(field);
107
            }
108
        }
109
    };
110
 
111
 
112
    var validator = $('#form').validate({
113
        debug: true,
114
        onclick: false,
115
        onkeyup: false,
116
        onfocusout: false,
117
        ignore: [],
118
        rules: {
119
            'last_date': {
120
                required: true,
121
            },
122
            'form_id' :  {
123
                required: true,
124
            },
125
            'supervisor_id' : {
126
                required: true,
127
            },
128
            'employee_id' : {
129
                required: true,
130
            }
131
 
132
        },
133
        submitHandler: function(form)
134
        {
135
            NProgress.start();
136
            $.ajax({
137
                'dataType'  : 'json',
138
                'accept'    : 'application/json',
139
                'method'    : 'post',
140
                'url'       :  $('#form').attr('action'),
141
                'data'      :  $('#form').serialize(),
142
            }).done(function(response) {
143
                if(response['success']) {
144
                    $('#row-form').hide();
145
                    $('#row-listing').show();
146
                    $('#row-header').show();
147
                    gridTable.api().ajax.reload(null, false);
148
                } else {
149
                    validator.resetForm();
150
                    if(jQuery.type(response['data']) == 'string') {
151
                        $.fn.showError(response['data']);
152
                    } else  {
153
                        $.each(response['data'], function( fieldname, errors ) {
154
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
155
                        });
156
                    }
157
                }
158
            }).fail(function( jqXHR, textStatus, errorThrown) {
159
                $.fn.showError(textStatus);
160
            }).always(function() {
161
                NProgress.done();
162
            });
163
            return false;
164
        },
165
        invalidHandler: function(form, validator) {
166
 
167
        }
168
    });
169
 
170
        var gridTable = $('#gridTable').dataTable( {
171
            'processing': true,
172
            'serverSide': true,
173
            'searching': true,
174
            'order': [[ 1, 'asc' ]],
175
            'ordering':  true,
176
            'ordenable' : true,
177
            'responsive': true,
178
            'select' : false,
179
                'paging': true,
180
            'pagingType': 'simple_numbers',
181
            'lengthMenu': [ [10, 25, 50, -1], [10, 25, 50, 'All'] ],
182
 
183
                'ajax': {
184
                        'url' : '$routeDatatable',
185
                        'type' : 'get',
186
                'data': function ( d ) {
187
 
188
 
189
                },
190
                'beforeSend': function (request) {
191
                  NProgress.start();
192
                },
193
                'dataFilter': function(response) {
194
                    var response = jQuery.parseJSON( response );
195
 
196
                    var json                = {};
197
                    json.recordsTotal       = 0;
198
                    json.recordsFiltered    = 0;
199
                    json.data               = [];
200
 
201
                    if(response.success) {
202
                                               json.recordsTotal       = response.data.total;
203
                        json.recordsFiltered    = response.data.total;
204
                        json.data               = response.data.items;
205
                    } else {
206
                        $.fn.showError(response.data)
207
                    }
208
 
209
                    return JSON.stringify( json );
210
                }
211
                },
212
            'language' : {
213
                'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
214
                'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
215
                'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
216
                'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
217
                'sInfo':           'LABEL_DATATABLE_SINFO',
218
                'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
219
                'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
220
                'sInfoPostFix':    '',
221
                'sSearch':         'LABEL_DATATABLE_SSEARCH',
222
                'sUrl':            '',
223
                'sInfoThousands':  ',',
224
                'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
225
                'oPaginate': {
226
                    'sFirst':    'LABEL_DATATABLE_SFIRST',
227
                    'sLast':     'LABEL_DATATABLE_SLAST',
228
                    'sNext':     'LABEL_DATATABLE_SNEXT',
229
                    'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
230
                },
231
                'oAria': {
232
                    'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
233
                    'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
234
                },
235
            },
236
            'drawCallback': function( settings ) {
237
                NProgress.done();
238
                $('button.btn-delete').confirmation({
239
                    rootSelector: 'button.btn-delete',
240
                    title : 'LABEL_ARE_YOU_SURE',
241
                    singleton : true,
242
                    btnOkLabel: 'LABEL_YES',
243
                    btnCancelLabel: 'LABEL_NO',
244
                    onConfirm: function(value) {
245
                        action = $(this).data('href');
246
                        NProgress.start();
247
                        $.ajax({
248
                            'dataType'  : 'json',
249
                            'accept'    : 'application/json',
250
                            'method'    : 'post',
251
                            'url'       :  action,
252
                        }).done(function(response) {
253
                            if(response['success']) {
254
                                $.fn.showSuccess(response['data']);
255
                                gridTable.api().ajax.reload(null, false);
256
                            } else {
257
                                $.fn.showError(response['data']);
258
                            }
259
                        }).fail(function( jqXHR, textStatus, errorThrown) {
260
                            $.fn.showError(textStatus);
261
                        }).always(function() {
262
                            NProgress.done();
263
                        });
264
                    },
265
                });
266
 
267
 
268
            },
269
            'aoColumns': [
270
                { 'mDataProp': 'last_date' },
271
                { 'mDataProp': 'form' },
272
                { 'mDataProp': 'supervisor_first_name' },
273
                { 'mDataProp': 'employee_last_name' },
274
                { 'mDataProp': 'status' },
275
                { 'mDataProp': 'actions' },
276
            ],
277
            'columnDefs': [
278
                {
279
                    'targets': 0,
280
                    'render' : function ( data, type, row ) {
281
                        var s = data;
282
 
283
                        return s;
284
 
285
 
286
                     }
287
                },
288
                {
289
                    'targets': 1,
290
                    'render' : function ( data, type, row ) {
291
                        var s = row['form'];
292
 
293
                        if(allowReport && row['actions']['link_pdf_both']) {
294
                            s = s + '<br><button class="btn btn-default btn-pdf" data-href="' + row['actions']['link_pdf_both'] + '" data-toggle="tooltip" title="LABEL_PDF_BOTH"><i class="fa fa-pdf"></i> LABEL_PDF_BOTH </button>&nbsp;';
295
 
296
                        }
297
                        return s;
298
 
299
                     }
300
                },
301
                {
302
                    'targets': 2,
303
                    'render' : function ( data, type, row ) {
304
                        var s = row['supervisor_first_name'] + ' ' + row['supervisor_last_name'];
305
 
306
                        if(allowReport && row['actions']['link_pdf_supervisor']) {
307
                            s = s + '<br><button class="btn btn-default btn-pdf" data-href="' + row['actions']['link_pdf_supervisor'] + '" data-toggle="tooltip" title="LABEL_PDF_SUPERVISOR"><i class="fa fa-pdf"></i> LABEL_PDF_SUPERVISOR </button>&nbsp;';
308
 
309
                        }
310
 
311
                        return s;
312
 
313
 
314
                     }
315
                },
316
                {
317
                    'targets': 3,
318
                    'render' : function ( data, type, row ) {
319
                        var s = row['employee_first_name'] + ' ' + row['employee_last_name'];
320
 
321
                        if(allowReport && row['actions']['link_pdf_employee']) {
322
                            s = s + '<br><button class="btn btn-default btn-pdf" data-href="' + row['actions']['link_pdf_employee'] + '" data-toggle="tooltip" title="LABEL_PDF_EMPLOYEE"><i class="fa fa-pdf"></i> LABEL_PDF_EMPLOYEE </button>&nbsp;';
323
 
324
                        }
325
 
326
                        return s;
327
 
328
 
329
                     }
330
                },
331
                {
332
                    'targets': -1,
333
                    'orderable': false,
334
                    'render' : function ( data, type, row ) {
335
                        s = '';
336
 
337
 
338
                        if (allowDelete && data['link_delete']) {
339
                            s = s + '<button class="btn btn-danger btn-delete" data-href="' + data['link_delete'] + '" data-toggle="tooltip" title="LABEL_DELETE"><i class="fa fa-trash"></i> LABEL_DELETE </button>&nbsp;';
340
                        }
341
 
342
 
343
 
344
 
345
                        return s;
346
                    }
347
                }
348
              ],
349
        });
350
 
351
$('body').on('click', 'button.btn-pdf', function(e) {
352
        e.preventDefault();
353
        var action   = $(this).data('href');
354
 
355
 
356
        NProgress.start();
357
        $.ajax({
358
            'dataType'  : 'json',
359
            'method'    : 'get',
360
            'url'       :  action,
361
        }).done(function(response) {
362
            if(response['success']) {
363
                var anchor = window.document.createElement("a");
364
                anchor.href = 'data:application/octet-stream;charset=utf-8;base64,' + response['data']['content'] ;
365
                anchor.download = response['data']['basename'];
366
                document.body.appendChild(anchor);
367
                anchor.click();  // IE: "Access is denied"; see: https://connect.microsoft.com/IE/feedback/details/797361/ie-10-treats-blob-url-as-cross-origin-and-denies-access
368
                document.body.removeChild(anchor);
369
            } else {
370
                $.fn.showError(response['data']);
371
            }
372
        }).fail(function( jqXHR, textStatus, errorThrown) {
373
            $.fn.showError(textStatus);
374
        }).always(function() {
375
            NProgress.done();
376
        });
377
 
378
 
379
 
380
    });
381
 
382
    $('.btn-evaluation-close').on("click", function(e){
383
        e.preventDefault();
384
 
385
        $('#row-form').hide();
386
        $('#row-listing').show();
387
        $('#row-header').show();
388
        return false;
389
    });
390
 
391
 
392
    $('body').on('click', 'button.btn-refresh', function(e) {
393
        e.preventDefault();
394
        gridTable.api().ajax.reload(null, false);
395
    });
396
 
397
 
398
    $('body').on('click', 'button.btn-cancel', function(e) {
399
        e.preventDefault();
400
        $('#row').show();
401
        $('#main').hide();
402
    });
403
 
404
    $('body').on('click', 'button.btn-add', function(e) {
405
        e.preventDefault();
406
 
407
 
408
        $('#form').attr('action','$routeAdd');
409
 
410
        $('#form #last_date').val('$startDate');
411
        $('#form #form_id').val('').trigger('change');
412
        $('#form #supervisor_id').val('').trigger('change');
413
        $('#form #employee_id').val('').trigger('change');
414
        validator.resetForm();
415
 
416
        $('#row-listing').hide();
417
        $('#row-header').hide();
418
        $('#row-form').show();
419
 
420
        return false;
421
    });
422
 
423
 
424
    $('#form #last_date').datepicker({
425
        language: 'es',
426
        format: 'dd/mm/yyyy',
427
        startDate: '$startDate',
428
 
429
    });
430
 
431
    $('#form #form_id').select2({
432
        theme: 'bootstrap4',
433
        width: '100%',
434
    });
435
 
436
    $('#form #supervisor_id').select2({
437
        theme: 'bootstrap4',
438
        width: '100%',
439
    });
440
 
441
    $('#form #employee_id').select2({
442
        theme: 'bootstrap4',
443
        width: '100%',
444
    });
445
 
446
 
447
 
448
});
449
JS;
450
$this->inlineScript()->captureEnd();
451
?>
452
 
453
<!-- Content Header (Page header) -->
454
<section id="row-header" class="content-header">
455
    <div class="container-fluid">
456
        <div class="row mb-2">
457
            <div class="col-sm-12">
16320 stevensc 458
                <h1>LABEL_EVALUATION</h1>
15443 efrain 459
            </div>
460
        </div>
461
    </div>
462
    <!-- /.container-fluid -->
463
</section>
464
<section id="row-listing" class="content">
465
    <div class="container-fluid" id="row-lists">
466
        <div class="row">
467
            <div class="col-12">
468
                <div class="card">
469
                    <div class="card-body">
470
                        <table id="gridTable" class="table   table-hover">
471
                            <thead>
472
                                <tr>
473
                                    <th style="width:15%">LABEL_LAST_DATE</th>
474
                                    <th style="width:35%">LABEL_FORM_NAME</th>
475
                                    <th style="width:35%">LABEL_SUPERVISOR</th>
476
                                    <th style="width:35%">LABEL_EMPLOYEE</th>
477
                                    <th style="width:15%">LABEL_STATUS</th>
478
                                    <th style="width:15%">LABEL_ACTIONS</th>
479
                                </tr>
480
                            </thead>
481
                            <tbody></tbody>
482
                        </table>
483
                    </div>
484
                    <div class="card-footer clearfix">
485
                        <div style="float:right;">
486
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
487
                            <?php if ($allowAdd) : ?>
488
                                <button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
489
                            <?php endif; ?>
490
                        </div>
491
                    </div>
492
                </div>
493
            </div>
494
        </div>
495
    </div>
16320 stevensc 496
</section>
497
 
498
 
15443 efrain 499
<section id="row-form" class="content" style="display: none">
500
    <div class="container-fluid" id="row-lists">
501
        <div class="row">
502
            <div class="col-12">
16320 stevensc 503
                <?php
15443 efrain 504
                $form = $this->form;
505
                $form->setAttributes([
506
                    'method' => 'post',
507
                    'name' => 'form',
508
                    'action' => $routeAdd,
509
                    'id' => 'form'
510
                ]);
511
                $form->prepare();
512
                echo $this->form()->openTag($form);
16320 stevensc 513
 
15443 efrain 514
                ?>
16320 stevensc 515
                <div class="card">
516
                    <div class="card-header">
517
                        <h3>LABEL_NEW_EVALUATION</h3>
518
                    </div>
15443 efrain 519
                    <div class="card-body">
520
                        <div class="form-group">
521
                            <?php
522
                            $element = $form->get('last_date');
523
                            $element->setOptions(['label' => 'LABEL_LAST_DATE']);
524
                            $element->setAttributes(['class' => 'form-control']);
525
                            echo $this->formLabel($element);
526
                            echo $this->formText($element);
527
                            ?>
528
                        </div>
529
                        <div class="form-group">
530
                            <?php
531
                            $element = $form->get('form_id');
532
                            $element->setOptions(['label' => 'LABEL_FORM_NAME']);
533
                            $element->setAttributes(['class' => 'form-control']);
534
                            echo $this->formLabel($element);
535
                            echo $this->formSelect($element);
536
                            ?>
537
                        </div>
538
                        <div class="form-group">
539
                            <?php
540
                            $element = $form->get('supervisor_id');
541
                            $element->setOptions(['label' => 'LABEL_SUPERVISOR']);
542
                            $element->setAttributes(['class' => 'form-control']);
543
                            echo $this->formLabel($element);
544
                            echo $this->formSelect($element);
545
                            ?>
546
                        </div>
16320 stevensc 547
                        <div class="form-group">
15443 efrain 548
                            <?php
549
                            $element = $form->get('employee_id');
550
                            $element->setOptions(['label' => 'LABEL_EMPLOYEE']);
551
                            $element->setAttributes(['class' => 'form-control']);
552
                            echo $this->formLabel($element);
553
                            echo $this->formSelect($element);
554
                            ?>
555
                        </div>
556
                    </div>
557
 
16320 stevensc 558
 
15443 efrain 559
                    <div class="card-footer">
560
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
561
                        <button type="button" class="btn btn-default btn-evaluation-close">LABEL_CANCEL</button>
562
                    </div>
563
                    <?php echo $this->form()->closeTag($form); ?>
16320 stevensc 564
                </div>
15443 efrain 565
            </div>
566
        </div>
567
    </div>
16320 stevensc 568
</section>