Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 3109 | Rev 3928 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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