Proyectos de Subversion LeadersLinked - Backend

Rev

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