Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 1196 | Rev 1213 | 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) {
1176 geraldo 419
        console.log('ee')
1175 geraldo 420
        if ($("#select-competency").val() == "") {
421
            $.fn.showError('LABEL_ERROR_SELECT_COMPETENCY');
422
        } else {
1176 geraldo 423
            competencies_selected.push(competencies.filter((item) => item.competency_id == $("#select-competency").val() ? item : false)[0]);
1196 geraldo 424
            $("#select-subordinate").val('');
1175 geraldo 425
            renderData(competencies_selected);
1178 geraldo 426
            setCompetencySelect();
1175 geraldo 427
        }
428
    });
1187 geraldo 429
    /**
1196 geraldo 430
     * Clicked select subordinate
1187 geraldo 431
     */
1196 geraldo 432
    $('body').on('click', 'button[id="btn-select-subordinate"]', function(e) {
1187 geraldo 433
        console.log('ee')
1196 geraldo 434
        if ($("#select-subordinate").val() == "") {
1187 geraldo 435
            $.fn.showError('LABEL_ERROR_SELECT_DEPENDENT');
436
        } else {
1196 geraldo 437
            subordinates_selected.push(subordinates.filter((item) => item.job_description_id == $("#select-subordinate").val() ? item : false)[0]);
438
            renderSubordinateData(subordinates_selected);
439
            setSubordinateSelect();
1187 geraldo 440
        }
441
    });
442
    /**
1196 geraldo 443
     * Clicked remove subordinate
1187 geraldo 444
     */
1196 geraldo 445
    $('body').on('click', 'button.btn-delete-subordinate', function(e) {
446
        var job_description_id = $(this).data('subordinate');
1187 geraldo 447
        bootbox.confirm({
448
            title: "LABEL_DELETE LABEL_DEPENDENT",
449
            message: "LABEL_QUESTION_DELETE",
450
            buttons: {
451
                cancel: {
452
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
453
                },
454
                confirm: {
455
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
456
                }
457
            },
458
            callback: function(result) {
459
                if (result) {
1199 geraldo 460
                    subordinates_selected = subordinates_selected.filter((item) => item.job_description_id != job_description_id);
461
                    renderSubordinateData(subordinates_selected);
462
                    return setSubordinateSelect();
1187 geraldo 463
                }
464
            }
465
        });
466
    });
1170 geraldo 467
    const setCompetencySelect = () => {
1177 geraldo 468
        $('#select-competency').children().remove();
469
        $('#select-competency').append($('<option>', {
470
            value: '',
471
            text: 'LABEL_SELECT'
472
        }));
1172 geraldo 473
        $.each(competencies, function(i, item) {
474
            if (!filterItemById(item.competency_id)) {
475
                var type = filterTypeById(item.competency_type_id);
476
                $('#select-competency').append($('<option>', {
477
                    value: item.competency_id,
1180 geraldo 478
                    text: type.name + ' - ' + item.name
1172 geraldo 479
                }));
480
            }
481
        });
1170 geraldo 482
    }
1196 geraldo 483
    const setSubordinateSelect = () => {
484
        $('#select-subordinate').children().remove();
485
        $('#select-subordinate').append($('<option>', {
1187 geraldo 486
            value: '',
487
            text: 'LABEL_SELECT'
488
        }));
1196 geraldo 489
        $.each(subordinates, function(i, item) {
1187 geraldo 490
            if (!filterDependedItemById(item.job_description_id)) {
1196 geraldo 491
                $('#select-subordinate').append($('<option>', {
1187 geraldo 492
                    value: item.job_description_id,
493
                    text: item.name
494
                }));
495
            }
496
        });
497
    }
1175 geraldo 498
    /**
499
     * Render Competencies data
500
     */
501
    const renderData = (data) => {
1199 geraldo 502
        data.length > 0 ?
503
            $("#competencies-job").html($("#sectionTemplate").render(data, {
504
                getType: filterTypeById
505
            })) :
506
            $("#competencies-job").html('');
1175 geraldo 507
    }
1176 geraldo 508
    /**
1187 geraldo 509
     * Render Competencies data
510
     */
1196 geraldo 511
    const renderSubordinateData = (data) => {
1199 geraldo 512
        data.length > 0 ?
513
            $("#subordinate").html($("#sectionJob").render(data)) :
514
            $("#subordinate").html('');
1187 geraldo 515
    }
