From 6bc6d8f478577ed09789d95c4838e3faed99182c Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Thu, 25 Apr 2013 00:59:03 +0200 Subject: [PATCH] Contacts: Fix loading default contact image --- js/contacts.js | 4 ++-- js/storage.js | 36 ++++++++++++++---------------------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/js/contacts.js b/js/contacts.js index 632cc2d2..4f1d66f4 100644 --- a/js/contacts.js +++ b/js/contacts.js @@ -1400,8 +1400,8 @@ OC.Contacts = OC.Contacts || {}; var finishLoad = function(image) { console.log('finishLoad', self.getDisplayName(), image.width, image.height); $(image).addClass('contactphoto'); + self.$photowrapper.removeClass('loading wait'); self.$photowrapper.css({width: image.width + 10, height: image.height + 10}); - self.$photowrapper.removeClass('loading').removeClass('wait'); $(image).insertAfter($phototools).fadeIn(); }; @@ -2080,7 +2080,7 @@ OC.Contacts = OC.Contacts || {}; $(document).trigger('status.contact.error', { message: t('contacts', 'Failed loading contacts from {addressbook}: {error}', - {addressbook:addressBook['displayname'], error:err}) + {addressbook:addressBook['displayname'], error:cbresponse.message}) }); } }); diff --git a/js/storage.js b/js/storage.js index e7d41628..0a03fcee 100644 --- a/js/storage.js +++ b/js/storage.js @@ -210,29 +210,21 @@ OC.Contacts = OC.Contacts || {}; */ Storage.prototype.getDefaultPhoto = function() { console.log('Storage.getDefaultPhoto'); - if(!this._defaultPhoto) { + if(!this.defaultPhoto) { + var defer = $.Deferred(); var url = OC.imagePath('contacts', 'person_large.png'); - this._defaultPhoto = new Image(); - $.when( - $(this._defaultPhoto) - .load(function() { - console.log('Default photo loaded', arguments); - }).error(function() { - console.log('Error loading default photo', arguments) - }).attr('src', url) - ) - .then(function(response) { - console.log('Storage.defaultPhoto', response); - }) - .fail(function(jqxhr, textStatus, error) { - var err = textStatus + ', ' + error; - console.log( "Request Failed: " + err); - $(document).trigger('status.contact.error', { - message: t('contacts', 'Failed loading default photo: {error}', {error:err}) - }); - }); - }; - return this._defaultPhoto; + this.defaultPhoto = new Image(); + var self = this; + $(this.defaultPhoto) + .load(function() { + defer.resolve(this); + }).error(function(event) { + defer.reject(); + }).attr('src', url) + return defer.promise(); + } else { + return this.defaultPhoto; + } } /**