Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
3896 stevensc 1
<?php
1 www 2
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
3
$currentUser    = $this->currentUserHelper();
4
 
5
$roleName = $currentUser->getUserTypeId();
6
 
7
 
8
$routeAdd       = $this->url('settings/competencies/add');
9
$routeDatatable = $this->url('settings/competencies');
28 efrain 10
$routeImport    = $this->url('settings/competencies/import');
1 www 11
 
1107 geraldo 12
 
13
$routeAddBehavior    = $this->url('settings/behaviors/add');
14
 
1108 geraldo 15
 
1107 geraldo 16
$routeImport    = $this->url('settings/competencies/import');
17
 
18
 
28 efrain 19
$allowAdd       = $acl->isAllowed($roleName, 'settings/competencies/add') ? 1 : 0;
20
$allowEdit      = $acl->isAllowed($roleName, 'settings/competencies/edit') ? 1 : 0;
21
$allowDelete    = $acl->isAllowed($roleName, 'settings/competencies/delete') ? 1 : 0;
22
$allowImport    = $acl->isAllowed($roleName, 'settings/competencies/import') ? 1 : 0;
1 www 23
 
24
 
25
 
26
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
27
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
28
 
29
$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));
30
 
31
 
32
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
33
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
34
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
35
 
36
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
37
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
38
 
39
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
40
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
41
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
42
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
43
 
44
 
45
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
46
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
47
 
48
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
49
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
50
 
51
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/select2.js'));
52
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/i18n/es.js'));
53
$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.css'));
54
 
55
$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.css'));
56
 
874 geraldo 57
// JsRender //
58
$this->inlineScript()->appendFile($this->basePath('plugins/jsrender/jsrender.min.js'));
1 www 59
 
883 geraldo 60
// bootbox Alert //
61
$this->inlineScript()->appendFile($this->basePath('plugins/bootbox/bootbox.min.js'));
1 www 62
 
883 geraldo 63
 
1 www 64
$status_active = \LeadersLinked\Model\Competency::STATUS_ACTIVE;
65
 
