Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 1054 Rev 1055
Línea 61... Línea 61...
61
$status_inactive = \LeadersLinked\Model\CompanyPerformanceEvaluationForm::STATUS_INACTIVE;
61
$status_inactive = \LeadersLinked\Model\CompanyPerformanceEvaluationForm::STATUS_INACTIVE;
Línea 62... Línea 62...
62
 
62
 
63
$this->inlineScript()->captureStart();
63
$this->inlineScript()->captureStart();
64
echo <<<JS
64
echo <<<JS
65
   jQuery(document).ready(function($) {
65
   jQuery(document).ready(function($) {
66
    var allowEdit = $allowEdit;
66
            var allowEdit = $allowEdit;
67
    var allowDelete = $allowDelete;
67
            var allowDelete = $allowDelete;
68
    var sections = [];
68
            var sections = [];
69
    /**
69
            /**
70
     * Get rows and set data table
70
             * Get rows and set data table
71
     */
71
             */
72
    var tableForm = $('#gridTable').dataTable({
72
            var tableForm = $('#gridTable').dataTable({
73
        'processing': true,
73
                'processing': true,
74
        'serverSide': true,
74
                'serverSide': true,
75
        'searching': true,
75
                'searching': true,
76
        'order': [
76
                'order': [
77
            [0, 'asc']
77
                    [0, 'asc']
78
        ],
78
                ],
79
        'ordering': true,
79
                'ordering': true,
80
        'ordenable': true,
80
                'ordenable': true,
81
        'responsive': true,
81
                'responsive': true,
82
        'select': false,
82
                'select': false,
83
        'paging': true,
83
                'paging': true,
84
        'pagingType': 'simple_numbers',
84
                'pagingType': 'simple_numbers',
85
        'ajax': {
85
                'ajax': {
86
            'url': '$routeDatatable',
86
                    'url': '$routeDatatable',
87
            'type': 'get',
87
                    'type': 'get',
88
            'beforeSend': function(request) {
88
                    'beforeSend': function(request) {
89
                NProgress.start();
89
                        NProgress.start();
90
            },
90
                    },
91
            'dataFilter': function(response) {
91
                    'dataFilter': function(response) {
92
                var response = jQuery.parseJSON(response);
92
                        var response = jQuery.parseJSON(response);
93
                var json = {};
93
                        var json = {};
94
                json.recordsTotal = 0;
94
                        json.recordsTotal = 0;
95
                json.recordsFiltered = 0;
95
                        json.recordsFiltered = 0;
96
                json.data = [];
96
                        json.data = [];
97
                if (response.success) {
97
                        if (response.success) {
98
                    json.recordsTotal = response.data.total;
98
                            json.recordsTotal = response.data.total;
99
                    json.recordsFiltered = response.data.total;
99
                            json.recordsFiltered = response.data.total;
100
                    json.data = response.data.items;
-
 
101
                } else {
-
 
102
                    $.fn.showError(response.data)
-
 
103
                }
-
 
104
                return JSON.stringify(json);
-
 
105
            }
-
 
106
        },
-
 
107
        'language': {
-
 
108
            'sProcessing': 'LABEL_DATATABLE_SPROCESSING',
-
 
109
            'sLengthMenu': 'LABEL_DATATABLE_SLENGTHMENU',
-
 
110
            'sZeroRecords': 'LABEL_DATATABLE_SZERORECORDS',
-
 
111
            'sEmptyTable': 'LABEL_DATATABLE_SEMPTYTABLE',
-
 
112
            'sInfo': 'LABEL_DATATABLE_SINFO',
-
 
113
            'sInfoEmpty': 'LABEL_DATATABLE_SINFOEMPTY',
-
 
114
            'sInfoFiltered': 'LABEL_DATATABLE_SINFOFILTERED',
-
 
115
            'sInfoPostFix': '',
-
 
116
            'sSearch': 'LABEL_DATATABLE_SSEARCH',
-
 
117
            'sUrl': '',
-
 
118
            'sInfoThousands': ',',
-
 
119
            'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
-
 
120
            'oPaginate': {
-
 
121
                'sFirst': 'LABEL_DATATABLE_SFIRST',
-
 
122
                'sLast': 'LABEL_DATATABLE_SLAST',
-
 
123
                'sNext': 'LABEL_DATATABLE_SNEXT',
-
 
124
                'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
-
 
125
            },
-
 
126
            'oAria': {
-
 
127
                'sSortAscending': ': LABEL_DATATABLE_SSORTASCENDING',
-
 
128
                'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
-
 
129
            },
-
 
130
        },
-
 
131
        'drawCallback': function(settings) {
-
 
132
            NProgress.done();
-
 
133
            $('button.btn-delete').confirmation({
-
 
134
                rootSelector: 'button.btn-delete',
-
 
135
                title: 'LABEL_ARE_YOU_SURE',
-
 
136
                singleton: true,
-
 
137
                btnOkLabel: 'LABEL_YES',
-
 
138
                btnCancelLabel: 'LABEL_NO',
-
 
139
                onConfirm: function(value) {
-
 
140
                    action = $(this).data('href');
-
 
141
                    NProgress.start();
-
 
142
                    $.ajax({
-
 
143
                        'dataType': 'json',
-
 
144
                        'accept': 'application/json',
-
 
145
                        'method': 'post',
-
 
146
                        'url': action,
-
 
147
                    }).done(function(response) {
-
 
148
                        if (response['success']) {
-
 
149
                            $.fn.showSuccess(response['data']);
-
 
150
                            tableForm.fnDraw();
100
                            json.data = response.data.items;
151
                        } else {
101
                        } else {
152
                            $.fn.showError(response['data']);
102
                            $.fn.showError(response.data)
-
 
103
                        }
-
 
104
                        return JSON.stringify(json);
-
 
105
                    }
-
 
106
                },
-
 
107
                'language': {
-
 
108
                    'sProcessing': 'LABEL_DATATABLE_SPROCESSING',
-
 
109
                    'sLengthMenu': 'LABEL_DATATABLE_SLENGTHMENU',
-
 
110
                    'sZeroRecords': 'LABEL_DATATABLE_SZERORECORDS',
-
 
111
                    'sEmptyTable': 'LABEL_DATATABLE_SEMPTYTABLE',
-
 
112
                    'sInfo': 'LABEL_DATATABLE_SINFO',
-
 
113
                    'sInfoEmpty': 'LABEL_DATATABLE_SINFOEMPTY',
-
 
114
                    'sInfoFiltered': 'LABEL_DATATABLE_SINFOFILTERED',
-
 
115
                    'sInfoPostFix': '',
-
 
116
                    'sSearch': 'LABEL_DATATABLE_SSEARCH',
-
 
117
                    'sUrl': '',
-
 
118
                    'sInfoThousands': ',',
-
 
119
                    'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
-
 
120
                    'oPaginate': {
-
 
121
                        'sFirst': 'LABEL_DATATABLE_SFIRST',
-
 
122
                        'sLast': 'LABEL_DATATABLE_SLAST',
-
 
123
                        'sNext': 'LABEL_DATATABLE_SNEXT',
-
 
124
                        'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
-
 
125
                    },
-
 
126
                    'oAria': {
-
 
127
                        'sSortAscending': ': LABEL_DATATABLE_SSORTASCENDING',
-
 
128
                        'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
-
 
129
                    },
-
 
130
                },
-
 
131
                'drawCallback': function(settings) {
-
 
132
                    NProgress.done();
-
 
133
                    $('button.btn-delete').confirmation({
-
 
134
                        rootSelector: 'button.btn-delete',
-
 
135
                        title: 'LABEL_ARE_YOU_SURE',
-
 
136
                        singleton: true,
-
 
137
                        btnOkLabel: 'LABEL_YES',
-
 
138
                        btnCancelLabel: 'LABEL_NO',
-
 
139
                        onConfirm: function(value) {
-
 
140
                            action = $(this).data('href');
-
 
141
                            NProgress.start();
-
 
142
                            $.ajax({
-
 
143
                                'dataType': 'json',
-
 
144
                                'accept': 'application/json',
-
 
145
                                'method': 'post',
-
 
146
                                'url': action,
-
 
147
                            }).done(function(response) {
-
 
148
                                if (response['success']) {
-
 
149
                                    $.fn.showSuccess(response['data']);
-
 
150
                                    tableForm.fnDraw();
-
 
151
                                } else {
-
 
152
                                    $.fn.showError(response['data']);
153
                        }
153
                                }
154
                    }).fail(function(jqXHR, textStatus, errorThrown) {
154
                            }).fail(function(jqXHR, textStatus, errorThrown) {
155
                        $.fn.showError(textStatus);
155
                                $.fn.showError(textStatus);
156
                    }).always(function() {
156
                            }).always(function() {
-
 
157
                                NProgress.done();
-
 
158
                            });
157
                        NProgress.done();
159
                        },
158
                    });
160
                    });
-
 
161
                },
-
 
162
                'aoColumns': [{
-
 
163
                        'mDataProp': 'name'
-
 
164
                    },
-
 
165
                    {
-
 
166
                        'mDataProp': 'language'
-
 
167
                    },
-
 
168
                    {
-
 
169
                        'mDataProp': 'status'
-
 
170
                    },
-
 
171
                    {
-
 
172
                        'mDataProp': 'actions'
-
 
173
                    },
-
 
174
                ],
-
 
175
                'columnDefs': [{
-
 
176
                        'targets': 0,
-
 
177
                        'className': 'text-vertical-middle',
-
 
178
                    },
-
 
179
                    {
-
 
180
                        'targets': 1,
-
 
181
                        'className': 'text-vertical-middle',
-
 
182
                    },
-
 
183
                    {
-
 
184
                        'targets': -2,
-
 
185
                        'orderable': false,
-
 
186
                        'className': 'text-center',
-
 
187
                        'render': function(data, type, row) {
-
 
188
                            checked = data == 'a' ? ' checked="checked" ' : '';
-
 
189
                            return '<div class="checkbox checkbox-success">' +
-
 
190
                                '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
-
 
191
                                '<label ></label></div>';
-
 
192
                        }
-
 
193
                    },
-
 
194
                    {
-
 
195
                        'targets': -1,
-
 
196
                        'orderable': false,
-
 
197
                        'render': function(data, type, row) {
-
 
198
                            s = '';
-
 
199
                            if (allowEdit) {
-
 
200
                                s = s + '<button class="btn btn-primary btn-edit-form" data-href="' + data['link_edit'] + '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pencil"></i> LABEL_EDIT </button>&nbsp;';
-
 
201
                            }
-
 
202
                            if (allowDelete) {
-
 
203
                                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;';
-
 
204
                            }
-
 
205
                            return s;
-
 
206
                        }
-
 
207
                    }
-
 
208
                ],
-
 
209
            });
-
 
210
            /**
-
 
211
             * Clicked on edit form
-
 
212
             */
-
 
213
            $('body').on('click', 'button.btn-edit-form', function(e) {
-
 
214
                e.preventDefault();
-
 
215
                form_id = $(this).data('id')
-
 
216
                var action = $(this).data('href');
-
 
217
                $.ajax({
-
 
218
                    'dataType': 'json',
-
 
219
                    'accept': 'application/json',
-
 
220
                    'method': 'get',
-
 
221
                    'url': action,
-
 
222
                }).done(function(response) {
-
 
223
                    if (response['success']) {
-
 
224
                        $("#rows").html('');
-
 
225
                        sections = [];
-
 
226
                        $('#form-main').attr('action', action);
-
 
227
                        $('#form-main #form-id').val(response['data']['id']),
-
 
228
                            $('#form-main #form-name').val(response['data']['name']),
-
 
229
                            $('#form-main #job_description_id').val(response['data']['job_description_id']);
-
 
230
                        $('#form-main #form-status').val(response['data']['status']);
-
 
231
                        sections = response['data']['content'] || [];
-
 
232
                        renderData(sections);
-
 
233
                        $('#row-lists').hide();
-
 
234
                        $('#row-form').show();
-
 
235
                    } else {
-
 
236
                        $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
-
 
237
                    }
-
 
238
                }).fail(function(jqXHR, textStatus, errorThrown) {
-
 
239
                    $.fn.showError(textStatus);
-
 
240
                });
-
 
241
            });
-
 
242
            /**
-
 
243
             * Clicked add new section
-
 
244
             */
-
 
245
            $('#btn-add-section').click(function(e) {
-
 
246
                $('#form-section #id-section').val('');
-
 
247
                $('#form-section #title-section').val('');
-
 
248
                $('#form-section #text-section').val('');
-
 
249
                $('#form-section #type-section').val($('#form-section #type-section option:first').val());
-
 
250
                $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
159
                },
251
                $('#modal-section').modal('show');
160
            });
252
            });
161
        },
-
 
162
        'aoColumns': [{
253
            /**
163
                'mDataProp': 'name'
254
             * Clicked edit section
164
            },
255
             */
165
            {
256
            /**
166
                'mDataProp': 'language'
257
             * Clicked save section
167
            },
258
             */
168
            {
259
            $('#btn-save-section').click(function(e) {
169
                'mDataProp': 'status'
-
 
170
            },
-
 
171
            {
260
                if ($('#title-section').val() == '') {
172
                'mDataProp': 'actions'
261
                    $.fn.showError('Ingrese un nombre');
173
            },
262
                    return;
174
        ],
263
                } else {
175
        'columnDefs': [{
264
                    if ($('#id-section').val() == "") {
176
                'targets': 0,
265
                        addSection(
177
                'className': 'text-vertical-middle',
-
 
178
            },
-
 
179
            {
266
                            $('#title-section').val(),
180
                'targets': 1,
267
                            $('#text-section').val(),
181
                'className': 'text-vertical-middle',
268
                            $('#type-section').val(),
182
            },
269
                        )
183
            {
270
                    } else {
184
                'targets': -2,
271
                        editSection(
185
                'orderable': false,
272
                            $('#id-section').val(),
186
                'className': 'text-center',
273
                            $('#title-section').val(),
187
                'render': function(data, type, row) {
274
                            $('#text-section').val(),
188
                    checked = data == 'a' ? ' checked="checked" ' : '';
275
                            $('#type-section').val()
-
 
276
                        )
189
                    return '<div class="checkbox checkbox-success">' +
277
                    }
190
                        '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
278
                    $('#modal-section').modal('hide');
191
                        '<label ></label></div>';
279
                    return;
192
                }
280
                }
-
 
281
            });
-
 
282
            /**
193
            },
283
             * Clicked remove section
-
 
284
             */
-
 
285
            $('body').on('click', 'button.btn-delete-section', function(e) {
-
 
286
                e.preventDefault();
-
 
287
                var id_section = $(this).data('section');
-
 
288
                bootbox.confirm({
-
 
289
                    title: "LABEL_DELETE LABEL_SECTION",
-
 
290
                    message: "LABEL_QUESTION_DELETE",
-
 
291
                    buttons: {
-
 
292
                        cancel: {
194
            {
293
                            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
-
 
294
                        },
-
 
295
                        confirm: {
-
 
296
                            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
-
 
297
                        }
-
 
298
                    },
-
 
299
                    callback: function(result) {
-
 
300
                        if (result) {
-
 
301
                            removeSection(id_section);
-
 
302
                        }
-
 
303
                    }
-
 
304
                });
-
 
305
            });
195
                'targets': -1,
306
            $('body').on('click', 'button.btn-edit-section', function(e) {
196
                'orderable': false,
307
                e.preventDefault();
-
 
308
                var id = $(this).data('section');
-
 
309
                console.log(id);
-
 
310
                sections.map((item) => {
-
 
311
                    if (item.id_section == id) {
-
 
312
                        $('#form-section #id-section').val(item.id_section);
-
 
313
                        $('#form-section #title-section').val(item.title);
-
 
314
                        $('#form-section #text-text').val(item.text);
-
 
315
                        $('#form-section #type-section').val(item.type);
-
 
316
                        $('#modal-section').modal('show');
-
 
317
                        return;
-
 
318
                    }
-
 
319
                });
-
 
320
            });
-
 
321
            /**
-
 
322
             * Clicked remove option
-
 
323
             */
-
 
324
            $('body').on('click', 'button.btn-delete-option', function(e) {
-
 
325
                e.preventDefault();
-
 
326
                var id_section = $(this).data('section');
-
 
327
                var id_option = $(this).data('option');
-
 
328
                bootbox.confirm({
-
 
329
                    title: "LABEL_DELETE LABEL_OPTION",
-
 
330
                    message: "LABEL_QUESTION_DELETE",
-
 
331
                    buttons: {
-
 
332
                        cancel: {
197
                'render': function(data, type, row) {
333
                            label: '<i class="fa fa-times"></i> LABEL_CANCEL'
198
                    s = '';
334
                        },
199
                    if (allowEdit) {
335
                        confirm: {
-
 
336
                            label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
-
 
337
                        }
-
 
338
                    },
-
 
339
                    callback: function(result) {
-
 
340
                        if (result) {
-
 
341
                            removeOption(id_section, id_option);
200
                        s = s + '<button class="btn btn-primary btn-edit-form" data-href="' + data['link_edit'] + '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pencil"></i> LABEL_EDIT </button>&nbsp;';
342
                        }
-
 
343
                    }
-
 
344
                });
-
 
345
            });
-
 
346
            /**
-
 
347
             * Clicked add new Option
-
 
348
             */
201
                    }
349
            $('body').on('click', 'button.btn-add-option', function(e) {
-
 
350
                e.preventDefault();
-
 
351
                var id = $(this).data('section');
-
 
352
                $('#section-option').val(id);
202
                    if (allowDelete) {
353
                $('#text-option').val('');
-
 
354
                $('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
-
 
355
                $('#modal-option').modal('show');
-
 
356
                return;
-
 
357
            });
-
 
358
            /**
-
 
359
             * Clicked add new Option
-
 
360
             */
-
 
361
            $('#btn-save-option').click(function(e) {
-
 
362
                if ($('#text-option').val() == '') {
-
 
363
                    $.fn.showError('Ingrese un texto');
-
 
364
                    return;
-
 
365
                } else {
-
 
366
                    if ($('#id-option').val() == "") {
-
 
367
                        addOption(
-
 
368
                            $('#section-option').val(),
-
 
369
                            $('#text-option').val(),
-
 
370
                        )
-
 
371
                    } else {
-
 
372
                        editOption(
-
 
373
                            $('#section-option').val(),
-
 
374
                            $('#id-option').val(),
-
 
375
                            $('#text-option').val(),
203
                        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;';
376
                        )
-
 
377
                    }
204
                    }
378
                    $('#modal-option').modal('hide');
205
                    return s;
379
                    return;
206
                }
380
                }
207
            }
381
            });
208
        ],
-
 
209
    });
-
 
210
    /**
382
            /**
211
     * Clicked on edit form
383
             * Clicked edit Option
212
     */
384
             */
213
    $('body').on('click', 'button.btn-edit-form', function(e) {
385
            $('body').on('click', 'button.btn-edit-option', function(e) {
214
        e.preventDefault();
386
                e.preventDefault();
215
        form_id = $(this).data('id')
387
                var id_section = $(this).data('section');
-
 
388
                var id_option = $(this).data('option');
-
 
389
                sections.map((item) => {
-
 
390
                    if (item.id_section == id_section) {
-
 
391
                        item.options.map((opt) => {
-
 
392
                            if (opt.id_option == id_option) {
-
 
393
                                $('#id-option').val(opt.id_option);
-
 
394
                                $('#section-option').val(opt.id_section);
-
 
395
                                $("#text-option").val(opt.title);
-
 
396
                                $('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
-
 
397
                                $('#modal-option').modal('show');
-
 
398
                                return;
-
 
399
                            }
216
        var action = $(this).data('href');
400
                        });
217
        $.ajax({
401
                    }
-
 
402
                });
218
            'dataType': 'json',
403
            });
219
            'accept': 'application/json',
404
            /**
220
            'method': 'get',
405
             * Clicked new Form
221
            'url': action,
406
             */
-
 
407
            $('button.btn-add-form').click(function(e) {
-
 
408
                $('#form-main').attr('action', '$routeAdd');
222
        }).done(function(response) {
409
                $('#form-main #form-id').val('0');
-
 
410
                $('#form-main #form-name').val('');
-
 
411
                $('#form-main #job_description_id').val('');
223
            if (response['success']) {
412
                $('#form-main #form-status').val('$status_active');
224
                $("#rows").html('');
413
                $("#rows").html('');
225
                sections = [];
-
 
226
                $('#form-main').attr('action', action);
-
 
227
                $('#form-main #form-id').val(response['data']['id']),
-
 
228
                $('#form-main #form-name').val(response['data']['name']),
-
 
229
        $('#form-main #job_description_id').val(response['data']['job_description_id']);
-
 
230
        $('#form-main #form-status').val(response['data']['status']);
-
 
231
        sections=response['data']['content'] || [];
-
 
232
                renderData(sections);
414
                sections = [];
233
                $('#row-lists').hide();
415
                $('#row-lists').hide();
234
                $('#row-form').show();
-
 
235
            } else {
416
                $('#row-form').show();
236
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
417
                $('#form-main #form-name').focus();
237
            }
-
 
238
        }).fail(function(jqXHR, textStatus, errorThrown) {
-
 
239
            $.fn.showError(textStatus);
418
            });
240
        });
-
 
241
    });
-
 
242
    /**
419
            /**
243
     * Clicked add new section
420
             * Clicked cancel new/edit Form
244
     */
421
             */
245
    $('#btn-add-section').click(function(e) {
422
            $('button.btn-edit-cancel').click(function(e) {
246
        $('#form-section #id-section').val('');
-
 
247
        $('#form-section #title-section').val('');
423
                e.preventDefault();
248
        $('#form-section #text-section').val('');
-
 
249
        $('#form-section #type-section').val($('#form-section #type-section option:first').val());
-
 
250
        $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
424
                $('#row-form').hide();
251
        $('#modal-section').modal('show');
425
                $('#row-lists').show();
252
    });
426
            });
253
    /**
427
            /**
254
     * Clicked edit section
428
             * Clicked save and close new/edit Form
255
     */
-
 
256
    /**
429
             */
257
     * Clicked save section
-
 
258
     */
430
            $('button.btn-form-save-close').click(function(e) {
259
    $('#btn-save-section').click(function(e) {
431
                e.preventDefault();
260
        if ($('#title-section').val() == '') {
432
                if ($('#form-name').val() == '') {
261
            $.fn.showError('Ingrese un nombre');
-
 
262
            return;
-
 
263
        } else {
433
                    $.fn.showError('Ingrese un nombre');
264
            if ($('#id-section').val() == "") {
434
                } else if ($('#form-status').val() == '') {
265
                addSection(
435
                    $.fn.showError('Seleccione un status');
266
                    $('#title-section').val(),
436
                } else if ($('#job_description_id').val() == '') {
267
                    $('#text-section').val(),
437
                    $.fn.showError('Seleccione una descripción de cargo');
-
 
438
                } else if (sections.length == 0) {
268
                    $('#type-section').val(),
439
                    $.fn.showError('Debe ingresar al menos una sección');
-
 
440
                } else {
269
                )
441
                    var formId = parseInt($('#form-main #form-id').val());
270
            } else {
442
                    var data = {
271
                editSection(
443
                        'id': formId,
272
                    $('#id-section').val(),
444
                        'name': $('#form-main #form-name').val(),
273
                    $('#title-section').val(),
445
                        'job_description_id': $('#form-main #job_description_id').val(),
274
                    $('#text-section').val(),
446
                        'status': $('#form-main #form-status').val(),
275
                    $('#type-section').val()
447
                        'content': JSON.stringify(objFormGenerator.sections)
276
                )
448
                    }
277
            }
449
                    $.ajax({
278
            $('#modal-section').modal('hide');
-
 
279
            return;
-
 
280
        }
-
 
281
    });
-
 
282
    /**
450
                        'dataType': 'json',
283
     * Clicked remove section
-
 
284
     */
451
                        'method': 'post',
285
    $('body').on('click', 'button.btn-delete-section', function(e) {
452
                        'url': $('#form-main').attr('action'),
286
        e.preventDefault();
453
                        'data': data,
287
        var id_section = $(this).data('section');
454
                    }).done(function(response) {
288
        bootbox.confirm({
455
                        if (response['success']) {
289
            title: "LABEL_DELETE LABEL_SECTION",
456
                            $.fn.showSuccess(response['data']);
290
            message: "LABEL_QUESTION_DELETE",
457
                            $('#row-form').hide();
291
            buttons: {
458
                            $('#row-lists').show();
292
                cancel: {
459
                            /*---------- Reset Form -------- */
293
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
460
                            $('#form-main')[0].reset();
294
                },
461
                            /*--------Reset Sections ----------*/
295
                confirm: {
462
                            sections = [];
296
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
463
                            tableForm.fnDraw();
297
                }
-
 
298
            },
464
                        } else {
299
            callback: function(result) {
465
                            $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
300
                if (result) {
466
                        }
301
                    removeSection(id_section);
467
                    });
-
 
468
                }
-
 
469
            });
-
 
470
            /**
-
 
471
             * Remove Html Tags
-
 
472
             */
-
 
473
            const removeTags = (str) => str.toString().replace(/(<([^>]+)>)/ig, '')
-
 
474
            /**
-
 
475
             * Render Sections data
-
 
476
             */
-
 
477
            const renderData = (data) => {
-
 
478
                console.log(data);
-
 
479
                $("#rows").html($("#sectionTemplate").render(data));
-
 
480
            }
-
 
481
            /**
-
 
482
             * Add Section to array
-
 
483
             */
-
 
484
            const addSection = (title, text, type) => {
-
 
485
                sections.push({
-
 
486
                    'id_section': new Date().getTime(),
-
 
487
                    'title': title,
-
 
488
                    'type': type,
-
 
489
                    'text': text,
-
 
490
                    'options': []
-
 
491
                });
302
                }
492
                renderData(sections);
303
            }
493
            }
304
        });
-
 
305
    });
-
 
306
    $('body').on('click', 'button.btn-edit-section', function(e) {
494
            /**
307
        e.preventDefault();
495
             * Edit item behavior
308
        var id = $(this).data('section');
496
             */
309
        console.log(id);
497
            const editSection = (id, title, text, type) => {
310
        sections.map((item) => {
498
                sections.map((item) => {
311
            if (item.id_section == id) {
499
                    if (item.id_section == id) {
312
                $('#form-section #id-section').val(item.id_section);
500
                        item.title = title;
313
                $('#form-section #title-section').val(item.title);
501
                        item.type = type;
314
                $('#form-section #text-text').val(item.text);
502
                        item.text = text;
315
                $('#form-section #type-section').val(item.type);
503
                    }
316
                $('#modal-section').modal('show');
504
                });
317
                return;
505
                renderData(sections);
318
            }
-
 
319
        });
-
 
320
    });
-
 
321
     /**
-
 
322
     * Clicked remove option
-
 
323
     */
-
 
324
    $('body').on('click', 'button.btn-delete-option', function(e) {
-
 
325
        e.preventDefault();
-
 
326
        var id_section = $(this).data('section');
-
 
327
        var id_option = $(this).data('option');
-
 
328
        bootbox.confirm({
-
 
329
            title: "LABEL_DELETE LABEL_OPTION",
-
 
330
            message: "LABEL_QUESTION_DELETE",
-
 
331
            buttons: {
-
 
332
                cancel: {
-
 
333
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
506
            }
334
                },
507
            /**
335
                confirm: {
-
 
336
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
-
 
337
                }
508
             * Remove behavior
338
            },
509
             */
339
            callback: function(result) {
-
 
340
                if (result) {
510
            const removeSection = (id) => {
341
                    removeOption(id_section, id_option);
511
                sections = sections.filter((item) => item.id_section != id);
342
                }
512
                renderData(sections);
343
            }
-
 
344
        });
-
 
345
    });
-
 
346
    /**
-
 
347
     * Clicked add new Option
-
 
348
     */
-
 
349
    $('body').on('click', 'button.btn-add-option', function(e) {
-
 
350
        e.preventDefault();
-
 
351
        var id = $(this).data('section');
-
 
352
        $('#section-option').val(id);
-
 
353
        $('#text-option').val('');
-
 
354
        $('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
-
 
355
        $('#modal-option').modal('show');
-
 
356
        return;
-
 
357
    });
-
 
358
    /**
-
 
359
     * Clicked add new Option
-
 
360
     */
-
 
361
    $('#btn-save-option').click(function(e) {
-
 
362
        if ($('#text-option').val() == '') {
-
 
363
            $.fn.showError('Ingrese un texto');
-
 
364
            return;
-
 
365
        } else {
-
 
366
            if ($('#id-option').val() == "") {
-
 
367
            addOption(
-
 
368
                $('#section-option').val(),
-
 
369
                $('#text-option').val(),
513
            }
370
            )
-
 
371
        } else {
-
 
372
            editOption(
-
 
373
                $('#section-option').val(),
514
            /**
374
                $('#id-option').val(),
-
 
375
                $('#text-option').val(),
515
             * Add Option to array
376
            )
-
 
377
        }
-
 
378
            $('#modal-option').modal('hide');
-
 
379
            return;
-
 
380
        }
-
 
381
    });
-
 
382
    /**
-
 
383
     * Clicked edit Option
-
 
384
     */
-
 
385
    $('body').on('click', 'button.btn-edit-option', function(e) {
-
 
386
        e.preventDefault();
-
 
387
        var id_section = $(this).data('section');
516
             */
388
        var id_option = $(this).data('option');
517
            const addOption = (id_section, title) => {
389
        sections.map((item) => {
518
                sections.map((item) => {
390
            if (item.id_section == id_section) {
519
                    if (item.id_section == id_section) {
391
                item.options.map((opt) => {
520
                        item.options.push({
392
                    if (opt.id_option == id_option) {
521
                            'id_section': id_section,
393
                        $('#id-option').val(opt.id_option);
-
 
394
                        $('#section-option').val(opt.id_section);
522
                            'id_option': new Date().getTime(),
395
                        $("#text-option").val(opt.title);
-
 
396
                        $('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
-
 
397
                        $('#modal-option').modal('show');
523
                            'title': title,
398
                        return;
524
                        });
399
                    }
525
                    }
-
 
526
                });
400
                });
527
                renderData(sections);
401
            }
-
 
402
        });
-
 
403
    });
-
 
404
    /**
-
 
405
     * Clicked new Form
-
 
406
     */
-
 
407
    $('button.btn-add-form').click(function(e) {
-
 
408
        $('#form-main').attr('action', '$routeAdd');
-
 
409
        $('#form-main #form-id').val('0');
-
 
410
        $('#form-main #form-name').val('');
-
 
411
        $('#form-main #job_description_id').val('');
-
 
412
        $('#form-main #form-status').val('$status_active');
-
 
413
        $("#rows").html('');
-
 
414
        sections = [];
-
 
415
        $('#row-lists').hide();
-
 
416
        $('#row-form').show();
-
 
417
        $('#form-main #form-name').focus();
-
 
418
    });
-
 
419
    /**
-
 
420
     * Clicked cancel new/edit Form
-
 
421
     */
-
 
422
    $('button.btn-edit-cancel').click(function(e) {
-
 
423
        e.preventDefault();
-
 
424
        $('#row-form').hide();
-
 
425
        $('#row-lists').show();
-
 
426
    });
-
 
427
    /**
-
 
428
     * Clicked save and close new/edit Form
-
 
429
     */
-
 
430
    $('button.btn-form-save-close').click(function(e) {
-
 
431
 
-
 
432
        e.preventDefault();
-
 
433
 
-
 
434
        if($('#form-name').val()==''){
-
 
435
            $.fn.showError('Ingrese un nombre');
-
 
436
        }
-
 
437
        else if($('#form-status').val()==''){
-
 
438
            $.fn.showError('Seleccione un status');
-
 
439
        }
-
 
440
        else if($('#job_description_id').val()==''){
-
 
441
            $.fn.showError('Seleccione una descripción de cargo');
-
 
442
        }
-
 
443
        else if(sections.length == 0){
-
 
444
            $.fn.showError('Debe ingresar al menos una sección');
528
            }
445
        }else{
-
 
446
 
-
 
447
            var formId = parseInt($('#form-main #form-id').val());
-
 
448
 
-
 
449
                var data = {
529
            /**
450
                    'id': formId,
-
 
451
                    'name': $('#form-main #form-name').val(),
-
 
452
                    'job_description_id': $('#form-main #job_description_id').val(),
-
 
453
                    'status': $('#form-main #form-status').val(),
-
 
454
                    'content': JSON.stringify(objFormGenerator.sections)
530
             * Edit item Option
455
                }
-
 
456
                $.ajax({
-
 
457
                    'dataType': 'json',
-
 
458
                    'method': 'post',
531
             */
459
                    'url': $('#form-main').attr('action'),
-
 
460
                    'data': data,
532
            const editOption = (id_section, id, title) => {
461
                }).done(function(response) {
533
                sections.map((item) => {
462
                    if (response['success']) {
534
                    if (item.id_section == id_section) {
463
                        $.fn.showSuccess(response['data']);
535
                        item.options.map((opt) => {
464
                            $('#row-form').hide();
536
                            if (opt.id_option == id) {
465
                            $('#row-lists').show();
-
 
466
                        /*---------- Reset Form -------- */
-
 
467
                        $('#form-main')[0].reset();
-
 
468
                        /*--------Reset Sections ----------*/
537
                                opt.title = title
469
                        sections = [];
-
 
470
                        tableForm.fnDraw();
538
                            }
471
                    } else {
-
 
472
                        $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
539
                        });
473
                    }
-
 
474
 
-
 
475
        }
-
 
476
     
-
 
477
    });
-
 
478
    /**
-
 
479
     * Remove Html Tags
-
 
480
     */
-
 
481
    const removeTags = (str) => str.toString().replace(/(<([^>]+)>)/ig, '')
-
 
482
    /**
-
 
483
     * Render Sections data
-
 
484
     */
-
 
485
    const renderData = (data) => {
-
 
486
        console.log(data);
-
 
487
        $("#rows").html($("#sectionTemplate").render(data));
-
 
488
    }
-
 
489
    /**
-
 
490
     * Add Section to array
-
 
491
     */
-
 
492
    const addSection = (title, text, type) => {
-
 
493
        sections.push({
-
 
494
            'id_section': new Date().getTime(),
-
 
495
            'title': title,
-
 
496
            'type': type,
-
 
497
            'text': text,
-
 
498
            'options': []
-
 
499
        });
-
 
500
        renderData(sections);
-
 
501
    }
-
 
502
    /**
-
 
503
     * Edit item behavior
-
 
504
     */
-
 
505
    const editSection = (id, title, text, type) => {
-
 
506
        sections.map((item) => {
-
 
507
            if (item.id_section == id) {
-
 
508
                item.title = title;
-
 
509
                item.type = type;
-
 
510
                item.text = text;
-
 
511
            }
-
 
512
        });
-
 
513
        renderData(sections);
-
 
514
    }
-
 
515
    /**
-
 
516
     * Remove behavior
-
 
517
     */
-
 
518
    const removeSection = (id) => {
-
 
519
        sections = sections.filter((item) => item.id_section != id);
-
 
520
        renderData(sections);
-
 
521
    }
-
 
522
    /**
-
 
523
     * Add Option to array
-
 
524
     */
-
 
525
    const addOption = (id_section, title) => {
-
 
526
        sections.map((item) => {
-
 
527
            if (item.id_section == id_section) {
-
 
528
                item.options.push({
-
 
529
                     'id_section': id_section,
-
 
530
                    'id_option': new Date().getTime(),
-
 
531
                    'title': title,
540
                    }
-
 
541
                });
532
                });
542
                renderData(sections);
533
            }
543
            }
534
        });
-
 
535
        renderData(sections);
-
 
536
    }
-
 
537
    /**
544
            /**
538
     * Edit item Option
545
             * Remove Option
539
     */
546
             */
540
    const editOption = (id_section, id, title ) => {
547
            const removeOption = (id_section, id) => {
541
        sections.map((item) => {
548
                sections.map((item) => {
542
            if (item.id_section == id_section) {
-
 
543
                item.options.map((opt) => {
549
                    if (item.id_section == id_section) {
544
                    if (opt.id_option == id) {
-
 
545
                        opt.title = title
550
                        item.options = item.options.filter((opt) => opt.id_option != id) || []
546
                    }
551
                    }
-
 
552
                });
547
                });
553
                renderData(sections);
548
            }
-
 
549
        });
-
 
550
        renderData(sections);
-
 
551
    }
-
 
552
    /**
-
 
553
     * Remove Option
-
 
554
     */
-
 
555
    const removeOption = (id_section, id) => {
-
 
556
        sections.map((item) => {
-
 
557
            if (item.id_section == id_section) {
-
 
558
                item.options = item.options.filter((opt) => opt.id_option != id) || []
554
            }
559
            }
-
 
560
        });
-
 
561
        renderData(sections);
-
 
562
    }
-
 
563
    /**
555
            /**
564
     * Clicked refresh button
556
             * Clicked refresh button
565
     */
557
             */
566
    $('button.btn-refresh').click(function(e) {
558
            $('button.btn-refresh').click(function(e) {
567
        tableForm.fnDraw();
559
                tableForm.fnDraw();
568
    });
560
            });
569
});
561
});
570
JS;
562
JS;
571
$this->inlineScript()->captureEnd();
563
$this->inlineScript()->captureEnd();
572
?>
564
?>