Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 4134 | Rev 14290 | 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) {
4132 stevensc 242
                        s = s + '<button class="btn btn-danger btn-delete" data-href="' + data['link_delete'] + '" data-toggle="delete-confirmation" data-popout="true" title="LABEL_DELETE"><i class="fa fa-trash"></i> LABEL_DELETE </button>&nbsp;';
1 www 243
                    }
863 geraldo 244
                    return s;
1 www 245
                }
863 geraldo 246
            }
247
        ],
248
    });
249
    var validator = $('#form').validate({
250
        debug: true,
251
        onclick: false,
252
        onkeyup: false,
253
        ignore: [],
254
        rules: {
255
            'competency_type_id': {
256
                required: true,
257
            },
258
            'name': {
259
                required: true,
260
                maxlength: 128,
261
            },
262
            'description': {
263
                updateCkeditor: function() {
264
                    CKEDITOR.instances.description.updateElement();
1 www 265
                },
863 geraldo 266
                required: true,
1 www 267
            },
863 geraldo 268
            'status': {
269
                required: false,
1 www 270
            },
863 geraldo 271
        },
272
        submitHandler: function(form) {
893 geraldo 273
            if (behaviors.length == 0) {
1085 geraldo 274
                $.fn.showError('ERROR_NOT_OBSERVABLE_CONDUCT');
893 geraldo 275
            } else {
891 geraldo 276
                $.ajax({
893 geraldo 277
                    'dataType': 'json',
278
                    'accept': 'application/json',
279
                    'method': 'post',
280
                    'url': $('#form').attr('action'),
281
                    'data': {
282
                        'name': $('#name').val(),
283
                        'description': $('#description').val(),
284
                        'competency_type_id': $('#competency_type_id').val(),
285
                        'status': $('#status').val(),
286
                        'behaviors': JSON.stringify(behaviors)
287
                    }
288
                }).done(function(response) {
289
                    NProgress.start();
290
                    if (response['success']) {
291
                        $.fn.showSuccess(response['data']);
292
                        $('#row-form').hide();
293
                        $('#row-list').show();
294
                        gridTable.api().ajax.reload(null, false);
863 geraldo 295
                    } else {
893 geraldo 296
                        validator.resetForm();
297
                        if (jQuery.type(response['data']) == 'string') {
298
                            $.fn.showError(response['data']);
299
                        } else {
300
                            $.each(response['data'], function(fieldname, errors) {
301
                                $.fn.showFormErrorValidator('#form #' + fieldname, errors);
302
                            });
303
                        }
863 geraldo 304
                    }
893 geraldo 305
                }).fail(function(jqXHR, textStatus, errorThrown) {
306
                    $.fn.showError(textStatus);
307
                }).always(function() {
308
                    NProgress.done();
309
                });
891 geraldo 310
            }
28 efrain 311
            return false;
863 geraldo 312
        },
313
        invalidHandler: function(form, validator) {}
314
    });
315
    $('body').on('click', 'button.btn-add', function(e) {
316
        e.preventDefault();
317
        $('span[id="form-title"]').html('LABEL_ADD');
318
        $('#form').attr('action', '$routeAdd');
319
        $('#form #name').val('');
320
        $('#form #competency_type_id').val('').trigger('change');
321
        $('#form #status').bootstrapToggle('on');
1115 geraldo 322
        behaviors = [];
863 geraldo 323
        CKEDITOR.instances.description.setData('');
324
        validator.resetForm();
866 geraldo 325
        $('#row-form').show();
873 geraldo 326
        $('#row-list').hide();
1132 geraldo 327
        renderData([]);
863 geraldo 328
        return false;
329
    });
330
    $('body').on('click', 'button.btn-edit', function(e) {
331
        e.preventDefault();
4134 stevensc 332
        $("button.btn-delete").confirmation('hide');
863 geraldo 333
        NProgress.start();
334
        var action = $(this).data('href');
335
        $.ajax({
336
            'dataType': 'json',
337
            'method': 'get',
338
            'url': action,
339
        }).done(function(response) {
14289 kerby 340
            console.log(response)
863 geraldo 341
            if (response['success']) {
342
                $('span[id="form-title"]').html('LABEL_EDIT');
343
                $('#form').attr('action', action);
344
                $('#form #name').val(response['data']['name']);
345
                $('#form #competency_type_id').val(response['data']['competency_type_id']).trigger('change');
346
                $('#form #status').bootstrapToggle(response['data']['status'] == '$status_active' ? 'on' : 'off')
347
                CKEDITOR.instances.description.setData(response['data']['description']);
1115 geraldo 348
                behaviors = response['data']['behaviors'] || [];
901 geraldo 349
                renderData(behaviors);
863 geraldo 350
                validator.resetForm();
866 geraldo 351
                $('#row-form').show();
873 geraldo 352
                $('#row-list').hide();
863 geraldo 353
            } else {
354
                $.fn.showError(response['data']);
355
            }
356
        }).fail(function(jqXHR, textStatus, errorThrown) {
357
            $.fn.showError(textStatus);
358
        }).always(function() {
359
            NProgress.done();
28 efrain 360
        });
863 geraldo 361
        return false;
362
    });
