From c50d8872ced7c09dd9fcf5b3bf460c31e5b0c0ce Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Wed, 03 Nov 2010 10:19:48 -0400
Subject: [PATCH] - Add missing confirmation/error messages on contact/group/message actions (#1486845) - Add 'loading' message on message move/copy/delete/mark actions

---
 CHANGELOG                               |    2 
 program/steps/addressbook/groups.inc    |   32 ++++++----
 program/localization/en_US/messages.inc |   15 ++++
 program/steps/mail/func.inc             |    3 
 program/steps/addressbook/delete.inc    |   39 +++++++------
 program/steps/mail/show.inc             |    3 
 program/localization/pl_PL/messages.inc |   13 ++++
 program/steps/mail/mark.inc             |    3 +
 program/js/app.js                       |   36 +++++++----
 program/steps/mail/copy.inc             |    5 +
 program/steps/mail/move_del.inc         |   10 ++
 11 files changed, 108 insertions(+), 53 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 0d844e7..c3cd2f3 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -60,6 +60,8 @@
 - Improve performance of message cache status checking with skip_disabled=true
 - Support contact's email addresses up to 255 characters long (#1487095)
 - Add option to place replies in the folder of the message being replied to (#1485945)
+- Add missing confirmation/error messages on contact/group/message actions (#1486845)
+- Add 'loading' message on message move/copy/delete/mark actions
 
 RELEASE 0.4.2
 -------------
diff --git a/program/js/app.js b/program/js/app.js
index 870459d..bbc4550 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -2362,6 +2362,7 @@
       return;
 
     var a_uids = [],
+      lock = this.display_message(this.get_label('copyingmessage'), 'loading'),
       add_url = '&_target_mbox='+urlencode(mbox)+'&_from='+(this.env.action ? this.env.action : '');
 
     if (this.env.uid)
@@ -2374,7 +2375,7 @@
     }
 
     // send request to server
-    this.http_post('copy', '_uid='+a_uids.join(',')+'&_mbox='+urlencode(this.env.mailbox)+add_url, false);
+    this.http_post('copy', '_uid='+a_uids.join(',')+'&_mbox='+urlencode(this.env.mailbox)+add_url, lock);
   };
 
   // move selected messages to the specified mailbox
@@ -2425,7 +2426,7 @@
       return false;
     }
     // if there isn't a defined trash mailbox or we are in it
-    else if (!this.env.trash_mailbox || this.env.mailbox == this.env.trash_mailbox) 
+    else if (!this.env.trash_mailbox || this.env.mailbox == this.env.trash_mailbox)
       this.permanently_remove_messages();
     // if there is a trash mailbox defined and we're not currently in it
     else {
@@ -2456,7 +2457,7 @@
   // @private
   this._with_selected_messages = function(action, lock, add_url)
   {
-    var a_uids = [], count = 0;
+    var a_uids = [], count = 0, msg;
 
     if (this.env.uid)
       a_uids[0] = this.env.uid;
@@ -2486,7 +2487,7 @@
       }
     }
 
-    // also send search request to get the right messages 
+    // also send search request to get the right messages
     if (this.env.search_request)
       add_url += '&_search='+this.env.search_request;
 
@@ -2500,6 +2501,11 @@
       this.delete_excessive_thread_rows();
 
     add_url += '&_uid='+this.uids_to_list(a_uids);
+
+    if (!lock) {
+      msg = action == 'moveto' ? 'movingmessage' : 'deletingmessage';
+      lock = this.display_message(this.get_label(msg), 'loading');
+    }
 
     // send request to server
     this.http_post(action, '_mbox='+urlencode(this.env.mailbox)+add_url, lock);
@@ -2564,13 +2570,14 @@
     for (var i=0; i<a_uids.length; i++)
       this.set_message(a_uids[i], 'unread', (flag=='unread' ? true : false));
 
