Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
15430 stevensc 1
<?php
2
 
66 efrain 3
use LeadersLinked\Model\JobDescription;
4
 
5
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
6
$currentUser    = $this->currentUserHelper();
7
 
8
$roleName = $currentUser->getUserTypeId();
9
 
15394 efrain 10
 
15443 efrain 11
$routeAdd       = $this->url('jobs-description/add');
12
$routeDatatable = $this->url('jobs-description');
13
$routeImport    = $this->url('jobs-description/import');
66 efrain 14
$routeDashboard = $this->url('dashboard');
15
 
15443 efrain 16
$allowAdd               = $acl->isAllowed($roleName, 'jobs-description/add') ? 1 : 0;
17
$allowEdit              = $acl->isAllowed($roleName, 'jobs-description/edit') ? 1 : 0;
18
$allowDelete            = $acl->isAllowed($roleName, 'jobs-description/delete') ? 1 : 0;
19
$allowReport            = $acl->isAllowed($roleName, 'jobs-description/report') ? 1 : 0;
20
$allowImport            = $acl->isAllowed($roleName, 'jobs-description/import') ? 1 : 0;
66 efrain 21
 
22
 
15394 efrain 23
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
24
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
25
 
15443 efrain 26
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-maxlenght/bootstrap-maxlength.min.js'));
15394 efrain 27
 
28
 
29
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
30
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
31
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
32
 
33
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
34
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
35
 
36
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
37
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
38
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
39
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
40
 
41
 
66 efrain 42
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
43
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
44
 
15394 efrain 45
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
46
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
47
 
1227 geraldo 48
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/select2.js'));
15394 efrain 49
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/i18n/es.js'));
1227 geraldo 50
$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.css'));
15394 efrain 51
 
1227 geraldo 52
$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.css'));
53
 
15394 efrain 54
 
55
// bootbox Alert //
56
$this->inlineScript()->appendFile($this->basePath('plugins/bootbox/bootbox.min.js'));
57
 
58
// JsRender //
59
$this->inlineScript()->appendFile($this->basePath('plugins/jsrender/jsrender.min.js'));
60
 
61
 
1175 geraldo 62
// Page Styles
15394 efrain 63
//$this->headLink()->appendStylesheet($this->basePath('css/pages/self-evaluation.css'));
1175 geraldo 64
 
15394 efrain 65
 
66
 
67
 
68
$status_active = JobDescription::STATUS_ACTIVE;
69
 
70
$this->inlineScript()->captureStart();
71
echo <<<JS
72
 
73
 