363
    $('body').on('click', 'button.btn-refresh', function(e) {
364
        e.preventDefault();
365
        gridTable.api().ajax.reload(null, false);
366
        return false;
367
    });
368
    $('body').on('click', 'button.btn-import', function(e) {
369
        e.preventDefault();
370
        NProgress.start();
371
        $.ajax({
372
            'dataType': 'json',
373
            'method': 'post',
374
            'url': '$routeImport',
375
        }).done(function(response) {
376
            if (response['success']) {
377
                $.fn.showSuccess(response['data']);
378
                gridTable.api().ajax.reload(null, false);
379
            } else {
380
                $.fn.showError(response['data']);
381
            }
382
        }).fail(function(jqXHR, textStatus, errorThrown) {
383
            $.fn.showError(textStatus);
384
        }).always(function() {
385
            NProgress.done();
1 www 386
        });
863 geraldo 387
        return false;
388
    });
389
    $('body').on('click', 'button.btn-cancel', function(e) {
390
        e.preventDefault();
391
        $('#modal').modal('hide');
392
    });
393
    $('#form #competency_type_id').select2({
394
        theme: 'bootstrap4',
395
        width: '100%',
396
    });
1226 geraldo 397
 
398
    $('#select-conduct').select2({
399
        theme: 'bootstrap4',
400
        width: '100%',
401
    });
402
 
863 geraldo 403
    $('#form #status').bootstrapToggle({
404
        'on': 'LABEL_ACTIVE',
405
        'off': 'LABEL_INACTIVE',
406
        'width': '160px',
407
        'height': '40px'
408
    });
