Rev 15831 | 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();
$routeSave = $this->url('settings/my-private-network/favicon');
$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->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 if(element.parent('.toggle').length) {
error.insertAfter(element.parent().parent());
} else {
error.insertAfter(element.parent());
}
}
});
$.fn.showFormErrorValidator = function(fieldname, errors) {
var element = $(elementname);
if(element) {
$(element).addClass('is-invalid');
var error = $('<span id="' + elementname +'-error" class="error invalid-feedback">' + errors + '</div>');
if(element.parent('.btn-file').length) {
error.insertAfter(element.parent().parent());
} else if(element.parent('.toggle').length) {
error.insertAfter(element.parent().parent());
} else {
error.insertAfter(element.parent());
}
}
};
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]);
}
$('input[type="submit"]').prop('disabled', true);
$.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']);
} 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-topic-edit #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();
?>
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-12">
<h1>LABEL_MY_PRIVATE_NETWORK_FAVICO</h1>
</div>
</div>
<div class="row mb-2">
<div class="col-sm-12">
<?php
$form = $this->form;
$form->setAttributes([
'method' => 'post',
'action' => $routeSave,
'name' => 'form',
'id' => 'form',
]);
$form->prepare();
echo $this->form()->openTag($form);
?>
<div class="form-group">
<?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>
LABEL_RECOMMENDED_SIZE <?php echo $image_size ?>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
</div>
<?php echo $this->form()->closeTag($form); ?>
</div>
</div>
</div><!-- /.container-fluid -->
</section>