Proyectos de Subversion LeadersLinked - Backend

Rev

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