Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16840 | | Comparar con el anterior | Ultima modificación | Ver Log |

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