1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-01 13:24:10 +01:00

Update contact list on adding/removing to/from groups. Fix #118

This commit is contained in:
Thomas Tanghus 2013-09-06 20:33:31 +02:00
parent 3ee20ca1b6
commit e8d0807fd2
3 changed files with 56 additions and 44 deletions

View File

@ -615,14 +615,6 @@ OC.Contacts = OC.Contacts || {
});
});
$(document).bind('status.contact.removedfromgroup', function(e, result) {
console.log('status.contact.removedfromgroup', result);
if(self.currentgroup == result.groupid) {
self.contacts.hideContact(result.contactid);
self.closeContact(result.contactid);
}
});
$(document).bind('status.group.groupremoved', function(e, result) {
console.log('status.group.groupremoved', result);
if(parseInt(result.groupid) === parseInt(self.currentgroup)) {
@ -641,20 +633,39 @@ OC.Contacts = OC.Contacts || {
$.each(result.contacts, function(idx, contactid) {
var contact = self.contacts.findById(contactid);
if(!contact) {
console.log('Couldn\'t find contact', contactid)
console.warn('Couldn\'t find contact', contactid)
return true; // continue
}
contact.renameGroup(result.from, result.to);
});
});
$(document).bind('status.group.contactremoved', function(e, result) {
console.log('status.group.contactremoved', result, self.currentgroup, result.groupid);
var contact = self.contacts.findById(result.contactid);
if(contact) {
if(contact.inGroup(result.groupname)) {
contact.removeFromGroup(result.groupname);
}
if(parseInt(self.currentgroup) === parseInt(result.groupid)) {
console.log('Hiding', contact.getId());
contact.hide();
}
}
});
$(document).bind('status.group.contactadded', function(e, result) {
console.log('status.group.contactadded', result);
var contact = self.contacts.findById(result.contactid);
if(!contact) {
return false;
if(contact) {
if(!contact.inGroup(result.groupname)) {
contact.addToGroup(result.groupname);
}
if(parseInt(self.currentgroup) === parseInt(result.groupid)) {
console.log('Showing', contact.getId());
contact.show();
}
}
contact.addToGroup(result.groupname);
});
// Group sorted, save the sort order
@ -838,11 +849,6 @@ OC.Contacts = OC.Contacts || {
if(buildnow) {
self.buildGroupSelect();
}
$(document).trigger('status.contact.addedtogroup', {
contactid: id,
groupid: groupId,
groupname: groupName
});
}, 1000);
});
} else {
@ -876,11 +882,6 @@ OC.Contacts = OC.Contacts || {
if(buildnow) {
self.buildGroupSelect();
}
$(document).trigger('status.contact.addedtogroup', {
contactid: id,
groupid: groupId,
groupname: groupName
});
}, 1000);
});
} else {
@ -892,7 +893,7 @@ OC.Contacts = OC.Contacts || {
self.$groups.val(-1).hide().find('optgroup,option:not([value="-1"])').remove();
}
} else if(action === 'remove') {
self.groups.removeFrom(ids, $opt.val(), function(result) {
self.groups.removeFrom(ids, $opt.val(), false, function(result) {
console.log('after remove', result);
if(!result.error) {
var groupname = $opt.text(), groupid = $opt.val();
@ -905,12 +906,6 @@ OC.Contacts = OC.Contacts || {
if(buildnow) {
self.buildGroupSelect();
}
// If a group is selected the contact has to be removed from the list
$(document).trigger('status.contact.removedfromgroup', {
contactid: id,
groupid: groupId,
groupname: groupName
});
});
} else {
var msg = result.message ? result.message : t('contacts', 'Error removing from group.');

View File

@ -672,6 +672,13 @@ OC.Contacts = OC.Contacts || {};
this.getListItemElement().hide();
};
/**
* Show contact list element.
*/
Contact.prototype.show = function() {
this.getListItemElement().show();
};
/**
* Remove any open contact from the DOM.
*/
@ -1754,7 +1761,6 @@ OC.Contacts = OC.Contacts || {};
}
});
if(!found) {
console.log('not found');
return;
}
this.data.CATEGORIES[0].value = categories;

View File

@ -291,13 +291,14 @@ OC.Contacts = OC.Contacts || {};
}, 2000);
if(typeof cb === 'function') {
cb({ids:ids});
} else {
}
$.each(ids, function(idx, contactid) {
$(document).trigger('status.group.contactadded', {
contactid: contactid,
groupid: groupid,
groupname: groupname
});
}
});
} else {
if(typeof cb == 'function') {
cb({error:true, message:response.message});
@ -319,6 +320,7 @@ OC.Contacts = OC.Contacts || {};
GroupList.prototype.removeFrom = function(contactid, groupid, onlyInternal, cb) {
console.log('GroupList.removeFrom', contactid, groupid);
var $groupelem = this.findById(groupid);
var groupname = this.nameById(groupid);
var contacts = $groupelem.data('contacts');
var ids = [];
@ -371,19 +373,28 @@ OC.Contacts = OC.Contacts || {};
$groupelem.find('.numcontacts').text(contacts.length);
//console.log('contacts', contacts, contacts.indexOf(id), contacts.indexOf(String(id)));
$groupelem.data('contacts', contacts);
if(doPost && !onlyInternal) {
var groupname = this.nameById(groupid);
$.when(this.storage.removeFromGroup(ids, groupid, groupname)).then(function(response) {
if(!response.error) {
if(typeof cb === 'function') {
cb({ids:ids});
}
} else {
if(typeof cb == 'function') {
cb({error:true, message:response.message});
}
}
if(doPost) {
// If a group is selected the contact has to be removed from the list
$.each(ids, function(idx, contactid) {
$(document).trigger('status.group.contactremoved', {
contactid: contactid,
groupid: parseInt(groupid),
groupname: groupname
});
});
if(!onlyInternal) {
$.when(this.storage.removeFromGroup(ids, groupid, groupname)).then(function(response) {
if(!response.error) {
if(typeof cb === 'function') {
cb({ids:ids});
}
} else {
if(typeof cb == 'function') {
cb({error:true, message:response.message});
}
}
});
}
}
};