Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 14181 | Rev 14184 | 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;
667
$this->inlineScript()->captureEnd();
14183 stevensc 668
// $this->headLink()->appendStylesheet('/react-bundles/job_description/main.css');
669
$this->inlineScript()->appendFile('/react-bundles/job_description/jobDescription.js');
66 efrain 670
?>
14181 stevensc 671
<div id="react-job_description">
672
</div>
1231 geraldo 673
<section class="content" id="row-lists">
674
 
3788 stevensc 675
    <!-- Content Header (Page header) -->
676
    <div class="content-header">
677
        <div class="container-fluid">
678
            <div class="row mb-2">
679
                <div class="col-sm-12">
680
                    <h1>LABEL_JOBS_DESCRIPTION</h1>
681
                </div>
1170 geraldo 682
            </div>
3788 stevensc 683
        </div>
684
        <!-- /.container-fluid -->
685
    </div>
686
    <div class="container-fluid">
687
        <div class="row">
688
            <div class="col-12">
689
                <div class="card">
690
                    <div class="card-body">
691
                        <table id="gridTable" class="table   table-hover">
692
                            <thead>
693
                                <tr>
694
                                    <th>LABEL_NAME</th>
695
                                    <th>LABEL_ACTIVE</th>
696
                                    <th>LABEL_ACTIONS</th>
697
                                </tr>
698
                            </thead>
699
                            <tbody>
700
                            </tbody>
701
                        </table>
702
                    </div>
703
                    <div class="card-footer clearfix">
704
                        <div style="float:right;">
705
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
706
                            <?php if ($allowAdd) : ?>
707
                                <?php if ($allowImport) : ?>
708
                                    <button type="button" class="btn btn-primary btn-import"><i class="fa fa-upload"></i> LABEL_IMPORT </button>
709
                                <?php endif; ?>
710
                                <button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
711
                            <?php endif; ?>
712
                        </div>
713
                    </div>
714
                </div>
715
            </div>
716
        </div>
717
    </div>
1170 geraldo 718
</section>
1231 geraldo 719
 
720
<section id="row-form" style="display:none">
3788 stevensc 721
    <div class="container">
722
        <!-- Modal Header -->
723
        <div class="modal-header">
724
            <h4 class="modal-title">LABEL_JOB_DESCRIPTION - <span id="form-title"></span></h4>
725
        </div>
726
        <!-- Modal body -->
727
        <div class="modal-body">
728
            <div class="card card-primary card-outline card-tabs">
729
                <div class="card-header p-0 pt-1 border-bottom-0">
730
                    <ul class="nav nav-tabs" id="custom-tabs" role="tablist">
731
                        <li class="nav-item">
732
                            <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>
733
                        </li>
734
                        <li class="nav-item">
735
                            <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>
736
                        </li>
737
                        <li class="nav-item">
738
                            <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>
739
                        </li>
740
                    </ul>
741
                </div>
742
                <div class="card-body">
743
                    <?php
744
                    $form = $this->form;
745
                    $form->setAttributes([
746
                        'method'    => 'post',
747
                        'name'      => 'form',
748
                        'id'        => 'form'
749
                    ]);
750
 
751
                    $form->prepare();
752
                    echo $this->form()->openTag($form);
753
                    ?>
754
                    <input type="hidden" id="subordinates_selected" name="subordinates_selected" value="">
755
                    <input type="hidden" id="competencies_selected" name="competencies_selected" value="">
756
                    <div class="tab-content" id="custom-tabs-three-tabContent">
757
                        <div class="tab-pane fade show active" id="custom-tabs-general" role="tabpanel" aria-labelledby="custom-tabs-general-tab">
758
                            <div class="row">
759
                                <div class="col-md col-sm-12 col-12">
760
                                    <div class="form-group m-0">
761
                                        <?php
762
                                        $element = $form->get('name');
763
                                        $element->setOptions(['label' => 'LABEL_NAME']);
764
                                        $element->setAttributes(['class' => 'form-control']);
765
 
766
                                        echo $this->formLabel($element);
767
                                        echo $this->formText($element);
768
                                        ?>
769
                                    </div>
770
                                </div>
771
                                <div class="col-md col-sm-12 col-12">
772
                                    <div class="form-group m-0">
773
                                        <?php
774
                                        $element = $form->get('job_description_id_boss');
775
                                        $element->setOptions(['label' => 'LABEL_BOSS']);
776
                                        $element->setAttributes(['class' => 'form-control']);
777
 
778
                                        echo $this->formLabel($element);
