Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 934 | Rev 936 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 934 Rev 935
Línea 47... Línea 47...
47
 
47
 
Línea 48... Línea 48...
48
$status_active = JobDescription::STATUS_ACTIVE;
48
$status_active = JobDescription::STATUS_ACTIVE;
49
 
49
 
50
$this->inlineScript()->captureStart();
50
$this->inlineScript()->captureStart();
51
echo <<<JS
-
 
52
    jQuery( document ).ready(function( $ ) {
-
 
53
 
51
echo <<<JS
54
 
52
   jQuery(document).ready(function($) {
55
        $.validator.setDefaults({
53
    $.validator.setDefaults({
56
            debug: true,
54
        debug: true,
57
            highlight: function(element) {
55
        highlight: function(element) {
58
                $(element).addClass('is-invalid');
56
            $(element).addClass('is-invalid');
59
            },
57
        },
60
            unhighlight: function(element) {
58
        unhighlight: function(element) {
61
                $(element).removeClass('is-invalid');
59
            $(element).removeClass('is-invalid');
62
            },
60
        },
63
            errorElement: 'span',
61
        errorElement: 'span',
64
            errorClass: 'error invalid-feedback',
62
        errorClass: 'error invalid-feedback',
65
            errorPlacement: function(error, element) {
63
        errorPlacement: function(error, element) {
66
                if(element.parent('.form-group').length) {
64
            if (element.parent('.form-group').length) {
67
                    error.insertAfter(element);
65
                error.insertAfter(element);
68
                } else if(element.parent('.toggle').length) {
66
            } else if (element.parent('.toggle').length) {
69
                    error.insertAfter(element.parent().parent());
67
                error.insertAfter(element.parent().parent());
70
                } else {
-
 
71
                    error.insertAfter(element.parent());
68
            } else {
72
                }
69
                error.insertAfter(element.parent());
73
            }
-
 
74
        });
70
            }
75
    
71
        }
76
    
72
    });
77
        $.fn.showFormErrorValidator = function(fieldname, errors) {
73
    $.fn.showFormErrorValidator = function(fieldname, errors) {
78
            var field = $(fieldname);
74
        var field = $(fieldname);
79
            if(field) {
-
 
80
                $(field).addClass('is-invalid');
-
 
81
    
75
        if (field) {
82
 
76
            $(field).addClass('is-invalid');
83
                var error = $('<span id="' + fieldname +'-error" class="error invalid-feedback">' + errors + '</div>');
77
            var error = $('<span id="' + fieldname + '-error" class="error invalid-feedback">' + errors + '</div>');
84
                if(field.parent('.form-group').length) {
78
            if (field.parent('.form-group').length) {
85
                    error.insertAfter(field);
79
                error.insertAfter(field);
-
 
80
            } else if (field.parent('.toggle').length) {
-
 
81
                error.insertAfter(field.parent().parent());
-
 
82
            } else {
-
 
83
                error.insertAfter(field.parent());
-
 
84
            }
-
 
85
        }
-
 
86
    };
-
 
87
    var allowEdit = $allowEdit;
-
 
88
    var allowDelete = $allowDelete;
-
 
89
    var allowReport = $allowReport;
-
 
90
    var gridTable = $('#gridTable').dataTable({
-
 
91
        'processing': true,
-
 
92
        'serverSide': true,
-
 
93
        'searching': true,
-
 
94
        'order': [
-
 
95
            [0, 'asc']
-
 
96
        ],
-
 
97
        'ordering': true,
-
 
98
        'ordenable': true,
-
 
99
        'responsive': true,
-
 
100
        'select': false,
-
 
101
        'paging': true,
-
 
102
        'pagingType': 'simple_numbers',
-
 
103
        'ajax': {
-
 
104
            'url': '$routeDatatable',
-
 
105
            'type': 'get',
-
 
106
            'beforeSend': function(request) {
-
 
107
                NProgress.start();
-
 
108
            },
-
 
109
            'dataFilter': function(response) {
-
 
110
                var response = jQuery.parseJSON(response);
-
 
111
                var json = {};
-
 
112
                json.recordsTotal = 0;
-
 
113
                json.recordsFiltered = 0;
-
 
114
                json.data = [];
-
 
115
                if (response.success) {
-
 
116
                    json.recordsTotal = response.data.total;
86
                } else  if(field.parent('.toggle').length) {
117
                    json.recordsFiltered = response.data.total;
87
                    error.insertAfter(field.parent().parent());
118
                    json.data = response.data.items;
88
                } else {
119
                } else {
-
 
120
                    $.fn.showError(response.data)
89
                    error.insertAfter(field.parent());
121
                }
90
                }
122
                return JSON.stringify(json);
91
            }
-
 
92
        };
-
 
93
 
-
 
94
 
-
 
95
 
-
 
96
 
-
 
97
 
-
 
98
        var allowEdit   = $allowEdit;
-
 
99
        var allowDelete = $allowDelete;
-
 
100
        var allowReport = $allowReport;
-
 
101
        
-
 
102
        var gridTable = $('#gridTable').dataTable( {
-
 
103
            'processing': true,
-
 
104
            'serverSide': true,
-
 
105
            'searching': true,
-
 
106
            'order': [[ 0, 'asc' ]],
-
 
107
            'ordering':  true,
-
 
108
            'ordenable' : true,
-
 
109
            'responsive': true,
-
 
110
            'select' : false,
-
 
111
        	'paging': true,
-
 
112
            'pagingType': 'simple_numbers',
-
 
113
    		'ajax': {
-
 
114
    			'url' : '$routeDatatable',
-
 
115
    			'type' : 'get',
-
 
116
                'beforeSend': function (request) {
-
 
117
                  NProgress.start();
-
 
118
                },
-
 
119
                'dataFilter': function(response) {
-
 
120
                    var response = jQuery.parseJSON( response );
-
 
121
                    
-
 
122
                    var json                = {};
-
 
123
                    json.recordsTotal       = 0;
-
 
124
                    json.recordsFiltered    = 0;
-
 
125
                    json.data               = [];
-
 
126
                    
-
 
127
                    
-
 
128
                    if(response.success) {
-
 
129
                        json.recordsTotal       = response.data.total;
-
 
130
                        json.recordsFiltered    = response.data.total;
-
 
131
                        json.data               = response.data.items;
-
 
132
                    } else {
-
 
133
                        $.fn.showError(response.data)
-
 
134
                    }
-
 
135
                    
-
 
136
                    return JSON.stringify( json );
-
 
137
                }
123
            }
138
    		},
124
        },
139
            'language' : {
125
        'language': {
140
                'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
126
            'sProcessing': 'LABEL_DATATABLE_SPROCESSING',
141
                'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
127
            'sLengthMenu': 'LABEL_DATATABLE_SLENGTHMENU',
142
                'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
128
            'sZeroRecords': 'LABEL_DATATABLE_SZERORECORDS',
143
                'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
129
            'sEmptyTable': 'LABEL_DATATABLE_SEMPTYTABLE',
144
                'sInfo':           'LABEL_DATATABLE_SINFO',
130
            'sInfo': 'LABEL_DATATABLE_SINFO',
145
                'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
131
            'sInfoEmpty': 'LABEL_DATATABLE_SINFOEMPTY',
146
                'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
132
            'sInfoFiltered': 'LABEL_DATATABLE_SINFOFILTERED',
147
                'sInfoPostFix':    '',
133
            'sInfoPostFix': '',
148
                'sSearch':         'LABEL_DATATABLE_SSEARCH',
134
            'sSearch': 'LABEL_DATATABLE_SSEARCH',
149
                'sUrl':            '',
135
            'sUrl': '',
150
                'sInfoThousands':  ',',
136
            'sInfoThousands': ',',
151
                'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
137
            'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
152
                'oPaginate': {
138
            'oPaginate': {
153
                    'sFirst':    'LABEL_DATATABLE_SFIRST',
139
                'sFirst': 'LABEL_DATATABLE_SFIRST',
154
                    'sLast':     'LABEL_DATATABLE_SLAST',
140
                'sLast': 'LABEL_DATATABLE_SLAST',
155
                    'sNext':     'LABEL_DATATABLE_SNEXT',
-
 
156
                    'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
-
 
157
                },
-
 
158
                'oAria': {
-
 
159
                    'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
-
 
160
                    'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
141
                'sNext': 'LABEL_DATATABLE_SNEXT',
161
                },
-
 
162
            },
142
                'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
163
            'drawCallback': function( settings ) {
-
 
164
                NProgress.done();
-
 
165
                $('button.btn-delete').confirmation({
143
            },
166
                    rootSelector: 'button.btn-delete',
-
 
167
                    title : 'LABEL_ARE_YOU_SURE',
-
 
168
                    singleton : true,
144
            'oAria': {
169
                    btnOkLabel: 'LABEL_YES',
-
 
170
                    btnCancelLabel: 'LABEL_NO',
-
 
171
                    onConfirm: function(value) {
-
 
172
                        action = $(this).data('href');
-
 
173
                        NProgress.start();
-
 
174
                        $.ajax({
-
 
175
                            'dataType'  : 'json',
-
 
176
                            'accept'    : 'application/json',
-
 
177
                            'method'    : 'post',
-
 
178
                            'url'       :  action,
-
 
179
                        }).done(function(response) {
-
 
180
                            if(response['success']) {
-
 
181
                                $.fn.showSuccess(response['data']);
-
 
182
                                gridTable.api().ajax.reload(null, false);
-
 
183
                            } else {
-
 
184
                                $.fn.showError(response['data']);
-
 
185
                            }
-
 
186
                        }).fail(function( jqXHR, textStatus, errorThrown) {
-
 
187
                            $.fn.showError(textStatus);
-
 
188
                        }).always(function() {
-
 
189
                            NProgress.done();
-
 
190
                        });
-
 
191
                    },
145
                'sSortAscending': ': LABEL_DATATABLE_SSORTASCENDING',
-
 
146
                'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
-
 
147
            },
192
                });
148
        },
193
            },
-
 
-
 
149
        'drawCallback': function(settings) {
-
 
150
            NProgress.done();
-
 
151
            $('button.btn-delete').confirmation({
194
            'aoColumns': [
152
                rootSelector: 'button.btn-delete',
195
    
153
                title: 'LABEL_ARE_YOU_SURE',
-
 
154
                singleton: true,
-
 
155
                btnOkLabel: 'LABEL_YES',
-
 
156
                btnCancelLabel: 'LABEL_NO',
196
                { 'mDataProp': 'name' },
157
                onConfirm: function(value) {
197
                { 'mDataProp': 'status' },
158
                    action = $(this).data('href');
-
 
159
                    NProgress.start();
-
 
160
                    $.ajax({
-
 
161
                        'dataType': 'json',
-
 
162
                        'accept': 'application/json',
-
 
163
                        'method': 'post',
-
 
164
                        'url': action,
-
 
165
                    }).done(function(response) {
-
 
166
                        if (response['success']) {
198
                { 'mDataProp': 'actions' },
167
                            $.fn.showSuccess(response['data']);
199
    	    ],
-
 
-
 
168
                            gridTable.api().ajax.reload(null, false);
200
            'columnDefs': [
169
                        } else {
-
 
170
                            $.fn.showError(response['data']);
-
 
171
                        }
201
 
172
                    }).fail(function(jqXHR, textStatus, errorThrown) {
202
                {
173
                        $.fn.showError(textStatus);
-
 
174
                    }).always(function() {
203
                    'targets': 0,
175
                        NProgress.done();
-
 
176
                    });
-
 
177
                },
-
 
178
            });
-
 
179
        },
-
 
180
        'aoColumns': [{
204
                    'className' : 'text-vertical-middle',
181
                'mDataProp': 'name'
-
 
182
            },
-
 
183
            {
-
 
184
                'mDataProp': 'status'
-
 
185
            },
-
 
186
            {
-
 
187
                'mDataProp': 'actions'
-
 
188
            },
-
 
189
        ],
-
 
190
        'columnDefs': [{
-
 
191
                'targets': 0,
-
 
192
                'className': 'text-vertical-middle',
205
                },
193
            },
206
                {
194
            {
207
                    'targets': -2,
195
                'targets': -2,
208
                    'orderable': false,
196
                'orderable': false,
209
                    'className' : 'text-center',
-
 
210
                      'render' : function ( data, type, row ) {
197
                'className': 'text-center',
211
                      
198
                'render': function(data, type, row) {
212
                        checked = data == 'a' ? ' checked="checked" ' : '';
199
                    checked = data == 'a' ? ' checked="checked" ' : '';
213
                        return '<div class="checkbox checkbox-success">' +
200
                    return '<div class="checkbox checkbox-success">' +
-
 
201
                        '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
-
 
202
                        '<label ></label></div>';
-
 
203
                }
-
 
204
            },
-
 
205
            {
-
 
206
                'targets': -1,
-
 
207
                'orderable': false,
-
 
208
                'render': function(data, type, row) {
-
 
209
                    s = '';
214
                            '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
210
                    if (allowEdit) {
215
                            '<label ></label></div>';
-
 
216
                    }
-
 
217
                },
-
 
218
                {
-
 
219
                    'targets': -1,
-
 
220
                    'orderable': false,
-
 
221
                    'render' : function ( data, type, row ) {
-
 
222
                        s = '';
-
 
223
                        
-
 
224
                        if(allowEdit) {
-
 
225
                            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;';
211
                        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;';
226
                        }
212
                    }
227
                        if(allowDelete) {
-
 
228
                            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;';
-
 
229
                        }
-
 
230
                        if(allowReport) {
-
 
231
                            s = s + '<a class="btn btn-default btn-pdf" href="' + data['link_report']+ '" target="_blank" data-toggle="tooltip" title="LABEL_PDF"><i class="fa fa-file-o"></i> LABEL_PDF </button>&nbsp;';
-
 
232
                        }
213
                    if (allowDelete) {
-
 
214
                        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;';
-
 
215
                    }
-
 
216
                    if (allowReport) {
-
 
217
                        s = s + '<a class="btn btn-default btn-pdf" href="' + data['link_report'] + '" target="_blank" data-toggle="tooltip" title="LABEL_PDF"><i class="fa fa-file-o"></i> LABEL_PDF </button>&nbsp;';
233
                        return s;
218
                    }
234
                    }
219
                    return s;
235
                }
220
                }
236
              ],
-
 
237
        });
221
            }
238
 
222
        ],
239
 
223
    });
240
        var validator = $('#form').validate({
224
    var validator = $('#form').validate({
241
            debug: true,
225
        debug: true,
242
            onclick: false,
226
        onclick: false,
243
            onkeyup: false,
227
        onkeyup: false,
244
            ignore: [],
228
        ignore: [],
245
            rules: {
229
        rules: {
246
                'name': {
230
            'name': {
247
                    required: true,
231
                required: true,
248
                    maxlength: 64,
232
                maxlength: 64,
249
                },
233
            },
250
                'functions': {
234
            'functions': {
251
                    updateCkeditor:function() {
-
 
252
                        CKEDITOR.instances.functions.updateElement();
-
 
253
                    },
-
 
254
                    required: true,
-
 
255
                },
-
 
256
                'objectives': {
-
 
257
                    updateCkeditor:function() {
-
 
258
                        CKEDITOR.instances.objectives.updateElement();
-
 
259
                    },
235
                updateCkeditor: function() {
-
 
236
                    CKEDITOR.instances.functions.updateElement();
-
 
237
                },
260
                    required: true,
238
                required: true,
261
                },
239
            },
262
                'status': {
-
 
-
 
240
            'objectives': {
263
                    required: false,
241
                updateCkeditor: function() {
-
 
242
                    CKEDITOR.instances.objectives.updateElement();
264
                    
243
                },
265
                },
-
 
266
            },
-
 
267
            submitHandler: function(form)
-
 
268
            {
-
 
269
                $.ajax({
-
 
270
                    'dataType'  : 'json',
-
 
271
                    'accept'    : 'application/json',
-
 
272
                    'method'    : 'post',
-
 
273
                    'url'       :  $('#form').attr('action'),
-
 
274
                    'data'      :  $('#form').serialize()
-
 
275
                }).done(function(response) {
-
 
276
                    NProgress.start();
-
 
277
                    if(response['success']) {
-
 
278
                        $.fn.showSuccess(response['data']);
-
 
279
                        
-
 
280
                        $('#modal').modal('hide');
-
 
281
                        
-
 
282
                         gridTable.api().ajax.reload(null, false);
-
 
283
                    } else {
-
 
284
                        validator.resetForm();
-
 
285
                        if(jQuery.type(response['data']) == 'string') {
-
 
286
                            $.fn.showError(response['data']);
-
 
287
                        } else  {
-
 
288
                            $.each(response['data'], function( fieldname, errors ) {
-
 
289
                                $.fn.showFormErrorValidator('#form #' + fieldname, errors);
-
 
290
                            });
244
                required: true,
291
                        }
-
 
292
                    }
-
 
293
                }).fail(function( jqXHR, textStatus, errorThrown) {
-
 
294
                   $.fn.showError(textStatus);
-
 
295
                }).always(function() {
-
 
296
                    NProgress.done();
245
            },
297
                });
246
            'status': {
298
                return false;
-
 
299
            },
-
 
300
            invalidHandler: function(form, validator) {
-
 
301
            
247
                required: false,
302
            }
-
 
303
        });
-
 
304
        
248
            },
305
        $('body').on('click', 'button.btn-add', function(e) {
-
 
306
            e.preventDefault();
-
 
307
 
-
 
308
 
-
 
309
            NProgress.start();
249
        },
310
 
250
        submitHandler: function(form) {
311
            $.ajax({
251
            $.ajax({
312
                'dataType'  : 'json',
252
                'dataType': 'json',
313
                'accept'    : 'application/json',
253
                'accept': 'application/json',
-
 
254
                'method': 'post',
314
                'method'    : 'get',
255
                'url': $('#form').attr('action'),
315
                'url'       : '$routeAdd',
-
 
316
            }).done(function(response) {
-
 
317
                if(response['success']) {
-
 
318
 
-
 
319
                    $('span[id="form-title"]').html('LABEL_ADD');
-
 
320
                    $('#form').attr('action', '$routeAdd');
-
 
321
                    $('#form #name').val('');
-
 
322
                    $('#form #status').bootstrapToggle('on');
-
 
323
                    CKEDITOR.instances.functions.setData('');
-
 
324
                    CKEDITOR.instances.objectives.setData('');
-
 
325
 
-
 
326
                    $('#tableCompetencies tbody').empty();
-
 
327
 
-
 
328
 
256
                'data': $('#form').serialize()
329
                    var s = '';
-
 
330
                    var first = true;
-
 
331
                    $.each(response['data']['competency_types'], function(index, rowCompetencyType) {
-
 
332
                        
-
 
333
                        first = true;
-
 
334
                        $.each(response['data']['competencies'], function(index, rowCompetency) {
-
 
335
 
257
            }).done(function(response) {
336
                            if(rowCompetencyType['competency_type_id'] == rowCompetency['competency_type_id']) {
-
 
337
                                if(first) {
-
 
338
                                    first = false;
-
 
339
    
-
 
340
                                    s = '<tr>'  + 
-
 
341
                                        '<td><big><b>' + rowCompetencyType['name'] + '</b></big></td>' +
-
 
342
                                        '<td><big><b>LABEL_LEVEL</b></big></td>' +
-
 
343
                                        '</tr>'; 
-
 
344
 
-
 
345
                                    $('#tableCompetencies tbody').append(s)
-
 
346
                                }
-
 
347
 
-
 
348
                                s = '<tr>'  + 
-
 
349
                                    '<td>' + rowCompetency['name'] + '</td>' +
-
 
350
                                    '<td>' + 
-
 
351
                                    '<select class="form-control" id="competency_level' + rowCompetency['competency_id'] + '" name="competency_level' + rowCompetency['competency_id'] + '">' +
-
 
352
                                    '<option value="0">LABEL_NA</option>' + 
-
 
353
                                    '<option value="1">LABEL_LEVEL_ONE</option>' + 
-
 
354
                                    '<option value="2">LABEL_LEVEL_TWO</option>' + 
-
 
355
                                    '<option value="3">LABEL_LEVEL_THREE</option>' + 
-
 
356
                                    '<option value="4">LABEL_LEVEL_FOUR</option>' + 
-
 
357
                                     '</td>' +
-
 
358
                                    '</tr>'; 
-
 
359
 
-
 
360
                                 $('#tableCompetencies tbody').append(s)
-
 
361
 
-
 
362
                            }
-
 
363
 
-
 
364
         
-
 
365
                        });
-
 
366
 
-
 
367
                    });
258
                NProgress.start();
368
 
-
 
369
                    $('#tableSubordinates tbody').empty();
-
 
370
                    $('#job_description_id_boss option:not(:first)').remove(); 
-
 
371
 
-
 
372
                    $.each(response['data']['jobs_description'], function(index, rowJobDescription) {
-
 
373
                        $('#job_description_id_boss').append(new Option(rowJobDescription['name'], rowJobDescription['job_description_id']));
-
 
374
                    
259
                if (response['success']) {
375
                            s = '<tr>'  + 
-
 
376
                                '<td>' +
260
                    $.fn.showSuccess(response['data']);
377
                                '<div class="custom-control custom-checkbox">' +
-
 
378
                                '<input class="custom-control-input" type="checkbox" name="job_description_id_subordinate' + rowJobDescription['job_description_id']  + '" id="job_description_id_subordinate' + rowJobDescription['job_description_id']  + '" value="1">' +
-
 
379
                                '<label for="job_description_id_subordinate' + rowJobDescription['job_description_id']  + '" class="custom-control-label">' + rowJobDescription['name'] + '</label>' +
-
 
380
                                '</div>' +
-
 
381
                                '</td>' +
-
 
382
                                '</tr>'; 
-
 
383
 
-
 
384
                            $('#tableSubordinates tbody').append(s)
-
 
385
 
-
 
386
 
-
 
387
                    });
-
 
388
        
-
 
389
                    validator.resetForm();
-
 
390
                    $('#custom-tabs #custom-tabs-general-tab').tab('show');
-
 
391
                    $('#modal').modal('show');
261
                    $('#modal').modal('hide');
-
 
262
                    gridTable.api().ajax.reload(null, false);
-
 
263
                } else {
392
 
264
                    validator.resetForm();
-
 
265
                    if (jQuery.type(response['data']) == 'string') {
-
 
266
                        $.fn.showError(response['data']);
-
 
267
                    } else {
-
 
268
                        $.each(response['data'], function(fieldname, errors) {
-
 
269
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
393
                } else {
270
                        });
394
                    $.fn.showError(response['data']);
271
                    }
395
                }
272
                }
396
            }).fail(function( jqXHR, textStatus, errorThrown) {
273
            }).fail(function(jqXHR, textStatus, errorThrown) {
397
                $.fn.showError(textStatus);
274
                $.fn.showError(textStatus);
398
            }).always(function() {
275
            }).always(function() {
399
                NProgress.done();
-
 
400
            });
-
 
-
 
276
                NProgress.done();
401
 
277
            });
-
 
278
            return false;
402
 
279
        },
403
        });
280
        invalidHandler: function(form, validator) {}
404
        
281
    });
405
        $('body').on('click', 'button.btn-edit', function(e) {
282
    $('body').on('click', 'button.btn-add', function(e) {
406
            e.preventDefault();
-
 
407
            NProgress.start();
-
 
408
            var action = $(this).data('href');
283
        e.preventDefault();
409
 
284
        NProgress.start();
410
            $.ajax({
285
        $.ajax({
411
                'dataType'  : 'json',
286
            'dataType': 'json',
412
                'accept'    : 'application/json',
287
            'accept': 'application/json',
413
                'method'    : 'get',
288
            'method': 'get',
414
                'url'       :  action,
289
            'url': '$routeAdd',
415
            }).done(function(response) {
-
 
416
                if(response['success']) {
290
        }).done(function(response) {
417
 
291
            if (response['success']) {
418
                    $('span[id="form-title"]').html('LABEL_EDIT');
292
                $('span[id="form-title"]').html('LABEL_ADD');
419
                    $('#form').attr('action', action);
293
                $('#form').attr('action', '$routeAdd');
420
                    $('#form #name').val(response['data']['name']);
-
 
421
                    $('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
-
 
422
 
294
                $('#form #name').val('');
423
 
295
                $('#form #status').bootstrapToggle('on');
424
                    CKEDITOR.instances.functions.setData(response['data']['functions']);
-
 
425
                    CKEDITOR.instances.objectives.setData(response['data']['objectives']);
296
                CKEDITOR.instances.functions.setData('');
426
 
-
 
427
                    $('#tableCompetencies tbody').empty();
-
 
428
 
297
                CKEDITOR.instances.objectives.setData('');
429
 
298
                $('#tableCompetencies tbody').empty();
430
                    var s = '';
299
                var s = '';
431
                    var first = true;
-
 
432
                    $.each(response['data']['competency_types'], function(index, rowCompetencyType) {
300
                var first = true;
433
                        
301
                $.each(response['data']['competency_types'], function(index, rowCompetencyType) {
434
                        first = true;
-
 
435
                        $.each(response['data']['competencies'], function(index, rowCompetency) {
-
 
436
 
-
 
437
 
302
                    first = true;
438
 
303
                    $.each(response['data']['competencies'], function(index, rowCompetency) {
439
                            if(rowCompetencyType['competency_type_id'] == rowCompetency['competency_type_id']) {
304
                        if (rowCompetencyType['competency_type_id'] == rowCompetency['competency_type_id']) {
440
                                if(first) {
-
 
441
                                    first = false;
305
                            if (first) {
442
    
306
                                first = false;
443
                                    s = '<tr>'  + 
-
 
444
                                        '<td><big><b>' + rowCompetencyType['name'] + '</b></big></td>' +
-
 
445
                                        '</tr>'; 
-
 
446
 
-
 
447
                                    $('#tableCompetencies tbody').append(s)
-
 
448
                                }
-
 
449
 
307
                                s = '<tr>' +
450
                                s = '<tr>'  + 
308
                                    '<td><big><b>' + rowCompetencyType['name'] + '</b></big></td>' +
451
                                    '<td>' + rowCompetency['name'] + '</td>' +
-
 
452
                                    '<td>'; 
309
                                    '<td><big><b>LABEL_LEVEL</b></big></td>' +
453
 
-
 
454
                                 $('#tableCompetencies tbody').append(s)
310
                                    '</tr>';
455
 
-
 
456
                            }
-
 
457
 
-
 
458
         
-
 
459
                        });
-
 
460
 
-
 
461
                    });
-
 
462
 
-
 
463
                    $('#tableSubordinates tbody').empty();
-
 
464
                    $('#job_description_id_boss option:not(:first)').remove(); 
-
 
465
 
-
 
466
                    $.each(response['data']['jobs_description'], function(index, rowJobDescription) {
-
 
467
                        $('#job_description_id_boss').append(new Option(rowJobDescription['name'], rowJobDescription['job_description_id']));
311
                                $('#tableCompetencies tbody').append(s)
468
 
-
 
469
                            checked = '';
-
 
470
                            if($.isArray(response['data']['subordinates'])) {
312
                            }
471
                                if ($.inArray(rowJobDescription['job_description_id'], response['data']['subordinates']) != -1) {
-
 
472
                                    checked = ' checked="checked" ';
-
 
473
                                }
-
 
474
                            }       
-
 
475
 
313
                            s = '<tr>' +
-
 
314
                                '<td>' + rowCompetency['name'] + '</td>' +
-
 
315
                                '<td>' +
476
                            s = '<tr>'  + 
316
                                '<select class="form-control" id="competency_level' + rowCompetency['competency_id'] + '" name="competency_level' + rowCompetency['competency_id'] + '">' +
477
                                '<td>' +
317
                                '<option value="0">LABEL_NA</option>' +
478
                                '<div class="custom-control custom-checkbox">' +
318
                                '<option value="1">LABEL_LEVEL_ONE</option>' +
479
                                '<input class="custom-control-input" type="checkbox" ' + checked + ' name="job_description_id_subordinate' + rowJobDescription['job_description_id']  + '" id="job_description_id_subordinate' + rowJobDescription['job_description_id']  + '" value="1">' +
319
                                '<option value="2">LABEL_LEVEL_TWO</option>' +
480
                                '<label for="job_description_id_subordinate' + rowJobDescription['job_description_id']  + '" class="custom-control-label">' + rowJobDescription['name'] + '</label>' +
320
                                '<option value="3">LABEL_LEVEL_THREE</option>' +
481
                                '</div>' +
321
                                '<option value="4">LABEL_LEVEL_FOUR</option>' +
482
                                '</td>' +
-
 
483
                                '</tr>'; 
322
                                '</td>' +
484
 
-
 
485
                            $('#tableSubordinates tbody').append(s)
-
 
-
 
323
                                '</tr>';
486
 
324
                            $('#tableCompetencies tbody').append(s)
-
 
325
                        }
-
 
326
                    });
-
 
327
                });
-
 
328
                $('#tableSubordinates tbody').empty();
487
 
329
                $('#job_description_id_boss option:not(:first)').remove();
488
                    });
-
 
-
 
330
                $.each(response['data']['jobs_description'], function(index, rowJobDescription) {
-
 
331
                    $('#job_description_id_boss').append(new Option(rowJobDescription['name'], rowJobDescription['job_description_id']));
-
 
332
                    s = '<tr>' +
489
                    $('#job_description_id_boss').val(response['data']['job_description_id_boss']);
333
                        '<td>' +
-
 
334
                        '<div class="custom-control custom-checkbox">' +
-
 
335
                        '<input class="custom-control-input" type="checkbox" name="job_description_id_subordinate' + rowJobDescription['job_description_id'] + '" id="job_description_id_subordinate' + rowJobDescription['job_description_id'] + '" value="1">' +
-
 
336
                        '<label for="job_description_id_subordinate' + rowJobDescription['job_description_id'] + '" class="custom-control-label">' + rowJobDescription['name'] + '</label>' +
-
 
337
                        '</div>' +
-
 
338
                        '</td>' +
-
 
339
                        '</tr>';
490
        
340
                    $('#tableSubordinates tbody').append(s)
491
 
341
                });
492
                    validator.resetForm();
342
                validator.resetForm();
493
                    $('#custom-tabs #custom-tabs-general-tab').tab('show');
343
                $('#custom-tabs #custom-tabs-general-tab').tab('show');
494
                    $('#modal').modal('show');
344
                $('#modal').modal('show');
495
                } else {
345
            } else {
496
                    $.fn.showError(response['data']);
346
                $.fn.showError(response['data']);
497
                }
347
            }
498
            }).fail(function( jqXHR, textStatus, errorThrown) {
348
        }).fail(function(jqXHR, textStatus, errorThrown) {
499
                $.fn.showError(textStatus);
349
            $.fn.showError(textStatus);
500
            }).always(function() {
-
 
501
                NProgress.done();
-
 
502
            });
-
 
503
        });
-
 
504
 
-
 
505
        $('body').on('click', 'button.btn-refresh', function(e) {
-
 
506
            e.preventDefault();
350
        }).always(function() {
507
            gridTable.api().ajax.reload(null, false);
351
            NProgress.done();
-
 
352
        });
-
 
353
    });
-
 
354
    $('body').on('click', 'button.btn-edit', function(e) {
-
 
355
        e.preventDefault();
-
 
356
        NProgress.start();
-
 
357
        var action = $(this).data('href');
-
 
358
        $.ajax({
-
 
359
            'dataType': 'json',
-
 
360
            'accept': 'application/json',
-
 
361
            'method': 'get',
-
 
362
            'url': action,
-
 
363
        }).done(function(response) {
-
 
364
            if (response['success']) {
-
 
365
                $('span[id="form-title"]').html('LABEL_EDIT');
-
 
366
                $('#form').attr('action', action);
-
 
367
                $('#form #name').val(response['data']['name']);
-
 
368
                $('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
-
 
369
                CKEDITOR.instances.functions.setData(response['data']['functions']);
-
 
370
                CKEDITOR.instances.objectives.setData(response['data']['objectives']);
-
 
371
                $('#tableCompetencies tbody').empty();
-
 
372
                var s = '';
-
 
373
                var first = true;
-
 
374
                $.each(response['data']['competency_types'], function(index, rowCompetencyType) {
-
 
375
                    first = true;
-
 
376
                    $.each(response['data']['competencies'], function(index, rowCompetency) {
-
 
377
                        if (rowCompetencyType['competency_type_id'] == rowCompetency['competency_type_id']) {
-
 
378
                            if (first) {
-
 
379
                                first = false;
-
 
380
                                s = '<tr>' +
-
 
381
                                    '<td><big><b>' + rowCompetencyType['name'] + '</b></big></td>' +
-
 
382
                                    '</tr>';
-
 
383
                                $('#tableCompetencies tbody').append(s)
-
 
384
                            }
-
 
385
                            s = '<tr>' +
-
 
386
                                '<td> ' +
-
 
387
                                '<div class="custom-control custom-checkbox">' +
-
 
388
                                '<input class="custom-control-input" type="checkbox" ' + checked + ' name="competency_level' + rowCompetency['competency_id'] + '" id="competency_level' + rowCompetency['competency_id'] + '" value="1">' +
-
 
389
                                '<label for="competency_level' + rowCompetency['competency_id'] + '" class="custom-control-label">' + rowCompetency['name'] + '</label>' +
-
 
390
                                '</div>' +
-
 
391
                                '<td>';
-
 
392
                            $('#tableCompetencies tbody').append(s)
-
 
393
                        }
-
 
394
                    });
-
 
395
                });
-
 
396
                $('#tableSubordinates tbody').empty();
-
 
397
                $('#job_description_id_boss option:not(:first)').remove();
-
 
398
                $.each(response['data']['jobs_description'], function(index, rowJobDescription) {
-
 
399
                    $('#job_description_id_boss').append(new Option(rowJobDescription['name'], rowJobDescription['job_description_id']));
-
 
400
                    checked = '';
-
 
401
                    if ($.isArray(response['data']['subordinates'])) {
-
 
402
                        if ($.inArray(rowJobDescription['job_description_id'], response['data']['subordinates']) != -1) {
-
 
403
                            checked = ' checked="checked" ';
-
 
404
                        }
-
 
405
                    }
-
 
406
                    s = '<tr>' +
508
        });
407
                        '<td>' +
-
 
408
                        '<div class="custom-control custom-checkbox">' +
-
 
409
                        '<input class="custom-control-input" type="checkbox" ' + checked + ' name="job_description_id_subordinate' + rowJobDescription['job_description_id'] + '" id="job_description_id_subordinate' + rowJobDescription['job_description_id'] + '" value="1">' +
-
 
410
                        '<label for="job_description_id_subordinate' + rowJobDescription['job_description_id'] + '" class="custom-control-label">' + rowJobDescription['name'] + '</label>' +
-
 
411
                        '</div>' +
509
        
412
                        '</td>' +
-
 
413
                        '</tr>';
-
 
414
                    $('#tableSubordinates tbody').append(s)
510
 
415
                });
-
 
416
                $('#job_description_id_boss').val(response['data']['job_description_id_boss']);
511
        $('body').on('click', 'button.btn-cancel', function(e) {
417
                validator.resetForm();
-
 
418
                $('#custom-tabs #custom-tabs-general-tab').tab('show');
-
 
419
                $('#modal').modal('show');
-
 
420
            } else {
-
 
421
                $.fn.showError(response['data']);
-
 
422
            }
-
 
423
        }).fail(function(jqXHR, textStatus, errorThrown) {
512
            e.preventDefault();
424
            $.fn.showError(textStatus);
513
            $('#modal').modal('hide');
425
        }).always(function() {
-
 
426
            NProgress.done();
-
 
427
        });
-
 
428
    });
-
 
429
    $('body').on('click', 'button.btn-refresh', function(e) {
514
            $('#div-listing').show();
430
        e.preventDefault();
-
 
431
        gridTable.api().ajax.reload(null, false);
-
 
432
    });
-
 
433
    $('body').on('click', 'button.btn-cancel', function(e) {
-
 
434
        e.preventDefault();
-
 
435
        $('#modal').modal('hide');
515
        });
436
        $('#div-listing').show();
516
 
437
    });
517
        $('body').on('click', 'button.btn-import', function(e) {
438
    $('body').on('click', 'button.btn-import', function(e) {
518
            e.preventDefault();
-
 
519
            NProgress.start();
-
 
520
 
439
        e.preventDefault();
521
 
440
        NProgress.start();
522
            $.ajax({
441
        $.ajax({
523
                'dataType'  : 'json',
442
            'dataType': 'json',
524
                'method'    : 'post',
443
            'method': 'post',
525
                'url'       : '$routeImport',
444
            'url': '$routeImport',
526
            }).done(function(response) {
445
        }).done(function(response) {
527
                if(response['success']) {
446
            if (response['success']) {
528
                    $.fn.showSuccess(response['data']);
447
                $.fn.showSuccess(response['data']);
529
                    gridTable.api().ajax.reload(null, false);
448
                gridTable.api().ajax.reload(null, false);
530
                } else {
449
            } else {
531
                    $.fn.showError(response['data']);
450
                $.fn.showError(response['data']);
532
                }
451
            }
533
            }).fail(function( jqXHR, textStatus, errorThrown) {
452
        }).fail(function(jqXHR, textStatus, errorThrown) {
534
                $.fn.showError(textStatus);
453
            $.fn.showError(textStatus);
535
            }).always(function() {
-
 
536
                NProgress.done();
-
 
537
            });
-
 
538
 
454
        }).always(function() {
539
            return false;
-
 
540
        });
-
 
-
 
455
            NProgress.done();
541
 
456
        });
542
 
457
        return false;
543
 
458
    });
544
        $('#form #status').bootstrapToggle({'on' : 'LABEL_ACTIVE',  'off' : 'LABEL_INACTIVE', 'width' : '160px', 'height' : '40px'});
459
    $('#form #status').bootstrapToggle({
-
 
460
        'on': 'LABEL_ACTIVE',
-
 
461
        'off': 'LABEL_INACTIVE',
545
        CKEDITOR.replace('functions');
462
        'width': '160px',
-
 
463
        'height': '40px'
-
 
464
    });
-
 
465
    CKEDITOR.replace('functions');
546
        CKEDITOR.replace('objectives');
466
    CKEDITOR.replace('objectives');
547
    });
467
});
548
JS;
468
JS;