Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
15430 stevensc 1
<?php
2
 
66 efrain 3
use LeadersLinked\Model\JobDescription;
4
 
5
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
6
$currentUser    = $this->currentUserHelper();
7
 
8
$roleName = $currentUser->getUserTypeId();
9
 
15394 efrain 10
 
15443 efrain 11
$routeAdd       = $this->url('jobs-description/add');
12
$routeDatatable = $this->url('jobs-description');
13
$routeImport    = $this->url('jobs-description/import');
66 efrain 14
$routeDashboard = $this->url('dashboard');
15
 
15443 efrain 16
$allowAdd               = $acl->isAllowed($roleName, 'jobs-description/add') ? 1 : 0;
17
$allowEdit              = $acl->isAllowed($roleName, 'jobs-description/edit') ? 1 : 0;
18
$allowDelete            = $acl->isAllowed($roleName, 'jobs-description/delete') ? 1 : 0;
19
$allowReport            = $acl->isAllowed($roleName, 'jobs-description/report') ? 1 : 0;
20
$allowImport            = $acl->isAllowed($roleName, 'jobs-description/import') ? 1 : 0;
66 efrain 21
 
22
 
15394 efrain 23
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
24
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
15443 efrain 25
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-maxlenght/bootstrap-maxlength.min.js'));
15394 efrain 26
 
27
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
28
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
29
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
30
 
31
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
32
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
33
 
34
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
35
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
36
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
37
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
38
 
66 efrain 39
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
40
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
41
 
15394 efrain 42
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
43
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
44
 
1227 geraldo 45
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/select2.js'));
15394 efrain 46
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/i18n/es.js'));
1227 geraldo 47
$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.css'));
15394 efrain 48
 
1227 geraldo 49
$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.css'));
50
 
15394 efrain 51
// bootbox Alert //
52
$this->inlineScript()->appendFile($this->basePath('plugins/bootbox/bootbox.min.js'));
53
 
54
// JsRender //
55
$this->inlineScript()->appendFile($this->basePath('plugins/jsrender/jsrender.min.js'));
56
 
16787 efrain 57
$this->inlineScript()->appendFile($this->basePath('plugins/orgchart/js/jquery.orgchart.js'));
58
$this->headLink()->appendStylesheet($this->basePath('plugins/orgchart/css/jquery.orgchart.css'));
15394 efrain 59
 
16787 efrain 60
 
61
 
15394 efrain 62
$status_active = JobDescription::STATUS_ACTIVE;
16778 efrain 63
$status_inactive = JobDescription::STATUS_INACTIVE;
15394 efrain 64
 
16787 efrain 65
$this->headStyle()->captureStart();
66
echo <<<CSS
67
div.orgchart
68
{
69
    width: 100%;
70
    height: 600px
71
}
72
CSS;
73
$this->headStyle()->captureEnd();
74
 
75
 
15394 efrain 76
$this->inlineScript()->captureStart();
77
echo <<<JS
78
 
79
 
