Proyectos de Subversion LeadersLinked - Backend

Rev

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