Proyectos de Subversion LeadersLinked - Backend

Rev

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

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