Proyectos de Subversion LeadersLinked - Backend

Rev

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