-    var url = '_uid='+this.uids_to_list(a_uids)+'&_flag='+flag;
+    var url = '_uid='+this.uids_to_list(a_uids)+'&_flag='+flag,
+      lock = this.display_message(this.get_label('markingmessage'), 'loading');
 
     // also send search request to get the right messages
     if (this.env.search_request)
       url += '&_search='+this.env.search_request;
 
-    this.http_post('mark', url);
+    this.http_post('mark', url, lock);
 
     for (var i=0; i<a_uids.length; i++)
       this.update_thread_root(a_uids[i], flag);
@@ -2583,13 +2590,14 @@
     for (var i=0; i<a_uids.length; i++)
       this.set_message(a_uids[i], 'flagged', (flag=='flagged' ? true : false));
 
-    var url = '_uid='+this.uids_to_list(a_uids)+'&_flag='+flag;
+    var url = '_uid='+this.uids_to_list(a_uids)+'&_flag='+flag,
+      lock = this.display_message(this.get_label('markingmessage'), 'loading');
 
     // also send search request to get the right messages
     if (this.env.search_request)
       url += '&_search='+this.env.search_request;
 
-    this.http_post('mark', url);
+    this.http_post('mark', url, lock);
   };
 
   // mark all message rows as deleted/undeleted
@@ -2628,13 +2636,14 @@
     for (var i=0, len=a_uids.length; i<len; i++)
       this.set_message(a_uids[i], 'deleted', false);
 
-    var url = '_uid='+this.uids_to_list(a_uids)+'&_flag=undelete';
+    var url = '_uid='+this.uids_to_list(a_uids)+'&_flag=undelete',
+      lock = this.display_message(this.get_label('markingmessage'), 'loading');
 
     // also send search request to get the right messages
     if (this.env.search_request)
       url += '&_search='+this.env.search_request;
 
-    this.http_post('mark', url);
+    this.http_post('mark', url, lock);
     return true;
   };
 
@@ -2671,7 +2680,8 @@
         this.delete_excessive_thread_rows();
     }
 
-    add_url = '&_from='+(this.env.action ? this.env.action : '');
+    add_url = '&_from='+(this.env.action ? this.env.action : ''),
+      lock = this.display_message(this.get_label('markingmessage'), 'loading');
 
     // ??
     if (r_uids.length)
@@ -2686,8 +2696,8 @@
     if (this.env.search_request)
       add_url += '&_search='+this.env.search_request;
 
-    this.http_post('mark', '_uid='+this.uids_to_list(a_uids)+'&_flag=delete'+add_url);
-    return true;  
+    this.http_post('mark', '_uid='+this.uids_to_list(a_uids)+'&_flag=delete'+add_url, lock);
+    return true;
   };
 
   // flag as read without mark request (called from backend)
diff --git a/program/localization/en_US/messages.inc b/program/localization/en_US/messages.inc
index 6474c9d..a5ac431 100644
--- a/program/localization/en_US/messages.inc
+++ b/program/localization/en_US/messages.inc
@@ -87,8 +87,10 @@
 $messages['copyerror'] = 'Could not copy any addresses';
 $messages['sourceisreadonly'] = 'This address source is read only';
 $messages['errorsavingcontact'] = 'Could not save the contact address';
-$messages['movingmessage'] = 'Moving message...';
-$messages['copyingmessage'] = 'Copying message...';
+$messages['movingmessage'] = 'Moving message(s)...';
+$messages['copyingmessage'] = 'Copying message(s)...';
+$messages['deletingmessage'] = 'Deleting message(s)...';
+$messages['markingmessage'] = 'Marking message(s)...';
 $messages['receiptsent'] = 'Successfully sent a read receipt';
 $messages['errorsendingreceipt'] = 'Could not send the receipt';
 $messages['nodeletelastidentity'] = 'You cannot delete this identity, it\'s your last one.';
