Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 1199 | Rev 1227 | 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 = [];
1196 geraldo 65
var subordinates = [];
1170 geraldo 66
var competencies_selected = [];
1196 geraldo 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) {
1192 geraldo 267
            $("#competencies_selected").val(JSON.stringify(competencies_selected));
1196 geraldo 268
            $("#subordinates_selected").val(JSON.stringify(subordinates_selected));
66 efrain 269
            $.ajax({
935 geraldo 270
                'dataType': 'json',
271
                'accept': 'application/json',
272
                'method': 'post',
273
                'url': $('#form').attr('action'),
274
                'data': $('#form').serialize()
66 efrain 275
            }).done(function(response) {
935 geraldo 276
                NProgress.start();
277
                if (response['success']) {
278
                    $.fn.showSuccess(response['data']);
279
                    $('#modal').modal('hide');
280
                    gridTable.api().ajax.reload(null, false);
281
                } else {
282
                    validator.resetForm();
283
                    if (jQuery.type(response['data']) == 'string') {
284
                        $.fn.showError(response['data']);
285
                    } else {
286
                        $.each(response['data'], function(fieldname, errors) {
287
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
66 efrain 288
                        });
935 geraldo 289
                    }
66 efrain 290
                }
935 geraldo 291
            }).fail(function(jqXHR, textStatus, errorThrown) {
66 efrain 292
                $.fn.showError(textStatus);
293
            }).always(function() {
294
                NProgress.done();
295
            });
935 geraldo 296
            return false;
297
        },
298
        invalidHandler: function(form, validator) {}
299
    });
300
    $('body').on('click', 'button.btn-add', function(e) {
301
        e.preventDefault();
302
        NProgress.start();
303
        $.ajax({
304
            'dataType': 'json',
305
            'accept': 'application/json',
306
            'method': 'get',
307
            'url': '$routeAdd',
308
        }).done(function(response) {
309
            if (response['success']) {
310
                $('span[id="form-title"]').html('LABEL_ADD');
311
                $('#form').attr('action', '$routeAdd');
312
                $('#form #name').val('');
313
                $('#form #status').bootstrapToggle('on');
314
                CKEDITOR.instances.functions.setData('');
315
                CKEDITOR.instances.objectives.setData('');
1196 geraldo 316
                subordinates_selected = [];
1192 geraldo 317
                competencies_selected = [];
1170 geraldo 318
                competencies = response['data']['competencies'];
319
                competencies_type = response['data']['competency_types'];
1196 geraldo 320
                subordinates = response['data']['jobs_description'];
1186 geraldo 321
                renderData([]);
1196 geraldo 322
                renderSubordinateData([]);
1170 geraldo 323
                setCompetencySelect();
1196 geraldo 324
                setSubordinateSelect();
935 geraldo 325
                validator.resetForm();
326
                $('#custom-tabs #custom-tabs-general-tab').tab('show');
327
                $('#modal').modal('show');
328
            } else {
329
                $.fn.showError(response['data']);
330
            }
331
        }).fail(function(jqXHR, textStatus, errorThrown) {
332
            $.fn.showError(textStatus);
333
        }).always(function() {
334
            NProgress.done();
66 efrain 335
        });
935 geraldo 336
    });
