mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 02:13:15 +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);
|
$(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) {
|
$("#download-image-template").on('click', function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var imageInBase64 = $('#original-image-placeholder').attr('src');
|
var imageInBase64 = $('#original-image-placeholder').attr('src');
|
||||||
@@ -69,21 +65,27 @@
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
function readURL(input) {
|
$("#setupForm").fileupload({
|
||||||
if (input.files && input.files[0]) {
|
dataType: 'html',
|
||||||
|
add: function (e, data) {
|
||||||
|
$.each(data.files, function (i, file) {
|
||||||
var reader = new FileReader();
|
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();
|
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 () {
|
image.onload = function () {
|
||||||
var height = this.height;
|
var w = this.width,
|
||||||
var width = this.width;
|
h = this.height;
|
||||||
|
|
||||||
//check file extension
|
var ext = this.file.type.split('/').pop().toLowerCase();
|
||||||
var ext = $('#general_personalize-logo-choice_personalizeLogoInput').val().split('.').pop().toLowerCase();
|
|
||||||
if (ext != 'png') {
|
if (ext != 'png') {
|
||||||
$('#general_personalize-logo-choice_personalizeLogoInput').val("");
|
$('#general_personalize-logo-choice_personalizeLogoInput').val("");
|
||||||
$('#error-text').text(errorFileType);
|
$('#error-text').text(errorFileType);
|
||||||
@@ -93,8 +95,7 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//check dimensions
|
if (h > 42 || w > 52) {
|
||||||
if (height > 42 || width > 52) {
|
|
||||||
$('#error-text').text(errorDimension);
|
$('#error-text').text(errorDimension);
|
||||||
$('#error-text').show();
|
$('#error-text').show();
|
||||||
$('#help-text').hide();
|
$('#help-text').hide();
|
||||||
@@ -103,22 +104,47 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileToUpload = input.files[0];
|
require([
|
||||||
|
"blueimp.loadimage"
|
||||||
|
], function (loadImage) {
|
||||||
|
loadImage(file, function (img) {
|
||||||
$('#personalize-image-container').show();
|
$('#personalize-image-container').show();
|
||||||
$('#error-text').hide();
|
$('#error-text').hide();
|
||||||
$('#help-text').hide();
|
$('#help-text').hide();
|
||||||
$('#personalise-image-placeholder').attr('src', e.target.result);
|
$('#personalize-image-container').empty().append(img);
|
||||||
return true;
|
}, {
|
||||||
};
|
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>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user