74
jQuery(document).ready(function($) {
75
 
15443 efrain 76
    var competencies_selected = new Array();
77
    var subordinates_selected = new Array();
78
    var behaviors = new Array();
79
    var subordinates = new Array();
80
    var competency_types = new Array();
81
    var competencies = new Array();
15394 efrain 82
 
83
    var allowEdit = $allowEdit;
84
    var allowDelete = $allowDelete;
85
    var allowReport = $allowReport;
86
 
87
 
88
    $.fn.renderCompetencies = function() {
89
        if(competencies_selected.length > 0) {
16766 efrain 90
 
91
            console.log( competencies_selected );
92
            console.log( competency_types );
93
            console.log( competencies );
94
 
95
 
96
 
15394 efrain 97
            $('#renderCompetencies').html($('#competencyTemplate').render(competencies_selected, {
98
                getCompetencyType: (uuid) => competency_types.filter((item) => item.uuid == uuid ? item : false)[0],
99
                getCompetency: (uuid) => competencies.filter((item) => item.uuid == uuid ? item : false)[0],
100
                getBehavior: (uuid) => behaviors.filter((item) => item.uuid == uuid ? item : false)[0]
101
            }));
102
        } else {
103
            $('#renderCompetencies').html('');
104
        }
105
    }
106
 
107
    $.fn.renderSubordinates = function() {
108
 
109
 
110
        if(subordinates_selected.length > 0) {
111
            $('#renderSubordinates').html($('#subordinateTemplate').render(subordinates_selected, {
112
                getSubordinate: (uuid) => subordinates.filter((item) => item.uuid == uuid ? item : false)[0],
113
 
114
            }));
115
        } else {
116
            $('#renderSubordinates').html('');
117
        }
118
    }
119
 
120
    $.fn.comboCompetencies = function() {
121
        $('#select-competency').children().remove();
122
        $.each(competency_types, function(i, competency_type) {
123
            competencies_filtered = competencies.filter((item) => item.competency_type_uuid == competency_type.uuid ? item : false)
124
            $.each(competencies_filtered, function(i, competency) {
125
 
126
 
127
                selected = competencies_selected.filter((item) => item.uuid == competency.uuid ? item : false)[0];
128
                if(!selected) {
129
                    $('#select-competency').append($('<option>', {
130
                        value: competency.uuid,
131
                        text: competency_type.name +  ' - ' + competency.name
132
                    }));
133
                }
134
 
135
            });
136
        });
137
 
138
    }
139
 
140
    $.fn.comboSubordinates = function() {
141
 
142
 
143
        $('#select-subordinate').children().remove();
144
        $.each(subordinates, function(i, subordinate) {
145
            var subordinate_selected = subordinates_selected.filter((item) => item.uuid == subordinate.uuid ? item : false)[0];
146
            if(!subordinate_selected) {
147
 
148
                $('#select-subordinate').append($('<option>', {
149
                    value: subordinate.uuid,
150
                    text: subordinate.name
151
                }));
152
            }
153
        });
154
    }
155
 
156
 
157
    $.validator.setDefaults({
158
        debug: true,
159
        highlight: function(element) {
160
            $(element).addClass('is-invalid');
161
        },
162
        unhighlight: function(element) {
163
            $(element).removeClass('is-invalid');
164
        },
165
        errorElement: 'span',
166
        errorClass: 'error invalid-feedback',
167
        errorPlacement: function(error, element) {
168
            if (element.parent('.form-group').length) {
169
                error.insertAfter(element);
170
            } else if (element.parent('.toggle').length) {
171
                error.insertAfter(element.parent().parent());
172
            } else {
173
                error.insertAfter(element.parent());
174
            }
175
        }
176
    });
177
 
178
    $.fn.showFormErrorValidator = function(fieldname, errors) {
179
        var field = $(fieldname);
180
        if (field) {
181
            $(field).addClass('is-invalid');
182
            var error = $('<span id="' + fieldname + '-error" class="error invalid-feedback">' + errors + '</div>');
183
            if (field.parent('.form-group').length) {
184
                error.insertAfter(field);
185
            } else if (field.parent('.toggle').length) {
186
                error.insertAfter(field.parent().parent());
187
            } else {
188
                error.insertAfter(field.parent());
189
            }
190
        }
191
    };
192
 
193
    var gridTable = $('#gridTable').dataTable({
194
        'processing': true,
195
        'serverSide': true,
196
        'searching': true,
197
        'order': [
198
            [0, 'asc']
199
        ],
200
        'ordering': true,
201
        'ordenable': true,
202
        'responsive': true,
203
        'select': false,
204
        'paging': true,
205
        'pagingType': 'simple_numbers',
206
        'ajax': {
207
            'url': '$routeDatatable',
208
            'type': 'get',
209
            'beforeSend': function(request) {
210
                NProgress.start();
211
            },
212
            'dataFilter': function(response) {
213
                var response = jQuery.parseJSON(response);
214
                var json = {};
215
                json.recordsTotal = 0;
216
                json.recordsFiltered = 0;
217
                json.data = [];
218
                if (response.success) {
219
                    json.recordsTotal = response.data.total;
220
                    json.recordsFiltered = response.data.total;
221
                    json.data = response.data.items;
222
                } else {
223
                    $.fn.showError(response.data)
224
                }
225
                return JSON.stringify(json);
226
            }
227
        },
228
        'language': {
229
            'sProcessing': 'LABEL_DATATABLE_SPROCESSING',
230
            'sLengthMenu': 'LABEL_DATATABLE_SLENGTHMENU',
231
            'sZeroRecords': 'LABEL_DATATABLE_SZERORECORDS',
232
            'sEmptyTable': 'LABEL_DATATABLE_SEMPTYTABLE',
233
            'sInfo': 'LABEL_DATATABLE_SINFO',
234
            'sInfoEmpty': 'LABEL_DATATABLE_SINFOEMPTY',
235
            'sInfoFiltered': 'LABEL_DATATABLE_SINFOFILTERED',
236
            'sInfoPostFix': '',
237
            'sSearch': 'LABEL_DATATABLE_SSEARCH',
238
            'sUrl': '',
239
            'sInfoThousands': ',',
240
            'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
241
            'oPaginate': {
242
                'sFirst': 'LABEL_DATATABLE_SFIRST',
243
                'sLast': 'LABEL_DATATABLE_SLAST',
244
                'sNext': 'LABEL_DATATABLE_SNEXT',
245
                'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
246
            },
247
            'oAria': {
248
                'sSortAscending': ': LABEL_DATATABLE_SSORTASCENDING',
249
                'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
250
            },
251
        },
252
        'drawCallback': function(settings) {
253
            NProgress.done();
254
            $('button.btn-delete').confirmation({
255
                rootSelector: 'button.btn-delete',
256
                title: 'LABEL_ARE_YOU_SURE',
257
                singleton: true,
258
                btnOkLabel: 'LABEL_YES',
259
                btnCancelLabel: 'LABEL_NO',
260
                onConfirm: function(value) {
261
                    action = $(this).data('href');
262
                    NProgress.start();
263
                    $.ajax({
264
                        'dataType': 'json',
265
                        'accept': 'application/json',
266
                        'method': 'post',
267
                        'url': action,
268
                    }).done(function(response) {
269
                        if (response['success']) {
270
                            $.fn.showSuccess(response['data']);
271
                            gridTable.api().ajax.reload(null, false);
272
                        } else {
273
                            $.fn.showError(response['data']);
274
                        }
275
                    }).fail(function(jqXHR, textStatus, errorThrown) {
276
                        $.fn.showError(textStatus);
277
                    }).always(function() {
278
                        NProgress.done();
279
                    });
280
                },
281
            });
282
        },
283
        'aoColumns': [{
284
                'mDataProp': 'name'
285
            },
286
            {
287
                'mDataProp': 'status'
288
            },
289
            {
290
                'mDataProp': 'actions'
291
            },
292
        ],
293
        'columnDefs': [{
294
                'targets': 0,
295
                'className': 'text-vertical-middle',
296
            },
297
            {
298
                'targets': -2,
299
                'orderable': false,
300
                'className': 'text-center',
301
                'render': function(data, type, row) {
302
                    checked = data == 'a' ? ' checked="checked" ' : '';
303
                    return '<div class="checkbox checkbox-success">' +
304
                        '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
305
                        '<label ></label></div>';
306
                }
307
            },
308
            {
309
                'targets': -1,
310
                'orderable': false,
311
                'render': function(data, type, row) {
312
                    s = '';
15443 efrain 313
                    if (allowEdit && data['link_edit']) {
15394 efrain 314
                        s = s + '<button class="btn btn-primary btn-edit" data-href="' + data['link_edit'] + '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pencil"></i> LABEL_EDIT </button>&nbsp;';
315
                    }
15443 efrain 316
                    if (allowDelete && data['link_delete']) {
15394 efrain 317
                        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;';
318
                    }
15443 efrain 319
                    if (allowReport && data['link_report']) {
15394 efrain 320
                        s = s + '<button class="btn btn-primary btn-pdf"  data-href="' + data['link_report'] + '"  data-toggle="tooltip" title="LABEL_PDF"><i class="fa fa-file-o"></i> LABEL_PDF </button>&nbsp;';
321
                    }
322
                    return s;
323
                }
324
            }
325
        ],
326
    });
327
 
328
    var validator = $('#form').validate({
329
        debug: true,
330
        onclick: false,
331
        onkeyup: false,
332
        ignore: [],
333
        rules: {
334
            'name': {
335
                required: true,
336
                maxlength: 64,
337
            },
338
            'functions': {
339
                required: true,
15443 efrain 340
                maxlength: 1024,
15394 efrain 341
            },
342
            'objectives': {
15443 efrain 343
               required: true,
344
                maxlength: 1024,
15394 efrain 345
            },
346
            'status': {
347
                required: false,
348
            },
349
            'job_description_id_boss': {
350
                required: false,
351
            }
352
        },
353
        submitHandler: function(form) {
354
 
355
            var data = {
356
                name : $('#form #name').val(),
357
                functions : $('#form #functions').val(),
358
                objectives : $('#form #objectives').val(),
359
                status :  $('#form #status').val(),
360
                job_description_id_boss: $('#form #job_description_id_boss').val(),
361
                subordinates_selected : new Array(),
362
                competencies_selected : new Array(),
363
            };
364
 
365
 
366
            $.each(competencies_selected, function(i, c) {
367
                $.each(c.behaviors, function(i, b) {
368
                    data.competencies_selected.push({'competency_uuid' : c.uuid, 'behavior_uuid' : b.uuid, 'level' : b.level});
369
                });
370
            });
371
 
372
 
373
            $.each(subordinates_selected, function(i, subordinate_selected) {
374
                data.subordinates_selected.push(subordinate_selected.uuid);
375
            });
376
 
377
            NProgress.start();
378
            $.ajax({
379
                'dataType': 'json',
380
                'accept': 'application/json',
381
                'method': 'post',
382
                'url': $('#form').attr('action'),
383
                'data': data,
384
            }).done(function(response) {
385
                if (response['success']) {
386
                    $.fn.showSuccess(response['data']);
387
                    $('#row-lists').show();
388
                    $('#row-form').hide();
389
                    gridTable.api().ajax.reload(null, false);
390
                } else {
391
                    validator.resetForm();
392
                    if (jQuery.type(response['data']) == 'string') {
393
                        $.fn.showError(response['data']);
394
                    } else {
395
                        $.each(response['data'], function(fieldname, errors) {
396
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
397
                        });
398
                    }
399
                }
400
            }).fail(function(jqXHR, textStatus, errorThrown) {
401
                $.fn.showError(textStatus);
402
            }).always(function() {
403
                NProgress.done();
404
            });
405
            return false;
406
        },
407
        invalidHandler: function(form, validator) {}
408
    });
409
 
410
    $('body').on('click', 'button.btn-add', function(e) {
411
        e.preventDefault();
412
        NProgress.start();
413
        $.ajax({
414
            'dataType': 'json',
415
            'accept': 'application/json',
416
            'method': 'get',
417
            'url': '$routeAdd',
418
        }).done(function(response) {
419
 
420
            if (response['success']) {
421
 
15443 efrain 422
 
423
                behaviors = response['data']['behaviors'];
424
                competency_types = response['data']['competency_types'];
425
                competencies = response['data']['competencies'];
426
 
427
 
15394 efrain 428
                competencies_selected = [];
429
                subordinates = [];
430
 
431
                $('#select-subordinate').children().remove();
432
                $('#job_description_id_boss').children().not(':first').remove();
433
 
434
                $.each(response['data']['jobs_description'], function(value, text) {
435
                    subordinates.push({uuid:  value, name: text});
436
 
437
                    $('#select-subordinate').append($('<option>', {
438
                        value: value,
439
                        text: text
440
                    }));
441
 
442
                    $('#job_description_id_boss').append($('<option>', {
443
                        value: value,
444
                        text: text
445
                    }));
446
                });
447
 
448
                $('#form #job_description_id_boss').val('').trigger('change');
449
 
450
 
451
 
452
                $.fn.renderSubordinates();
453
                $.fn.comboSubordinates();
454
 
455
 
456
                $.each(competencies, function(i, competency) {
457
                    $.each(competency.behaviors, function(j, behavior) {
458
                        competencies[i].behaviors[j].level = 0;
459
                    });
460
                });
461
 
462
                $.fn.renderCompetencies();
463
                $.fn.comboCompetencies();
464
 
465
                $('span[id="form-title"]').html('LABEL_ADD');
466
                $('#form').attr('action', '$routeAdd');
467
                $('#form #name').val('');
468
                $('#form #status').bootstrapToggle('on');
469
 
15443 efrain 470
                $('#form #functions').val('');
471
                $('#form #objectives').val('');
15394 efrain 472
 
473
                validator.resetForm();
474
 
475
 
476
                $('#custom-tabs #custom-tabs-general-tab').tab('show');
477
                $('#row-lists').hide();
478
                $('#row-form').show();
479
 
480
           } else   {
481
                $.fn.showError(response['data']);
482
            }
483
        }).fail(function(jqXHR, textStatus, errorThrown) {
484
            $.fn.showError(textStatus);
485
        }).always(function() {
486
            NProgress.done();
487
        });
488
        return false
489
    });
490
 
491
    $('body').on('click', 'button.btn-edit', function(e) {
492
        e.preventDefault();
493
        NProgress.start();
494
        var action = $(this).data('href');
495
        $.ajax({
496
            'dataType': 'json',
497
            'accept': 'application/json',
498
            'method': 'get',
499
            'url': action,
500
        }).done(function(response) {
501
            if (response['success']) {
502
                $('span[id="form-title"]').html('LABEL_EDIT');
503
                $('#form').attr('action', action);
504
                $('#form #name').val(response['data']['name']);
505
                $('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
506
 
15443 efrain 507
                $('#form #functions').val(response['data']['functions']);
508
                $('#form #objectives').val(response['data']['objectives']);
15394 efrain 509
 
15443 efrain 510
                behaviors = response['data']['behaviors'];
511
                competency_types = response['data']['competency_types'];
16766 efrain 512
 
513
 
15443 efrain 514
                competencies = response['data']['competencies'];
515
 
15394 efrain 516
                subordinates = [];
517
                $('#select-subordinate').children().remove();
518
                $('#job_description_id_boss').children().not(':first').remove();
519
 
520
 
521
                $.each(response['data']['jobs_description'], function(value, text) {
522
                    subordinates.push({uuid:  value, name: text});
523
 
524
 
525
                    $('#select-subordinate').append($('<option>', {
526
                        value: value,
527
                        text: text
528
                    }));
529
 
530
                    $('#job_description_id_boss').append($('<option>', {
531
                        value: value,
532
                        text: text
533
                    }));
534
                });
535
 
536
 
537
                $('#form #job_description_id_boss').val(response['data']['job_description_id_boss']).trigger('change');
538
 
539
 
540
                competencies_selected = response['data']['competencies_selected'];
541
                subordinates_selected = response['data']['subordinates_selected'];
542
 
543
 
544
 
545
                $.fn.renderCompetencies();
546
                $.fn.comboCompetencies();
547
 
548
                $.fn.renderSubordinates();
549
                $.fn.comboSubordinates();
550
 
551
 
552
                validator.resetForm();
553
                $('#custom-tabs #custom-tabs-general-tab').tab('show');
554
                $('#row-lists').hide();
555
                $('#row-form').show();
556
            } else {
557
                $.fn.showError(response['data']);
558
            }
559
        }).fail(function(jqXHR, textStatus, errorThrown) {
560
            $.fn.showError(textStatus);
561
        }).always(function() {
562
            NProgress.done();
563
        });
564
    });
565
    $('body').on('click', 'button.btn-refresh', function(e) {
566
        e.preventDefault();
567
        gridTable.api().ajax.reload(null, false);
568
    });
569
 
570
    $('body').on('click', 'button.btn-cancel', function(e) {
571
        e.preventDefault();
572
        $('#row-lists').show();
573
        $('#row-form').hide();
574
        $('#div-listing').show();
575
    });
576
 
577
    $('body').on('click', 'button.btn-import', function(e) {
578
        e.preventDefault();
579
        NProgress.start();
580
        $.ajax({
581
            'dataType': 'json',
582
            'method': 'post',
583
            'url': '$routeImport',
584
        }).done(function(response) {
585
            if (response['success']) {
586
                $.fn.showSuccess(response['data']);
587
                gridTable.api().ajax.reload(null, false);
588
            } else {
589
                $.fn.showError(response['data']);
590
            }
591
        }).fail(function(jqXHR, textStatus, errorThrown) {
592
            $.fn.showError(textStatus);
593
        }).always(function() {
594
            NProgress.done();
595
        });
596
        return false;
597
    });
598
 
599
 
600
    $('body').on('click', 'button.btn-pdf', function(e) {
601
        e.preventDefault();
602
        var action   = $(this).data('href');
603
 
15443 efrain 604
 
15394 efrain 605
        NProgress.start();
606
        $.ajax({
607
            'dataType'  : 'json',
608
            'method'    : 'get',
609
            'url'       :  action,
610
        }).done(function(response) {
611
            if(response['success']) {
612
                var anchor = window.document.createElement("a");
613
                anchor.href = 'data:application/octet-stream;charset=utf-8;base64,' + response['data']['content'] ;
614
                anchor.download = response['data']['basename'];
615
                document.body.appendChild(anchor);
616
                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
617
                document.body.removeChild(anchor);
618
            } else {
619
                $.fn.showError(response['data']);
620
            }
621
        }).fail(function( jqXHR, textStatus, errorThrown) {
15443 efrain 622
            $.fn.showError(textStatus);
15394 efrain 623
        }).always(function() {
624
            NProgress.done();
625
        });
626
 
627
 
15443 efrain 628
 
15394 efrain 629
    });
630
 
631
 
632
 
633
    $('body').on('click', 'button[id="btn-select-competency"]', function(e) {
634
        var competency_uuid = $('#select-competency').val();
635
 
636
        if (competency_uuid.length == '') {
637
            $.fn.showError('ERROR_SELECT_COMPETENCY_IS_EMPTY');
638
        } else {
639
 
640
            competency = competencies.filter((item) => item.uuid == competency_uuid ? item : false)[0];
641
            if(competency) {
642
 
643
                var competency_selected = {
644
                    uuid : competency.uuid,
645
                    competency_type_uuid: competency.competency_type_uuid,
646
                    behaviors : new Array(),
647
                }
648
 
649
                $.each(competency.behaviors, function(index, uuid) {
650
                    competency_selected.behaviors.push({uuid: uuid, level: 0});
651
 
652
                })
653
 
654
 
655
                competencies_selected.push(competency_selected);
656
 
657
                $.fn.renderCompetencies();
658
                $.fn.comboCompetencies();
659
            }
660
        }
661
    });
662
 
663
 
664
    $('body').on('click', 'button[id="btn-select-subordinate"]', function(e) {
665
        e.preventDefault();
666
 
667
        var uuid = $("#select-subordinate").val();
668
 
669
        if (uuid == "") {
670
            $.fn.showError('ERROR_SELECT_DEPENDENT_IS_EMPTY');
671
        } else {
672
            subordinate = subordinates.filter((item) => item.uuid == uuid ? item : false)[0];
673
            if(subordinate) {
674
                subordinates_selected.push({uuid: subordinate.uuid});
675
                $.fn.renderSubordinates();
676
                $.fn.comboSubordinates();
677
            }
678
        }
679
    });
680
 
681
    $('body').on('click', 'button.btn-delete-subordinate', function(e) {
682
        var uuid = $(this).data('subordinate');
683
        bootbox.confirm({
684
            title: 'LABEL_DEPENDENT_DELETE_TITLE',
685
            message: 'LABEL_DEPENDENT_DELETE_MESSAGE',
686
            buttons: {
687
                cancel: {
688
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
689
                },
690
                confirm: {
691
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
692
                }
693
            },
694
            callback: function(result) {
695
                if (result) {
696
                    subordinates_selected = subordinates_selected.filter((item) => item.uuid != uuid ? item : false);
697
 
698
                    $.fn.renderSubordinates();
699
                    $.fn.comboSubordinates();
700
                }
701
            }
702
        });
703
    });
704
 
705
 
706
 
707
    $('body').on('click', 'button.btn-delete-competency', function(e) {
708
        e.preventDefault();
709
 
710
        var uuid = $(this).data('competency');
711
        bootbox.confirm({
712
             title: 'LABEL_COMPETENCY_DELETE_TITLE',
713
            message: 'LABEL_COMPETENCY_DELETE_MESSAGE',
714
            buttons: {
715
                cancel: {
716
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
717
                },
718
                confirm: {
719
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
720
                }
721
            },
722
            callback: function(result) {
723
                if (result) {
724
                    competencies_selected = competencies_selected.filter((item) => item.uuid != uuid ? item : false);
725
 
726
 
727
                    $.fn.renderCompetencies();
728
                    $.fn.comboCompetencies();
729
 
730
                }
731
            }
732
        });
733
    });
734
 
735
    $('body').on('click','button.btn-edit-behavior', function(e) {
736
        e.preventDefault();
737
 
738
        var competency_uuid = $(this).closest('div.panel-competency').data('competency');
739
        var behavior_uuid = $(this).data('behavior');
740
 
741
 
742
        competency_selected = competencies_selected.filter((item) => item.uuid == competency_uuid ? item : false)[0];
743
        if(competency_selected) {
744
            console.log(competency_selected);
745
 
746
            behavior = competency_selected .behaviors.filter((item) => item.uuid  == behavior_uuid ? item : false)[0];
747
            if(behavior) {
748
 
749
                console.log(behavior);
750
                $('#form-behavior #competency-uuid').val(competency_uuid);
751
                $('#form-behavior #behavior-uuid').val(behavior_uuid);
752
                $('#form-behavior #level').val(behavior.level);
753
 
754
                $('#modal-behavior').modal('show');
755
            }
756
 
757
        }
758
    });
759
 
760
    $('body').on('click','button.btn-behavior-submit', function(e) {
761
         e.preventDefault();
762
         $('#modal-behavior').modal('hide');
763
 
764
         var competency_uuid = $('#form-behavior #competency-uuid').val();
765
         var behavior_uuid = $('#form-behavior #behavior-uuid').val();
766
         var level = $('#form-behavior #level').val();
767
 
768
        competency_selected = competencies_selected.filter((item) => item.uuid == competency_uuid ? item : false)[0];
769
        if(competency_selected) {
770
            behavior = competency_selected .behaviors.filter((item) => item.uuid  == behavior_uuid ? item : false)[0];
771
            if(behavior) {
772
                behavior.level = level;
773
                $.fn.renderCompetencies();
774
            }
775
 
776
        }
777
 
778
    });
779
 
780
    $('body').on('click', 'button.btn-edit-cancel', function(e) {
781
        $('#row-lists').show();
782
        $('#row-form').hide();
783
    });
784
 
785
    $('#form #status').bootstrapToggle({
786
        'on': 'LABEL_ACTIVE',
787
        'off': 'LABEL_INACTIVE',
788
        'width': '160px',
789
        'height': '40px'
790
    });
791
 
15443 efrain 792
    $('#form #functions').maxlength({
793
        alwaysShow: true,
794
         validate: true
795
    });
796
 
797
    $('#form #objectives').maxlength({
798
        alwaysShow: true,
799
        validate: true
800
    });
801
 
802
 
15394 efrain 803
    $('#form #job_description_id_boss').select2({
804
        theme: 'bootstrap4',
805
        width: '100%',
806
    });
807
 
808
 
809
 
810
    $('#select-subordinate').select2({
811
        theme: 'bootstrap4',
812
        width: '100%',
813
    });
814
 
815
 
816
 
817
    $('#select-competency').select2({
818
        theme: 'bootstrap4',
819
        width: '100%',
820
    });
15434 stevensc 821
 
15435 stevensc 822
 
15394 efrain 823
});
824
 
14184 stevensc 825
JS;
66 efrain 826
$this->inlineScript()->captureEnd();
15394 efrain 827
?>
828
<section class="content" id="row-lists">
14185 stevensc 829
 
15430 stevensc 830
    <!-- Content Header (Page header) -->
831
    <div class="content-header">
832
        <div class="container-fluid">
833
            <div class="row mb-2">
834
                <div class="col-sm-12">
835
                    <h1>LABEL_JOBS_DESCRIPTION</h1>
836
                </div>
15394 efrain 837
            </div>
15430 stevensc 838
        </div>
839
        <!-- /.container-fluid -->
840
    </div>
841
    <div class="container-fluid">
842
        <div class="row">
843
            <div class="col-12">
844
                <div class="card">
845
                    <div class="card-body">
846
                        <table id="gridTable" class="table table-hover">
847
                            <thead>
848
                                <tr>
849
                                    <th style="width: 50%">LABEL_NAME</th>
850
                                    <th style="width: 15%">LABEL_ACTIVE</th>
851
                                    <th style="width: 35%">LABEL_ACTIONS</th>
852
                                </tr>
853
                            </thead>
854
                            <tbody>
855
                            </tbody>
856
                        </table>
857
                    </div>
858
                    <div class="card-footer clearfix">
859
                        <div style="float:right;">
860
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
861
                            <?php if ($allowAdd) : ?>
862
                                <?php if ($allowImport) : ?>
863
                                    <button type="button" class="btn btn-primary btn-import"><i class="fa fa-upload"></i> LABEL_IMPORT </button>
864
                                <?php endif; ?>
865
                                <button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
866
                            <?php endif; ?>
867
                        </div>
868
                    </div>
869
                </div>
870
            </div>
871
        </div>
872
    </div>
15394 efrain 873
</section>
874
 
875
<section id="row-form" style="display:none">
15430 stevensc 876
    <div class="container">
877
        <!-- Modal Header -->
878
        <div class="modal-header">
15432 stevensc 879
            <h4 class="modal-title">LABEL_JOB_DESCRIPTION - <span id="form-title"></span></h4>
15430 stevensc 880
        </div>
881
        <!-- Modal body -->
882
        <div class="modal-body">
883
            <div class="card card-primary card-outline card-tabs">
884
                <div class="card-header p-0 pt-1 border-bottom-0">
885
                    <ul class="nav nav-tabs" id="custom-tabs" role="tablist">
886
                        <li class="nav-item">
887
                            <a class="nav-link active" id="custom-tabs-general-tab" data-toggle="pill" href="#custom-tabs-general" role="tab" aria-controls="custom-tabs-general" aria-selected="true">LABEL_GENERAL</a>
888
                        </li>
889
                        <li class="nav-item">
890
                            <a class="nav-link" id="custom-tabs-compentencies-tab" data-toggle="pill" href="#custom-tabs-compentencies" role="tab" aria-controls="custom-tabs-compentencies" aria-selected="false">LABEL_COMPETENCIES</a>
891
                        </li>
892
                        <li class="nav-item">
893
                            <a class="nav-link" id="custom-tabs-subordinate-tab" data-toggle="pill" href="#custom-tabs-subordinate" role="tab" aria-controls="custom-tabs-subordinate" aria-selected="false">LABEL_SUBORDINATES</a>
894
                        </li>
895
                    </ul>
896
                </div>
897
                <div class="card-body">
898
                    <?php
899
                    $form = $this->form;
900
                    $form->setAttributes([
901
                        'method'    => 'post',
902
                        'name'      => 'form',
903
                        'id'        => 'form'
904
                    ]);
905
 
906
                    $form->prepare();
907
                    echo $this->form()->openTag($form);
908
 
909
 
910
                    $element = $form->get('subordinates');
911
                    echo $this->formHidden($element);
912
 
913
                    $element = $form->get('competencies');
914
                    echo $this->formHidden($element);
915
 
916
 
917
                    ?>
918
 
919
                    <div class="tab-content" id="custom-tabs-three-tabContent">
920
                        <div class="tab-pane fade show active" id="custom-tabs-general" role="tabpanel" aria-labelledby="custom-tabs-general-tab">
921
                            <div class="row">
922
                                <div class="col-md col-sm-12 col-12">
923
                                    <div class="form-group m-0">
924
                                        <?php
925
                                        $element = $form->get('name');
926
                                        $element->setOptions(['label' => 'LABEL_NAME']);
927
                                        $element->setAttributes(['class' => 'form-control']);
928
 
929
                                        echo $this->formLabel($element);
930
                                        echo $this->formText($element);
931
                                        ?>
932
                                    </div>
933
                                </div>
934
                                <div class="col-md col-sm-12 col-12">
935
                                    <div class="form-group m-0">
936
                                        <?php
937
                                        $element = $form->get('job_description_id_boss');
938
                                        $element->setOptions(['label' => 'LABEL_BOSS']);
939
                                        $element->setAttributes(['class' => 'form-control']);
940
 
941
                                        echo $this->formLabel($element);
942
                                        echo $this->formSelect($element);
943
                                        ?>
944
                                    </div>
945
                                </div>
946
                                <div class="col-md col-sm-12 col-12 d-flex align-items-center justify-content-center">
947
                                    <div class="form-group m-0">
948
                                        <label>LABEL_STATUS</label>
949
                                        <br />
950
                                        <?php
951
                                        $element = $form->get('status');
952
                                        $element->setOptions(['label' => 'LABEL_STATUS']);
953
                                        // echo $this->formLabel($element);
954
                                        echo $this->formCheckbox($element);
955
                                        ?>
956
                                    </div>
957
                                </div>
958
                            </div>
959
                            <div class="form-group">
960
                                <?php
961
                                $element = $form->get('objectives');
962
                                $element->setOptions(['label' => 'LABEL_OBJECTIVES']);
963
                                $element->setAttributes(['class' => 'form-control']);
964
 
965
                                echo $this->formLabel($element);
966
                                echo $this->formTextArea($element);
967
                                ?>
968
                            </div>
969
                            <div class="form-group">
970
                                <?php
971
                                $element = $form->get('functions');
972
                                $element->setOptions(['label' => 'LABEL_FUNCTIONS']);
973
                                $element->setAttributes(['class' => 'form-control']);
974
 
975
                                echo $this->formLabel($element);
976
                                echo $this->formTextArea($element);
977
                                ?>
978
                            </div>
15394 efrain 979
                        </div>
15430 stevensc 980
                        <div class="tab-pane fade" id="custom-tabs-compentencies" role="tabpanel" aria-labelledby="custom-tabs-compentencies-tab">
981
                            <div class="row">
982
                                <div class="col-md-8 col-sm-8 col-xs-12">
983
                                    <select id="select-competency" class="form-control"> </select>
984
                                </div>
985
                                <div class="col-md-4 col-sm-4 col-xs-12">
986
                                    <button type="button" class="btn btn-primary" id="btn-select-competency" data-toggle="tooltip" title="LABEL_ADD LABEL_COMPETENCY">LABEL_ADD LABEL_COMPETENCY</button>
987
                                </div>
988
                            </div>
989
                            <div class="row">
990
                                <br>
991
                                <div class="col-md-12 col-sm-12 col-xs-12" id="renderCompetencies" style="margin-top: 10px;">
992
                                </div>
993
                            </div>
15394 efrain 994
                        </div>
15430 stevensc 995
                        <div class="tab-pane fade" id="custom-tabs-subordinate" role="tabpanel" aria-labelledby="custom-tabs-subordinate-tab">
996
                            <div class="row">
997
                                <div class="col-md-8 col-sm-8 col-xs-12">
998
                                    <select id="select-subordinate" class="form-control"></select>
999
                                </div>
1000
                                <div class="col-md-4 col-sm-4 col-xs-12">
1001
                                    <button type="button" class="btn btn-primary" id="btn-select-subordinate" data-toggle="tooltip" title="LABEL_ADD ">LABEL_ADD </button>
1002
                                </div>
1003
                            </div>
1004
                            <div class="row">
1005
                                <div class="col-md-12 col-sm-12 col-xs-12" style="margin-top: 10px;">
1006
                                    <table class="table table-bordered">
1007
                                        <thead>
1008
                                            <tr>
1009
                                                <th style="width: 60%;">LABEL_NAME</th>
1010
                                                <th style="width: 20%;">LABEL_ACTIONS</th>
1011
                                            </tr>
1012
                                        </thead>
1013
                                        <tbody id="renderSubordinates"></tbody>
1014
                                    </table>
1015
                                </div>
1016
                            </div>
15394 efrain 1017
                        </div>
15430 stevensc 1018
                    </div>
1019
                </div>
15394 efrain 1020
            </div>
15430 stevensc 1021
            <?php echo $this->form()->closeTag($form); ?>
1022
            <!-- /.card -->
1023
        </div>
1024
        <!-- Modal footer -->
1025
        <div class="modal-footer">
1026
            <button type="submit" form="form" class="btn btn-primary">LABEL_SAVE</button>
1027
            <button type="button" class="btn btn-danger btn-edit-cancel">Cerrar</button>
1028
        </div>
15394 efrain 1029
</section>
1030
 
1031
 
1032
<!--start modal behavior-->
15430 stevensc 1033
<div id="modal-behavior" class="modal" tabindex="-1" role="dialog">
1034
    <div class="modal-dialog modal-lg" role="document">
1035
        <form action="#" name="form-behavior" id="form-behavior">
1036
            <input type="hidden" id="behavior-uuid" name="behavior-uuid" value="" />
1037
            <input type="hidden" id="competency-uuid" name="competency-uuid value="" />
1038
         <div class=" modal-content">
15394 efrain 1039
            <div class="modal-header">
15430 stevensc 1040
                <h4 class="modal-title">LABEL_EDIT LABEL_LEVEL</h4>
1041
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
1042
                    <span aria-hidden="true">&times;</span>
1043
                </button>
15394 efrain 1044
            </div>
1045
            <div class="modal-body">
15443 efrain 1046
               <div class="form-group">
1047
                  <label for="behavior-value">LABEL_LEVEL</label>
1048
                  <input type="number" step="1" min="0" max="100" id="level" name="level">
15394 efrain 1049
            </div>
1050
            <div class="modal-footer">
15430 stevensc 1051
                <button type="button" class="btn btn-primary btn-behavior-submit">LABEL_SAVE</button>
1052
                <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
15394 efrain 1053
            </div>
15430 stevensc 1054
    </div>
1055
    </form>
15394 efrain 1056
</div>
15430 stevensc 1057
</div>
15436 stevensc 1058
 
15394 efrain 1059
 
15443 efrain 1060
 
15430 stevensc 1061
<!---Template Competencies --->
1062
<script id="competencyTemplate" type="text/x-jsrender">
1063
    <div class="panel panel-default panel-competency" id="panel-{{:uuid}}" data-competency="{{:uuid}}">
15394 efrain 1064
   <div class="panel-heading">
1065
      <h4 class="panel-title" style="    font-size: 18px;">
1066
         <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:uuid}}" href="#collapse-{{:uuid}}">