337
    $('body').on('click', 'button.btn-edit', function(e) {
338
        e.preventDefault();
339
        NProgress.start();
340
        var action = $(this).data('href');
341
        $.ajax({
342
            'dataType': 'json',
343
            'accept': 'application/json',
344
            'method': 'get',
345
            'url': action,
346
        }).done(function(response) {
347
            if (response['success']) {
348
                $('span[id="form-title"]').html('LABEL_EDIT');
349
                $('#form').attr('action', action);
350
                $('#form #name').val(response['data']['name']);
351
                $('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
352
                CKEDITOR.instances.functions.setData(response['data']['functions']);
353
                CKEDITOR.instances.objectives.setData(response['data']['objectives']);
354
                $('#tableCompetencies tbody').empty();
1186 geraldo 355
                competencies = response['data']['competencies'];
356
                competencies_type = response['data']['competency_types'];
357
                competencies_selected = response['data']['competencies_selected'];
1196 geraldo 358
                subordinates_selected = response['data']['subordinates_selected'];
359
                subordinates = response['data']['jobs_description'];
1186 geraldo 360
                renderData(competencies_selected);
1196 geraldo 361
                renderSubordinateData(subordinates_selected);
1186 geraldo 362
                setCompetencySelect();
1196 geraldo 363
                setSubordinateSelect();
935 geraldo 364
                $('#job_description_id_boss').val(response['data']['job_description_id_boss']);
365
                validator.resetForm();
366
                $('#custom-tabs #custom-tabs-general-tab').tab('show');
367
                $('#modal').modal('show');
368
            } else {
369
                $.fn.showError(response['data']);
370
            }
371
        }).fail(function(jqXHR, textStatus, errorThrown) {
372
            $.fn.showError(textStatus);
373
        }).always(function() {
374
            NProgress.done();
66 efrain 375
        });
935 geraldo 376
    });
377
    $('body').on('click', 'button.btn-refresh', function(e) {
378
        e.preventDefault();
379
        gridTable.api().ajax.reload(null, false);
380
    });
381
    $('body').on('click', 'button.btn-cancel', function(e) {
382
        e.preventDefault();
383
        $('#modal').modal('hide');
384
        $('#div-listing').show();
385
    });
386
    $('body').on('click', 'button.btn-import', function(e) {
387
        e.preventDefault();
388
        NProgress.start();
389
        $.ajax({
390
            'dataType': 'json',
391
            'method': 'post',
392
            'url': '$routeImport',
393
        }).done(function(response) {
394
            if (response['success']) {
395
                $.fn.showSuccess(response['data']);
396
                gridTable.api().ajax.reload(null, false);
397
            } else {
398
                $.fn.showError(response['data']);
399
            }
400
        }).fail(function(jqXHR, textStatus, errorThrown) {
401
            $.fn.showError(textStatus);
402
        }).always(function() {
403
            NProgress.done();
66 efrain 404
        });
935 geraldo 405
        return false;
66 efrain 406
    });
935 geraldo 407
    $('#form #status').bootstrapToggle({
408
        'on': 'LABEL_ACTIVE',
409
        'off': 'LABEL_INACTIVE',
410
        'width': '160px',
411
        'height': '40px'
412
    });
413
    CKEDITOR.replace('functions');
414
    CKEDITOR.replace('objectives');
1175 geraldo 415
    /**
1187 geraldo 416
     * Clicked select competency
1175 geraldo 417
     */
418
    $('body').on('click', 'button[id="btn-select-competency"]', function(e) {
419
        if ($("#select-competency").val() == "") {
420
            $.fn.showError('LABEL_ERROR_SELECT_COMPETENCY');
421
        } else {
1176 geraldo 422
            competencies_selected.push(competencies.filter((item) => item.competency_id == $("#select-competency").val() ? item : false)[0]);
1196 geraldo 423
            $("#select-subordinate").val('');
1175 geraldo 424
            renderData(competencies_selected);
1178 geraldo 425
            setCompetencySelect();
1175 geraldo 426
        }
427
    });
1187 geraldo 428
    /**
1196 geraldo 429
     * Clicked select subordinate
1187 geraldo 430
     */
1196 geraldo 431
    $('body').on('click', 'button[id="btn-select-subordinate"]', function(e) {
432
        if ($("#select-subordinate").val() == "") {
1187 geraldo 433
            $.fn.showError('LABEL_ERROR_SELECT_DEPENDENT');
434
        } else {
1196 geraldo 435
            subordinates_selected.push(subordinates.filter((item) => item.job_description_id == $("#select-subordinate").val() ? item : false)[0]);
436
            renderSubordinateData(subordinates_selected);
437
            setSubordinateSelect();
1187 geraldo 438
        }
439
    });
440
    /**
1196 geraldo 441
     * Clicked remove subordinate
1187 geraldo 442
     */
1196 geraldo 443
    $('body').on('click', 'button.btn-delete-subordinate', function(e) {
444
        var job_description_id = $(this).data('subordinate');
1187 geraldo 445
        bootbox.confirm({
446
            title: "LABEL_DELETE LABEL_DEPENDENT",
447
            message: "LABEL_QUESTION_DELETE",
448
            buttons: {
449
                cancel: {
450
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
451
                },
452
                confirm: {
453
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
454
                }
455
            },
456
            callback: function(result) {
457
                if (result) {
1199 geraldo 458
                    subordinates_selected = subordinates_selected.filter((item) => item.job_description_id != job_description_id);
459
                    renderSubordinateData(subordinates_selected);
460
                    return setSubordinateSelect();
1187 geraldo 461
                }
462
            }
463
        });
464
    });
1170 geraldo 465
    const setCompetencySelect = () => {
1177 geraldo 466
        $('#select-competency').children().remove();
467
        $('#select-competency').append($('<option>', {
468
            value: '',
469
            text: 'LABEL_SELECT'
470
        }));
1172 geraldo 471
        $.each(competencies, function(i, item) {
472
            if (!filterItemById(item.competency_id)) {
473
                var type = filterTypeById(item.competency_type_id);
474
                $('#select-competency').append($('<option>', {
475
                    value: item.competency_id,
1180 geraldo 476
                    text: type.name + ' - ' + item.name
1172 geraldo 477
                }));
478
            }
479
        });
1170 geraldo 480
    }
1196 geraldo 481
    const setSubordinateSelect = () => {
482
        $('#select-subordinate').children().remove();
483
        $('#select-subordinate').append($('<option>', {
1187 geraldo 484
            value: '',
485
            text: 'LABEL_SELECT'
486
        }));
1196 geraldo 487
        $.each(subordinates, function(i, item) {
1187 geraldo 488
            if (!filterDependedItemById(item.job_description_id)) {
1196 geraldo 489
                $('#select-subordinate').append($('<option>', {
1187 geraldo 490
                    value: item.job_description_id,
491
                    text: item.name
492
                }));
493
            }
494
        });
495
    }
1175 geraldo 496
    /**
497
     * Render Competencies data
498
     */
499
    const renderData = (data) => {
1199 geraldo 500
        data.length > 0 ?
501
            $("#competencies-job").html($("#sectionTemplate").render(data, {
502
                getType: filterTypeById
503
            })) :
504
            $("#competencies-job").html('');
1175 geraldo 505
    }
1176 geraldo 506
    /**
1187 geraldo 507
     * Render Competencies data
508
     */
1196 geraldo 509
    const renderSubordinateData = (data) => {
1199 geraldo 510
        data.length > 0 ?
511
            $("#subordinate").html($("#sectionJob").render(data)) :
512
            $("#subordinate").html('');
1187 geraldo 513
    }
514
    /**
1176 geraldo 515
     * Filter competencies selected
516
     */
1172 geraldo 517
    const filterItemById = (id) => competencies_selected.filter((item) => item.competency_id == id ? item : false)[0];
1199 geraldo 518
    /**
1187 geraldo 519
     * Filter depended selected
520
     */
1196 geraldo 521
    const filterDependedItemById = (id) => subordinates_selected.filter((item) => item.job_description_id == id ? item : false)[0];
1175 geraldo 522
    /**
523
     * Filter competencie type
524
     */
1172 geraldo 525
    const filterTypeById = (id) => competencies_type.filter((item) => item.competency_type_id == id ? item : false)[0];
1180 geraldo 526
    /**
527
     * Clicked remove competency
528
     */
529
    $('body').on('click', 'button.btn-delete-competency', function(e) {
530
        var id_competency = $(this).data('competency');
531
        bootbox.confirm({
532
            title: "LABEL_DELETE LABEL_COMPETENCY",
533
            message: "LABEL_QUESTION_DELETE",
534
            buttons: {
535
                cancel: {
536
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
537
                },
538
                confirm: {
539
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
540
                }
541
            },
542
            callback: function(result) {
543
                if (result) {
544
                    removeCompetency(id_competency);
545
                }
546
            }
547
        });
548
    });
549
    /**
550
     * Clicked on edit behavior
551
     */
552
    $('body').on('click', 'button.btn-edit-behavior', function(e) {
553
        e.preventDefault();
554
        var competency_id = $(this).data('competency');
555
        var behavior_id = $(this).data('behavior');
1181 geraldo 556
        competencies_selected.map((item) => {
1180 geraldo 557
            if (item.competency_id == competency_id) {
558
                item.behaviors.map((b) => {
559
                    if (b.behavior_id == behavior_id) {
1183 geraldo 560
                        $('#form-behavior #behavior-id').val(b.behavior_id);
561
                        $('#form-behavior #behavior-competency').val(b.competency_id);
562
                        $('#form-behavior #behavior-level').val(b.level);
1180 geraldo 563
                        $('#modal-behavior h4[class="modal-title"]').html('LABEL_EDIT LABEL_CONDUCT');
564
                        $('#modal-behavior').modal('show');
565
                        return;
566
                    }
567
                });
568
            }
569
        });
570
    });
571
    /**
572
     * Remove Competency
573
     */
574
    const removeCompetency = (competency_id) => {
575
        competencies_selected = competencies_selected.filter((item) => item.competency_id != competency_id);
576
        return renderData(competencies_selected);
577
    }
578
    /**
579
     * Edit item Behavior
580
     */
581
    const editBehavior = (competency_id, behavior_id, level) => {
582
        competencies_selected.map((item) => {
583
            if (item.competency_id == competency_id) {
584
                item.behaviors.map((opt) => {
585
                    if (opt.behavior_id == behavior_id) {
586
                        opt.level = level
587
                    }
588
                });
589
            }
590
        });
591
        return renderData(competencies_selected);
592
    }
593
    /**
594
     * Clicked cancel new/edit Form
595
     */
596
    $('button.btn-behavior-submit').click(function(e) {
597
        if ($("#behavior-description").val() == "") {
598
            $.fn.showError('ERROR_ENTER_DESCRIPTION');
599
            return;
600
        } else {
1199 geraldo 601
            editBehavior($("#behavior-competency").val(), $("#behavior-id").val(), $("#behavior-level").val())
1180 geraldo 602
            $('#modal-behavior').modal('hide');
603
            return;
604
        }
605
    });
935 geraldo 606
});
1170 geraldo 607
 
