Proyectos de Subversion LeadersLinked - Backend

Rev

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

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