Proyectos de Subversion LeadersLinked - Backend

Rev

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