516
    /**
1176 geraldo 517
     * Filter competencies selected
518
     */
1172 geraldo 519
    const filterItemById = (id) => competencies_selected.filter((item) => item.competency_id == id ? item : false)[0];
1199 geraldo 520
    /**
1187 geraldo 521
     * Filter depended selected
522
     */
1196 geraldo 523
    const filterDependedItemById = (id) => subordinates_selected.filter((item) => item.job_description_id == id ? item : false)[0];
1175 geraldo 524
    /**
525
     * Filter competencie type
526
     */
1172 geraldo 527
    const filterTypeById = (id) => competencies_type.filter((item) => item.competency_type_id == id ? item : false)[0];
1180 geraldo 528
    /**
529
     * Clicked remove competency
530
     */
531
    $('body').on('click', 'button.btn-delete-competency', function(e) {
532
        var id_competency = $(this).data('competency');
533
        bootbox.confirm({
534
            title: "LABEL_DELETE LABEL_COMPETENCY",
535
            message: "LABEL_QUESTION_DELETE",
536
            buttons: {
537
                cancel: {
538
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
539
                },
540
                confirm: {
541
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
542
                }
543
            },
544
            callback: function(result) {
545
                if (result) {
546
                    removeCompetency(id_competency);
547
                }
548
            }
549
        });
550
    });
551
    /**
552
     * Clicked on edit behavior
553
     */
554
    $('body').on('click', 'button.btn-edit-behavior', function(e) {
555
        e.preventDefault();
556
        var competency_id = $(this).data('competency');
557
        var behavior_id = $(this).data('behavior');
1181 geraldo 558
        competencies_selected.map((item) => {
1180 geraldo 559
            if (item.competency_id == competency_id) {
560
                item.behaviors.map((b) => {
561
                    if (b.behavior_id == behavior_id) {
1183 geraldo 562
                        $('#form-behavior #behavior-id').val(b.behavior_id);
563
                        $('#form-behavior #behavior-competency').val(b.competency_id);
564
                        $('#form-behavior #behavior-level').val(b.level);
1180 geraldo 565
                        $('#modal-behavior h4[class="modal-title"]').html('LABEL_EDIT LABEL_CONDUCT');
566
                        $('#modal-behavior').modal('show');
567
                        return;
568
                    }
569
                });
570
            }
571
        });
572
    });
573
    /**
574
     * Remove Competency
575
     */
576
    const removeCompetency = (competency_id) => {
577
        competencies_selected = competencies_selected.filter((item) => item.competency_id != competency_id);
578
        return renderData(competencies_selected);
579
    }
580
    /**
581
     * Edit item Behavior
582
     */
583
    const editBehavior = (competency_id, behavior_id, level) => {
584
        competencies_selected.map((item) => {
585
            if (item.competency_id == competency_id) {
586
                item.behaviors.map((opt) => {
587
                    if (opt.behavior_id == behavior_id) {
588
                        opt.level = level
589
                    }
590
                });
591
            }
592
        });
593
        return renderData(competencies_selected);
594
    }
595
    /**
596
     * Clicked cancel new/edit Form
597
     */
598
    $('button.btn-behavior-submit').click(function(e) {
599
        if ($("#behavior-description").val() == "") {
600
            $.fn.showError('ERROR_ENTER_DESCRIPTION');
601
            return;
602
        } else {
1199 geraldo 603
            editBehavior($("#behavior-competency").val(), $("#behavior-id").val(), $("#behavior-level").val())
1180 geraldo 604
            $('#modal-behavior').modal('hide');
605
            return;
606
        }
607
    });
935 geraldo 608
});
1170 geraldo 609
 
66 efrain 610
JS;
611
$this->inlineScript()->captureEnd();
612
?>
613
<!-- Content Header (Page header) -->
614
<section class="content-header">
1170 geraldo 615
   <div class="container-fluid">
616
      <div class="row mb-2">
617
         <div class="col-sm-12">
618
            <h1>LABEL_JOBS_DESCRIPTION</h1>
619
         </div>
620
      </div>
621
   </div>
622
   <!-- /.container-fluid -->
66 efrain 623
</section>
624
<section class="content">
1170 geraldo 625
   <div class="container-fluid">
626
      <div class="row">
627
         <div class="col-12">
628
            <div class="card">