66
$this->inlineScript()->captureStart();
67
echo <<<JS
877 geraldo 68
let behaviors = [];
69
jQuery(document).ready(function($) {
863 geraldo 70
    $.validator.setDefaults({
71
        debug: true,
72
        highlight: function(element) {
73
            $(element).addClass('is-invalid');
74
        },
75
        unhighlight: function(element) {
76
            $(element).removeClass('is-invalid');
77
        },
78
        errorElement: 'span',
79
        errorClass: 'error invalid-feedback',
80
        errorPlacement: function(error, element) {
81
            const child = element.children(':first-child');
82
            if (element[0].localName == 'input') {
83
                let _error = error
84
                _error[0].style.display = 'block'
85
                _error.insertBefore(element);
86
            } else if (element.parent('.form-group').length) {
87
                error.insertAfter(element);
88
            } else if (element.parent('.toggle').length) {
89
                error.insertAfter(element.parent().parent());
90
            } else {
91
                error.insertAfter(element.parent());
92
            }
93
        }
94
    });
95
    $.fn.showFormErrorValidator = function(fieldname, errors) {
96
        var field = $(fieldname);
97
        if (field) {
98
            $(field).addClass('is-invalid');
99
            var error = $('<span id="' + fieldname + '-error" class="error invalid-feedback">' + errors + '</div>');
100
            if (field.parent('.form-group').length) {
101
                error.insertAfter(field);
102
            } else if (field.parent('.toggle').length) {
103
                error.insertAfter(field.parent().parent());
104
            } else {
105
                error.insertAfter(field.parent());
106
            }
107
        }
108
    };
109
    var allowEdit = $allowEdit;
110
    var allowDelete = $allowDelete;
111
    var gridTable = $('#gridTable').dataTable({
112
        'processing': true,
113
        'serverSide': true,
114
        'searching': true,
115
        'order': [
116
            [0, 'asc']
117
        ],
118
        'ordering': true,
119
        'ordenable': true,
120
        'responsive': true,
121
        'select': false,
122
        'paging': true,
123
        'pagingType': 'simple_numbers',
124
        'ajax': {
125
            'url': '$routeDatatable',
126
            'type': 'get',
127
            'beforeSend': function(request) {
128
                NProgress.start();
1 www 129
            },
863 geraldo 130
            'dataFilter': function(response) {
131
                var response = jQuery.parseJSON(response);
132
                var json = {};
133
                json.recordsTotal = 0;
134
                json.recordsFiltered = 0;
135
                json.data = [];
136
                if (response.success) {
137
                    json.recordsTotal = response.data.total;
138
                    json.recordsFiltered = response.data.total;
139
                    json.data = response.data.items;
1 www 140
                } else {
863 geraldo 141
                    $.fn.showError(response.data)
1 www 142
                }
863 geraldo 143
                return JSON.stringify(json);
1 www 144
            }
863 geraldo 145
        },
146
        'language': {
147
            'sProcessing': 'LABEL_DATATABLE_SPROCESSING',
148
            'sLengthMenu': 'LABEL_DATATABLE_SLENGTHMENU',
149
            'sZeroRecords': 'LABEL_DATATABLE_SZERORECORDS',
150
            'sEmptyTable': 'LABEL_DATATABLE_SEMPTYTABLE',
151
            'sInfo': 'LABEL_DATATABLE_SINFO',
152
            'sInfoEmpty': 'LABEL_DATATABLE_SINFOEMPTY',
153
            'sInfoFiltered': 'LABEL_DATATABLE_SINFOFILTERED',
154
            'sInfoPostFix': '',
155
            'sSearch': 'LABEL_DATATABLE_SSEARCH',
156
            'sUrl': '',
157
            'sInfoThousands': ',',
158
            'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
159
            'oPaginate': {
160
                'sFirst': 'LABEL_DATATABLE_SFIRST',
161
                'sLast': 'LABEL_DATATABLE_SLAST',
162
                'sNext': 'LABEL_DATATABLE_SNEXT',
163
                'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
164
            },
165
            'oAria': {
166
                'sSortAscending': ': LABEL_DATATABLE_SSORTASCENDING',
167
                'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
168
            },
169
        },
4116 stevensc 170
        'drawCallback': function(settings) {
171
            NProgress.done();
172
            $('button.btn-delete').confirmation({
173
                rootSelector: 'button.btn-delete',
174
                title: 'LABEL_ARE_YOU_SURE',
175
                singleton: true,
176
                btnOkLabel: 'LABEL_YES',
177
                btnCancelLabel: 'LABEL_NO',
178
                onConfirm: function(value) {
179
                    action = $(this).data('href');
180
                    NProgress.start();
181
                    $.ajax({
182
                        'dataType': 'json',
183
                        'accept': 'application/json',
184
                        'method': 'post',
185
                        'url': action,
186
                    }).done(function(response) {
187
                        if (response['success']) {
188
                            $.fn.showSuccess(response['data']);
189
                            gridTable.api().ajax.reload(null, false);
190
                        } else {
191
                            $.fn.showError(response['data']);
192
                        }
193
                    }).fail(function(jqXHR, textStatus, errorThrown) {
194
                        $.fn.showError(textStatus);
195
                    }).always(function() {
196
                        NProgress.done();
197
                    });
198
                }
199
            });
200
        },
863 geraldo 201
        'aoColumns': [{
202
                'mDataProp': 'type'
203
            },
204
            {
205
                'mDataProp': 'name'
206
            },
207
            {
208
                'mDataProp': 'status'
209
            },
210
            {
211
                'mDataProp': 'actions'
212
            },
213
        ],
214
        'columnDefs': [{
215
                'targets': 0,
216
                'className': 'text-vertical-middle',
217
            },
218
            {
219
                'targets': 1,
220
                'className': 'text-vertical-middle',
221
            },
222
            {
223
                'targets': -2,
224
                'orderable': false,
225
                'className': 'text-center',
226
                'render': function(data, type, row) {
227
                    checked = data == 'a' ? ' checked="checked" ' : '';
228
                    return '<div class="checkbox checkbox-success">' +
229
                        '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
230
                        '<label ></label></div>';
1 www 231
                }
232
            },
863 geraldo 233
            {
234
                'targets': -1,
235
                'orderable': false,
236
                'render': function(data, type, row) {
237
                    s = '';
238
                    if (allowEdit) {
239
                        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;';
1 www 240
                    }
863 geraldo 241
                    if (allowDelete) {
4130 stevensc 242
                        s =
243
                        s + '<button
244
                                class="btn btn-danger btn-delete"
245
                                data-href="' + data['link_delete'] + '"
246
                                data-toggle="delete-confirmation"
247
                                data-popout="true"
248
                                title="LABEL_DELETE"
249
                            >
250
                                <i class="fa fa-trash"></i>
251
                                LABEL_DELETE
252
                            </button>&nbsp;';
1 www 253
                    }
863 geraldo 254
                    return s;
1 www 255
                }
863 geraldo 256
            }
257
        ],
258
    });
259
    var validator = $('#form').validate({
260
        debug: true,
261
        onclick: false,
262
        onkeyup: false,
263
        ignore: [],
264
        rules: {
265
            'competency_type_id': {
266
                required: true,
267
            },
268
            'name': {
269
                required: true,
270
                maxlength: 128,
271
            },
272
            'description': {
273
                updateCkeditor: function() {
274
                    CKEDITOR.instances.description.updateElement();
1 www 275
                },
863 geraldo 276
                required: true,
1 www 277
            },
863 geraldo 278
            'status': {
279
                required: false,
1 www 280
            },
863 geraldo 281
        },
282
        submitHandler: function(form) {
893 geraldo 283
            if (behaviors.length == 0) {
1085 geraldo 284
                $.fn.showError('ERROR_NOT_OBSERVABLE_CONDUCT');
893 geraldo 285
            } else {
891 geraldo 286
                $.ajax({
893 geraldo 287
                    'dataType': 'json',
288
                    'accept': 'application/json',
289
                    'method': 'post',
290
                    'url': $('#form').attr('action'),
291
                    'data': {
292
                        'name': $('#name').val(),
293
                        'description': $('#description').val(),
294
                        'competency_type_id': $('#competency_type_id').val(),
295
                        'status': $('#status').val(),
296
                        'behaviors': JSON.stringify(behaviors)
297
                    }
298
                }).done(function(response) {
299
                    NProgress.start();
300
                    if (response['success']) {
301
                        $.fn.showSuccess(response['data']);
302
                        $('#row-form').hide();
303
                        $('#row-list').show();
304
                        gridTable.api().ajax.reload(null, false);
863 geraldo 305
                    } else {
893 geraldo 306
                        validator.resetForm();
307
                        if (jQuery.type(response['data']) == 'string') {
308
                            $.fn.showError(response['data']);
309
                        } else {
310
                            $.each(response['data'], function(fieldname, errors) {
311
                                $.fn.showFormErrorValidator('#form #' + fieldname, errors);
312
                            });
313
                        }
863 geraldo 314
                    }
893 geraldo 315
                }).fail(function(jqXHR, textStatus, errorThrown) {
316
                    $.fn.showError(textStatus);
317
                }).always(function() {
318
                    NProgress.done();
319
                });
891 geraldo 320
            }
28 efrain 321
            return false;
863 geraldo 322
        },
323
        invalidHandler: function(form, validator) {}
324
    });
325
    $('body').on('click', 'button.btn-add', function(e) {
326
        e.preventDefault();
327
        $('span[id="form-title"]').html('LABEL_ADD');
328
        $('#form').attr('action', '$routeAdd');
329
        $('#form #name').val('');
330
        $('#form #competency_type_id').val('').trigger('change');
331
        $('#form #status').bootstrapToggle('on');
1115 geraldo 332
        behaviors = [];
863 geraldo 333
        CKEDITOR.instances.description.setData('');
334
        validator.resetForm();
866 geraldo 335
        $('#row-form').show();
873 geraldo 336
        $('#row-list').hide();
1132 geraldo 337
        renderData([]);
863 geraldo 338
        return false;
339
    });
340
    $('body').on('click', 'button.btn-edit', function(e) {
341
        e.preventDefault();
342
        NProgress.start();
343
        var action = $(this).data('href');
344
        $.ajax({
345
            'dataType': 'json',
346
            'method': 'get',
347
            'url': action,
348
        }).done(function(response) {
349
            if (response['success']) {
350
                $('span[id="form-title"]').html('LABEL_EDIT');
351
                $('#form').attr('action', action);
352
                $('#form #name').val(response['data']['name']);
353
                $('#form #competency_type_id').val(response['data']['competency_type_id']).trigger('change');
354
                $('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
355
                CKEDITOR.instances.description.setData(response['data']['description']);
1115 geraldo 356
                behaviors = response['data']['behaviors'] || [];
901 geraldo 357
                renderData(behaviors);
863 geraldo 358
                validator.resetForm();
866 geraldo 359
                $('#row-form').show();
873 geraldo 360
                $('#row-list').hide();
863 geraldo 361
            } else {
362
                $.fn.showError(response['data']);
363
            }
364
        }).fail(function(jqXHR, textStatus, errorThrown) {
365
            $.fn.showError(textStatus);
366
        }).always(function() {
367
            NProgress.done();
28 efrain 368
        });
863 geraldo 369
        return false;
370
    });
371
    $('body').on('click', 'button.btn-refresh', function(e) {
372
        e.preventDefault();
373
        gridTable.api().ajax.reload(null, false);
374
        return false;
375
    });
376
    $('body').on('click', 'button.btn-import', function(e) {
377
        e.preventDefault();
378
        NProgress.start();
379
        $.ajax({
380
            'dataType': 'json',
381
            'method': 'post',
382
            'url': '$routeImport',
383
        }).done(function(response) {
384
            if (response['success']) {
385
                $.fn.showSuccess(response['data']);
386
                gridTable.api().ajax.reload(null, false);
387
            } else {
388
                $.fn.showError(response['data']);
389
            }
390
        }).fail(function(jqXHR, textStatus, errorThrown) {
391
            $.fn.showError(textStatus);
392
        }).always(function() {
393
            NProgress.done();
1 www 394
        });
863 geraldo 395
        return false;
396
    });
397
    $('body').on('click', 'button.btn-cancel', function(e) {
398
        e.preventDefault();
399
        $('#modal').modal('hide');
400
    });
401
    $('#form #competency_type_id').select2({
402
        theme: 'bootstrap4',
403
        width: '100%',
404
    });
1226 geraldo 405
 
406
    $('#select-conduct').select2({
407
        theme: 'bootstrap4',
408
        width: '100%',
409
    });
410
 
863 geraldo 411
    $('#form #status').bootstrapToggle({
412
        'on': 'LABEL_ACTIVE',
413
        'off': 'LABEL_INACTIVE',
414
        'width': '160px',
415
        'height': '40px'
416
    });
3842 stevensc 417
    CKEDITOR.replace('description', {
418
        toolbar: [
419
            { name: 'editing', items: [ 'Scayt' ] },
420
            { name: 'links', items: [ 'Link', 'Unlink'] },
421
            { name: 'paragraph', items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote' ] },
422
            { name: 'basicstyles', items: [ 'Bold', 'Italic', 'Strike', 'RemoveFormat' ] },
423
            '/',
424
            { name: 'insert', items: [ 'Image', 'Table', 'HorizontalRule', 'SpecialChar' ] },
425
            { name: 'styles', items: [ 'Styles', 'Format' ] },
426
            { name: 'tools', items: [ 'Maximize' ] }
427
        ],
3926 stevensc 428
        removePlugins: 'elementspath,Anchor',
3842 stevensc 429
        heigth: 100
430
    });
863 geraldo 431
    /**
862 geraldo 432
     * Clicked on add new conduct
433
     */
434
    $('body').on('click', 'button[id="btn-add-conduct"]', function(e) {
435
        e.preventDefault();
436
        $('#form-conduct #conduct-id').val('');
437
        $('#form-conduct #conduct-description').val('');
438
        $('#modal-conduct h4[class="modal-title"]').html('LABEL_ADD LABEL_CONDUCT');
439
        $('#modal-conduct').modal('show');
1 www 440
    });
862 geraldo 441
    /**
442
     * Clicked on edit conduct
443
     */
444
    $('body').on('click', 'button.btn-edit-conduct', function(e) {
445
        e.preventDefault();
877 geraldo 446
        var id = $(this).data('conduct');
447
        behaviors.map((item) => {
448
            if (item.id == id) {
882 geraldo 449
                $('#form-conduct #conduct-id').val(item.id);
450
                $('#form-conduct #conduct-description').val(item.description);
877 geraldo 451
                $('#modal-conduct h4[class="modal-title"]').html('LABEL_EDIT LABEL_CONDUCT');
452
                $('#modal-conduct').modal('show');
862 geraldo 453
                return;
454
            }
877 geraldo 455
        });
862 geraldo 456
    });
457
    /**
458
     * Clicked on remove conduct
459
     */
460
    $('body').on('click', 'button.btn-delete-conduct', function(e) {
461
        e.preventDefault();
888 geraldo 462
        var id = $(this).data('conduct');
862 geraldo 463
        bootbox.confirm({
464
            title: "LABEL_DELETE LABEL_CONDUCT",
465
            message: "LABEL_QUESTION_DELETE",
466
            buttons: {
467
                cancel: {
468
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
469
                },
470
                confirm: {
471
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
472
                }
473
            },
474
            callback: function(result) {
886 geraldo 475
                if (result) {
888 geraldo 476
                    removeBehavior(id);
886 geraldo 477
                }
862 geraldo 478
            }
479
        });
480
    });
863 geraldo 481
    /**
879 geraldo 482
     * Clicked cancel new/edit Form
863 geraldo 483
     */
879 geraldo 484
    $('button.btn-conduct-submit').click(function(e) {
893 geraldo 485
        if ($("#conduct-description").val() == "") {
1085 geraldo 486
            $.fn.showError('ERROR_ENTER_DESCRIPTION');
883 geraldo 487
            return;
893 geraldo 488
        } else {
3896 stevensc 489
            $("#conduct-id").val() == ""
490
                ?addBehavior($("#conduct-description").val())
491
                :editBehavior($("#conduct-id").val(), $("#conduct-description").val())
893 geraldo 492
            $('#modal-conduct').modal('hide');
493
            return;
863 geraldo 494
        }
862 geraldo 495
    });
873 geraldo 496
    /**
497
     * Clicked cancel new/edit Form
498
     */
499
    $('button.btn-edit-cancel').click(function(e) {
500
        e.preventDefault();
501
        $('#row-form').hide();
502
        $('#row-list').show();
503
    });
874 geraldo 504
    /**
505
     * Add Behavior to array
506
     */
1101 geraldo 507
    const addBehavior = (description) => {
1113 geraldo 508
        $.ajax({
1115 geraldo 509
            'dataType': 'json',
510
            'accept': 'application/json',
511
            'method': 'post',
512
            'url': '$routeAddBehavior',
513
            'data': {
514
                'description': description
515
            }
516
        }).done(function(response) {
517
            if (response['success']) {
518
                behaviors.push({
1133 geraldo 519
                    'id': response['uuid'],
1115 geraldo 520
                    'description': description
521
                });
522
                renderData(behaviors);
523
            } else {
524
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
525
            }
878 geraldo 526
        });
874 geraldo 527
    }
528
    /**
529
     * Edit item behavior
530
     */
1101 geraldo 531
    const editBehavior = (id, description) => {
1115 geraldo 532
        $.ajax({
533
            'dataType': 'json',
534
            'accept': 'application/json',
535
            'method': 'post',
536
            'url': '/settings/behaviors/edit/' + id,
537
            'data': {
538
                'description': description
874 geraldo 539
            }
1115 geraldo 540
        }).done(function(response) {
541
            if (response['success']) {
542
                behaviors.map((item) => {
543
                    if (item.id == id) {
544
                        item.description = description;
545
                    }
546
                });
547
                renderData(behaviors);
548
            } else {
549
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
550
            }
874 geraldo 551
        });
552
    }
553
    /**
554
     * Remove behavior
555
     */
877 geraldo 556
    const removeBehavior = (id) => {
3896 stevensc 557
        $.ajax({
558
            'dataType': 'json',
559
            'accept': 'application/json',
3908 stevensc 560
            'method': 'post',
3896 stevensc 561
            'url': '/settings/behaviors/delete/' + id,
562
        })
563
        .done(function(response) {
564
            if (response['success']) {
565
                behaviors = behaviors.filter((item) => item.id != id);
566
                renderData(behaviors);
567
            } else {
568
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
569
            }
570
        })
874 geraldo 571
    }
877 geraldo 572
    /**
874 geraldo 573
     * Render Sections data
574
     */
1129 geraldo 575
    const renderData = (data) => {
576
        getAllBehaviors();
1133 geraldo 577
        data.length > 0 ?
578
            $("#rows").html($("#behaviorTemplate").render(data)) :
1132 geraldo 579
            $("#rows").html('')
1129 geraldo 580
    }
1127 geraldo 581
    /**
582
     * get alls Behavios
583
     */
1129 geraldo 584
    const getAllBehaviors = () => {
1154 geraldo 585
        $('#select-conduct').children().remove();
586
        $('#select-conduct').append($('<option>', {
587
            value: '',
588
            text: 'LABEL_SELECT'
589
        }));
1127 geraldo 590
        $.getJSON("/settings/behaviors", function(data) {
591
            $.each(data.data, function(i, item) {
1162 geraldo 592
                console.log(filterItemById(item.uuid));
1163 geraldo 593
                if (!filterItemById(item.uuid)) {
1129 geraldo 594
                    $('#select-conduct').append($('<option>', {
1133 geraldo 595
                        value: item.uuid,
596
                        text: item.description
597
                    }));
1129 geraldo 598
                }
1127 geraldo 599
            });
1115 geraldo 600
        });
601
    }
1127 geraldo 602
    /**
603
     * Clicked cancel new/edit Form
604
     */
1128 geraldo 605
    $('body').on('click', 'button[id="btn-select-conduct"]', function(e) {
1127 geraldo 606
        if ($("#select-conduct").val() == "") {
607
            $.fn.showError('LABEL_ERROR_SELECT_CONDUCT');
608
        } else {
609
            behaviors.push({
610
                'id': $("#select-conduct").val(),
611
                'description': $('select[name="select-conduct"] option:selected').text()
612
            });
613
            renderData(behaviors);
614
        }
615
    });
1161 geraldo 616
    /**
617
     * Filter section selected
618
     */
619
    const filterItemById = (id) => behaviors.filter((item) => item.id == id ? item : false)[0];
863 geraldo 620
});
1115 geraldo 621
 
1 www 622
JS;
623
$this->inlineScript()->captureEnd();
624
?>
3896 stevensc 625
 
1 www 626
<!-- Content Header (Page header) -->
627
<section class="content-header">
3896 stevensc 628
    <div class="container-fluid">
629
        <div class="row mb-2">
630
            <div class="col-sm-12">
631
                <h1>LABEL_COMPETENCIES</h1>
632
            </div>
633
        </div>
634
    </div>
635
    <!-- /.container-fluid -->
1 www 636
</section>
873 geraldo 637
<section class="content" id="row-list">
3896 stevensc 638
    <div class="container-fluid">
639
        <div class="row">
640
            <div class="col-12">
641
                <div class="card">
642
                    <div class="card-body">
643
                        <table id="gridTable" class="table   table-hover">
644
                            <thead>
645
                                <tr>
646
                                    <th>LABEL_TYPE</th>
647
                                    <th>LABEL_NAME</th>
648
                                    <th>LABEL_ACTIVE</th>
649
                                    <th>LABEL_ACTIONS</th>
650
                                </tr>
651
                            </thead>
652
                            <tbody>
653
                            </tbody>
654
                        </table>
655
                    </div>
656
                    <div class="card-footer clearfix">
657
                        <div style="float:right;">
658
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
659
                            <?php if ($allowImport) : ?>
660
                                <button type="button" class="btn btn-primary btn-import"><i class="fa fa-upload"></i> LABEL_IMPORT </button>
661
                            <?php endif; ?>
662
                            <?php if ($allowAdd) : ?>
663
                                <button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
664
                            <?php endif; ?>
665
                        </div>
666
                    </div>
667
                </div>
890 geraldo 668
            </div>
3896 stevensc 669
        </div>
670
    </div>
890 geraldo 671
</section>
865 geraldo 672
<!-- The Form creation -->
673
<section class="content" id="row-form" style="display: none">
3896 stevensc 674
    <div class="container-fluid">
675
        <div class="row">
676
            <div class="col-md-12 col-sm-12 col-12">
677
                <div class="panel">
678
                    <div class="panel-body">
1110 geraldo 679
                        <?php
3896 stevensc 680
                        $form = $this->form;
681
                        $form->setAttributes([
682
                            'method'    => 'post',
683
                            'name'      => 'form',
684
                            'id'        => 'form'
685
                        ]);
686
 
687
                        $form->prepare();
688
                        echo $this->form()->openTag($form);
689
                        ?>
1111 geraldo 690
                        <div class="row">
3896 stevensc 691
                            <div class="col-md-4 col-sm-12 col-12">
692
                                <div class="from-group">
693
                                    <?php
694
                                    $element = $form->get('competency_type_id');
695
                                    $element->setOptions(['label' => 'LABEL_TYPE']);
696
 
697
                                    echo $this->formLabel($element);
698
                                    echo $this->formSelect($element);
699
                                    ?>
700
                                </div>
701
                            </div>
702
                            <div class="col-md-4 col-sm-12 col-12">
703
                                <div class="from-group">
704
                                    <?php
705
                                    $element = $form->get('name');
706
                                    $element->setOptions(['label' => 'LABEL_NAME']);
707
                                    $element->setAttributes(['class' => 'form-control']);
708
 
709
                                    echo $this->formLabel($element);
710
                                    echo $this->formText($element);
711
                                    ?>
712
                                </div>
713
                            </div>
714
                            <div class="col-md-4 col-sm-12 col-12">
715
                                <div class="from-group">
716
                                    <label>LABEL_STATUS</label>
717
                                    <br />
718
                                    <?php
719
                                    $element = $form->get('status');
720
                                    $element->setOptions(['label' => 'LABEL_STATUS']);
721
                                    // echo $this->formLabel($element);
722
                                    echo $this->formCheckbox($element);
723
                                    ?>
724
                                </div>
725
                            </div>
726
                            <div class="col-md-12 col-sm-12 col-12">
727
                                <div class="form-group">
728
                                    <?php
729
                                    $element = $form->get('description');
730
                                    $element->setOptions(['label' => 'LABEL_DESCRIPTION']);
731
                                    $element->setAttributes(['class' => 'form-control']);
732
 
733
                                    echo $this->formLabel($element);
734
                                    echo $this->formTextArea($element);
735
                                    ?>
736
                                </div>
737
                            </div>
738
                            <?php echo $this->form()->closeTag($form); ?>
739
                            <div class="col-md-12 col-sm-12 col-12">
740
                                <div class="form-group">
741
                                    <div class="row">
742
                                        <div class="col-md-4 col-sm-4 col-xs-12">
743
                                            <select name="select-conduct" id="select-conduct" class="form-control">
744
                                            </select>
745
                                        </div>
746
                                        <div class="col-md-4 col-sm-4 col-xs-12">
747
                                            <button type="button" class="btn btn-primary" id="btn-select-conduct" data-toggle="tooltip" title="LABEL_ADD LABEL_CONDUCT">LABEL_ADD LABEL_CONDUCT</button>
748
                                        </div>
749
                                        <div class="col-md-4 col-sm-4 col-xs-12 text-right">
750
                                            <button type="button" class="btn btn-primary" id="btn-add-conduct" data-toggle="tooltip" title="LABEL_NEWS LABEL_CONDUCT"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_NEWS LABEL_CONDUCT</button>
751
                                        </div>
752
                                    </div>
753
                                </div>
754
                            </div>
1111 geraldo 755
                        </div>
3896 stevensc 756
                        <div class="col-xs-12 col-md-12">
757
                            <br />
758
                            <div class="table-responsive">
759
                                <table class="table table-bordered">
760
                                    <thead>
761
                                        <tr>
762
                                            <th style="width: 60%;">LABEL_DESCRIPTION</th>
763
                                            <th style="width: 20%;">LABEL_ACTIONS</th>
764
                                        </tr>
765
                                    </thead>
766
                                    <tbody id="rows"></tbody>
767
                                </table>
768
                            </div>
769
                            <div class="col-xs-12 col-md-12">
770
                                <div class="form-group">
771
                                    <button type="submit" form="form" class="btn btn-primary">LABEL_SAVE</button>
772
                                    <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
773
                                </div>
774
                            </div>
775
                        </div>
776
                    </div>
777
                </div>
865 geraldo 778
            </div>
3896 stevensc 779
        </div>
865 geraldo 780
</section>
890 geraldo 781
<!---end form--->
782
<!--start modal conduct-->
3896 stevensc 783
<div id="modal-conduct" class="modal" tabindex="-1" role="dialog">
784
    <div class="modal-dialog modal-lg" role="document">
785
        <form action="#" name="form-conduct" id="form-conduct">
786
            <input type="hidden" name="conduct-id" id="conduct-id" value="" />
787
            <input type="hidden" name="conduct-competencia" id="conduct-competencia" value="" />
788
            <div class="modal-content">
789
                <div class="modal-header">
790
                    <h4 class="modal-title">LABEL_ADD LABEL_CONDUCT</h4>
791
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
792
                        <span aria-hidden="true">&times;</span>
793
                    </button>
794
                </div>
795
                <div class="modal-body">
796
                    <div class="form-group">
797
                        <label for="conduct-name">LABEL_DESCRIPTION</label>
798
                        <input type="text" name="conduct-description" id="conduct-description" class="form-control" maxlength="200" value="" />
799
                    </div>
800
                </div>
801
                <div class="modal-footer">
802
                    <button type="button" class="btn btn-primary btn-conduct-submit">LABEL_SAVE</button>
803
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
804
                </div>
861 geraldo 805
            </div>
3896 stevensc 806
        </form>
807
    </div>
861 geraldo 808
</div>
890 geraldo 809
<!---end modal conduct --->
810
<!--start template--->
874 geraldo 811
<script id="behaviorTemplate" type="text/x-jsrender">
3896 stevensc 812
    <tr>
1105 geraldo 813
       <td class="text-left">{{:description}}</td>
890 geraldo 814
       <td>
815
           <button class="btn btn-default btn-edit-conduct" data-conduct="{{:id}}" data-toggle="tooltip"  data-original-title="LABEL_EDIT"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT</button>
816
           <button class="btn btn-default btn-delete-conduct" data-conduct="{{:id}}" data-toggle="tooltip"  data-original-title="LABEL_DELETE"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE</button>
817
       </td>
818
   </tr>
819
</script>
820
<!--end template--->