Proyectos de Subversion LeadersLinked - Backend

Rev

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

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