mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
refactor function to upload image file to server
This commit is contained in:
@@ -44,10 +44,6 @@
|
||||
$(this).closest('td').siblings().find('input').prop('checked', false);
|
||||
});
|
||||
|
||||
$("#general_personalize-logo-choice_personalizeLogoInput").change(function () {
|
||||
readURL(this);
|
||||
});
|
||||
|
||||
$("#download-image-template").on('click', function (event) {
|
||||
event.preventDefault();
|
||||
var imageInBase64 = $('#original-image-placeholder').attr('src');
|
||||
@@ -69,21 +65,27 @@
|
||||
return result;
|
||||
};
|
||||
|
||||
function readURL(input) {
|
||||
if (input.files && input.files[0]) {
|
||||
$("#setupForm").fileupload({
|
||||
dataType: 'html',
|
||||
add: function (e, data) {
|
||||
$.each(data.files, function (i, file) {
|
||||
var reader = new FileReader();
|
||||
|
||||
reader.onload = function (e) {
|
||||
reader.readAsDataURL(data.files[0]);
|
||||
reader.data = data;
|
||||
reader.file = data.files[0];
|
||||
|
||||
reader.onload = function (_file) {
|
||||
var image = new Image();
|
||||
image.src = e.target.result;
|
||||
|
||||
//Validate the File Height and Width.
|
||||
image.src = _file.target.result;
|
||||
image.file = this.file;
|
||||
image.data = this.data;
|
||||
image.onload = function () {
|
||||
var height = this.height;
|
||||
var width = this.width;
|
||||
var w = this.width,
|
||||
h = this.height;
|
||||
|
||||
//check file extension
|
||||
var ext = $('#general_personalize-logo-choice_personalizeLogoInput').val().split('.').pop().toLowerCase();
|
||||
var ext = this.file.type.split('/').pop().toLowerCase();
|
||||
if (ext != 'png') {
|
||||
$('#general_personalize-logo-choice_personalizeLogoInput').val("");
|
||||
$('#error-text').text(errorFileType);
|
||||
@@ -93,8 +95,7 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
//check dimensions
|
||||
if (height > 42 || width > 52) {
|
||||
if (h > 42 || w > 52) {
|
||||
$('#error-text').text(errorDimension);
|
||||
$('#error-text').show();
|
||||
$('#help-text').hide();
|
||||
@@ -103,22 +104,47 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
fileToUpload = input.files[0];
|
||||
require([
|
||||
"blueimp.loadimage"
|
||||
], function (loadImage) {
|
||||
loadImage(file, function (img) {
|
||||
$('#personalize-image-container').show();
|
||||
$('#error-text').hide();
|
||||
$('#help-text').hide();
|
||||
$('#personalise-image-placeholder').attr('src', e.target.result);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
$('#personalize-image-container').empty().append(img);
|
||||
}, {
|
||||
fileType: /^image\/(png)$/,
|
||||
maxSize: 5242880, // 5MB
|
||||
maxWidth: 52,
|
||||
maxHeight: 42,
|
||||
});
|
||||
});
|
||||
|
||||
reader.readAsDataURL(input.files[0]);
|
||||
fileToUpload = this.data;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
submit: function (e, data) {
|
||||
},
|
||||
done: function (e, data) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$("#submitSetupForm").bind('click', function () {
|
||||
if (fileToUpload != null) {
|
||||
fileToUpload.submit();
|
||||
} else {
|
||||
$("#setupForm").submit();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user