Proyectos de Subversion LeadersLinked - Backend

Rev

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