mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-11-29 11:24:11 +01:00
Contacts: refactor adding to/removing from group.
This commit is contained in:
parent
a0d307ef16
commit
e9de8f406b
@ -24,12 +24,11 @@ if(is_null($contactids)) {
|
||||
bailOut(OCA\Contacts\App::$l10n->t('Contact ID missing from request.'));
|
||||
}
|
||||
|
||||
debug('id: ' . print_r($contactids, true) .', categoryid: ' . $categoryid);
|
||||
|
||||
$catmgr = OCA\Contacts\App::getVCategories();
|
||||
|
||||
foreach($contactids as $contactid) {
|
||||
$catmgr->addToCategory($contactids, $categoryid);
|
||||
debug('contactid: ' . $contactid . ', categoryid: ' . $categoryid);
|
||||
$catmgr->addToCategory($contactid, $categoryid);
|
||||
}
|
||||
|
||||
OCP\JSON::success();
|
||||
|
@ -24,11 +24,10 @@ if(is_null($contactids)) {
|
||||
bailOut(OCA\Contacts\App::$l10n->t('Contact ID missing from request.'));
|
||||
}
|
||||
|
||||
debug('id: ' . $contactids .', categoryid: ' . $categoryids);
|
||||
|
||||
$catmgr = OCA\Contacts\App::getVCategories();
|
||||
|
||||
foreach($contactids as $contactid) {
|
||||
debug('id: ' . $contactid .', categoryid: ' . $categoryid);
|
||||
$catmgr->removeFromCategory($contactid, $categoryid);
|
||||
}
|
||||
|
||||
|
36
js/app.js
36
js/app.js
@ -803,22 +803,19 @@ OC.Contacts = OC.Contacts || {
|
||||
}
|
||||
self.currentlistid = result.id
|
||||
});
|
||||
$(document).bind('status.contact.removedfromgroup', function(e, result) {
|
||||
console.log('status.contact.removedfromgroup', result);
|
||||
if(self.currentgroup == result.groupid) {
|
||||
self.closeContact(result.contactid);
|
||||
}
|
||||
});
|
||||
|
||||
$(document).bind('status.nomorecontacts', function(e, result) {
|
||||
console.log('status.nomorecontacts', result);
|
||||
self.$contactList.hide();
|
||||
self.$firstRun.show();
|
||||
// TODO: Show a first-run page.
|
||||
});
|
||||
|
||||
$(document).bind('status.visiblecontacts', function(e, result) {
|
||||
console.log('status.visiblecontacts', result);
|
||||
// TODO: To be decided.
|
||||
});
|
||||
|
||||
// A contact id was in the request
|
||||
$(document).bind('request.loadcontact', function(e, result) {
|
||||
console.log('request.loadcontact', result);
|
||||
@ -834,28 +831,49 @@ OC.Contacts = OC.Contacts || {
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
$(document).bind('request.select.contactphoto.fromlocal', function(e, result) {
|
||||
console.log('request.select.contactphoto.fromlocal', result);
|
||||
$('#contactphoto_fileupload').trigger('click');
|
||||
});
|
||||
|
||||
$(document).bind('request.select.contactphoto.fromcloud', function(e, result) {
|
||||
console.log('request.select.contactphoto.fromcloud', result);
|
||||
OC.dialogs.filepicker(t('contacts', 'Select photo'), function(path) {
|
||||
self.cloudPhotoSelected(self.currentid, path);
|
||||
}, false, 'image', true);
|
||||
});
|
||||
|
||||
$(document).bind('request.edit.contactphoto', function(e, result) {
|
||||
console.log('request.edit.contactphoto', result);
|
||||
self.editCurrentPhoto(result.id);
|
||||
});
|
||||
|
||||
$(document).bind('request.addressbook.activate', function(e, result) {
|
||||
console.log('request.addressbook.activate', result);
|
||||
self.Contacts.showFromAddressbook(result.id, result.activate);
|
||||
});
|
||||
|
||||
$(document).bind('status.group.contactremoved', function(e, result) {
|
||||
console.log('status.group.contactremoved', result);
|
||||
self.Contacts.contacts[parseInt(result.contactid)].removeFromGroup(result.groupname);
|
||||
$(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)) {
|
||||
console.time('hiding');
|
||||
self.Contacts.showContacts([]);
|
||||
console.timeEnd('hiding');
|
||||
self.currentgroup = 'all';
|
||||
}
|
||||
$.each(result.contacts, function(idx, contactid) {
|
||||
console.log('contactid', contactid);
|
||||
self.Contacts.contacts[parseInt(result.contactid)].removeFromGroup(result.groupname);
|
||||
});
|
||||
});
|
||||
|
||||
$(document).bind('status.group.contactadded', function(e, result) {
|
||||
|
@ -969,6 +969,16 @@ OC.Contacts = OC.Contacts || {};
|
||||
if(!this.data.CATEGORIES) {
|
||||
this.data.CATEGORIES = [{value:[name]},];
|
||||
} else {
|
||||
var found = false;
|
||||
$.each(this.data.CATEGORIES[0].value, function(idx, category) {
|
||||
if(name.toLowerCase() === category.toLowerCase()) {
|
||||
found = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if(found) {
|
||||
return;
|
||||
}
|
||||
this.data.CATEGORIES[0].value.push(name);
|
||||
console.log('listelem categories', this.getPreferredValue('CATEGORIES', []).clean('').join(' / '));
|
||||
if(this.$listelem) {
|
||||
@ -988,7 +998,21 @@ OC.Contacts = OC.Contacts || {};
|
||||
if(!this.data.CATEGORIES) {
|
||||
return;
|
||||
} else {
|
||||
this.data.CATEGORIES[0].value.splice(this.data.CATEGORIES[0].value.indexOf(name), 1);
|
||||
var found = false;
|
||||
var categories = [];
|
||||
$.each(this.data.CATEGORIES[0].value, function(idx, category) {
|
||||
if(name.toLowerCase() === category.toLowerCase()) {
|
||||
found = true;
|
||||
// Not breaking out of loop 'cause there could be dupes.
|
||||
} else {
|
||||
categories.push(category);
|
||||
}
|
||||
});
|
||||
if(!found) {
|
||||
return;
|
||||
}
|
||||
this.data.CATEGORIES[0].value = categories;
|
||||
//this.data.CATEGORIES[0].value.splice(this.data.CATEGORIES[0].value.indexOf(name), 1);
|
||||
if(this.$listelem) {
|
||||
this.$listelem.find('td.categories')
|
||||
.text(this.getPreferredValue('CATEGORIES', []).clean('').join(' / '));
|
||||
|
Loading…
Reference in New Issue
Block a user