Proyectos de Subversion LeadersLinked - Backend

Rev

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

<?php

use LeadersLinked\Model\UserExperience;

$acl = $this->viewModel()
    ->getRoot()
    ->getVariable('acl');
$currentUserHelper = $this->currentUserHelper();
$currentUser = $currentUserHelper->getUser();
$currentCompany = $currentUserHelper->getCompany();
$companyId = $currentCompany->uuid;

$roleName = $currentUserHelper->getUserTypeId();

$routeWebsite = $this->url('profile/website', ['id' => $currentCompany->uuid]);
$routeCompanySize = $this->url('profile/company-size', ['id' => $currentCompany->uuid]);
$routeIndustry = $this->url('profile/industry', ['id' => $currentCompany->uuid]);
$routeExtended = $this->url('profile/extended', ['id' => $currentCompany->uuid]);
$routeSocialNetworks = $this->url('profile/social-network', ['id' => $currentCompany->uuid]);
$routeLocationAdd = $this->url('profile/location', ['id' => $currentCompany->uuid, 'operation' => 'add']);
$routeFoundationYear = $this->url('profile/foundation_year', ['id' => $currentCompany->uuid, 'operation' => 'add']);
$routeImageUpload = $this->url('profile/image', ['id' => $currentCompany->uuid, 'operation' => 'upload']);
$routeCoverUpload = $this->url('profile/cover', ['id' => $currentCompany->uuid, 'operation' => 'upload']);
$routeFooterUpload = $this->url('profile/footer', ['id' => $currentCompany->uuid, 'operation' => 'upload']);
$routeHeaderUpload = $this->url('profile/header', ['id' => $currentCompany->uuid, 'operation' => 'upload']);

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

$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));

$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-fileinput/css/fileinput.min.css'));
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-fileinput/themes/explorer-fas/theme.css'));

$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/js/plugins/piexif.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/js/plugins/sortable.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/js/fileinput.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/js/locales/es.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/themes/fas/theme.js'));
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-fileinput/themes/explorer-fas/theme.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/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.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()->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 validatorExtended = $('#form-extended').validate({
        debug: true,
        onclick: false,
        onkeyup: false,
        onfocusout: false,
        ignore: [],
        rules: {
            'description': {
                updateCkeditor:function() {
                        CKEDITOR.instances.description.updateElement();
                },
                required: false,
            },
        },

        submitHandler: function(form)
        {
            NProgress.start();
            $.ajax({
                'dataType'  : 'json',
                'accept'    : 'application/json',
                'method'    : 'post',
                'url'       :  $('#form-extended').attr('action'),
                'data'      :  $('#form-extended').serialize()
            }).done(function(response) {
                if(response['success']) {

                    $('#overview-description').html(response['data']['description']);
                    $("#extended-box").modal('hide');
                } else {
                    validatorExtended.resetForm();
                    if(jQuery.type(response['data']) == 'string') {
                        $.fn.showError(response['data']);
                    } else  {
                        $.each(response['data'], function( fieldname, errors ) {
                            $.fn.showFormErrorValidator('#form-extended #' + fieldname, errors);
                        });
                    }
                }
            }).fail(function( jqXHR, textStatus, errorThrown) {
                $.fn.showError(textStatus);
            }).always(function() {
                NProgress.done();
            });
            return false;
        },
        invalidHandler: function(form, validator) {
        
        }
    });


    $('.btn-extended-edit').on("click", function(e){
        e.preventDefault();

        NProgress.start();
        $.ajax({
            'dataType'  : 'json',
            'accept'    : 'application/json',
            'method'    : 'get',
            'url'       : '$routeExtended',
        }).done(function(response) {
           if(response['success']) {
                CKEDITOR.instances.description.setData(response['data']['description']);
                validatorExtended.resetForm();

                $("#extended-box").modal('show');
            } else {
                $.fn.showError(response['data']);
            }
        }).fail(function( jqXHR, textStatus, errorThrown) {
            $.fn.showError(textStatus);
        }).always(function() {
            NProgress.done();
        });
        return false;

    });
    
    $('.btn-extended-close').on("click", function(e){
        e.preventDefault();
        
        $("#extended-box").modal('hide');
        return false;
    });
    
    CKEDITOR.replace('description', {
        toolbar: [
                    { name: 'editing', items: ['Scayt'] },
                    { name: 'links', items: ['Link', 'Unlink'] },
                    { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'] },
                    { name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', 'RemoveFormat'] },
                    '/',
                    { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },
                    { name: 'styles', items: ['Styles', 'Format'] },
                    { name: 'tools', items: ['Maximize'] }
                ],
                removePlugins: 'elementspath,Anchor',
                heigth: 100
    });
    
});


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

$jsonLocations = json_encode($locations);

$js = <<<JS
const urlVars = {
    routeWebsite: "$routeWebsite",
    routeCompanySize: "$routeCompanySize",
    routeIndustry: "$routeIndustry",
    routeExtended: "$routeExtended",
    routeSocialNetworks: "$routeSocialNetworks",
    routeLocationAdd: "$routeLocationAdd",
    routeFoundationYear: "$routeFoundationYear",
    routeImageUpload: "$routeImageUpload",
    routeCoverUpload: "$routeCoverUpload",
    routeFooterUpload: "$routeFooterUpload",
    routeHeaderUpload: "$routeHeaderUpload",
    cover: "$cover",
    companyId: "$companyId",
    followers: "$follower",
    image: "$image",
    overview: "$overview",
    locations: JSON.parse('$jsonLocations'),
    industry: "$industry",
    companySize: "$company_size",
    companyName: "$company_name",
    foundationYear: "$foundation_year",
    website: "$website",
    header: "$header",
    footer: "$footer"
}
JS;

$this->inlineScript()->appendScript($js);
$this->headLink()->appendStylesheet('/react-bundles/profile/main.css');
$this->inlineScript()->appendFile('/react-bundles/profile/profileBundle.js');
?>

<style>
    .user-profile-ov {
        position: relative;
    }

    .user-profile-ov .add-dp {
        position: absolute;
        top: 30%;
        right: 10%;
    }

    .user-profile-ov .add-dp i {
        font-size: 14px;
        border: 2px solid #fff;
        background: #e44d3a;
        padding: 11px;
        color: #ffff
    }
</style>

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

<div class="modal" tabindex="-1" role="dialog" id="extended-box">
    <div class="modal-dialog" role="document">
        <?php
        $form = $this->formExtended;
        $form->setAttributes([
            'method' => 'post',
            'action' => $routeExtended,
            'name' => 'form-extended',
            'id' => 'form-extended'
        ]);
        $form->prepare();
        echo $this->form()->openTag($form);
        ?>
        <div class="modal-content">
            <div class="modal-header">
                <h3 class="modal-title">LABEL_CHANGE</h3>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <?php
                    $element = $form->get('description');
                    $element->setAttributes(['class' => 'form-control']);
                    $element->setOptions(['label' => 'LABEL_OVERVIEW']);
                    echo $this->formLabel($element);
                    echo $this->formTextArea($element);
                    ?>
                </div>
            </div>
            <div class="modal-footer">
                <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
                <button type="button" class="btn btn-default btn-extended-close">LABEL_CANCEL</button>
            </div>
            <?php echo $this->form()->closeTag($form); ?>
        </div>
    </div>
</div>