779
                                        echo $this->formSelect($element);
780
                                        ?>
781
                                    </div>
782
                                </div>
783
                                <div class="col-md col-sm-12 col-12 d-flex align-items-center justify-content-center">
784
                                    <div class="form-group m-0">
785
                                        <label>LABEL_STATUS</label>
786
                                        <br />
787
                                        <?php
788
                                        $element = $form->get('status');
789
                                        $element->setOptions(['label' => 'LABEL_STATUS']);
790
                                        // echo $this->formLabel($element);
791
                                        echo $this->formCheckbox($element);
792
                                        ?>
793
                                    </div>
794
                                </div>
795
                            </div>
796
                            <div class="form-group">
797
                                <?php
798
                                $element = $form->get('objectives');
799
                                $element->setOptions(['label' => 'LABEL_OBJECTIVES']);
800
                                $element->setAttributes(['class' => 'form-control']);
801
 
802
                                echo $this->formLabel($element);
803
                                echo $this->formTextArea($element);
804
                                ?>
805
                            </div>
806
                            <div class="form-group">
807
                                <?php
808
                                $element = $form->get('functions');
809
                                $element->setOptions(['label' => 'LABEL_FUNCTIONS']);
810
                                $element->setAttributes(['class' => 'form-control']);
811
 
812
                                echo $this->formLabel($element);
813
                                echo $this->formTextArea($element);
814
                                ?>
815
                            </div>
1194 geraldo 816
                        </div>
3788 stevensc 817
                        <div class="tab-pane fade" id="custom-tabs-compentencies" role="tabpanel" aria-labelledby="custom-tabs-compentencies-tab">
818
                            <div class="row">
819
                                <div class="col-md-8 col-sm-8 col-xs-12">
820
                                    <select id="select-competency" class="form-control"> </select>
821
                                </div>
822
                                <div class="col-md-4 col-sm-4 col-xs-12">
823
                                    <button type="button" class="btn btn-primary" id="btn-select-competency" data-toggle="tooltip" title="LABEL_ADD LABEL_COMPETENCY">LABEL_ADD LABEL_COMPETENCY</button>
824
                                </div>
825
                            </div>
826
                            <div class="row">
827
                                <br>
828
                                <div class="col-md-12 col-sm-12 col-xs-12" id="competencies-job" style="margin-top: 10px;">
829
                                </div>
830
                            </div>
1194 geraldo 831
                        </div>
3788 stevensc 832
                        <div class="tab-pane fade" id="custom-tabs-subordinate" role="tabpanel" aria-labelledby="custom-tabs-subordinate-tab">
833
                            <div class="row">
834
                                <div class="col-md-8 col-sm-8 col-xs-12">
835
                                    <select id="select-subordinate" class="form-control"></select>
836
                                </div>
837
                                <div class="col-md-4 col-sm-4 col-xs-12">
838
                                    <button type="button" class="btn btn-primary" id="btn-select-subordinate" data-toggle="tooltip" title="LABEL_ADD ">LABEL_ADD </button>
839
                                </div>
840
                            </div>
841
                            <div class="row">
842
                                <div class="col-md-12 col-sm-12 col-xs-12" style="margin-top: 10px;">
843
                                    <table class="table table-bordered">
844
                                        <thead>
845
                                            <tr>
846
                                                <th style="width: 60%;">LABEL_NAME</th>
847
                                                <th style="width: 20%;">LABEL_ACTIONS</th>
848
                                            </tr>
849
                                        </thead>
850
                                        <tbody id="subordinate"></tbody>
851
                                    </table>
852
                                </div>
853
                            </div>
1170 geraldo 854
                        </div>
3788 stevensc 855
                    </div>
856
                </div>
1170 geraldo 857
            </div>
3788 stevensc 858
            <?php echo $this->form()->closeTag($form); ?>
859
            <!-- /.card -->
860
        </div>
861
        <!-- Modal footer -->
862
        <div class="modal-footer">
863
            <button type="submit" form="form" class="btn btn-primary">LABEL_SAVE</button>
864
            <button type="button" class="btn btn-danger btn-edit-cancel">Cerrar</button>
865
        </div>
1231 geraldo 866
</section>
867
 
868
 
1180 geraldo 869
<!--start modal behavior-->
3788 stevensc 870
<div id="modal-behavior" class="modal" tabindex="-1" role="dialog">
871
    <div class="modal-dialog modal-lg" role="document">
872
        <form action="#" name="form-behavior" id="form-behavior">
