Proyectos de Subversion LeadersLinked - Backend

Rev

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