Wrap image uploading in anonymous function.

remotes/origin/stable5
Thomas Tanghus 13 years ago
parent 001a47afb0
commit 502f420678
  1. 88
      apps/contacts/js/contacts.js

@ -1643,53 +1643,55 @@ $(document).ready(function(){
Contacts.UI.Card.saveProperty(this); Contacts.UI.Card.saveProperty(this);
}); });
// Upload function for dropped contact photos files. Should go in the Contacts class/object. $(function() {
$.fileUpload = function(files){ // Upload function for dropped contact photos files. Should go in the Contacts class/object.
var file = files[0]; $.fileUpload = function(files){
if(file.size > $('#max_upload').val()){ var file = files[0];
OC.dialogs.alert(t('contacts','The file you are trying to upload exceed the maximum size for file uploads on this server.'), t('contacts','Upload too large')); if(file.size > $('#max_upload').val()){
return; OC.dialogs.alert(t('contacts','The file you are trying to upload exceed the maximum size for file uploads on this server.'), t('contacts','Upload too large'));
} return;
if (file.type.indexOf("image") != 0) { }
OC.dialogs.alert(t('contacts','Only image files can be used as profile picture.'), t('contacts','Wrong file type')); if (file.type.indexOf("image") != 0) {
return; OC.dialogs.alert(t('contacts','Only image files can be used as profile picture.'), t('contacts','Wrong file type'));
} return;
var xhr = new XMLHttpRequest(); }
var xhr = new XMLHttpRequest();
if (!xhr.upload) { if (!xhr.upload) {
OC.dialogs.alert(t('contacts', 'Your browser doesn\'t support AJAX upload. Please click on the profile picture to select a photo to upload.'), t('contacts', 'Error')) OC.dialogs.alert(t('contacts', 'Your browser doesn\'t support AJAX upload. Please click on the profile picture to select a photo to upload.'), t('contacts', 'Error'))
} }
fileUpload = xhr.upload, fileUpload = xhr.upload,
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState == 4){ if (xhr.readyState == 4){
response = $.parseJSON(xhr.responseText); response = $.parseJSON(xhr.responseText);
if(response.status == 'success') { if(response.status == 'success') {
if(xhr.status == 200) { if(xhr.status == 200) {
Contacts.UI.Card.editPhoto(response.data.id, response.data.tmp); Contacts.UI.Card.editPhoto(response.data.id, response.data.tmp);
} else {
OC.dialogs.alert(xhr.status + ': ' + xhr.responseText, t('contacts', 'Error'));
}
} else { } else {
OC.dialogs.alert(xhr.status + ': ' + xhr.responseText, t('contacts', 'Error')); OC.dialogs.alert(response.data.message, t('contacts', 'Error'));
} }
} else {
OC.dialogs.alert(response.data.message, t('contacts', 'Error'));
} }
} };
};
fileUpload.onprogress = function(e){
fileUpload.onprogress = function(e){ if (e.lengthComputable){
if (e.lengthComputable){ var _progress = Math.round((e.loaded * 100) / e.total);
var _progress = Math.round((e.loaded * 100) / e.total); //if (_progress != 100){
//if (_progress != 100){ //}
//} }
} };
}; xhr.open('POST', OC.filePath('contacts', 'ajax', 'uploadphoto.php')+'?id='+Contacts.UI.Card.id+'&requesttoken='+requesttoken+'&imagefile='+encodeURIComponent(file.name), true);
xhr.open('POST', OC.filePath('contacts', 'ajax', 'uploadphoto.php')+'?id='+Contacts.UI.Card.id+'&requesttoken='+requesttoken+'&imagefile='+encodeURIComponent(file.name), true); xhr.setRequestHeader('Cache-Control', 'no-cache');
xhr.setRequestHeader('Cache-Control', 'no-cache'); xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhr.setRequestHeader('X_FILE_NAME', encodeURIComponent(file.name));
xhr.setRequestHeader('X_FILE_NAME', encodeURIComponent(file.name)); xhr.setRequestHeader('X-File-Size', file.size);
xhr.setRequestHeader('X-File-Size', file.size); xhr.setRequestHeader('Content-Type', file.type);
xhr.setRequestHeader('Content-Type', file.type); xhr.send(file);
xhr.send(file); }
} });
$(document).bind('drop dragover', function (e) { $(document).bind('drop dragover', function (e) {
e.preventDefault(); // prevent browser from doing anything, if file isn't dropped in dropZone e.preventDefault(); // prevent browser from doing anything, if file isn't dropped in dropZone

Loading…
Cancel
Save