mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-30 19:52:17 +01:00
Proper updating on deletion of contact photo. Fix #77
This commit is contained in:
parent
65c4b71965
commit
23b6e074da
@ -307,10 +307,15 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
newvalue: $container.find('input.value').val()
|
newvalue: $container.find('input.value').val()
|
||||||
});
|
});
|
||||||
self.setAsSaving(obj, false);
|
self.setAsSaving(obj, false);
|
||||||
|
if(element === 'PHOTO') {
|
||||||
|
self.data.PHOTO[0].value = false;
|
||||||
|
self.data.thumbnail = null;
|
||||||
|
} else {
|
||||||
self.$fullelem.find('[data-element="' + element.toLowerCase() + '"]').hide();
|
self.$fullelem.find('[data-element="' + element.toLowerCase() + '"]').hide();
|
||||||
$container.find('input.value').val('');
|
$container.find('input.value').val('');
|
||||||
self.$addMenu.find('option[value="' + element.toUpperCase() + '"]').prop('disabled', false);
|
self.$addMenu.find('option[value="' + element.toUpperCase() + '"]').prop('disabled', false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$(document).trigger('status.contact.updated', {
|
$(document).trigger('status.contact.updated', {
|
||||||
property: element,
|
property: element,
|
||||||
contact: self
|
contact: self
|
||||||
@ -1439,13 +1444,14 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
$elem.css('background-image', 'url(data:image/png;base64,' + this.data.thumbnail + ')');
|
$elem.css('background-image', 'url(data:image/png;base64,' + this.data.thumbnail + ')');
|
||||||
} else {
|
} else {
|
||||||
$elem.addClass('thumbnail');
|
$elem.addClass('thumbnail');
|
||||||
|
$elem.removeAttr('style');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the PHOTO property.
|
* Render the PHOTO property.
|
||||||
*/
|
*/
|
||||||
Contact.prototype.loadPhoto = function(dontloadhandlers) {
|
Contact.prototype.loadPhoto = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var id = this.id || 'new',
|
var id = this.id || 'new',
|
||||||
backend = this.metadata.backend,
|
backend = this.metadata.backend,
|
||||||
@ -1478,13 +1484,18 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
$('img.contactphoto').remove();
|
$('img.contactphoto').remove();
|
||||||
finishLoad(image);
|
finishLoad(image);
|
||||||
})
|
})
|
||||||
.fail(function(defaultImage) {
|
.fail(function() {
|
||||||
|
console.log('Error getting photo, trying default image');
|
||||||
$('img.contactphoto').remove();
|
$('img.contactphoto').remove();
|
||||||
finishLoad(defaultImage);
|
$.when(self.storage.getDefaultPhoto())
|
||||||
|
.then(function(image) {
|
||||||
|
$('img.contactphoto').detach();
|
||||||
|
finishLoad(image);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!dontloadhandlers && this.isEditable()) {
|
if(this.isEditable()) {
|
||||||
this.$photowrapper.on('mouseenter', function(event) {
|
this.$photowrapper.on('mouseenter', function(event) {
|
||||||
if($(event.target).is('.favorite') || !self.data) {
|
if($(event.target).is('.favorite') || !self.data) {
|
||||||
return;
|
return;
|
||||||
@ -1500,6 +1511,7 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
});
|
});
|
||||||
$phototools.find('li a').tipsy();
|
$phototools.find('li a').tipsy();
|
||||||
|
|
||||||
|
$phototools.find('.action').off('click');
|
||||||
$phototools.find('.edit').on('click', function() {
|
$phototools.find('.edit').on('click', function() {
|
||||||
$(document).trigger('request.edit.contactphoto', self.metaData());
|
$(document).trigger('request.edit.contactphoto', self.metaData());
|
||||||
});
|
});
|
||||||
@ -1509,7 +1521,7 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
$phototools.find('.upload').on('click', function() {
|
$phototools.find('.upload').on('click', function() {
|
||||||
$(document).trigger('request.select.contactphoto.fromlocal', self.metaData());
|
$(document).trigger('request.select.contactphoto.fromlocal', self.metaData());
|
||||||
});
|
});
|
||||||
if(this.data && this.data.PHOTO) {
|
if(this.getPreferredValue('PHOTO', false)) {
|
||||||
$phototools.find('.delete').show();
|
$phototools.find('.delete').show();
|
||||||
$phototools.find('.edit').show();
|
$phototools.find('.edit').show();
|
||||||
} else {
|
} else {
|
||||||
@ -1518,8 +1530,17 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
}
|
}
|
||||||
$(document).bind('status.contact.photoupdated', function(e, data) {
|
$(document).bind('status.contact.photoupdated', function(e, data) {
|
||||||
console.log('status.contact.photoupdated', data);
|
console.log('status.contact.photoupdated', data);
|
||||||
self.loadPhoto(true);
|
if(!self.data.PHOTO) {
|
||||||
|
self.data.PHOTO = [];
|
||||||
|
}
|
||||||
|
if(data.thumbnail) {
|
||||||
self.data.thumbnail = data.thumbnail;
|
self.data.thumbnail = data.thumbnail;
|
||||||
|
self.data.PHOTO[0] = {value:true};
|
||||||
|
} else {
|
||||||
|
self.data.thumbnail = null;
|
||||||
|
self.data.PHOTO[0] = {value:false};
|
||||||
|
}
|
||||||
|
self.loadPhoto(true);
|
||||||
self.setThumbnail(null, true);
|
self.setThumbnail(null, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1717,6 +1738,10 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
if(['FN', 'EMAIL', 'TEL', 'ADR', 'CATEGORIES'].indexOf(data.property) !== -1) {
|
if(['FN', 'EMAIL', 'TEL', 'ADR', 'CATEGORIES'].indexOf(data.property) !== -1) {
|
||||||
data.contact.getListItemElement().remove();
|
data.contact.getListItemElement().remove();
|
||||||
self.insertContact(data.contact.renderListItem(true));
|
self.insertContact(data.contact.renderListItem(true));
|
||||||
|
} else if(data.property === 'PHOTO') {
|
||||||
|
$(document).trigger('status.contact.photoupdated', {
|
||||||
|
id: data.contact.getId()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$(document).bind('status.addressbook.removed', function(e, data) {
|
$(document).bind('status.addressbook.removed', function(e, data) {
|
||||||
@ -1795,7 +1820,7 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
ContactList.prototype.showUncategorized = function() {
|
ContactList.prototype.showUncategorized = function() {
|
||||||
console.log('ContactList.showUncategorized');
|
console.log('ContactList.showUncategorized');
|
||||||
for(var contact in this.contacts) {
|
for(var contact in this.contacts) {
|
||||||
if(this.contacts[contact].getPreferredValue('CATEGORIES', []).length > 0) {
|
if(this.contacts[contact].getPreferredValue('CATEGORIES', []).length === 0) {
|
||||||
this.contacts[contact].getListItemElement().show();
|
this.contacts[contact].getListItemElement().show();
|
||||||
} else {
|
} else {
|
||||||
this.contacts[contact].getListItemElement().hide();
|
this.contacts[contact].getListItemElement().hide();
|
||||||
|
@ -228,12 +228,14 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
{backend: backend, addressbookid: addressbookid, contactid: contactid}
|
{backend: backend, addressbookid: addressbookid, contactid: contactid}
|
||||||
);
|
);
|
||||||
var defer = $.Deferred();
|
var defer = $.Deferred();
|
||||||
|
var self = this;
|
||||||
$.when(
|
$.when(
|
||||||
$(photo).load(function() {
|
$(photo).load(function() {
|
||||||
defer.resolve(photo);
|
defer.resolve(photo);
|
||||||
})
|
})
|
||||||
.error(function() {
|
.error(function() {
|
||||||
console.log('Error loading default photo', arguments)
|
console.log('Error loading contact photo')
|
||||||
|
defer.reject();
|
||||||
})
|
})
|
||||||
.attr('src', url + '?refresh=' + Math.random())
|
.attr('src', url + '?refresh=' + Math.random())
|
||||||
)
|
)
|
||||||
|
@ -609,12 +609,16 @@ class Contact extends VObject\VCard implements IPIMObject {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cacheThumbnail(\OC_Image $image = null) {
|
public function cacheThumbnail(\OC_Image $image = null, $remove = false) {
|
||||||
$key = self::THUMBNAIL_PREFIX . $this->combinedKey();
|
$key = self::THUMBNAIL_PREFIX . $this->combinedKey();
|
||||||
//\OC_Cache::remove($key);
|
//\OC_Cache::remove($key);
|
||||||
if(\OC_Cache::hasKey($key) && $image === null) {
|
if(\OC_Cache::hasKey($key) && $image === null && $remove === false) {
|
||||||
return \OC_Cache::get($key);
|
return \OC_Cache::get($key);
|
||||||
}
|
}
|
||||||
|
if($remove) {
|
||||||
|
\OC_Cache::remove($key);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if(is_null($image)) {
|
if(is_null($image)) {
|
||||||
$this->retrieve();
|
$this->retrieve();
|
||||||
$image = new \OC_Image();
|
$image = new \OC_Image();
|
||||||
@ -652,6 +656,9 @@ class Contact extends VObject\VCard implements IPIMObject {
|
|||||||
|
|
||||||
public function __unset($key) {
|
public function __unset($key) {
|
||||||
parent::__unset($key);
|
parent::__unset($key);
|
||||||
|
if($key === 'PHOTO') {
|
||||||
|
$this->cacheThumbnail(null, true);
|
||||||
|
}
|
||||||
$this->setSaved(false);
|
$this->setSaved(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user