@@ -116,5 +118,14 @@
 $messages['toomanyrecipients'] = 'Too many recipients. Reduce the number of recipients to $max.';
 $messages['maxgroupmembersreached'] = 'The number of group members exceeds the maximum of $max';
 $messages['internalerror'] = 'An internal error occured. Please try again';
+$messages['contactdelerror'] = 'Could not delete contact(s)';
+$messages['contactdeleted'] = 'Contact(s) deleted successfully';
+$messages['groupdeleted'] = 'Group deleted successfully';
+$messages['grouprenamed'] = 'Group renamed successfully';
+$messages['groupcreated'] = 'Group created successfully';
+$messages['messagedeleted'] = 'Message(s) deleted successfully';
+$messages['messagemoved'] = 'Message(s) moved successfully';
+$messages['messagecopied'] = 'Message(s) copied successfully';
+$messages['messagemarked'] = 'Message(s) marked successfully';
 
 ?>
diff --git a/program/localization/pl_PL/messages.inc b/program/localization/pl_PL/messages.inc
index 83c5664..db9eaca 100644
--- a/program/localization/pl_PL/messages.inc
+++ b/program/localization/pl_PL/messages.inc
@@ -94,6 +94,8 @@
 $messages['errorsavingcontact'] = 'Nie można było zapisać adresu kontaktu';
 $messages['movingmessage'] = 'Przenoszenie wiadomości...';
 $messages['copyingmessage'] = 'Kopiowanie wiadomości...';
+$messages['deletingmessage'] = 'Usuwanie wiadomości...';
+$messages['markingmessage'] = 'Oznaczanie wiadomości...';
 $messages['receiptsent'] = 'Pomyślnie wysłano potwierdzenie dostarczenia';
 $messages['errorsendingreceipt'] = 'Nie można wysłać potwierdzenia';
 $messages['nodeletelastidentity'] = 'Nie można skasować tej tożsamości, ponieważ jest ostatnią.';
@@ -120,6 +122,15 @@
 $messages['emailformaterror'] = 'Błędny adres e-mail: $email';
 $messages['toomanyrecipients'] = 'Zbyt wielu odbiorców. Zmniejsz ich liczbę do $max.';
 $messages['maxgroupmembersreached'] = 'Liczba członków grupy nie może być większa niż $max';
-$messages['internalerror'] = 'Wystąpił wewnętrzny błąd systemu. Spróbuj jeszcze raz'
+$messages['internalerror'] = 'Wystąpił wewnętrzny błąd systemu. Spróbuj jeszcze raz';
+$messages['contactdelerror'] = 'Usuwanie kontaktów nie powiodło się';
+$messages['contactdeleted'] = 'Kontakt(y) został(y) usunięte';
+$messages['groupdeleted'] = 'Grupa została usunięta';
+$messages['grouprenamed'] = 'Nazwa grupy została zmieniona';
+$messages['groupcreated'] = 'Grupa została utworzona';
+$messages['messagedeleted'] = 'Wiadomości zostały usunięte';
+$messages['messagemoved'] = 'Wiadomości zostały przeniesione';
+$messages['messagecopied'] = 'Wiadomości zostały skopiowane';
+$messages['messagemarked'] = 'Wiadomości zostały oznaczone';
 
 ?>