80
jQuery(document).ready(function($) {
81
 
16770 efrain 82
 
83
 
15443 efrain 84
    var competencies_selected = new Array();
85
    var behaviors = new Array();
86
    var competency_types = new Array();
87
    var competencies = new Array();
15394 efrain 88
 
89
    var allowEdit = $allowEdit;
90
    var allowDelete = $allowDelete;
91
    var allowReport = $allowReport;
92
 
93
 
16787 efrain 94
    var datasource = {};
95
    var dataactions = [];
96
    var oc = null;
97
 
15394 efrain 98
    $.fn.renderCompetencies = function() {
99
        if(competencies_selected.length > 0) {
16766 efrain 100
 
101
 
15394 efrain 102
            $('#renderCompetencies').html($('#competencyTemplate').render(competencies_selected, {
103
                getCompetencyType: (uuid) => competency_types.filter((item) => item.uuid == uuid ? item : false)[0],
104
                getCompetency: (uuid) => competencies.filter((item) => item.uuid == uuid ? item : false)[0],
105
                getBehavior: (uuid) => behaviors.filter((item) => item.uuid == uuid ? item : false)[0]
106
            }));
107
        } else {
108
            $('#renderCompetencies').html('');
109
        }
110
    }
111
 
112
    $.fn.comboCompetencies = function() {
113
        $('#select-competency').children().remove();
114
        $.each(competency_types, function(i, competency_type) {
115
            competencies_filtered = competencies.filter((item) => item.competency_type_uuid == competency_type.uuid ? item : false)
116
            $.each(competencies_filtered, function(i, competency) {
117
 
118
 
119
                selected = competencies_selected.filter((item) => item.uuid == competency.uuid ? item : false)[0];
120
                if(!selected) {
121
                    $('#select-competency').append($('<option>', {
122
                        value: competency.uuid,
123
                        text: competency_type.name +  ' - ' + competency.name
124
                    }));
125
                }
126
 
127
            });
128
        });
129
 
130
    }
131
 
132
 
133
 
134
    $.validator.setDefaults({
135
        debug: true,
136
        highlight: function(element) {
137
            $(element).addClass('is-invalid');
138
        },
139
        unhighlight: function(element) {
140
            $(element).removeClass('is-invalid');
141
        },
142
        errorElement: 'span',
143
        errorClass: 'error invalid-feedback',
144
        errorPlacement: function(error, element) {
145
            if (element.parent('.form-group').length) {
146
                error.insertAfter(element);
147
            } else if (element.parent('.toggle').length) {
148
                error.insertAfter(element.parent().parent());
149
            } else {
150
                error.insertAfter(element.parent());
151
            }
152
        }
153
    });
154
 
155
    $.fn.showFormErrorValidator = function(fieldname, errors) {
156
        var field = $(fieldname);
157
        if (field) {
158
            $(field).addClass('is-invalid');
159
            var error = $('<span id="' + fieldname + '-error" class="error invalid-feedback">' + errors + '</div>');
160
            if (field.parent('.form-group').length) {
161
                error.insertAfter(field);
162
            } else if (field.parent('.toggle').length) {
163
                error.insertAfter(field.parent().parent());
164
            } else {
165
                error.insertAfter(field.parent());
166
            }
167
        }
168
    };
169
 
16770 efrain 170
 
171
 
16779 efrain 172
 
16787 efrain 173
    $.fn.recursiveTree = function(parent_branch, parent_item) {
174
        $.each(parent_item, function(i, item) {
175
            dataactions.push({
176
                'uuid' : item['uuid'],
177
                'link_report' : item['link_report'],
178
                'link_edit' : item['link_edit'],
179
                'link_delete' : item['link_delete'],
180
            })
16779 efrain 181
 
16787 efrain 182
            var branch  = {
183
                'uuid' : item['uuid'],
184
                'name' : item['name'],
185
                'children' : [
16770 efrain 186
 
16787 efrain 187
                ]
188
            }
16770 efrain 189
 
16787 efrain 190
            if(item.children.length > 0) {
191
                $.fn.recursiveTree(branch, item.children);
192
            }
16779 efrain 193
 
16787 efrain 194
            parent_branch.children.push(branch)
16779 efrain 195
 
16787 efrain 196
        });
16770 efrain 197
 
16787 efrain 198
    }
16770 efrain 199
 
200
 
201
 
202
 
203
    $.fn.refreshTree = function() {
204
        NProgress.start();
205
        $.ajax({
206
            'dataType': 'json',
207
            'accept': 'application/json',
208
            'method': 'get',
209
            'url': '$routeDatatable',
210
        }).done(function(response) {
211
            if (response['success']) {
16787 efrain 212
                if(response['data']['items'].length == 0) {
16777 efrain 213
                    $('#divNoRecordsAvailable').show();
214
                } else {
215
                    $('#divNoRecordsAvailable').hide();
16770 efrain 216
 
16777 efrain 217
                }
16787 efrain 218
 
219
                dataactions = [];
16777 efrain 220
 
16787 efrain 221
 
222
                datasource = {
223
                    'uuid' : 'n-a',
224
                    'name' : '$company_name',
225
                    'children' : [
226
 
227
                    ]
228
                }
229
 
230
 
231
                $.fn.recursiveTree(datasource, response['data']['items']);
232
 
233
 
234
 
235
                oc.init({ 'data': datasource });
236
                oc.\$chart.find('.node').on('mouseover', function(e) {
237
                    e.preventDefault();
238
 
239
                    $('.horizontalEdge').hide();
240
                    $('.verticalEdge').hide();
16770 efrain 241
                });
16787 efrain 242
 
243
                oc.\$chart.find('.node').on('click', function() {
244
                    var message = $(this).children('.title').text();
245
 
246
 
247
                    if(!allowEdit && !allowDelete && !allowReport) {
248
                        return;
249
                    }
250
 
251
 
252
                    var uuid = $(this).attr('id');
253
                    var link_report = '';
254
                    var link_edit = '';
255
                    var link_delete = '';
256
 
257
                    $.each(dataactions, function(i, item) {
258
                        if(uuid == item.uuid) {
259
                            link_report = item.link_report;
260
                            link_edit = item.link_edit;
261
                            link_delete = item.link_delete;
262
                        }
263
                    });
264
 
265
                    var buttons =  {}
266
 
267
                    buttons.cancel = {
268
                        label: 'LABEL_CANCEL',
269
                        className: 'btn-default',
270
                        callback: function(){
271
                            console.log('CANCEL clicked');
272
                        }
273
                    };
274
 
275
 
276
                    if(allowEdit && link_edit) {
277
                        buttons.edit = {
278
                            label: 'LABEL_EDIT',
279
                            className: 'btn-edit',
280
                            callback: function(){
281
 
282
                                setTimeout(() => {
283
                                    $.fn.editJobDescription(link_edit);
284
                                },  250);
285
 
286
                            }
287
                        };
288
                    }
289
                    if(allowDelete && link_delete) {
290
                        buttons.delete = {
291
                            label: 'LABEL_DELETE',
292
                            className: 'btn-delete',
293
                            callback: function(){
294
                                setTimeout(() => {
295
                                    $.fn.deleteJobDescription(link_delete);
296
                                },  250);
297
 
298
 
299
 
300
 
301
                            }
302
                        };
303
                    }
304
 
305
                    if(allowReport && link_report) {
306
                        buttons.report = {
307
                            label: 'LABEL_REPORT',
308
                            className: 'btn-default',
309
                            callback: function() {
310
                                setTimeout(() => {
311
                                    $.fn.reportJobDescription(link_report);
312
                                },  250);
313
                            }
314
                        };
315
                    }
316
 
317
 
318
                    let dialog = bootbox.dialog({
319
                        title: 'LABEL_JOB_DESCRIPTION',
320
                        message: message,
321
                        size: 'large',
322
                        buttons: buttons,
323
                    });
324
                    dialog.show();
325
 
326
                });
327
 
16770 efrain 328
            } else {
329
                $.fn.showError(response['data']);
330
            }
331
        }).fail(function(jqXHR, textStatus, errorThrown) {
332
            $.fn.showError(textStatus);
333
         }).always(function() {
334
            NProgress.done();
335
        });
336
    }
337
 
15394 efrain 338
    var validator = $('#form').validate({
339
        debug: true,
340
        onclick: false,
341
        onkeyup: false,
342
        ignore: [],
343
        rules: {
344
            'name': {
345
                required: true,
346
                maxlength: 64,
347
            },
348
            'functions': {
349
                required: true,
15443 efrain 350
                maxlength: 1024,
15394 efrain 351
            },
352
            'objectives': {
15443 efrain 353
               required: true,
354
                maxlength: 1024,
15394 efrain 355
            },
356
            'status': {
357
                required: false,
358
            },
16787 efrain 359
            'job_description_id_boss' : {
360
                required: false,
361
            },
15394 efrain 362
        },
363
        submitHandler: function(form) {
364
 
16778 efrain 365
 
366
 
15394 efrain 367
            var data = {
368
                name : $('#form #name').val(),
369
                functions : $('#form #functions').val(),
370
                objectives : $('#form #objectives').val(),
16778 efrain 371
                status :  $('#form #status').prop('checked') ?  '$status_active' : '$status_inactive',
16787 efrain 372
                job_description_id_boss: $('#form #job_description_id_boss').val(),
15394 efrain 373
                competencies_selected : new Array(),
374
            };
375
 
376
 
377
            $.each(competencies_selected, function(i, c) {
378
                $.each(c.behaviors, function(i, b) {
379
                    data.competencies_selected.push({'competency_uuid' : c.uuid, 'behavior_uuid' : b.uuid, 'level' : b.level});
380
                });
381
            });
382
 
383
 
384
            NProgress.start();
385
            $.ajax({
386
                'dataType': 'json',
387
                'accept': 'application/json',
388
                'method': 'post',
389
                'url': $('#form').attr('action'),
390
                'data': data,
391
            }).done(function(response) {
392
                if (response['success']) {
393
                    $.fn.showSuccess(response['data']);
394
                    $('#row-lists').show();
395
                    $('#row-form').hide();
16770 efrain 396
                    $.fn.refreshTree();
15394 efrain 397
                } else {
398
                    validator.resetForm();
399
                    if (jQuery.type(response['data']) == 'string') {
400
                        $.fn.showError(response['data']);
401
                    } else {
402
                        $.each(response['data'], function(fieldname, errors) {
403
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
404
                        });
405
                    }
406
                }
407
            }).fail(function(jqXHR, textStatus, errorThrown) {
408
                $.fn.showError(textStatus);
409
            }).always(function() {
410
                NProgress.done();
411
            });
412
            return false;
413
        },
414
        invalidHandler: function(form, validator) {}
415
    });
416
 
16770 efrain 417
    $('body').on('click', 'button.btn-refresh', function(e) {
15394 efrain 418
        e.preventDefault();
16770 efrain 419
        $.fn.refreshTree();
420
    });
421
 
422
    $('body').on('click', 'button.btn-cancel', function(e) {
423
        e.preventDefault();
424
        $('#row-lists').show();
425
        $('#row-form').hide();
426
        $('#div-listing').show();
427
    });
428
 
429
    $('body').on('click', 'button.btn-import', function(e) {
430
        e.preventDefault();
15394 efrain 431
        NProgress.start();
432
        $.ajax({
433
            'dataType': 'json',
16770 efrain 434
            'method': 'post',
435
            'url': '$routeImport',
436
        }).done(function(response) {
437
            if (response['success']) {
438
                $.fn.showSuccess(response['data']);
439
                $.fn.refreshTree();
440
            } else {
441
                $.fn.showError(response['data']);
442
            }
443
        }).fail(function(jqXHR, textStatus, errorThrown) {
444
            $.fn.showError(textStatus);
445
        }).always(function() {
446
            NProgress.done();
447
        });
448
        return false;
449
    });
450
 
451
    $('body').on('click', 'button.btn-add-job-description', function(e) {
452
        e.preventDefault();
453
 
16787 efrain 454
        var action = $(this).data('link');
15394 efrain 455
 
16787 efrain 456
        NProgress.start();
457
        $.ajax({
458
            'dataType': 'json',
459
            'accept': 'application/json',
460
            'method': 'get',
461
            'url' : '$routeAdd',
462
        }).done(function(response) {
16778 efrain 463
 
16787 efrain 464
            if (response['success']) {
465
                behaviors = response['data']['behaviors'];
466
                competency_types = response['data']['competency_types'];
467
                competencies = response['data']['competencies'];
16778 efrain 468
 
469
 
16787 efrain 470
                competencies_selected = [];
471
                $.each(competencies, function(i, competency) {
472
                    $.each(competency.behaviors, function(j, behavior) {
473
                        competencies[i].behaviors[j].level = 0;
16770 efrain 474
                    });
16787 efrain 475
                });
16778 efrain 476
 
16787 efrain 477
                $.fn.renderCompetencies();
478
                $.fn.comboCompetencies();
16778 efrain 479
 
16787 efrain 480
                $('span[id="form-title"]').html('LABEL_ADD');
481
                $('#form').attr('action', action);
482
                $('#form #name').val('');
483
                $('#form #status').bootstrapToggle('on');
16778 efrain 484
 
16787 efrain 485
                $('#form #functions').val('');
486
                $('#form #objectives').val('');
487
 
488
 
489
                $('#job_description_id_boss').empty();
490
                $.each(response['data']['jobs_description'], function(id, text) {
491
 
492
                    var option = new Option(text, id, false, false);
493
                    $('#job_description_id_boss').append(option).trigger('change');
494
                });
495
                $('#job_description_id_boss').trigger('change');
496
                $('#job_description_id_boss').val('').trigger('change');
16778 efrain 497
 
16787 efrain 498
                validator.resetForm();
16778 efrain 499
 
500
 
16787 efrain 501
                $('#custom-tabs #custom-tabs-general-tab').tab('show');
502
                $('#row-lists').hide();
503
                $('#row-form').show();
16778 efrain 504
 
16787 efrain 505
            } else   {
506
                $.fn.showError(response['data']);
507
            }
16778 efrain 508
 
16787 efrain 509
        }).fail(function(jqXHR, textStatus, errorThrown) {
510
            $.fn.showError(textStatus);
511
        }).always(function() {
512
            NProgress.done();
513
        });
514
    });
15394 efrain 515
 
16787 efrain 516
    $.fn.deleteJobDescription = function(action)
517
    {
518
        bootbox.confirm({
519
            message: 'LABEL_ARE_YOU_SURE',
520
            buttons: {
521
                confirm: {
522
                    label: 'LABEL_YES',
523
                    className: 'btn-success'
524
                },
525
                cancel: {
526
                    label: 'LABEL_NO',
527
                    className: 'btn-danger'
528
                }
529
            },
530
            callback: function (result) {
531
                if(result) {
532
                    NProgress.start();
533
                    $.ajax({
534
                        'dataType'  : 'json',
535
                        'accept'    : 'application/json',
536
                        'method'    : 'post',
537
                        'url'       :  action,
538
                    }).done(function(response) {
539
                        if(response['success']) {
540
                            $.fn.showSuccess(response['data']);
541
                            $.fn.refreshTree();
542
                        } else {
543
                            $.fn.showError(response['data']);
544
                        }
545
                    }).fail(function( jqXHR, textStatus, errorThrown) {
546
                        $.fn.showError(textStatus);
547
                    }).always(function() {
548
                        NProgress.done();
549
                    });
550
                }
551
            }
552
        });
16778 efrain 553
    }
15394 efrain 554
 
16787 efrain 555
    $.fn.editJobDescription = function(action)
556
    {
557
        NProgress.start();
15394 efrain 558
 
559
        $.ajax({
560
            'dataType': 'json',
16770 efrain 561
            'accept': 'application/json',
562
            'method': 'get',
563
            'url': action,
15394 efrain 564
        }).done(function(response) {
565
            if (response['success']) {
16770 efrain 566
                $('span[id="form-title"]').html('LABEL_EDIT');
567
                $('#form').attr('action', action);
16787 efrain 568
                $('#form #id').val(response['data']['id']);
16770 efrain 569
                $('#form #name').val(response['data']['name']);
570
                $('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
571
 
572
                $('#form #functions').val(response['data']['functions']);
573
                $('#form #objectives').val(response['data']['objectives']);
574
 
575
                behaviors = response['data']['behaviors'];
576
                competency_types = response['data']['competency_types'];
577
 
578
                competencies = response['data']['competencies'];
579
                competencies_selected = response['data']['competencies_selected'];
16787 efrain 580
 
581
                $('#job_description_id_boss').empty();
582
                $.each(response['data']['jobs_description'], function(id, text) {
583
 
584
                    var option = new Option(text, id, false, false);
585
                    $('#job_description_id_boss').append(option).trigger('change');
586
                });
587
 
588
                $('#job_description_id_boss').trigger('change');
589
                $('#job_description_id_boss').val(response['data']['job_description_id_boss']).trigger('change');
590
 
16770 efrain 591
 
592
                $.fn.renderCompetencies();
593
                $.fn.comboCompetencies();
594
 
595
 
596
                validator.resetForm();
597
                $('#custom-tabs #custom-tabs-general-tab').tab('show');
598
                $('#row-lists').hide();
599
                $('#row-form').show();
15394 efrain 600
            } else {
601
                $.fn.showError(response['data']);
602
            }
603
        }).fail(function(jqXHR, textStatus, errorThrown) {
604
            $.fn.showError(textStatus);
605
        }).always(function() {
606
            NProgress.done();
607
        });
16787 efrain 608
    }
15394 efrain 609
 
16787 efrain 610
    $.fn.reportJobDescription = function(action)
611
    {
16770 efrain 612
        window.open(action, '_blank');
15443 efrain 613
 
16787 efrain 614
    }
15394 efrain 615
 
616
    $('body').on('click', 'button[id="btn-select-competency"]', function(e) {
617
        var competency_uuid = $('#select-competency').val();
618
 
619
        if (competency_uuid.length == '') {
620
            $.fn.showError('ERROR_SELECT_COMPETENCY_IS_EMPTY');
621
        } else {
622
 
623
            competency = competencies.filter((item) => item.uuid == competency_uuid ? item : false)[0];
624
            if(competency) {
625
 
626
                var competency_selected = {
627
                    uuid : competency.uuid,
628
                    competency_type_uuid: competency.competency_type_uuid,
629
                    behaviors : new Array(),
630
                }
631
 
632
                $.each(competency.behaviors, function(index, uuid) {
633
                    competency_selected.behaviors.push({uuid: uuid, level: 0});
634
 
635
                })
636
 
637
 
638
                competencies_selected.push(competency_selected);
639
 
640
                $.fn.renderCompetencies();
641
                $.fn.comboCompetencies();
642
            }
643
        }
644
    });
645
 
16770 efrain 646
    $('body').on('click', 'i.btn-delete-job-description', function(e) {
15394 efrain 647
        e.preventDefault();
16777 efrain 648
        var action = $(this).data('link');
649
 
650
        bootbox.confirm({
651
            message: 'LABEL_ARE_YOU_SURE',
652
            buttons: {
653
                confirm: {
654
                    label: 'LABEL_YES',
655
                    className: 'btn-success'
656
                },
657
                cancel: {
658
                    label: 'LABEL_NO',
659
                    className: 'btn-danger'
660
                }
661
            },
662
            callback: function (result) {
663
                if(result) {
664
                    NProgress.start();
665
                    $.ajax({
666
                        'dataType': 'json',
667
                        'accept': 'application/json',
668
                        'method': 'post',
669
                        'url': action,
670
                    }).done(function(response) {
671
                        if (response['success']) {
672
                            $.fn.showSuccess(response['data']);
673
                           $.fn.refreshTree();
674
                        } else {
675
                            $.fn.showError(response['data']);
676
                        }
677
                    }).fail(function(jqXHR, textStatus, errorThrown) {
678
                        $.fn.showError(textStatus);
679
                    }).always(function() {
680
                        NProgress.done();
681
                    });
682
                }
15394 efrain 683
            }
684
        });
16777 efrain 685
 
686
 
687
 
15394 efrain 688
    });
689
 
16770 efrain 690
    $('body').on('click', 'button.btn-delete-job-description-competency', function(e) {
15394 efrain 691
        e.preventDefault();
692
 
693
        var uuid = $(this).data('competency');
694
        bootbox.confirm({
695
             title: 'LABEL_COMPETENCY_DELETE_TITLE',
696
            message: 'LABEL_COMPETENCY_DELETE_MESSAGE',
697
            buttons: {
698
                cancel: {
699
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
700
                },
701
                confirm: {
702
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
703
                }
704
            },
705
            callback: function(result) {
706
                if (result) {
707
                    competencies_selected = competencies_selected.filter((item) => item.uuid != uuid ? item : false);
708
 
709
 
710
                    $.fn.renderCompetencies();
711
                    $.fn.comboCompetencies();
712
 
713
                }
714
            }
715
        });
716
    });
717
 
16770 efrain 718
    $('body').on('click','button.btn-edit-job-description-behavior', function(e) {
15394 efrain 719
        e.preventDefault();
720
 
721
        var competency_uuid = $(this).closest('div.panel-competency').data('competency');
722
        var behavior_uuid = $(this).data('behavior');
723
 
724
 
725
        competency_selected = competencies_selected.filter((item) => item.uuid == competency_uuid ? item : false)[0];
726
        if(competency_selected) {
727
            console.log(competency_selected);
728
 
729
            behavior = competency_selected .behaviors.filter((item) => item.uuid  == behavior_uuid ? item : false)[0];
730
            if(behavior) {
731
 
732
                console.log(behavior);
733
                $('#form-behavior #competency-uuid').val(competency_uuid);
734
                $('#form-behavior #behavior-uuid').val(behavior_uuid);
735
                $('#form-behavior #level').val(behavior.level);
736
 
737
                $('#modal-behavior').modal('show');
738
            }
739
 
740
        }
741
    });
742
 
743
    $('body').on('click','button.btn-behavior-submit', function(e) {
744
         e.preventDefault();
745
         $('#modal-behavior').modal('hide');
746
 
747
         var competency_uuid = $('#form-behavior #competency-uuid').val();
748
         var behavior_uuid = $('#form-behavior #behavior-uuid').val();
749
         var level = $('#form-behavior #level').val();
750
 
751
        competency_selected = competencies_selected.filter((item) => item.uuid == competency_uuid ? item : false)[0];
752
        if(competency_selected) {
753
            behavior = competency_selected .behaviors.filter((item) => item.uuid  == behavior_uuid ? item : false)[0];
754
            if(behavior) {
755
                behavior.level = level;
756
                $.fn.renderCompetencies();
757
            }
758
 
759
        }
760
 
761
    });
762
 
16770 efrain 763
    $('body').on('click', 'button.btn-edit-job-description-cancel', function(e) {
15394 efrain 764
        $('#row-lists').show();
765
        $('#row-form').hide();
766
    });
767
 
768
    $('#form #status').bootstrapToggle({
769
        'on': 'LABEL_ACTIVE',
770
        'off': 'LABEL_INACTIVE',
771
        'width': '160px',
772
        'height': '40px'
773
    });
774
 
15443 efrain 775
    $('#form #functions').maxlength({
776
        alwaysShow: true,
777
         validate: true
778
    });
779
 
780
    $('#form #objectives').maxlength({
781
        alwaysShow: true,
782
        validate: true
783
    });
784
 
16770 efrain 785
    $('#select-competency').select2({
15394 efrain 786
        theme: 'bootstrap4',
787
        width: '100%',
788
    });
789
 
16787 efrain 790
    $('#boss_id').select2({
791
        theme: 'bootstrap4',
792
        width: '100%',
793
    });
15394 efrain 794
 
795
 
16787 efrain 796
    oc = $('#chart-container').orgchart({
797
        'data' : datasource,
798
        'nodeId': 'uuid' ,
799
    });
15394 efrain 800
 
16787 efrain 801
 
802
 
803
 
804
    $.fn.refreshTree();
15394 efrain 805
});
806
 
14184 stevensc 807
JS;
66 efrain 808
$this->inlineScript()->captureEnd();
15394 efrain 809
?>
16770 efrain 810
 
811
 
16773 efrain 812
<section class="content" id="row-lists" style="margin-bottom: 20px">
14185 stevensc 813
 
15430 stevensc 814
    <!-- Content Header (Page header) -->
815
    <div class="content-header">
816
        <div class="container-fluid">
817
            <div class="row mb-2">
818
                <div class="col-sm-12">
819
                    <h1>LABEL_JOBS_DESCRIPTION</h1>
820
                </div>
15394 efrain 821
            </div>
15430 stevensc 822
        </div>
823
        <!-- /.container-fluid -->
824
    </div>
825
    <div class="container-fluid">
826
        <div class="row">
827
            <div class="col-12">
828
                <div class="card">
829
                    <div class="card-body">
16777 efrain 830
                   	  <div id="divNoRecordsAvailable" class="text-center" style="display: none"><h3>LABEL_NO_RECORDS_AVAILABLE</h3></div>
16787 efrain 831
 
832
                   	<!--
833
                   	; scroll: auto; overflow: auto;
834
                   	 -->
835
                   	 <div id="chart-container" style="width: 100%; height: 600px">
16770 efrain 836
 
16787 efrain 837
 
838
 
16779 efrain 839
 
840
            		 </div>
841
 
842
 
16770 efrain 843
 
15430 stevensc 844
                    </div>
845
                    <div class="card-footer clearfix">
16776 efrain 846
                		<div  style="float:right;" >
15430 stevensc 847
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
848
                            <?php if ($allowAdd) : ?>
849
                                <?php if ($allowImport) : ?>
850
                                    <button type="button" class="btn btn-primary btn-import"><i class="fa fa-upload"></i> LABEL_IMPORT </button>
851
                                <?php endif; ?>
16770 efrain 852
                                <button type="button" class="btn btn-primary btn-add-job-description" data-link="<?php echo $routeAdd ?>"><i class="fa fa-plus"></i> LABEL_ADD </button>
15430 stevensc 853
                            <?php endif; ?>
854
                        </div>
855
                    </div>
856
                </div>
857
            </div>
858
        </div>
859
    </div>
15394 efrain 860
</section>
861
 
862
<section id="row-form" style="display:none">
16776 efrain 863
	<div class="card">
864
        <div class="card-header">
15432 stevensc 865
            <h4 class="modal-title">LABEL_JOB_DESCRIPTION - <span id="form-title"></span></h4>
15430 stevensc 866
        </div>
16784 efrain 867
 		<div class="card-body">
15430 stevensc 868
            <div class="card card-primary card-outline card-tabs">
869
                <div class="card-header p-0 pt-1 border-bottom-0">
870
                    <ul class="nav nav-tabs" id="custom-tabs" role="tablist">
871
                        <li class="nav-item">
872
                            <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>
873
                        </li>
874
                        <li class="nav-item">
875
                            <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>
876
                        </li>
877
                    </ul>
878
                </div>
879
                <div class="card-body">
880
                    <?php
881
                    $form = $this->form;
882
                    $form->setAttributes([
883
                        'method'    => 'post',
884
                        'name'      => 'form',
885
                        'id'        => 'form'
886
                    ]);
887
 
888
                    $form->prepare();
889
                    echo $this->form()->openTag($form);
890
 
891
 
892
                    $element = $form->get('competencies');
893
                    echo $this->formHidden($element);
894
 
895
                    ?>
896
 
897
                    <div class="tab-content" id="custom-tabs-three-tabContent">
898
                        <div class="tab-pane fade show active" id="custom-tabs-general" role="tabpanel" aria-labelledby="custom-tabs-general-tab">
899
                            <div class="row">
900
                                <div class="col-md col-sm-12 col-12">
901
                                    <div class="form-group m-0">
902
                                        <?php
903
                                        $element = $form->get('name');
904
                                        $element->setOptions(['label' => 'LABEL_NAME']);
905
                                        $element->setAttributes(['class' => 'form-control']);
906
 
907
                                        echo $this->formLabel($element);
908
                                        echo $this->formText($element);
909
                                        ?>
910
                                    </div>
911
                                </div>
912
                                <div class="col-md col-sm-12 col-12 d-flex align-items-center justify-content-center">
913
                                    <div class="form-group m-0">
914
                                        <label>LABEL_STATUS</label>
915
                                        <br />
916
                                        <?php
917
                                        $element = $form->get('status');
918
                                        $element->setOptions(['label' => 'LABEL_STATUS']);
919
                                        // echo $this->formLabel($element);
920
                                        echo $this->formCheckbox($element);
921
                                        ?>
922
                                    </div>
923
                                </div>
924
                            </div>
925
                            <div class="form-group">
926
                                <?php
927
                                $element = $form->get('objectives');
928
                                $element->setOptions(['label' => 'LABEL_OBJECTIVES']);
929
                                $element->setAttributes(['class' => 'form-control']);
930
 
931
                                echo $this->formLabel($element);
932
                                echo $this->formTextArea($element);
933
                                ?>
934
                            </div>
935
                            <div class="form-group">
936
                                <?php
937
                                $element = $form->get('functions');
938
                                $element->setOptions(['label' => 'LABEL_FUNCTIONS']);
939
                                $element->setAttributes(['class' => 'form-control']);
940
 
941
                                echo $this->formLabel($element);
942
                                echo $this->formTextArea($element);
943
                                ?>
944
                            </div>
16787 efrain 945
                     		<div class="form-group">
946
                                <?php
947
                                $element = $form->get('job_description_id_boss');
948
                                $element->setOptions(['label' => 'LABEL_BOSS']);
949
                                $element->setAttributes(['class' => 'form-control']);
950
 
951
                                echo $this->formLabel($element);
952
                                echo $this->formSelect($element);
953
                                ?>
954
                            </div>
15394 efrain 955
                        </div>
15430 stevensc 956
                        <div class="tab-pane fade" id="custom-tabs-compentencies" role="tabpanel" aria-labelledby="custom-tabs-compentencies-tab">
957
                            <div class="row">
958
                                <div class="col-md-8 col-sm-8 col-xs-12">
959
                                    <select id="select-competency" class="form-control"> </select>
960
                                </div>
961
                                <div class="col-md-4 col-sm-4 col-xs-12">
962
                                    <button type="button" class="btn btn-primary" id="btn-select-competency" data-toggle="tooltip" title="LABEL_ADD LABEL_COMPETENCY">LABEL_ADD LABEL_COMPETENCY</button>
963
                                </div>
964
                            </div>
965
                            <div class="row">
966
                                <br>
967
                                <div class="col-md-12 col-sm-12 col-xs-12" id="renderCompetencies" style="margin-top: 10px;">
968
                                </div>
969
                            </div>
15394 efrain 970
                        </div>
15430 stevensc 971
                    </div>
972
                </div>
15394 efrain 973
            </div>
15430 stevensc 974
            <?php echo $this->form()->closeTag($form); ?>
16776 efrain 975
 
15430 stevensc 976
        </div>
16776 efrain 977
        <div class="card-footer clearfix">
15430 stevensc 978
            <button type="submit" form="form" class="btn btn-primary">LABEL_SAVE</button>
16770 efrain 979
            <button type="button" class="btn btn-danger btn-edit-job-description-cancel">Cerrar</button>
15430 stevensc 980
        </div>
16776 efrain 981
	</div>
982
 
983
 
15394 efrain 984
</section>
985
 
986
 
987
<!--start modal behavior-->
15430 stevensc 988
<div id="modal-behavior" class="modal" tabindex="-1" role="dialog">
16778 efrain 989
	<form action="#" name="form-behavior" id="form-behavior">
990
        <div class="modal-dialog " role="document">
991
    		<input type="hidden" id="behavior-uuid" name="behavior-uuid" value="" />
992
       		<input type="hidden" id="competency-uuid" name="competency-uuid value="" />
993
       		<div class=" modal-content">
994
                <div class="modal-header">
995
                    <h4 class="modal-title">LABEL_EDIT LABEL_LEVEL</h4>
996
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
997
                        <span aria-hidden="true">&times;</span>
998
                    </button>
999
                </div>
1000
                <div class="modal-body">
1001
                       <div class="form-group">
1002
                          <label for="behavior-value">LABEL_LEVEL</label>
1003
                          <input type="number" step="1" min="0" max="100" id="level" name="level">
1004
                    </div>
1005
                    <div class="modal-footer">
1006
                        <button type="button" class="btn btn-primary btn-behavior-submit">LABEL_SAVE</button>
1007
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
1008
                    </div>
1009
            	</div>
1010
        	</div>
1011
    	</div>
1012
	</form>
15394 efrain 1013
</div>
15436 stevensc 1014
 
15394 efrain 1015
 
15443 efrain 1016
 
15430 stevensc 1017
<!---Template Competencies --->
1018
<script id="competencyTemplate" type="text/x-jsrender">
1019
    <div class="panel panel-default panel-competency" id="panel-{{:uuid}}" data-competency="{{:uuid}}">
15394 efrain 1020
   <div class="panel-heading">
1021
      <h4 class="panel-title" style="    font-size: 18px;">
1022
         <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:uuid}}" href="#collapse-{{:uuid}}">