3842 stevensc 409
    CKEDITOR.replace('description', {
410
        toolbar: [
411
            { name: 'editing', items: [ 'Scayt' ] },
412
            { name: 'links', items: [ 'Link', 'Unlink'] },
413
            { name: 'paragraph', items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote' ] },
414
            { name: 'basicstyles', items: [ 'Bold', 'Italic', 'Strike', 'RemoveFormat' ] },
415
            '/',
416
            { name: 'insert', items: [ 'Image', 'Table', 'HorizontalRule', 'SpecialChar' ] },
417
            { name: 'styles', items: [ 'Styles', 'Format' ] },
418
            { name: 'tools', items: [ 'Maximize' ] }
419
        ],
3926 stevensc 420
        removePlugins: 'elementspath,Anchor',
3842 stevensc 421
        heigth: 100
422
    });
863 geraldo 423
    /**
862 geraldo 424
     * Clicked on add new conduct
425
     */
426
    $('body').on('click', 'button[id="btn-add-conduct"]', function(e) {
427
        e.preventDefault();
428
        $('#form-conduct #conduct-id').val('');
429
        $('#form-conduct #conduct-description').val('');
430
        $('#modal-conduct h4[class="modal-title"]').html('LABEL_ADD LABEL_CONDUCT');
431
        $('#modal-conduct').modal('show');
1 www 432
    });
862 geraldo 433
    /**
434
     * Clicked on edit conduct
435
     */
436
    $('body').on('click', 'button.btn-edit-conduct', function(e) {
437
        e.preventDefault();
877 geraldo 438
        var id = $(this).data('conduct');
439
        behaviors.map((item) => {
440
            if (item.id == id) {
882 geraldo 441
                $('#form-conduct #conduct-id').val(item.id);
442
                $('#form-conduct #conduct-description').val(item.description);
877 geraldo 443
                $('#modal-conduct h4[class="modal-title"]').html('LABEL_EDIT LABEL_CONDUCT');
444
                $('#modal-conduct').modal('show');
862 geraldo 445
                return;
446
            }
877 geraldo 447
        });
862 geraldo 448
    });
449
    /**
450
     * Clicked on remove conduct
451
     */
452
    $('body').on('click', 'button.btn-delete-conduct', function(e) {
453
        e.preventDefault();
888 geraldo 454
        var id = $(this).data('conduct');
862 geraldo 455
        bootbox.confirm({
456
            title: "LABEL_DELETE LABEL_CONDUCT",
457
            message: "LABEL_QUESTION_DELETE",
458
            buttons: {
459
                cancel: {
460
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
461
                },
462
                confirm: {
463
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
464
                }
465
            },
466
            callback: function(result) {
886 geraldo 467
                if (result) {
888 geraldo 468
                    removeBehavior(id);
886 geraldo 469
                }
862 geraldo 470
            }
471
        });
472
    });
863 geraldo 473
    /**
879 geraldo 474
     * Clicked cancel new/edit Form
863 geraldo 475
     */
879 geraldo 476
    $('button.btn-conduct-submit').click(function(e) {
893 geraldo 477
        if ($("#conduct-description").val() == "") {
1085 geraldo 478
            $.fn.showError('ERROR_ENTER_DESCRIPTION');
883 geraldo 479
            return;
893 geraldo 480
        } else {
3896 stevensc 481
            $("#conduct-id").val() == ""
482
                ?addBehavior($("#conduct-description").val())
483
                :editBehavior($("#conduct-id").val(), $("#conduct-description").val())
893 geraldo 484
            $('#modal-conduct').modal('hide');
485
            return;
863 geraldo 486
        }
862 geraldo 487
    });
873 geraldo 488
    /**
489
     * Clicked cancel new/edit Form
490
     */
491
    $('button.btn-edit-cancel').click(function(e) {
492
        e.preventDefault();
493
        $('#row-form').hide();
494
        $('#row-list').show();
495
    });
874 geraldo 496
    /**
497
     * Add Behavior to array
498
     */
1101 geraldo 499
    const addBehavior = (description) => {
1113 geraldo 500
        $.ajax({
1115 geraldo 501
            'dataType': 'json',
502
            'accept': 'application/json',
503
            'method': 'post',
504
            'url': '$routeAddBehavior',
505
            'data': {
506
                'description': description
507
            }
508
        }).done(function(response) {
509
            if (response['success']) {
510
                behaviors.push({
1133 geraldo 511
                    'id': response['uuid'],
1115 geraldo 512
                    'description': description
513
                });
514
                renderData(behaviors);
515
            } else {
516
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
517
            }
878 geraldo 518
        });
874 geraldo 519
    }
520
    /**
521
     * Edit item behavior
522
     */
1101 geraldo 523
    const editBehavior = (id, description) => {
1115 geraldo 524
        $.ajax({
525
            'dataType': 'json',
526
            'accept': 'application/json',
527
            'method': 'post',
528
            'url': '/settings/behaviors/edit/' + id,
529
            'data': {
530
                'description': description
874 geraldo 531
            }
1115 geraldo 532
        }).done(function(response) {
533
            if (response['success']) {
534
                behaviors.map((item) => {
535
                    if (item.id == id) {
536
                        item.description = description;
537
                    }
538
                });
539
                renderData(behaviors);
540
            } else {
541
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
542
            }
874 geraldo 543
        });
544
    }
545
    /**
546
     * Remove behavior
547
     */
877 geraldo 548
    const removeBehavior = (id) => {
3896 stevensc 549
        $.ajax({
550
            'dataType': 'json',
551
            'accept': 'application/json',
3908 stevensc 552
            'method': 'post',
14289 kerby 553
            'url': '/settings/behaviors/delete/' + id+'/',
3896 stevensc 554
        })
555
        .done(function(response) {
556
            if (response['success']) {
557
                behaviors = behaviors.filter((item) => item.id != id);
558
                renderData(behaviors);
559
            } else {
560
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
561
            }
562
        })
874 geraldo 563
    }
877 geraldo 564
    /**
874 geraldo 565
     * Render Sections data
566
     */
1129 geraldo 567
    const renderData = (data) => {
568
        getAllBehaviors();
1133 geraldo 569
        data.length > 0 ?
570
            $("#rows").html($("#behaviorTemplate").render(data)) :
1132 geraldo 571
            $("#rows").html('')
1129 geraldo 572
    }
1127 geraldo 573
    /**
574
     * get alls Behavios
575
     */
1129 geraldo 576
    const getAllBehaviors = () => {
1154 geraldo 577
        $('#select-conduct').children().remove();
578
        $('#select-conduct').append($('<option>', {
579
            value: '',
580
            text: 'LABEL_SELECT'
581
        }));
1127 geraldo 582
        $.getJSON("/settings/behaviors", function(data) {
583
            $.each(data.data, function(i, item) {
1162 geraldo 584
                console.log(filterItemById(item.uuid));
1163 geraldo 585
                if (!filterItemById(item.uuid)) {
1129 geraldo 586
                    $('#select-conduct').append($('<option>', {
1133 geraldo 587
                        value: item.uuid,
588
                        text: item.description
589
                    }));
1129 geraldo 590
                }
1127 geraldo 591
            });
1115 geraldo 592
        });
593
    }
1127 geraldo 594
    /**
595
     * Clicked cancel new/edit Form
596
     */
1128 geraldo 597
    $('body').on('click', 'button[id="btn-select-conduct"]', function(e) {
1127 geraldo 598
        if ($("#select-conduct").val() == "") {
599
            $.fn.showError('LABEL_ERROR_SELECT_CONDUCT');
600
        } else {
601
            behaviors.push({
602
                'id': $("#select-conduct").val(),
603
                'description': $('select[name="select-conduct"] option:selected').text()
604
            });
605
            renderData(behaviors);
606
        }
607
    });
1161 geraldo 608
    /**
609
     * Filter section selected
610
     */
611
    const filterItemById = (id) => behaviors.filter((item) => item.id == id ? item : false)[0];
863 geraldo 612
});
1115 geraldo 613
 