diff --git a/program/steps/addressbook/delete.inc b/program/steps/addressbook/delete.inc
index bb0457b..a41065f 100644
--- a/program/steps/addressbook/delete.inc
+++ b/program/steps/addressbook/delete.inc
@@ -23,30 +23,33 @@
     ($cid = get_input_value('_cid', RCUBE_INPUT_POST)) &&
     preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid)
 ) {
-  $plugin = $RCMAIL->plugins->exec_hook('contact_delete', array(
-    'id' => $cid, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
+    $plugin = $RCMAIL->plugins->exec_hook('contact_delete', array(
+        'id' => $cid, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
 
-  $deleted = !$plugin['abort'] ? $CONTACTS->delete($cid) : $plugin['result'];
+    $deleted = !$plugin['abort'] ? $CONTACTS->delete($cid) : $plugin['result'];
 
-  if (!$deleted) {
-    // send error message
-    exit;
-  }
+    if (!$deleted) {
+        $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'contactdelerror', 'error');
+        $OUTPUT->command('list_contacts');
+    }
+    else {
+        $OUTPUT->show_message('contactdeleted', 'confirmation');
 
-  // count contacts for this user
-  $result = $CONTACTS->count();
+        // count contacts for this user
+        $result = $CONTACTS->count();
 
-  // update message count display
-  $OUTPUT->set_env('pagecount', ceil($result->count / $CONTACTS->page_size));
-  $OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result->count));
+        // update message count display
+        $OUTPUT->set_env('pagecount', ceil($result->count / $CONTACTS->page_size));
+        $OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result->count));
 
-  // add new rows from next page (if any)
-  $pages = ceil(($result->count + $deleted) / $CONTACTS->page_size);
-  if ($_GET['_from'] != 'show' && $pages > 1 && $CONTACTS->list_page < $pages)
-    rcmail_js_contacts_list($CONTACTS->list_records(null, -$deleted));
+        // add new rows from next page (if any)
+        $pages = ceil(($result->count + $deleted) / $CONTACTS->page_size);
+        if ($_GET['_from'] != 'show' && $pages > 1 && $CONTACTS->list_page < $pages)
+            rcmail_js_contacts_list($CONTACTS->list_records(null, -$deleted));
+    }
 
-  // send response
-  $OUTPUT->send();
+    // send response
+    $OUTPUT->send();
 }
 
 exit;
diff --git a/program/steps/addressbook/groups.inc b/program/steps/addressbook/groups.inc
index 66619fa..f8bd0d7 100644
--- a/program/steps/addressbook/groups.inc
+++ b/program/steps/addressbook/groups.inc
@@ -29,10 +29,10 @@
 if ($RCMAIL->action == 'group-addmembers') {
   if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST))) {
     $plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array('group_id' => $gid, 'ids' => $ids, 'source' => $source));
-    
+
     $CONTACTS->set_group($gid);
     $num2add = count(explode(',', $plugin['ids']));
-    
+
     if (!$plugin['abort']) {
       if (($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($CONTACTS->count()->count + $num2add > $maxnum)) {
         $OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum));
@@ -44,26 +44,26 @@
       $result = $plugin['result'];
     }
 
-    if ($result) 
+    if ($result)
       $OUTPUT->show_message('contactaddedtogroup');
-    else if ($plugin['message'])
-      $OUTPUT->show_message($plugin['message'], 'warning');
+    else
+      $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
   }
 }
 
 else if ($RCMAIL->action == 'group-delmembers') {
   if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST))) {
     $plugin = $RCMAIL->plugins->exec_hook('group_delmembers', array('group_id' => $gid, 'ids' => $ids, 'source' => $source));
-    
+
     if (!$plugin['abort'])
       $result = $CONTACTS->remove_from_group($gid, $plugin['ids']);
     else
       $result = $plugin['result'];
 
-    if ($result) 
+    if ($result)
       $OUTPUT->show_message('contactremovedfromgroup');
-    else if ($plugin['message'])
-      $OUTPUT->show_message($plugin['message'], 'warning');
+    else
+      $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
   }
 }
 
@@ -76,10 +76,10 @@
     else
       $created = $plugin['result'];
   }
-  
+
   if ($created && $OUTPUT->ajax_call) {
-    $created['source'] = $source;
-    $OUTPUT->command('insert_contact_group', $created);
+    $OUTPUT->show_message('groupcreated', 'confirmation');
+    $OUTPUT->command('insert_contact_group', array('source' => $created));
   }
   else if (!$created) {
     $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
@@ -96,8 +96,10 @@
       $newname = $plugin['result'];
   }
 