1067
         <span class="section-name{{:uuid}}">
1068
            {{:~getCompetencyType(competency_type_uuid).name}} - {{:~getCompetency(uuid).name}}
1069
         </span>
1070
         </a>
1071
      </h4>
1072
   </div>
1073
   <div id="collapse-{{:uuid}}" class="panel-collapse in collapse show">
1074
      <div class="panel-body">
1075
         <div class="table-responsive">
1076
            <table class="table table-bordered">
1077
               <thead>
1078
                  <tr>
1079
                     <th style="width: 20%;">LABEL_ELEMENT</th>
1080
                     <th style="width: 50%;">LABEL_TITLE</th>
1081
                     <th style="width: 10%;">LABEL_LEVEL</th>
1082
                     <th style="width: 20%;">LABEL_ACTIONS</th>
1083
                  </tr>
1084
               </thead>
1085
               <tbody>
1086
                  <tr>
1087
                     <td class="text-left">LABEL_COMPETENCY</td>
1088
                     <td class="text-left">{{:name}}</td>
1089
                     <td>
1090
                     </td>
1091
                     <td>
1092
                        <button  type="button" class="btn btn-default btn-delete-competency" data-competency="{{:uuid}}" data-toggle="tooltip"  data-original-title="LABEL_DELETE LABEL_COMPETENCY"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_COMPETENCY </button>
