Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16841 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

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

$roleName = $currentUser->getUserTypeId();


$routeSave       = $this->url('settings/my-private-network/moodle');

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






$this->headLink()->appendStylesheet($this->basePath('assets/vendors/bootstrap-fileinput/css/fileinput.css'));
$this->inlineScript()->appendFile($this->basePath('assets/vendors/bootstrap-fileinput/js/fileinput.js'));

$this->inlineScript()->captureStart();
echo <<<JS
    jQuery( document ).ready(function( $ ) {
    
        $.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('.btn-file').length) {
                    error.insertAfter(element.parent().parent());
                }  else {
                    error.insertAfter(element.parent());
                }
            }
        });
        
        $.fn.handleDisable = function() {
            const disabledValue = $('button[type="submit"]').prop('disabled')
            $('button[type="submit"]').prop('disabled', !disabledValue);
        }


    var validator  = $('#form').validate({
        debug: true,
        onclick: false,
        onkeyup: false,
        ignore: [],
        rules: {
            'file': {
                required: false,
                extension: 'jpg|jpeg|png',
                accept: 'image/jpg,image/jpeg,image/png'
            },
          

        },
        submitHandler: function(form)
        {
            var formdata = false;
            if (window.FormData){
                formdata = new FormData(form); //form[0]);
            }

            $.fn.handleDisable()

            $.ajax({
                'dataType'  : 'json',
                'accept'    : 'application/json',
                'method'    : 'post',
                'url'       :  $('#form').attr('action'),
                'data'      :  formdata,
                'processData': false,
                'contentType': false,
            }).done(function(response) {
                if(response['success']) {
                    $.fn.showSuccess(response['data'], $.fn.handleDisable)
                       
                } 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) {
            
        }
    });


    $('#form #file').fileinput({
        theme: 'fas',
        language: 'es',
        showUpload: false,
        dropZoneEnabled: false,
        maxFileCount: 1,
        allowedFileExtensions: ['jpeg', 'jpg', 'png'],
        msgPlaceholder: 'LABEL_RECOMMENDED_SIZE $image_size',
    });

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

<div class="container">
        <div class="card">
                <?php
                $form = $this->form;
                $form->setAttributes([
                    'method'  => 'post',
                    'action'  => $routeSave,
                    'name'    => 'form',
                    'id'      => 'form',
                ]);

                $form->prepare();
                echo $this->form()->openTag($form);
                ?>
                <div class="card-body">
                         <h6 class="card-title">LABEL_MY_PRIVATE_NETWORK_MOODLE</h6>
                         <div class="row">
                <div class="col-12  mt-3">
                                <?php
                        $element = $form->get('file');
    
                        $element->setAttributes(['class' => 'form-control',  'accept' => 'image/jpg,image/jpeg,image/png']);
                        $element->setOptions(['label' => 'LABEL_IMAGE']);
                        echo $this->formLabel($element);
                        ?>
                        <div class="file-loading">
                            <?php echo $this->formFile($element); ?>
                        </div>
                </div>
                </div>
                </div>
                <div class="card-footer text-right">
                <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
        </div>
                <?php echo $this->form()->closeTag($form); ?>
        </div>
</div>