Proyectos de Subversion LeadersLinked - Backend

Rev

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