629
               <div class="card-body">
630
                  <table id="gridTable" class="table   table-hover">
631
                     <thead>
632
                        <tr>
633
                           <th>LABEL_NAME</th>
634
                           <th>LABEL_ACTIVE</th>
635
                           <th>LABEL_ACTIONS</th>
636
                        </tr>
637
                     </thead>
638
                     <tbody>
639
                     </tbody>
640
                  </table>
641
               </div>
642
               <div class="card-footer clearfix">
643
                  <div style="float:right;">
644
                     <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH  </button>
645
                     <?php if($allowAdd) : ?>
646
                     <?php if($allowImport) : ?>
647
                     <button type="button" class="btn btn-primary btn-import"><i class="fa fa-upload"></i> LABEL_IMPORT </button>
648
                     <?php endif; ?>
649
                     <button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
650
                     <?php endif; ?>
651
                  </div>
652
               </div>
653
            </div>
654
         </div>
655
      </div>
656
   </div>
657
</section>
66 efrain 658
<!-- The Modal -->
659
<div class="modal" id="modal">
1194 geraldo 660
<div class="modal-dialog  modal-xl">
661
   <div class="modal-content">
662
      <!-- Modal Header -->
663
      <div class="modal-header">
664
         <h4 class="modal-title">LABEL_JOB_DESCRIPTION - <span id="form-title"></span></h4>
665
         <button type="button" class="close" data-dismiss="modal">&times;</button>
666
      </div>
667
      <!-- Modal body -->
668
      <div class="modal-body">
669
         <div class="card card-primary card-outline card-tabs">
670
            <div class="card-header p-0 pt-1 border-bottom-0">
671
               <ul class="nav nav-tabs" id="custom-tabs" role="tablist">
672
                  <li class="nav-item">
673
                     <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>
674
                  </li>
675
                  <li class="nav-item">
676
                     <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>
677
                  </li>
678
                  <li class="nav-item">
1196 geraldo 679
                     <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 680
                  </li>
681
               </ul>
682
            </div>
683
            <div class="card-body">
684
               <?php
685
                  $form = $this->form;
686
                  $form->setAttributes([
687
                      'method'    => 'post',
688
                      'name'      => 'form',
689
                      'id'        => 'form'
690
                  ]);
691
 
692
                  $form->prepare();
693
                  echo $this->form()->openTag($form);
694
                  ?>
1196 geraldo 695
               <input type="hidden" id="subordinates_selected" name="subordinates_selected" value="">
1194 geraldo 696
               <input type="hidden" id="competencies_selected" name="competencies_selected" value="">
697
               <div class="tab-content" id="custom-tabs-three-tabContent">
698
                  <div class="tab-pane fade show active" id="custom-tabs-general" role="tabpanel" aria-labelledby="custom-tabs-general-tab">
699
                     <div class="row">
700
                        <div class="col-md col-sm-12 col-12">
701
                           <div class="form-group m-0">
702
                              <?php
703
                                 $element = $form->get('name');
704
                                 $element->setOptions(['label' => 'LABEL_NAME']);
705
                                 $element->setAttributes(['class' => 'form-control']);
706
 
707
                                 echo $this->formLabel($element);
708
                                 echo $this->formText($element);
709
                                 ?>
1170 geraldo 710
                           </div>
1194 geraldo 711
                        </div>
712
                        <div class="col-md col-sm-12 col-12">
713
                           <div class="form-group m-0">
714
                              <?php
715
                                 $element = $form->get('job_description_id_boss');
716
                                 $element->setOptions(['label' => 'LABEL_BOSS']);
717
                                 $element->setAttributes(['class' => 'form-control']);
718
 
719
                                 echo $this->formLabel($element);
720
                                 echo $this->formSelect($element);
721
                                 ?>
1170 geraldo 722
                           </div>
1194 geraldo 723
                        </div>
724
                        <div
725
                           class="col-md col-sm-12 col-12 d-flex align-items-center justify-content-center"
726
                           >
727
                           <div class="form-group m-0">
728
                              <label>LABEL_STATUS</label>
729
                              <br />
730
                              <?php
731
                                 $element = $form->get('status');
732
                                 $element->setOptions(['label' => 'LABEL_STATUS']);
733
                                 // echo $this->formLabel($element);
734
                                 echo $this->formCheckbox($element);