1023
         <span class="section-name{{:uuid}}">
1024
            {{:~getCompetencyType(competency_type_uuid).name}} - {{:~getCompetency(uuid).name}}
1025
         </span>
1026
         </a>
1027
      </h4>
1028
   </div>
1029
   <div id="collapse-{{:uuid}}" class="panel-collapse in collapse show">
1030
      <div class="panel-body">
1031
         <div class="table-responsive">
1032
            <table class="table table-bordered">
1033
               <thead>
1034
                  <tr>
1035
                     <th style="width: 20%;">LABEL_ELEMENT</th>
1036
                     <th style="width: 50%;">LABEL_TITLE</th>
1037
                     <th style="width: 10%;">LABEL_LEVEL</th>
1038
                     <th style="width: 20%;">LABEL_ACTIONS</th>
1039
                  </tr>
1040
               </thead>
1041
               <tbody>
1042
                  <tr>
1043
                     <td class="text-left">LABEL_COMPETENCY</td>
1044
                     <td class="text-left">{{:name}}</td>
1045
                     <td>
1046
                     </td>
1047
                     <td>
16770 efrain 1048
                        <button  type="button" class="btn btn-default btn-delete-job-description-competency" data-competency="{{:uuid}}" data-toggle="tooltip"  data-original-title="LABEL_DELETE LABEL_COMPETENCY"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_COMPETENCY </button>
