Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 5436 | Rev 5696 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

<?php
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
$currentUser    = $this->currentUserHelper();

$roleName = $currentUser->getUserTypeId();

$routeAdd       = $this->url('settings/company-sizes/add');
$routeDatatable = $this->url('settings/company-sizes');
$routeDashboard = $this->url('dashboard');

$allowAdd               = $acl->isAllowed($roleName, 'settings/company-sizes/add') ? 1 : 0;
$allowEdit              = $acl->isAllowed($roleName, 'settings/company-sizes/edit') ? 1 : 0;
$allowDelete            = $acl->isAllowed($roleName, 'settings/company-sizes/delete') ? 1 : 0;


$this->inlineScript()->appendFile($this->basePath('plugins/jquery-input-number/input-number-format.jquery.min.js'));

$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));


$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));

$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));

$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));


$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.min.css'));
$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css'));

$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/select2.full.min.js'));

$this->inlineScript()->appendFile($this->basePath('plugins/moment/moment-with-locales.min.js'));
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'));


$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));

$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));

$status_active = \LeadersLinked\Model\CompanySize::STATUS_ACTIVE;


$this->inlineScript()->captureStart();
echo <<<JS
    jQuery( document ).ready(function( $ ) {
        
        $.validator.addMethod('greaterThan', function (value, element, param) {
            var otherElement = $(param);
            return parseInt(value, 10) > parseInt(otherElement.val(), 10);
        }, 'ERROR_INVALID_MINIMUM');
        
        $.validator.setDefaults({
            debug: true,
            highlight: function(element) {
                $(element).addClass('is-invalid');
            },
            unhighlight: function(element) {
                $(element).removeClass('is-invalid');
            },
            errorElement: 'span',
            errorClass: 'error invalid-feedback',
            errorPlacement: function(error, element) {
                if(element.parent('.form-group').length) {
                    error.insertAfter(element);
                } else if(element.parent('.toggle').length) {
                    error.insertAfter(element.parent().parent());
                } else {
                    error.insertAfter(element.parent());
                }
            }
        });
    
    
        $.fn.showFormErrorValidator = function(fieldname, errors) {
            var field = $(fieldname);
            if(field) {
                $(field).addClass('is-invalid');
    

                var error = $('<span id="' + fieldname +'-error" class="error invalid-feedback">' + errors + '</div>');
                if(field.parent('.form-group').length) {
                    error.insertAfter(field);
                } else  if(field.parent('.toggle').length) {
                    error.insertAfter(field.parent().parent());
                } else {
                    error.insertAfter(field.parent());
                }
            }
        };
        
        var allowEdit   = $allowEdit;
        var allowDelete = $allowDelete;
        
        /* var gridTable = $('#gridTable').dataTable( {
            'processing': true,
            'serverSide': true,
            'searching': true,
            'order': [[ 0, 'asc' ]],
            'ordering':  true,
            'ordenable' : true,
            'responsive': true,
            'select' : false,
                'paging': true,
            'pagingType': 'simple_numbers',
                'ajax': {
                        'url' : '$routeDatatable',
                        'type' : 'get',
                'beforeSend': function (request) {
                    NProgress.start();
                },
                'dataFilter': function(response) {
                    var response = jQuery.parseJSON( response );
                    
                    var json                = {};
                    json.recordsTotal       = 0;
                    json.recordsFiltered    = 0;
                    json.data               = [];
                    
                    
                    if(response.success) {
                        json.recordsTotal       = response.data.total;
                        json.recordsFiltered    = response.data.total;
                        json.data               = response.data.items;
                    } else {
                        $.fn.showError(response.data)
                    }
                    
                    return JSON.stringify( json );
                }
                },
            'language' : {
                'sProcessing':     'LABEL_DATATABLE_SPROCESSING',
                'sLengthMenu':     'LABEL_DATATABLE_SLENGTHMENU',
                'sZeroRecords':    'LABEL_DATATABLE_SZERORECORDS',
                'sEmptyTable':     'LABEL_DATATABLE_SEMPTYTABLE',
                'sInfo':           'LABEL_DATATABLE_SINFO',
                'sInfoEmpty':      'LABEL_DATATABLE_SINFOEMPTY',
                'sInfoFiltered':   'LABEL_DATATABLE_SINFOFILTERED',
                'sInfoPostFix':    '',
                'sSearch':         'LABEL_DATATABLE_SSEARCH',
                'sUrl':            '',
                'sInfoThousands':  ',',
                'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
                'oPaginate': {
                    'sFirst':    'LABEL_DATATABLE_SFIRST',
                    'sLast':     'LABEL_DATATABLE_SLAST',
                    'sNext':     'LABEL_DATATABLE_SNEXT',
                    'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
                },
                'oAria': {
                    'sSortAscending':  ': LABEL_DATATABLE_SSORTASCENDING',
                    'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
                },
            },
            'drawCallback': function( settings ) {
                NProgress.done();
                
            },
            'aoColumns': [
                { 'mDataProp': 'name' },
                { 'mDataProp': 'minimum_no_of_employee'},
                { 'mDataProp': 'maximum_no_of_employee'},
                { 'mDataProp': 'status' },
                { 'mDataProp': 'actions' },
            ],
            'columnDefs': [
                {
                    'targets': 0,
                    'className' : 'text-vertical-middle',
                },
                {
                    'targets': 1,
                    'className' : 'text-right text-vertical-middle',
                },
                {
                    'targets':2,
                    'className' : 'text-right text-vertical-middle',
                },
                {
                    'targets': -2,
                    'orderable': false,
                    'className' : 'text-center',
                    'render' : function ( data, type, row ) {
                      
                        checked = data == 'a' ? ' checked="checked" ' : '';
                        return '<div class="checkbox checkbox-success">' +
                            '<input class="styled" type="checkbox" ' + checked + ' disabled="disabled">' +
                            '<label ></label></div>';
                    }
                },
                {
                    'targets': -1,
                    'orderable': false,
                    'render' : function ( data, type, row ) {
                        s = '';
                        
                        if(allowEdit) {
                            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;';
                        }
                        if(allowDelete) {
                            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;';
                        }
                        return s;
                    }
                }
            ],
        }); */
        
        
        /* var validator = $('#form').validate({
            debug: true,
            onclick: false,
            onkeyup: false,
            ignore: [],
            rules: {
                'name': {
                    required: true,
                    maxlength: 64,
                },
                'minimum_no_of_employee': {
                    required: true,
                    min: 0
                },
                'maximum_no_of_employee': {
                    required: true,
                    min: 1,
                    greaterThan : '#minimum_no_of_employee'
                },
            },
            submitHandler: function(form)
            {
                $.ajax({
                    'dataType'  : 'json',
                    'accept'    : 'application/json',
                    'method'    : 'post',
                    'url'       :  $('#form').attr('action'),
                    'data'      :  $('#form').serialize()
                }).done(function(response) {
                    NProgress.start();
                    if(response['success']) {
                        $.fn.showSuccess(response['data']);
                        
                        $('#modal').modal( 'hide');
                        
                         gridTable.api().ajax.reload(null, false);
                    } else {
                        validator.resetForm();
                        if(jQuery.type(response['data']) == 'string') {
                            $.fn.showError(response['data']);
                        } else  {
                            $.each(response['data'], function( fieldname, errors ) {
                                $.fn.showFormErrorValidator('#form #' + fieldname, errors);
                            });
                        }
                    }
                }).fail(function( jqXHR, textStatus, errorThrown) {
                    $.fn.showError(textStatus);
                }).always(function() {
                    NProgress.done();
                });
                return false;
            },
            invalidHandler: function(form, validator) {
            
            }
        }); */

        /* $('button.btn-delete').confirmation({
                    rootSelector: 'button.btn-delete',
                    title : 'LABEL_ARE_YOU_SURE',
                    singleton : true,
                    btnOkLabel: 'LABEL_YES',
                    btnCancelLabel: 'LABEL_NO',
                    onConfirm: function(value) {
                        action = $(this).data('href');
                        NProgress.start();
                        $.ajax({
                            'dataType'  : 'json',
                            'accept'    : 'application/json',
                            'method'    : 'post',
                            'url'       :  action,
                        }).done(function(response) {
                            if(response['success']) {
                                $.fn.showSuccess(response['data']);
                                gridTable.api().ajax.reload(null, false);
                            } else {
                                $.fn.showError(response['data']);
                            }
                        }).fail(function( jqXHR, textStatus, errorThrown) {
                            $.fn.showError(textStatus);
                        }).always(function() {
                            NProgress.done();
                        });
                    },
                });
         */
        
        $('#toggle-btn').bootstrapToggle();
        $('#form #status').bootstrapToggle({'on' : 'LABEL_ACTIVE',  'off' : 'LABEL_INACTIVE', 'width' : '160px', 'height' : '40px'});

    });
JS;
$this->inlineScript()->captureEnd();

$js = <<<JS
const urlsVar = {
        linkTable: '$routeDatatable',
        addUrl: '$routeAdd',
        allowAdd: '$allowAdd',
        allowEdit: '$allowEdit',
        allowDelete: 0,
   }
JS;


$this->inlineScript()->appendScript($js);
$this->inlineScript()->appendFile('/react-bundles/settings/company-sizes/companySizesBundle.js');
?>

<!-- Content Header (Page header) -->
<div id="company-sizes">
</div>