1093
                     </td>
1094
                  </tr>
1095
                  {{for behaviors}}
1096
                  <tr >
1097
                     <td class="text-left">--LABEL_BEHAVIOR</td>
1098
                     <td class="text-left">
1099
                       {{:~getBehavior(uuid).description}}
1100
                     </td>
15443 efrain 1101
                     <td class="text-right">
1102
                        {{:level}}
1103
                     </td>
15394 efrain 1104
                     <td>
15443 efrain 1105
                        <button type="button"  class="btn btn-default btn-edit-behavior" data-behavior="{{:uuid}}" data-toggle="tooltip"  data-original-title="LABEL_EDIT LABEL_LEVEL"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_LEVEL</button>
1106
                     </td>
1107
                  </tr>
1108
                  {{/for}}
1109
               </tbody>
1110
            </table>
1111
         </div>
1112
      </div>
1113
   </div>
1114
</div>
1115
</script>
1116
 
1117
<script id="competencyTemplateWithLevel" type="text/x-jsrender">
1118
 <div class="panel panel-default panel-competency" id="panel-{{:uuid}}" data-competency="{{:uuid}}">
1119
   <div class="panel-heading">
1120
      <h4 class="panel-title" style="    font-size: 18px;">
1121
         <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:uuid}}" href="#collapse-{{:uuid}}">