-  if ($newname && $OUTPUT->ajax_call)
+  if ($newname && $OUTPUT->ajax_call) {
+    $OUTPUT->show_message('grouprenamed', 'confirmation');
     $OUTPUT->command('update_contact_group', array('source' => $source, 'id' => $gid, 'name' => $newname));
+  }
   else if (!$newname)
     $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
 }
@@ -112,8 +114,10 @@
       $deleted = $plugin['result'];
   }
 
-  if ($deleted)
+  if ($deleted) {
+    $OUTPUT->show_message('groupdeleted', 'confirmation');
     $OUTPUT->command('remove_group_item', array('source' => $source, 'id' => $gid));
+  }
   else
     $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
 }
diff --git a/program/steps/mail/copy.inc b/program/steps/mail/copy.inc
index b42ef39..ba5fa72 100644
--- a/program/steps/mail/copy.inc
+++ b/program/steps/mail/copy.inc
@@ -34,13 +34,16 @@
     $mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
 
     $copied = $IMAP->copy_message($uids, $target, $mbox);
-  
+
     if (!$copied) {
         // send error message
         $OUTPUT->show_message('errorcopying', 'error');
         $OUTPUT->send();
         exit;
     }
+    else {
+        $OUTPUT->show_message('messagecopied', 'confirmation');
+    }
 
     rcmail_send_unread_count($target, true);
 
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 629e68b..11df128 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -131,7 +131,8 @@
 
   if (!$OUTPUT->ajax_call)
     $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
-      'movingmessage', 'copyingmessage', 'copy', 'move', 'quota');
+      'movingmessage', 'copyingmessage', 'deletingmessage', 'markingmessage',
+      'copy', 'move', 'quota');
 
   $OUTPUT->set_pagetitle(rcmail_localize_foldername($mbox_name));
 }
diff --git a/program/steps/mail/mark.inc b/program/steps/mail/mark.inc
index 57eae64..4675481 100644
--- a/program/steps/mail/mark.inc
+++ b/program/steps/mail/mark.inc
@@ -51,6 +51,9 @@
     $OUTPUT->send();
     exit;
   }
+  else {
+    $OUTPUT->show_message('messagemarked', 'confirmation');
+  }
 
   if ($flag == 'DELETED' && $CONFIG['read_when_deleted'] && !empty($_POST['_ruid'])) {
     $ruids = get_input_value('_ruid', RCUBE_INPUT_POST);
diff --git a/program/steps/mail/move_del.inc b/program/steps/mail/move_del.inc
index 5078fb0..4f52a60 100644
--- a/program/steps/mail/move_del.inc
+++ b/program/steps/mail/move_del.inc
@@ -43,6 +43,9 @@
         $OUTPUT->send();
         exit;
     }
+    else {
+      $OUTPUT->show_message('messagemoved', 'confirmation');
+    }
 
     $addrows = true;
 }
@@ -52,7 +55,7 @@
     $mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
 
     $del = $IMAP->delete_message($uids, $mbox);
-  
+
     if (!$del) {
         // send error message
 	    if ($_POST['_from'] != 'show')
@@ -61,7 +64,10 @@
         $OUTPUT->send();
         exit;
     }
-    
+    else {
+      $OUTPUT->show_message('messagedeleted', 'confirmation');
+    }
+
     $addrows = true;
 }
 // unknown action or missing query param
diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc
index a5df347..13b7ed6 100644
--- a/program/steps/mail/show.inc
+++ b/program/steps/mail/show.inc
@@ -66,7 +66,8 @@
     $OUTPUT->set_env('list_post', true);
 
   if (!$OUTPUT->ajax_call)
-    $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', 'movingmessage');
+    $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
+      'movingmessage', 'deletingmessage');
 
   // check for unset disposition notification
   if ($MESSAGE->headers->mdn_to &&

--
Gitblit v1.9.1