66 efrain 608
JS;
609
$this->inlineScript()->captureEnd();
610
?>
611
<!-- Content Header (Page header) -->
612
<section class="content-header">
1170 geraldo 613
   <div class="container-fluid">
614
      <div class="row mb-2">
615
         <div class="col-sm-12">
616
            <h1>LABEL_JOBS_DESCRIPTION</h1>
617
         </div>
618
      </div>
619
   </div>
620
   <!-- /.container-fluid -->
66 efrain 621
</section>
622
<section class="content">
1170 geraldo 623
   <div class="container-fluid">
624
      <div class="row">
625
         <div class="col-12">
626
            <div class="card">
627
               <div class="card-body">
628
                  <table id="gridTable" class="table   table-hover">
629
                     <thead>
630
                        <tr>
631
                           <th>LABEL_NAME</th>
632
                           <th>LABEL_ACTIVE</th>
633
                           <th>LABEL_ACTIONS</th>
634
                        </tr>
635
                     </thead>
636
                     <tbody>
637
                     </tbody>
638
                  </table>
639
               </div>
640
               <div class="card-footer clearfix">
641
                  <div style="float:right;">
642
                     <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH  </button>
643
                     <?php if($allowAdd) : ?>
644
                     <?php if($allowImport) : ?>
645
                     <button type="button" class="btn btn-primary btn-import"><i class="fa fa-upload"></i> LABEL_IMPORT </button>
