From 3baa72a62fc69dda8306674da6d150efbf2cd55b Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Wed, 31 Mar 2010 10:53:02 -0400
Subject: [PATCH] Implement group renaming/deleting + use more consistent names for commands and actions (#1486587)

---
 program/steps/addressbook/groups.inc |   46 +++++++++++++++++++++++++++++++++-------------
 1 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/program/steps/addressbook/groups.inc b/program/steps/addressbook/groups.inc
index 8c7aef6..0141926 100644
--- a/program/steps/addressbook/groups.inc
+++ b/program/steps/addressbook/groups.inc
@@ -25,7 +25,23 @@
   $OUTPUT->send();
 }
 
-if ($RCMAIL->action == 'create-group') {
+if ($RCMAIL->action == 'group-addmember') {
+  if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST)))
+  if ($CONTACTS->add_to_group($gid, $ids))
+    $OUTPUT->show_message('contactaddedtogroup');
+  //else
+  //  $OUTPUT->show_message('erroraddingcontact', 'warning');
+}
+
+else if ($RCMAIL->action == 'group-delmember') {
+  if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST)))
+  if ($CONTACTS->remove_from_group($gid, $ids))
+    $OUTPUT->show_message('contactremovedfromgroup');
+  //else
+  //  $OUTPUT->show_message('erroraddingcontact', 'warning');
+}
+
+else if ($RCMAIL->action == 'group-create') {
   if (!empty($_POST['_name'])) {
     $name = trim(get_input_value('_name', RCUBE_INPUT_POST));
     $created = $CONTACTS->create_group($name);
@@ -39,20 +55,24 @@
   }
 }
 
-else if ($RCMAIL->action == 'add2group') {
-  if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST)))
-  if ($CONTACTS->add_to_group($gid, $ids))
-    $OUTPUT->show_message('contactaddedtogroup');
-  //else
-  //  $OUTPUT->show_message('erroraddingcontact', 'warning');
+else if ($RCMAIL->action == 'group-rename') {
+  if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($name = trim(get_input_value('_name', RCUBE_INPUT_POST))))
+    $newname = $CONTACTS->rename_group($gid, $name);
+
+  if ($newname && $OUTPUT->ajax_call)
+    $OUTPUT->command('update_contact_group', $gid, $newname);
+  else if (!$newname)
+    $OUTPUT->show_message('errorsaving', 'error');
 }
 
-else if ($RCMAIL->action == 'removefromgroup') {
-  if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST)))
-  if ($CONTACTS->remove_from_group($gid, $ids))
-    $OUTPUT->show_message('contactremovedfromgroup');
-  //else
-  //  $OUTPUT->show_message('erroraddingcontact', 'warning');
+else if ($RCMAIL->action == 'group-delete') {
+  if ($gid = get_input_value('_gid', RCUBE_INPUT_POST))
+    $deleted = $CONTACTS->delete_group($gid);
+
+  if ($deleted)
+    $OUTPUT->command('remove_group_item', $gid);
+  else
+    $OUTPUT->show_message('errorsaving', 'error');
 }
 
 // send response

--
Gitblit v1.9.1