Proyectos de Subversion LeadersLinked - Backend

Rev

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