646
                     <?php endif; ?>
647
                     <button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
648
                     <?php endif; ?>
649
                  </div>
650
               </div>
651
            </div>
652
         </div>
653
      </div>
654
   </div>
655
</section>
66 efrain 656
<!-- The Modal -->
657
<div class="modal" id="modal">
1194 geraldo 658
<div class="modal-dialog  modal-xl">
659
   <div class="modal-content">
660
      <!-- Modal Header -->
661
      <div class="modal-header">
662
         <h4 class="modal-title">LABEL_JOB_DESCRIPTION - <span id="form-title"></span></h4>
663
         <button type="button" class="close" data-dismiss="modal">&times;</button>
664
      </div>
665
      <!-- Modal body -->
666
      <div class="modal-body">
667
         <div class="card card-primary card-outline card-tabs">
668
            <div class="card-header p-0 pt-1 border-bottom-0">
669
               <ul class="nav nav-tabs" id="custom-tabs" role="tablist">
670
                  <li class="nav-item">
671
                     <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>
672
                  </li>
673
                  <li class="nav-item">
674
                     <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>
675
                  </li>
676
                  <li class="nav-item">
1196 geraldo 677
                     <a class="nav-link" id="custom-tabs-subordinate-tab" data-toggle="pill" href="#custom-tabs-subordinate" role="tab" aria-controls="custom-tabs-subordinate" aria-selected="false">LABEL_SUBORDINATES</a>
