Proyectos de Subversion LeadersLinked - Backend

Rev

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

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