Proyectos de Subversion LeadersLinked - Backend

Rev

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