15394 efrain 1049
                     </td>
1050
                  </tr>
1051
                  {{for behaviors}}
1052
                  <tr >
1053
                     <td class="text-left">--LABEL_BEHAVIOR</td>
1054
                     <td class="text-left">
1055
                       {{:~getBehavior(uuid).description}}
1056
                     </td>
15443 efrain 1057
                     <td class="text-right">
1058
                        {{:level}}
1059
                     </td>
15394 efrain 1060
                     <td>
16770 efrain 1061
                        <button type="button"  class="btn btn-default btn-edit-job-description-behavior" data-behavior="{{:uuid}}" data-toggle="tooltip"  data-original-title="LABEL_EDIT LABEL_LEVEL"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_LEVEL</button>
15443 efrain 1062
                     </td>
1063
                  </tr>
1064
                  {{/for}}
1065
               </tbody>
1066
            </table>
1067
         </div>
1068
      </div>
1069
   </div>
1070
</div>
1071
</script>
1072
 
1073
<script id="competencyTemplateWithLevel" type="text/x-jsrender">
1074
 <div class="panel panel-default panel-competency" id="panel-{{:uuid}}" data-competency="{{:uuid}}">
1075
   <div class="panel-heading">
1076
      <h4 class="panel-title" style="    font-size: 18px;">