1122
         <span class="section-name{{:uuid}}">
1123
            {{:~getCompetencyType(competency_type_uuid).name}} - {{:~getCompetency(uuid).name}}
1124
         </span>
1125
         </a>
1126
      </h4>
1127
   </div>
1128
   <div id="collapse-{{:uuid}}" class="panel-collapse in collapse show">
1129
      <div class="panel-body">
1130
         <div class="table-responsive">
1131
            <table class="table table-bordered">
1132
               <thead>
1133
                  <tr>
1134
                     <th style="width: 20%;">LABEL_ELEMENT</th>
1135
                     <th style="width: 50%;">LABEL_TITLE</th>
1136
                     <th style="width: 10%;">LABEL_LEVEL</th>
1137
                     <th style="width: 20%;">LABEL_ACTIONS</th>
1138
                  </tr>
1139
               </thead>
1140
               <tbody>
1141
                  <tr>
1142
                     <td class="text-left">LABEL_COMPETENCY</td>
1143
                     <td class="text-left">{{:name}}</td>
1144
                     <td>
1145
                     </td>
1146
                     <td>
1147
                        <button  type="button" class="btn btn-default btn-delete-competency" data-competency="{{:uuid}}" data-toggle="tooltip"  data-original-title="LABEL_DELETE LABEL_COMPETENCY"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_COMPETENCY </button>