1 www 614
JS;
615
$this->inlineScript()->captureEnd();
616
?>
3896 stevensc 617
 
1 www 618
<!-- Content Header (Page header) -->
619
<section class="content-header">
3896 stevensc 620
    <div class="container-fluid">
621
        <div class="row mb-2">
622
            <div class="col-sm-12">
623
                <h1>LABEL_COMPETENCIES</h1>
624
            </div>
625
        </div>
626
    </div>
627
    <!-- /.container-fluid -->
1 www 628
</section>
873 geraldo 629
<section class="content" id="row-list">
3896 stevensc 630
    <div class="container-fluid">
631
        <div class="row">
632
            <div class="col-12">
633
                <div class="card">
634
                    <div class="card-body">
635
                        <table id="gridTable" class="table   table-hover">
636
                            <thead>
637
                                <tr>
638
                                    <th>LABEL_TYPE</th>
639
                                    <th>LABEL_NAME</th>
640
                                    <th>LABEL_ACTIVE</th>
641
                                    <th>LABEL_ACTIONS</th>
642
                                </tr>
643
                            </thead>
644
                            <tbody>
645
                            </tbody>
646
                        </table>
647
                    </div>
648
                    <div class="card-footer clearfix">
649
                        <div style="float:right;">
650
                            <button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
651
                            <?php if ($allowImport) : ?>
652
                                <button type="button" class="btn btn-primary btn-import"><i class="fa fa-upload"></i> LABEL_IMPORT </button>
653
                            <?php endif; ?>
654
                            <?php if ($allowAdd) : ?>
655
                                <button type="button" class="btn btn-primary btn-add"><i class="fa fa-plus"></i> LABEL_ADD </button>
656
                            <?php endif; ?>
657
                        </div>
658
                    </div>
659
                </div>
890 geraldo 660
            </div>
3896 stevensc 661
        </div>
662
    </div>
890 geraldo 663
</section>
865 geraldo 664
<!-- The Form creation -->
665
<section class="content" id="row-form" style="display: none">
3896 stevensc 666
    <div class="container-fluid">
667
        <div class="row">
668
            <div class="col-md-12 col-sm-12 col-12">
669
                <div class="panel">
670
                    <div class="panel-body">
1110 geraldo 671
                        <?php
3896 stevensc 672
                        $form = $this->form;
673
                        $form->setAttributes([
674
                            'method'    => 'post',
675
                            'name'      => 'form',
676
                            'id'        => 'form'
677
                        ]);
678
 
679
                        $form->prepare();
680
                        echo $this->form()->openTag($form);
681
                        ?>
1111 geraldo 682
                        <div class="row">
3896 stevensc 683
                            <div class="col-md-4 col-sm-12 col-12">
684
                                <div class="from-group">
685
                                    <?php
686
                                    $element = $form->get('competency_type_id');
687
                                    $element->setOptions(['label' => 'LABEL_TYPE']);
688
 
689
                                    echo $this->formLabel($element);
690
                                    echo $this->formSelect($element);
691
                                    ?>
692
                                </div>
693
                            </div>
694
                            <div class="col-md-4 col-sm-12 col-12">
695
                                <div class="from-group">
696
                                    <?php
697
                                    $element = $form->get('name');
698
                                    $element->setOptions(['label' => 'LABEL_NAME']);
699
                                    $element->setAttributes(['class' => 'form-control']);
700
 
701
                                    echo $this->formLabel($element);
702
                                    echo $this->formText($element);
703
                                    ?>
704
                                </div>