1077
         <a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:uuid}}" href="#collapse-{{:uuid}}">
1078
         <span class="section-name{{:uuid}}">
1079
            {{:~getCompetencyType(competency_type_uuid).name}} - {{:~getCompetency(uuid).name}}
1080
         </span>
1081
         </a>
1082
      </h4>
1083
   </div>
1084
   <div id="collapse-{{:uuid}}" class="panel-collapse in collapse show">
1085
      <div class="panel-body">
1086
         <div class="table-responsive">
1087
            <table class="table table-bordered">
1088
               <thead>
1089
                  <tr>
1090
                     <th style="width: 20%;">LABEL_ELEMENT</th>
1091
                     <th style="width: 50%;">LABEL_TITLE</th>
1092
                     <th style="width: 10%;">LABEL_LEVEL</th>
1093
                     <th style="width: 20%;">LABEL_ACTIONS</th>
1094
                  </tr>
1095
               </thead>
1096
               <tbody>
1097
                  <tr>
1098
                     <td class="text-left">LABEL_COMPETENCY</td>
1099
                     <td class="text-left">{{:name}}</td>
1100
                     <td>
1101
                     </td>
1102
                     <td>
16770 efrain 1103
                        <button  type="button" class="btn btn-default btn-delete-job-description-competency" data-competency="{{:uuid}}" data-toggle="tooltip"  data-original-title="LABEL_DELETE LABEL_COMPETENCY"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_COMPETENCY </button>
