Proyectos de Subversion LeadersLinked - Backend

Rev

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