705
                            </div>
706
                            <div class="col-md-4 col-sm-12 col-12">
707
                                <div class="from-group">
708
                                    <label>LABEL_STATUS</label>
709
                                    <br />
710
                                    <?php
711
                                    $element = $form->get('status');
712
                                    $element->setOptions(['label' => 'LABEL_STATUS']);
713
                                    // echo $this->formLabel($element);
714
                                    echo $this->formCheckbox($element);
715
                                    ?>
716
                                </div>
717
                            </div>
718
                            <div class="col-md-12 col-sm-12 col-12">
719
                                <div class="form-group">
720
                                    <?php
721
                                    $element = $form->get('description');
722
                                    $element->setOptions(['label' => 'LABEL_DESCRIPTION']);
723
                                    $element->setAttributes(['class' => 'form-control']);
724
 
725
                                    echo $this->formLabel($element);
726
                                    echo $this->formTextArea($element);
727
                                    ?>
728
                                </div>
729
                            </div>
730
                            <?php echo $this->form()->closeTag($form); ?>
731
                            <div class="col-md-12 col-sm-12 col-12">
732
                                <div class="form-group">
733
                                    <div class="row">
734
                                        <div class="col-md-4 col-sm-4 col-xs-12">
735
                                            <select name="select-conduct" id="select-conduct" class="form-control">
736
                                            </select>
737
                                        </div>
738
                                        <div class="col-md-4 col-sm-4 col-xs-12">
739
                                            <button type="button" class="btn btn-primary" id="btn-select-conduct" data-toggle="tooltip" title="LABEL_ADD LABEL_CONDUCT">LABEL_ADD LABEL_CONDUCT</button>
740
                                        </div>
741
                                        <div class="col-md-4 col-sm-4 col-xs-12 text-right">
742
                                            <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>
743
                                        </div>
744
                                    </div>
745
                                </div>
746
                            </div>
1111 geraldo 747
                        </div>
3896 stevensc 748
                        <div class="col-xs-12 col-md-12">
749
                            <br />
750
                            <div class="table-responsive">
751
                                <table class="table table-bordered">
752
                                    <thead>
753
                                        <tr>
754
                                            <th style="width: 60%;">LABEL_DESCRIPTION</th>
755
                                            <th style="width: 20%;">LABEL_ACTIONS</th>
756
                                        </tr>
757
                                    </thead>
758
                                    <tbody id="rows"></tbody>
759
                                </table>
760
                            </div>
761
                            <div class="col-xs-12 col-md-12">
762
                                <div class="form-group">
763
                                    <button type="submit" form="form" class="btn btn-primary">LABEL_SAVE</button>
764
                                    <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
765
                                </div>
766
                            </div>
767
                        </div>
768
                    </div>
769
                </div>
865 geraldo 770
            </div>
3896 stevensc 771
        </div>
865 geraldo 772
</section>
890 geraldo 773
<!---end form--->
774
<!--start modal conduct-->
3896 stevensc 775
<div id="modal-conduct" class="modal" tabindex="-1" role="dialog">
776
    <div class="modal-dialog modal-lg" role="document">
777
        <form action="#" name="form-conduct" id="form-conduct">
778
            <input type="hidden" name="conduct-id" id="conduct-id" value="" />
779
            <input type="hidden" name="conduct-competencia" id="conduct-competencia" value="" />
780
            <div class="modal-content">
781
                <div class="modal-header">
782
                    <h4 class="modal-title">LABEL_ADD LABEL_CONDUCT</h4>
783
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
784
                        <span aria-hidden="true">&times;</span>
785
                    </button>
786
                </div>
787
                <div class="modal-body">
788
                    <div class="form-group">
789
                        <label for="conduct-name">LABEL_DESCRIPTION</label>
790
                        <input type="text" name="conduct-description" id="conduct-description" class="form-control" maxlength="200" value="" />
791
                    </div>
792
                </div>
793
                <div class="modal-footer">
794
                    <button type="button" class="btn btn-primary btn-conduct-submit">LABEL_SAVE</button>
795
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
796
                </div>
861 geraldo 797
            </div>
3896 stevensc 798
        </form>
799
    </div>
861 geraldo 800
</div>
890 geraldo 801
<!---end modal conduct --->
802
<!--start template--->
874 geraldo 803
<script id="behaviorTemplate" type="text/x-jsrender">
3896 stevensc 804
    <tr>
1105 geraldo 805
       <td class="text-left">{{:description}}</td>
890 geraldo 806
       <td>
807
           <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>
808
           <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>
809
       </td>
810
   </tr>
811
</script>
812
<!--end template--->