1194 geraldo 678
                  </li>
679
               </ul>
680
            </div>
681
            <div class="card-body">
682
               <?php
683
                  $form = $this->form;
684
                  $form->setAttributes([
685
                      'method'    => 'post',
686
                      'name'      => 'form',
687
                      'id'        => 'form'
688
                  ]);
689
 
690
                  $form->prepare();
691
                  echo $this->form()->openTag($form);
692
                  ?>
1196 geraldo 693
               <input type="hidden" id="subordinates_selected" name="subordinates_selected" value="">
1194 geraldo 694
               <input type="hidden" id="competencies_selected" name="competencies_selected" value="">
695
               <div class="tab-content" id="custom-tabs-three-tabContent">
696
                  <div class="tab-pane fade show active" id="custom-tabs-general" role="tabpanel" aria-labelledby="custom-tabs-general-tab">
697
                     <div class="row">
698
                        <div class="col-md col-sm-12 col-12">
699
                           <div class="form-group m-0">
700
                              <?php
701
                                 $element = $form->get('name');
702
                                 $element->setOptions(['label' => 'LABEL_NAME']);
703
                                 $element->setAttributes(['class' => 'form-control']);
704
 
705
                                 echo $this->formLabel($element);
706
                                 echo $this->formText($element);
707
                                 ?>
1170 geraldo 708
                           </div>
1194 geraldo 709
                        </div>
710
                        <div class="col-md col-sm-12 col-12">
711
                           <div class="form-group m-0">
712
                              <?php
713
                                 $element = $form->get('job_description_id_boss');
714
                                 $element->setOptions(['label' => 'LABEL_BOSS']);
715
                                 $element->setAttributes(['class' => 'form-control']);
716
 
717
                                 echo $this->formLabel($element);
718
                                 echo $this->formSelect($element);
719
                                 ?>
1170 geraldo 720
                           </div>
1194 geraldo 721
                        </div>
722
                        <div
723
                           class="col-md col-sm-12 col-12 d-flex align-items-center justify-content-center"
724
                           >
725
                           <div class="form-group m-0">
726
                              <label>LABEL_STATUS</label>
727
                              <br />
728
                              <?php
729
                                 $element = $form->get('status');
730
                                 $element->setOptions(['label' => 'LABEL_STATUS']);
731
                                 // echo $this->formLabel($element);
732
                                 echo $this->formCheckbox($element);
733
                                 ?>
1170 geraldo 734
                           </div>
735
                        </div>
1194 geraldo 736
                     </div>
737
                     <div class="form-group">
738
                        <?php
739
                           $element = $form->get('objectives');
740
                           $element->setOptions(['label' => 'LABEL_OBJECTIVES']);
741
                           $element->setAttributes(['class' => 'form-control']);
742
 
743
                           echo $this->formLabel($element);
744
                           echo $this->formTextArea($element);
745
                           ?>
746
                     </div>
747
                     <div class="form-group">
748
                        <?php
749
                           $element = $form->get('functions');
750
                           $element->setOptions(['label' => 'LABEL_FUNCTIONS']);
751
                           $element->setAttributes(['class' => 'form-control']);
752
 
753
                           echo $this->formLabel($element);
754
                           echo $this->formTextArea($element);