735
                                 ?>
1170 geraldo 736
                           </div>
737
                        </div>
1194 geraldo 738
                     </div>
739
                     <div class="form-group">
740
                        <?php
741
                           $element = $form->get('objectives');
742
                           $element->setOptions(['label' => 'LABEL_OBJECTIVES']);
743
                           $element->setAttributes(['class' => 'form-control']);
744
 
745
                           echo $this->formLabel($element);
746
                           echo $this->formTextArea($element);
747
                           ?>
748
                     </div>
749
                     <div class="form-group">
750
                        <?php
751
                           $element = $form->get('functions');
752
                           $element->setOptions(['label' => 'LABEL_FUNCTIONS']);
753
                           $element->setAttributes(['class' => 'form-control']);
754
 
755
                           echo $this->formLabel($element);
756
                           echo $this->formTextArea($element);
757
                           ?>
758
                     </div>
759
                  </div>
760
                  <div class="tab-pane fade" id="custom-tabs-compentencies" role="tabpanel" aria-labelledby="custom-tabs-compentencies-tab">
761
                     <div class="row">
762
                        <div class="col-md-8 col-sm-8 col-xs-12">
1195 geraldo 763
                           <select id="select-competency" class="form-control"> </select>
1170 geraldo 764
                        </div>
1194 geraldo 765
                        <div class="col-md-4 col-sm-4 col-xs-12">
766
                           <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 767
                        </div>
768
                     </div>
1194 geraldo 769
                     <div class="row" >
770
                        <br>
771
                        <div class="col-md-12 col-sm-12 col-xs-12" id="competencies-job" style="margin-top: 10px;">
1170 geraldo 772
                        </div>
1187 geraldo 773
                     </div>
1194 geraldo 774
                  </div>
1196 geraldo 775
                  <div class="tab-pane fade" id="custom-tabs-subordinate" role="tabpanel" aria-labelledby="custom-tabs-subordinate-tab">
1194 geraldo 776
                     <div class="row">
777
                        <div class="col-md-8 col-sm-8 col-xs-12">
1196 geraldo 778
                           <select id="select-subordinate" class="form-control"></select>
1170 geraldo 779
                        </div>
1194 geraldo 780
                        <div class="col-md-4 col-sm-4 col-xs-12">
1196 geraldo 781
                           <button type="button" class="btn btn-primary" id="btn-select-subordinate" data-toggle="tooltip" title="LABEL_ADD ">LABEL_ADD </button>
1187 geraldo 782
                        </div>
1170 geraldo 783
                     </div>
1194 geraldo 784
                     <div class="row" >
785
                        <div class="col-md-12 col-sm-12 col-xs-12"  style="margin-top: 10px;">
786
                           <table class="table table-bordered">
787
                              <thead>
788
                                 <tr>
789
                                    <th style="width: 60%;">LABEL_NAME</th>
790
                                    <th style="width: 20%;">LABEL_ACTIONS</th>
791
                                 </tr>
792
                              </thead>
1196 geraldo 793
                              <tbody id="subordinate"></tbody>
1194 geraldo 794
                           </table>
795
                        </div>
796
                     </div>
1170 geraldo 797
                  </div>
798
               </div>
799
            </div>
800
         </div>
1194 geraldo 801
         <?php echo $this->form()->closeTag($form); ?>
802
         <!-- /.card -->
803
      </div>
1187 geraldo 804
      <!-- Modal footer -->
805
      <div class="modal-footer">
806
         <button type="submit" form="form" class="btn btn-primary">LABEL_SAVE</button>
807
         <button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
808
      </div>
1170 geraldo 809
   </div>
1187 geraldo 810
</div>
1180 geraldo 811
<!--start modal behavior-->
812
<div  id="modal-behavior" class="modal" tabindex="-1" role="dialog">
813
   <div class="modal-dialog modal-lg" role="document">
814
      <form action="#" name="form-behavior" id="form-behavior">
815
         <input type="hidden" name="behavior-id" id="behavior-id" value="" />
816
         <input type="hidden" name="behavior-competency" id="behavior-competency" value="" />
817
         <div class="modal-content">
818
            <div class="modal-header">
1185 geraldo 819
               <h4 class="modal-title">LABEL_EDIT LABEL_LEVEL</h4>
1180 geraldo 820
               <button type="button" class="close" data-dismiss="modal" aria-label="Close">