873
            <input type="hidden" name="behavior-id" id="behavior-id" value="" />
874
            <input type="hidden" name="behavior-competency" id="behavior-competency" value="" />
875
            <div class="modal-content">
876
                <div class="modal-header">
877
                    <h4 class="modal-title">LABEL_EDIT LABEL_LEVEL</h4>
878
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
879
                        <span aria-hidden="true">&times;</span>
880
                    </button>
881
                </div>
882
                <div class="modal-body">
883
                    <div class="form-group">
884
                        <label for="behavior-value">LABEL_LEVEL</label>
885
                        <select class="form-control" id="behavior-level" name="behavior-level">
886
                            <option value="0">LABEL_NA</option>
887
                            <option value="1">LABEL_LEVEL_ONE</option>
888
                            <option value="2">LABEL_LEVEL_TWO</option>
889
                            <option value="3">LABEL_LEVEL_THREE</option>
890
                            <option value="4">LABEL_LEVEL_FOUR</option>
891
                        </select>
892
                    </div>
893
                </div>
894
                <div class="modal-footer">
895
                    <button type="button" class="btn btn-primary btn-behavior-submit">LABEL_SAVE</button>
896
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
897
                </div>
1180 geraldo 898
            </div>
3788 stevensc 899
        </form>
900
    </div>
1180 geraldo 901
</div>
902
<!---end modal behavior --->
903
 
3788 stevensc 904
<!---Template Competencies --->
905
<script id="sectionTemplate" type="text/x-jsrender">
906
    <div class="panel panel-default" id="panel-{{:competency_id}}">
1175 geraldo 907
   <div class="panel-heading">
1184 geraldo 908
      <h4 class="panel-title" style="    font-size: 18px;">
1175 geraldo 909
         <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:competency_id}}" href="#collapse-{{:competency_id}}">
910
         <span class="section-name{{:competency_id}}">
1178 geraldo 911
         {{:~getType(competency_type_id).name}} - {{:name}}
1175 geraldo 912
         </span>
913
         </a>
914
      </h4>
915
   </div>
916
   <div id="collapse-{{:competency_id}}" class="panel-collapse in collapse show">
917
      <div class="panel-body">
918
         <div class="table-responsive">
919
            <table class="table table-bordered">
920
               <thead>
921
                  <tr>
1181 geraldo 922
                     <th style="width: 20%;">LABEL_ELEMENT</th>
923
                     <th style="width: 50%;">LABEL_TITLE</th>
1175 geraldo 924
                     <th style="width: 10%;">LABEL_LEVEL</th>
1181 geraldo 925
                     <th style="width: 20%;">LABEL_ACTIONS</th>
1175 geraldo 926
                  </tr>
927
               </thead>
928
               <tbody>
1243 geraldo 929
                  <tr>
1175 geraldo 930
                     <td class="text-left">LABEL_COMPETENCY</td>
1177 geraldo 931
                     <td class="text-left">{{:name}}</td>
1175 geraldo 932
                     <td>
933
                     </td>
934
                     <td>
1180 geraldo 935
                        <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 936
                     </td>
937
                  </tr>
1177 geraldo 938
                  {{for behaviors}}
1175 geraldo 939
                  <tr >
940
                     <td class="text-left">--LABEL_CONDUCT</td>
941
                     <td class="text-left">
942
                        {{:description}}
943
                     </td>
944
                     <td>
1243 geraldo 945
                        {{if level == '0'}} LABEL_NA {{/if}}
946
                        {{if level == '1' }} LABEL_LEVEL_ONE {{/if}}
947
                        {{if level == '2' }} LABEL_LEVEL_TWO {{/if}}
948
                        {{if level == '3' }} LABEL_LEVEL_THREE {{/if}}
949
                        {{if level == '4' }} LABEL_LEVEL_FOUR {{/if}}
950
                     </td>
1175 geraldo 951
                     <td>
1180 geraldo 952
                        <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 953
                     </td>
954
                  </tr>
955
                  {{/for}}
956
               </tbody>
957
            </table>
958
         </div>
959
      </div>
960
   </div>
961
</div>
962
   </script>
1187 geraldo 963
 
964
 
3788 stevensc 965
<script id="sectionJob" type="text/x-jsrender">
966
    <tr>
1243 geraldo 967
   <td class="text-left">{{:name}}</td>
968
   <td>
969
      <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>
970
   </td>
971
</tr>
1187 geraldo 972
    </script>
973
 
3788 stevensc 974
<!-- End Template Competencies-->