755
                           ?>
756
                     </div>
757
                  </div>
758
                  <div class="tab-pane fade" id="custom-tabs-compentencies" role="tabpanel" aria-labelledby="custom-tabs-compentencies-tab">
759
                     <div class="row">
760
                        <div class="col-md-8 col-sm-8 col-xs-12">
1195 geraldo 761
                           <select id="select-competency" class="form-control"> </select>
1170 geraldo 762
                        </div>
1194 geraldo 763
                        <div class="col-md-4 col-sm-4 col-xs-12">
764
                           <button type="button" class="btn btn-primary" id="btn-select-competency" data-toggle="tooltip" title="LABEL_ADD LABEL_COMPETENCY">LABEL_ADD LABEL_COMPETENCY</button>
1170 geraldo 765
                        </div>
766
                     </div>
1194 geraldo 767
                     <div class="row" >
768
                        <br>
769
                        <div class="col-md-12 col-sm-12 col-xs-12" id="competencies-job" style="margin-top: 10px;">
1170 geraldo 770
                        </div>
1187 geraldo 771
                     </div>
1194 geraldo 772
                  </div>
1196 geraldo 773
                  <div class="tab-pane fade" id="custom-tabs-subordinate" role="tabpanel" aria-labelledby="custom-tabs-subordinate-tab">
1194 geraldo 774
                     <div class="row">
775
                        <div class="col-md-8 col-sm-8 col-xs-12">
1196 geraldo 776
                           <select id="select-subordinate" class="form-control"></select>
1170 geraldo 777
                        </div>
1194 geraldo 778
                        <div class="col-md-4 col-sm-4 col-xs-12">
1196 geraldo 779
                           <button type="button" class="btn btn-primary" id="btn-select-subordinate" data-toggle="tooltip" title="LABEL_ADD ">LABEL_ADD </button>
1187 geraldo 780
                        </div>
1170 geraldo 781
                     </div>
1194 geraldo 782
                     <div class="row" >
783
                        <div class="col-md-12 col-sm-12 col-xs-12"  style="margin-top: 10px;">
784
                           <table class="table table-bordered">
785
                              <thead>
786
                                 <tr>
787
                                    <th style="width: 60%;">LABEL_NAME</th>
788
                                    <th style="width: 20%;">LABEL_ACTIONS</th>
789
                                 </tr>
790
                              </thead>
1196 geraldo 791
                              <tbody id="subordinate"></tbody>
1194 geraldo 792
                           </table>
793
                        </div>
794
                     </div>
1170 geraldo 795
                  </div>
796
               </div>
797
            </div>
798
         </div>
1194 geraldo 799
         <?php echo $this->form()->closeTag($form); ?>
800
         <!-- /.card -->
801
      </div>
1187 geraldo 802
      <!-- Modal footer -->
803
      <div class="modal-footer">
804
         <button type="submit" form="form" class="btn btn-primary">LABEL_SAVE</button>
805
         <button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
806
      </div>
1170 geraldo 807
   </div>
1187 geraldo 808
</div>
1180 geraldo 809
<!--start modal behavior-->
810
<div  id="modal-behavior" class="modal" tabindex="-1" role="dialog">
811
   <div class="modal-dialog modal-lg" role="document">
812
      <form action="#" name="form-behavior" id="form-behavior">
813
         <input type="hidden" name="behavior-id" id="behavior-id" value="" />
814
         <input type="hidden" name="behavior-competency" id="behavior-competency" value="" />
815
         <div class="modal-content">
816
            <div class="modal-header">
1185 geraldo 817
               <h4 class="modal-title">LABEL_EDIT LABEL_LEVEL</h4>
1180 geraldo 818
               <button type="button" class="close" data-dismiss="modal" aria-label="Close">
819
               <span aria-hidden="true">&times;</span>
820
               </button>
821
            </div>
822
            <div class="modal-body">
823
               <div class="form-group">
824
                  <label for="behavior-value">LABEL_LEVEL</label>
825
                  <select class="form-control" id="behavior-level" name="behavior-level">
826
                     <option value="0">LABEL_NA</option>
