mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-11-29 11:24:11 +01:00
Contacts: Ported addToGroup and removeFromGroup
This commit is contained in:
parent
aa87d0de73
commit
01e4a01cab
@ -150,7 +150,7 @@ $this->create('contacts_contact_delete_property', 'addressbook/{user}/{backend}/
|
||||
->action(
|
||||
function($params) {
|
||||
session_write_close();
|
||||
$request = new Request($params);
|
||||
$request = new Request(array('urlParams' => $params));
|
||||
$name = $request->post['name'];
|
||||
$checksum = $request->post['checksum'];
|
||||
|
||||
@ -202,7 +202,7 @@ $this->create('contacts_contact_save_property', 'addressbook/{user}/{backend}/{a
|
||||
->action(
|
||||
function($params) {
|
||||
session_write_close();
|
||||
$request = new Request($params);
|
||||
$request = new Request(array('urlParams' => $params));
|
||||
// TODO: When value is empty unset the property and return a checksum of 'new' if multi_property
|
||||
$name = $request->post['name'];
|
||||
$value = $request->post['value'];
|
||||
@ -288,7 +288,7 @@ $this->create('contacts_categories_add', 'groups/{user}/add')
|
||||
->action(
|
||||
function($params) {
|
||||
session_write_close();
|
||||
$request = new Request($params);
|
||||
$request = new Request(array('urlParams' => $params));
|
||||
$name = $request->post['name'];
|
||||
|
||||
if(is_null($name) || $name === "") {
|
||||
@ -312,7 +312,7 @@ $this->create('contacts_categories_delete', 'groups/{user}/delete')
|
||||
->action(
|
||||
function($params) {
|
||||
session_write_close();
|
||||
$request = new Request($params);
|
||||
$request = new Request(array('urlParams' => $params));
|
||||
$name = $request->post['name'];
|
||||
|
||||
if(is_null($name) || $name === "") {
|
||||
@ -327,6 +327,64 @@ $this->create('contacts_categories_delete', 'groups/{user}/delete')
|
||||
)
|
||||
->defaults(array('user' => \OCP\User::getUser()));
|
||||
|
||||
$this->create('contacts_categories_addto', 'groups/{user}/addto/{categoryid}')
|
||||
->post()
|
||||
->action(
|
||||
function($params) {
|
||||
session_write_close();
|
||||
$request = new Request(array('urlParams' => $params));
|
||||
$categoryid = $request['categoryid'];
|
||||
$ids = $request['contactids'];
|
||||
debug('request: '.print_r($request->post, true));
|
||||
|
||||
if(is_null($categoryid) || $categoryid === '') {
|
||||
bailOut(App::$l10n->t('Group ID missing from request.'));
|
||||
}
|
||||
|
||||
if(is_null($ids)) {
|
||||
bailOut(App::$l10n->t('Contact ID missing from request.'));
|
||||
}
|
||||
|
||||
$catman = new \OC_VCategories('contact', $params['user']);
|
||||
foreach($ids as $contactid) {
|
||||
debug('contactid: ' . $contactid . ', categoryid: ' . $categoryid);
|
||||
$catman->addToCategory($contactid, $categoryid);
|
||||
}
|
||||
|
||||
\OCP\JSON::success();
|
||||
}
|
||||
)
|
||||
->defaults(array('user' => \OCP\User::getUser()));
|
||||
|
||||
$this->create('contacts_categories_removefrom', 'groups/{user}/removefrom/{categoryid}')
|
||||
->post()
|
||||
->action(
|
||||
function($params) {
|
||||
session_write_close();
|
||||
$request = new Request(array('urlParams' => $params));
|
||||
$categoryid = $request['categoryid'];
|
||||
$ids = $request['contactids'];
|
||||
debug('request: '.print_r($request->post, true));
|
||||
|
||||
if(is_null($categoryid) || $categoryid === '') {
|
||||
bailOut(App::$l10n->t('Group ID missing from request.'));
|
||||
}
|
||||
|
||||
if(is_null($ids)) {
|
||||
bailOut(App::$l10n->t('Contact ID missing from request.'));
|
||||
}
|
||||
|
||||
$catman = new \OC_VCategories('contact', $params['user']);
|
||||
foreach($ids as $contactid) {
|
||||
debug('contactid: ' . $contactid . ', categoryid: ' . $categoryid);
|
||||
$catman->removeFromCategory($contactid, $categoryid);
|
||||
}
|
||||
|
||||
\OCP\JSON::success();
|
||||
}
|
||||
)
|
||||
->defaults(array('user' => \OCP\User::getUser()));
|
||||
|
||||
$this->create('contacts_setpreference', 'preference/{user}/set')
|
||||
->post()
|
||||
->action(
|
||||
|
39
js/groups.js
39
js/groups.js
@ -30,7 +30,7 @@ OC.Contacts = OC.Contacts || {};
|
||||
if($(event.target).is('.action.delete')) {
|
||||
var id = $(event.target).parents('h3').first().data('id');
|
||||
self.deleteGroup(id, function(response) {
|
||||
if(response.status !== 'success') {
|
||||
if(response.error) {
|
||||
OC.notify({message:response.data.message});
|
||||
}
|
||||
});
|
||||
@ -211,14 +211,8 @@ OC.Contacts = OC.Contacts || {};
|
||||
console.warn('Invalid data type: ' + typeof contactid);
|
||||
}
|
||||
if(doPost) {
|
||||
$.post(OC.filePath('contacts', 'ajax', 'categories/addto.php'), {contactids: ids, categoryid: groupid},function(jsondata) {
|
||||
if(!jsondata) {
|
||||
if(typeof cb === 'function') {
|
||||
cb({status:'error', message:'Network or server error. Please inform administrator.'});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(jsondata.status === 'success') {
|
||||
$.when(this.storage.addToGroup(ids, groupid)).then(function(response) {
|
||||
if(!response.error) {
|
||||
contacts = contacts.concat(ids).sort();
|
||||
$groupelem.data('contacts', contacts);
|
||||
var $numelem = $groupelem.find('.numcontacts');
|
||||
@ -237,7 +231,7 @@ OC.Contacts = OC.Contacts || {};
|
||||
}
|
||||
} else {
|
||||
if(typeof cb == 'function') {
|
||||
cb({status:'error', message:jsondata.data.message});
|
||||
cb({status:'error', message:response.message});
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -300,15 +294,8 @@ OC.Contacts = OC.Contacts || {};
|
||||
}
|
||||
}
|
||||
if(doPost) {
|
||||
// TODO: Use Storage
|
||||
$.post(OC.filePath('contacts', 'ajax', 'categories/removefrom.php'), {contactids: ids, categoryid: groupid},function(jsondata) {
|
||||
if(!jsondata) {
|
||||
if(typeof cb === 'function') {
|
||||
cb({status:'error', message:'Network or server error. Please inform administrator.'});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(jsondata.status === 'success') {
|
||||
$.when(this.storage.removeFromGroup(ids, groupid)).then(function(response) {
|
||||
if(!response.error) {
|
||||
$.each(ids, function(idx, id) {
|
||||
contacts.splice(contacts.indexOf(id), 1);
|
||||
});
|
||||
@ -324,7 +311,7 @@ OC.Contacts = OC.Contacts || {};
|
||||
}
|
||||
} else {
|
||||
if(typeof cb == 'function') {
|
||||
cb({status:'error', message:jsondata.data.message});
|
||||
cb({status:'error', message:response.message});
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -399,7 +386,7 @@ OC.Contacts = OC.Contacts || {};
|
||||
var self = this;
|
||||
console.log('delete group', groupid, contacts);
|
||||
$.when(this.storage.deleteGroup(name)).then(function(response) {
|
||||
if (response && response.status == 'success') {
|
||||
if (!response.error) {
|
||||
$(document).trigger('status.group.groupremoved', {
|
||||
groupid: groupid,
|
||||
newgroupid: parseInt($newelem.data('id')),
|
||||
@ -409,7 +396,7 @@ OC.Contacts = OC.Contacts || {};
|
||||
$elem.remove();
|
||||
self.selectGroup({element:$newelem});
|
||||
} else {
|
||||
//
|
||||
console.log('Error', response);
|
||||
}
|
||||
if(typeof cb === 'function') {
|
||||
cb(response);
|
||||
@ -449,7 +436,7 @@ OC.Contacts = OC.Contacts || {};
|
||||
$input.prop('disabled', true);
|
||||
$elem.data('rawname', '');
|
||||
self.addGroup({name:name, element: $elem}, function(response) {
|
||||
if(response.status === 'success') {
|
||||
if(!response.error) {
|
||||
$elem.prepend(escapeHTML(response.name)).removeClass('editing').attr('data-id', response.id);
|
||||
$input.next('.checked').remove();
|
||||
$input.remove();
|
||||
@ -554,7 +541,7 @@ OC.Contacts = OC.Contacts || {};
|
||||
return;
|
||||
}
|
||||
$.when(this.storage.addGroup(name)).then(function(response) {
|
||||
if (response && response.status == 'success') {
|
||||
if (!response.error) {
|
||||
name = response.data.name;
|
||||
var id = response.data.id;
|
||||
var tmpl = self.$groupListItemTemplate;
|
||||
@ -586,11 +573,11 @@ OC.Contacts = OC.Contacts || {};
|
||||
$elem.tipsy({trigger:'manual', gravity:'w', fallback: t('contacts', 'You can drag groups to\narrange them as you like.')});
|
||||
$elem.tipsy('show');
|
||||
if(typeof cb === 'function') {
|
||||
cb({status:'success', id:parseInt(id), name:name});
|
||||
cb({id:parseInt(id), name:name});
|
||||
}
|
||||
} else {
|
||||
if(typeof cb === 'function') {
|
||||
cb({status:'error', message:response.data.message});
|
||||
cb({error:true, message:response.data.message});
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -263,6 +263,36 @@ OC.Contacts = OC.Contacts || {};
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add contacts to a group
|
||||
*
|
||||
* @param array contactids
|
||||
*/
|
||||
Storage.prototype.addToGroup = function(contactids, categoryid) {
|
||||
console.log('Storage.addToGroup', contactids, categoryid);
|
||||
return this.requestRoute(
|
||||
'contacts_categories_addto',
|
||||
'POST',
|
||||
{user: this.user, categoryid: categoryid},
|
||||
{contactids: contactids}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove contacts from a group
|
||||
*
|
||||
* @param array contactids
|
||||
*/
|
||||
Storage.prototype.removeFromGroup = function(contactids, categoryid) {
|
||||
console.log('Storage.addToGroup', contactids, categoryid);
|
||||
return this.requestRoute(
|
||||
'contacts_categories_removefrom',
|
||||
'POST',
|
||||
{user: this.user, categoryid: categoryid},
|
||||
{contactids: contactids}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a user preference
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user