15443 efrain 1104
                     </td>
1105
                  </tr>
1106
                  {{for behaviors}}
1107
                  <tr >
1108
                     <td class="text-left">--LABEL_BEHAVIOR</td>
1109
                     <td class="text-left">
1110
                       {{:~getBehavior(uuid).description}}
1111
                     </td>
1112
                     <td>
15394 efrain 1113
                        {{if level == '0'}} LABEL_NA {{/if}}
1114
                        {{if level == '1' }} LABEL_LEVEL_ONE {{/if}}
1115
                        {{if level == '2' }} LABEL_LEVEL_TWO {{/if}}
1116
                        {{if level == '3' }} LABEL_LEVEL_THREE {{/if}}
1117
                        {{if level == '4' }} LABEL_LEVEL_FOUR {{/if}}
1118
                     </td>
1119
                     <td>
16770 efrain 1120
                        <button type="button"  class="btn btn-default btn-edit-job-description-behavior" data-behavior="{{:uuid}}" data-toggle="tooltip"  data-original-title="LABEL_EDIT LABEL_LEVEL"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_LEVEL</button>
15394 efrain 1121
                     </td>
1122
                  </tr>
1123
                  {{/for}}
1124
               </tbody>
1125
            </table>
1126
         </div>
1127
      </div>