827
                     <option value="1">LABEL_LEVEL_ONE</option>
828
                     <option value="2">LABEL_LEVEL_TWO</option>
829
                     <option value="3">LABEL_LEVEL_THREE</option>
830
                     <option value="4">LABEL_LEVEL_FOUR</option>
831
                  </select>
832
               </div>
833
            </div>
834
            <div class="modal-footer">
835
               <button type="button" class="btn btn-primary btn-behavior-submit">LABEL_SAVE</button>
836
               <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
837
            </div>
838
         </div>
839
      </form>
840
   </div>
841
</div>
842
<!---end modal behavior --->
843
 
1175 geraldo 844
 <!---Template Competencies --->
845
 <script id="sectionTemplate" type="text/x-jsrender">
846
   <div class="panel panel-default" id="panel-{{:competency_id}}">
847
   <div class="panel-heading">
1184 geraldo 848
      <h4 class="panel-title" style="    font-size: 18px;">
1175 geraldo 849
         <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:competency_id}}" href="#collapse-{{:competency_id}}">
850
         <span class="section-name{{:competency_id}}">
1178 geraldo 851
         {{:~getType(competency_type_id).name}} - {{:name}}
1175 geraldo 852
         </span>
853
         </a>
854
      </h4>
855
   </div>
856
   <div id="collapse-{{:competency_id}}" class="panel-collapse in collapse show">
857
      <div class="panel-body">
858
         <div class="table-responsive">
859
            <table class="table table-bordered">
860
               <thead>
861
                  <tr>
1181 geraldo 862
                     <th style="width: 20%;">LABEL_ELEMENT</th>
863
                     <th style="width: 50%;">LABEL_TITLE</th>
1175 geraldo 864
                     <th style="width: 10%;">LABEL_LEVEL</th>
1181 geraldo 865
                     <th style="width: 20%;">LABEL_ACTIONS</th>
1175 geraldo 866
                  </tr>
867
               </thead>
868
               <tbody>
869
                  <tr class="tr-section">
870
                     <td class="text-left">LABEL_COMPETENCY</td>
1177 geraldo 871
                     <td class="text-left">{{:name}}</td>
1175 geraldo 872
                     <td>
873
                        {{if type == 'simple'}} Simple {{/if}}
874
                        {{if type == 'multiple'}} Multiple {{/if}}
875
                     </td>
876
                     <td>
877
 
1180 geraldo 878
                        <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 879
 
880
                     </td>
881
                  </tr>
1177 geraldo 882
                  {{for behaviors}}
1175 geraldo 883
                  <tr >
884
                     <td class="text-left">--LABEL_CONDUCT</td>
885
                     <td class="text-left">
886
                        {{:description}}
887
                     </td>
888
                     <td>
1180 geraldo 889
          {{if level == '0'}} LABEL_NA {{/if}}
890
          {{if level == '1' }} LABEL_LEVEL_ONE {{/if}}
891
          {{if level == '2' }} LABEL_LEVEL_TWO {{/if}}
892
          {{if level == '3' }} LABEL_LEVEL_THREE {{/if}}
893
          {{if level == '4' }} LABEL_LEVEL_FOUR {{/if}}
894
       </td>
1175 geraldo 895
                     <td>
1180 geraldo 896
                        <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 897
 
898
                     </td>
899
                  </tr>
900
                  {{/for}}
901
               </tbody>
902
            </table>
903
         </div>
904
      </div>
905
   </div>
906
</div>
907
   </script>
1187 geraldo 908
 
909
 
910
   <script id="sectionJob" type="text/x-jsrender">
911
   <tr>
912
       <td class="text-left">{{:name}}</td>
913
       <td>
914
 
1196 geraldo 915
           <button class="btn btn-default btn-delete-subordinate" data-subordinate="{{:job_description_id}}" data-toggle="tooltip"  data-original-title="LABEL_DELETE"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE</button>
1187 geraldo 916
       </td>
917
   </tr>
918
    </script>
919
 
1175 geraldo 920
   <!-- End Template Competencies-->
1169 geraldo 921
 
66 efrain 922
 
923
 
924
 
925
 
926
 
927
 
928
 
929