summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-08-16 00:24:38 +0200
committerThomas Tanghus <thomas@tanghus.net>2012-08-16 00:25:32 +0200
commit4c638f101e09cbe43a2114c64ebb30774bafce4b (patch)
tree80a01ed4cce75428b66e9fc343d336bf59f357cf
parentdd3208fe6fadff3ad831df2fa5220e2184738b21 (diff)
downloadnextcloud-server-4c638f101e09cbe43a2114c64ebb30774bafce4b.tar.gz
nextcloud-server-4c638f101e09cbe43a2114c64ebb30774bafce4b.zip
Merge addressbooks.
-rw-r--r--apps/contacts/ajax/contact/move.php30
-rw-r--r--apps/contacts/js/contacts.js30
-rw-r--r--apps/contacts/lib/vcard.php9
3 files changed, 43 insertions, 26 deletions
diff --git a/apps/contacts/ajax/contact/move.php b/apps/contacts/ajax/contact/move.php
index a3336c3cb6c..053343c47ed 100644
--- a/apps/contacts/ajax/contact/move.php
+++ b/apps/contacts/ajax/contact/move.php
@@ -7,35 +7,23 @@
* later.
* See the COPYING-README file.
*/
-
+
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
-$ids = $_POST['ids'];
+$id = intval($_POST['id']);
$aid = intval($_POST['aid']);
+$isaddressbook = isset($_POST['isaddressbook']) ? true: false;
+
+// Ownership checking
OC_Contacts_App::getAddressbook($aid);
-
-if(!is_array($ids)) {
- $ids = array($ids,);
-}
-$goodids = array();
-foreach ($ids as $id){
- try {
- $card = OC_Contacts_App::getContactObject( intval($id) );
- if($card) {
- $goodids[] = $id;
- }
- } catch (Exception $e) {
- OCP\Util::writeLog('contacts', 'Error moving contact "'.$id.'" to addressbook "'.$aid.'"'.$e->getMessage(), OCP\Util::ERROR);
- }
-}
try {
- OC_Contacts_VCard::moveToAddressBook($aid, $ids);
+ OC_Contacts_VCard::moveToAddressBook($aid, $id, $isaddressbook);
} catch (Exception $e) {
$msg = $e->getMessage();
- OCP\Util::writeLog('contacts', 'Error moving contacts "'.implode(',', $ids).'" to addressbook "'.$aid.'"'.$msg, OCP\Util::ERROR);
+ OCP\Util::writeLog('contacts', 'Error moving contacts "'.implode(',', $id).'" to addressbook "'.$aid.'"'.$msg, OCP\Util::ERROR);
OC_JSON::error(array('data' => array('message' => $msg,)));
}
-
-OC_JSON::success(array('data' => array('ids' => $goodids,))); \ No newline at end of file
+
+OC_JSON::success(array('data' => array('ids' => $id,))); \ No newline at end of file
diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js
index 35637de050d..f535dc03f3f 100644
--- a/apps/contacts/js/contacts.js
+++ b/apps/contacts/js/contacts.js
@@ -1437,8 +1437,12 @@ OC.Contacts={
if(dragitem.data('bookid') == droptarget.data('id')) {
return false;
}
- var droplist = (droptarget.is('ul'))?droptarget:droptarget.next();
- $.post(OC.filePath('contacts', 'ajax', 'contact/move.php'), { ids: dragitem.data('id'), aid: droptarget.data('id') },
+ var droplist = (droptarget.is('ul')) ? droptarget : droptarget.next();
+ $.post(OC.filePath('contacts', 'ajax', 'contact/move.php'),
+ {
+ id: dragitem.data('id'),
+ aid: droptarget.data('id')
+ },
function(jsondata){
if(jsondata.status == 'success'){
dragitem.attr('data-bookid', droptarget.data('id'))
@@ -1454,7 +1458,27 @@ OC.Contacts={
});
},
dropAddressbook:function(event, dragitem, droptarget) {
- alert('Dropping address books not implemented yet');
+ if(confirm(t('contacts', 'Do you want to merge these address books?'))) {
+ if(dragitem.data('bookid') == droptarget.data('id')) {
+ return false;
+ }
+ var droplist = (droptarget.is('ul')) ? droptarget : droptarget.next();
+ $.post(OC.filePath('contacts', 'ajax', 'contact/move.php'),
+ {
+ id: dragitem.data('id'),
+ aid: droptarget.data('id'),
+ isaddressbook: 1
+ },
+ function(jsondata){
+ if(jsondata.status == 'success'){
+ OC.Contacts.Contacts.update(); // Easier to refresh the whole bunch.
+ } else {
+ OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
+ }
+ });
+ } else {
+ return false;
+ }
},
/**
* @params params An object with the properties 'contactlist':a jquery object of the ul to insert into,
diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php
index b213bcd7623..91ac89f5535 100644
--- a/apps/contacts/lib/vcard.php
+++ b/apps/contacts/lib/vcard.php
@@ -589,7 +589,7 @@ class OC_Contacts_VCard{
* @return boolean
*
*/
- public static function moveToAddressBook($aid, $id) {
+ public static function moveToAddressBook($aid, $id, $isAddressbook = false) {
OC_Contacts_App::getAddressbook($aid); // check for user ownership.
if(is_array($id)) {
$id_sql = join(',', array_fill(0, count($id), '?'));
@@ -606,8 +606,13 @@ class OC_Contacts_VCard{
return false;
}
} else {
- try {
+ $stmt = null;
+ if($isAddressbook) {
+ $stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE addressbookid = ?' );
+ } else {
$stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id = ?' );
+ }
+ try {
$result = $stmt->execute(array($aid, $id));
} catch(Exception $e) {
OCP\Util::writeLog('contacts', __CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(), OCP\Util::DEBUG);