1148
                     </td>
1149
                  </tr>
1150
                  {{for behaviors}}
1151
                  <tr >
1152
                     <td class="text-left">--LABEL_BEHAVIOR</td>
1153
                     <td class="text-left">
1154
                       {{:~getBehavior(uuid).description}}
1155
                     </td>
1156
                     <td>
15394 efrain 1157
                        {{if level == '0'}} LABEL_NA {{/if}}
1158
                        {{if level == '1' }} LABEL_LEVEL_ONE {{/if}}
1159
                        {{if level == '2' }} LABEL_LEVEL_TWO {{/if}}
1160
                        {{if level == '3' }} LABEL_LEVEL_THREE {{/if}}
1161
                        {{if level == '4' }} LABEL_LEVEL_FOUR {{/if}}
1162
                     </td>
1163
                     <td>
1164
                        <button type="button"  class="btn btn-default btn-edit-behavior" data-behavior="{{:uuid}}" data-toggle="tooltip"  data-original-title="LABEL_EDIT LABEL_LEVEL"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_LEVEL</button>
1165
                     </td>
1166
                  </tr>
1167
                  {{/for}}
1168
               </tbody>
1169
            </table>
1170
         </div>
1171
      </div>
1172
   </div>
1173
</div>
1174
</script>
1175
 
1176
 
1177
<script id="subordinateTemplate" type="text/x-jsrender">
1178
    <tr>
1179
        <td class="text-left"> {{:~getSubordinate(uuid).name}}</td>
1180
        <td>
1181
            <button type="button" class="btn btn-default btn-delete-subordinate" data-subordinate="{{:uuid}}" data-toggle="tooltip"  data-original-title="LABEL_DELETE"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE</button>
1182
        </td>
1183
    </tr>
1184
    </script>
1185
 
15430 stevensc 1186
<!-- End Template Competencies-->