821
               <span aria-hidden="true">&times;</span>
822
               </button>
823
            </div>
824
            <div class="modal-body">
825
               <div class="form-group">
826
                  <label for="behavior-value">LABEL_LEVEL</label>
827
                  <select class="form-control" id="behavior-level" name="behavior-level">
828
                     <option value="0">LABEL_NA</option>
829
                     <option value="1">LABEL_LEVEL_ONE</option>
830
                     <option value="2">LABEL_LEVEL_TWO</option>
831
                     <option value="3">LABEL_LEVEL_THREE</option>
832
                     <option value="4">LABEL_LEVEL_FOUR</option>
833
                  </select>
834
               </div>
835
            </div>
836
            <div class="modal-footer">
837
               <button type="button" class="btn btn-primary btn-behavior-submit">LABEL_SAVE</button>
838
               <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
839
            </div>
840
         </div>
841
      </form>
842
   </div>
843
</div>
844
<!---end modal behavior --->
845
 
1175 geraldo 846
 <!---Template Competencies --->
847
 <script id="sectionTemplate" type="text/x-jsrender">
848
   <div class="panel panel-default" id="panel-{{:competency_id}}">
849
   <div class="panel-heading">
1184 geraldo 850
      <h4 class="panel-title" style="    font-size: 18px;">
1175 geraldo 851
         <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:competency_id}}" href="#collapse-{{:competency_id}}">
852
         <span class="section-name{{:competency_id}}">
1178 geraldo 853
         {{:~getType(competency_type_id).name}} - {{:name}}
1175 geraldo 854
         </span>
855
         </a>
856
      </h4>
857
   </div>
858
   <div id="collapse-{{:competency_id}}" class="panel-collapse in collapse show">
859
      <div class="panel-body">
860
         <div class="table-responsive">
861
            <table class="table table-bordered">
862
               <thead>
863
                  <tr>
1181 geraldo 864
                     <th style="width: 20%;">LABEL_ELEMENT</th>
865
                     <th style="width: 50%;">LABEL_TITLE</th>
1175 geraldo 866
                     <th style="width: 10%;">LABEL_LEVEL</th>
1181 geraldo 867
                     <th style="width: 20%;">LABEL_ACTIONS</th>
1175 geraldo 868
                  </tr>
869
               </thead>
870
               <tbody>
871
                  <tr class="tr-section">
872
                     <td class="text-left">LABEL_COMPETENCY</td>
1177 geraldo 873
                     <td class="text-left">{{:name}}</td>
1175 geraldo 874
                     <td>
875
                        {{if type == 'simple'}} Simple {{/if}}
876
                        {{if type == 'multiple'}} Multiple {{/if}}
877
                     </td>
878
                     <td>
879
 
1180 geraldo 880
                        <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 881
 
882
                     </td>
883
                  </tr>
1177 geraldo 884
                  {{for behaviors}}
1175 geraldo 885
                  <tr >
886
                     <td class="text-left">--LABEL_CONDUCT</td>
887
                     <td class="text-left">
888
                        {{:description}}
889
                     </td>
890
                     <td>
1180 geraldo 891
          {{if level == '0'}} LABEL_NA {{/if}}
892
          {{if level == '1' }} LABEL_LEVEL_ONE {{/if}}
893
          {{if level == '2' }} LABEL_LEVEL_TWO {{/if}}
894
          {{if level == '3' }} LABEL_LEVEL_THREE {{/if}}
895
          {{if level == '4' }} LABEL_LEVEL_FOUR {{/if}}
896
       </td>
1175 geraldo 897
                     <td>
1180 geraldo 898
                        <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 899
 
900
                     </td>
901
                  </tr>
902
                  {{/for}}
903
               </tbody>
904
            </table>
905
         </div>
906
      </div>
907
   </div>
908
</div>
909
   </script>
1187 geraldo 910
 
911
 
912
   <script id="sectionJob" type="text/x-jsrender">
913
   <tr>
914
       <td class="text-left">{{:name}}</td>
915
       <td>
916
 
1196 geraldo 917
           <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 918
       </td>
919
   </tr>
920
    </script>
921
 
1175 geraldo 922
   <!-- End Template Competencies-->
1169 geraldo 923
 
66 efrain 924
 
925
 
926
 
927
 
928
 
929
 
930
 
931