1128
   </div>
1129
</div>
1130
</script>
1131
 
16770 efrain 1132
<script id="listJobDescriptionTemplate" type="text/x-jsrender">
16779 efrain 1133
	<li data-id="{{:uuid}}" >
1134
        <div class="content">
1135
 
1136
 
1137
 
1138
        <div class="sidebar {{if status == '<?php echo JobDescription::STATUS_INACTIVE ?>' }} sidebar-inactive {{/if}}">
1139
 
16778 efrain 1140
        {{>name}}
16779 efrain 1141
        <div class="float-right right-sidebar">
16778 efrain 1142
            {{if status == '<?php echo JobDescription::STATUS_ACTIVE ?>' }}
16770 efrain 1143
            {{if link_add }}
1144
            <i class="fa fa-plus btn-add-job-description" data-link="{{:link_add}}"></i>&nbsp;
1145
            {{/if}}
16778 efrain 1146
            {{/if}}
16770 efrain 1147
            {{if link_edit }}
1148
            <i class="fa fa-pencil btn-edit-job-description" data-link="{{:link_edit}}"></i>&nbsp;
1149
            {{/if}}
1150
            {{if link_delete }}
1151
            <i class="fa fa-trash btn-delete-job-description" data-link="{{:link_delete}}"></i>&nbsp;
1152
            {{/if}}
16778 efrain 1153
            {{if status == '<?php echo JobDescription::STATUS_ACTIVE ?>' }}
16770 efrain 1154
            {{if link_report }}
1155
            <i class="fa fa-file-o btn-pdf-job-description" data-link="{{:link_report}}"></i>&nbsp;
1156
            {{/if}}
16778 efrain 1157
            {{/if}}
16770 efrain 1158
        </div>
16779 efrain 1159
        </div>
1160
        </div>
16770 efrain 1161
        <ol>
1162
	   {{for children tmpl="#listJobDescriptionTemplate"/}}
1163
	   </ol>
1164
	</li>
1165
</script>
15394 efrain 1166