From 9b3fdc25c171d2b2461af42224ea16ad6c032c49 Mon Sep 17 00:00:00 2001 From: alecpl Date: Fri, 19 Mar 2010 11:20:12 +0000 Subject: - Implemented messages copying using drag&drop + SHIFT (#1484086) --- program/include/rcube_imap.php | 57 +++++++++++++++++++++++---- program/include/rcube_template.php | 2 +- program/js/app.js | 68 ++++++++++++++++++++++++++++++--- program/localization/en_US/labels.inc | 2 + program/localization/en_US/messages.inc | 1 + program/localization/pl_PL/labels.inc | 2 + program/localization/pl_PL/messages.inc | 3 +- program/steps/mail/copy.inc | 59 ++++++++++++++++++++++++++++ program/steps/mail/func.inc | 5 ++- 9 files changed, 183 insertions(+), 16 deletions(-) create mode 100644 program/steps/mail/copy.inc (limited to 'program') diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php index 1e3c09dc1..651ecd61c 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -2202,6 +2202,13 @@ class rcube_imap $to_mbox = $this->mod_mailbox($to_mbox); $from_mbox = $from_mbox ? $this->mod_mailbox($from_mbox) : $this->mailbox; + // convert the list of uids to array + $a_uids = is_string($uids) ? explode(',', $uids) : (is_array($uids) ? $uids : NULL); + + // exit if no message uids are specified + if (!is_array($a_uids) || empty($a_uids)) + return false; + // make sure mailbox exists if ($to_mbox != 'INBOX' && !$this->mailbox_exists($tbox)) { @@ -2211,13 +2218,6 @@ class rcube_imap return false; } - // convert the list of uids to array - $a_uids = is_string($uids) ? explode(',', $uids) : (is_array($uids) ? $uids : NULL); - - // exit if no message uids are specified - if (!is_array($a_uids) || empty($a_uids)) - return false; - // flag messages as read before moving them $config = rcmail::get_instance()->config; if ($config->get('read_when_deleted') && $tbox == $config->get('trash_mbox')) { @@ -2269,6 +2269,49 @@ class rcube_imap } + /** + * Copy a message from one mailbox to another + * + * @param string List of UIDs to copy, separated by comma + * @param string Target mailbox + * @param string Source mailbox + * @return boolean True on success, False on error + */ + function copy_message($uids, $to_mbox, $from_mbox='') + { + $fbox = $from_mbox; + $tbox = $to_mbox; + $to_mbox = $this->mod_mailbox($to_mbox); + $from_mbox = $from_mbox ? $this->mod_mailbox($from_mbox) : $this->mailbox; + + // convert the list of uids to array + $a_uids = is_string($uids) ? explode(',', $uids) : (is_array($uids) ? $uids : NULL); + + // exit if no message uids are specified + if (!is_array($a_uids) || empty($a_uids)) + return false; + + // make sure mailbox exists + if ($to_mbox != 'INBOX' && !$this->mailbox_exists($tbox)) + { + if (in_array($tbox, $this->default_folders)) + $this->create_mailbox($tbox, true); + else + return false; + } + + // copy messages + $iil_copy = iil_C_Copy($this->conn, join(',', $a_uids), $from_mbox, $to_mbox); + $copied = !($iil_copy === false || $iil_copy < 0); + + if ($copied) { + $this->_clear_messagecount($to_mbox); + } + + return $copied; + } + + /** * Mark messages as deleted and expunge mailbox * diff --git a/program/include/rcube_template.php b/program/include/rcube_template.php index 6de32722c..ad498c9c5 100755 --- a/program/include/rcube_template.php +++ b/program/include/rcube_template.php @@ -860,7 +860,7 @@ class rcube_template extends rcube_html_page if (!$attrib['href']) { $attrib['href'] = '#'; } - if ($command) { + if ($command && !$attrib['onclick']) { $attrib['onclick'] = sprintf( "return %s.command('%s','%s',this)", JS_OBJECT_NAME, diff --git a/program/js/app.js b/program/js/app.js index 87ee76c8f..7c86bb0e8 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -197,7 +197,7 @@ function rcube_webmail() if (this.env.action=='show' || this.env.action=='preview') { - this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'delete', + this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'copy', 'delete', 'open', 'mark', 'edit', 'viewsource', 'download', 'print', 'load-attachment', 'load-headers', true); if (this.env.next_uid) @@ -674,6 +674,11 @@ function rcube_webmail() this.copy_contact(null, props); break; + case 'copy': + if (this.task == 'mail') + this.copy_messages(props); + break; + case 'mark': if (props) this.mark_message(props); @@ -1194,10 +1199,14 @@ function rcube_webmail() // handle mouse release when dragging if (this.drag_active && model && this.env.last_folder_target) { + var mbox = model[this.env.last_folder_target].id; + $(this.get_folder_li(this.env.last_folder_target)).removeClass('droptarget'); - this.command('moveto', model[this.env.last_folder_target].id); this.env.last_folder_target = null; list.draglayer.hide(); + + if (!this.drag_menu(e, mbox)) + this.command('moveto', mbox); } // reset 'pressed' buttons @@ -1209,6 +1218,29 @@ function rcube_webmail() } }; + this.drag_menu = function(e, mbox) + { + var modkey = rcube_event.get_modifier(e); + var menu = $('#'+this.gui_objects.message_dragmenu); + + if (menu && modkey == SHIFT_KEY) { + var pos = rcube_event.get_mouse_pos(e); + this.env.drag_mbox = mbox; + menu.css({top: (pos.y-10)+'px', left: (pos.x-10)+'px'}).show(); + return true; + } + }; + + this.drag_menu_action = function(action) + { + var menu = $('#'+this.gui_objects.message_dragmenu); + if (menu) { + menu.hide(); + } + this.command(action, this.env.drag_mbox); + this.env.drag_mbox = null; + }; + this.drag_start = function(list) { var model = this.task == 'mail' ? this.env.mailboxes : this.env.address_sources; @@ -1389,12 +1421,12 @@ function rcube_webmail() { this.enable_command('reply', 'reply-all', 'forward', false); this.enable_command('show', 'print', 'open', 'edit', 'download', 'viewsource', selected); - this.enable_command('delete', 'moveto', 'mark', (list.selection.length > 0 ? true : false)); + this.enable_command('delete', 'moveto', 'copy', 'mark', (list.selection.length > 0 ? true : false)); } else { this.enable_command('show', 'reply', 'reply-all', 'forward', 'print', 'edit', 'open', 'download', 'viewsource', selected); - this.enable_command('delete', 'moveto', 'mark', (list.selection.length > 0 ? true : false)); + this.enable_command('delete', 'moveto', 'copy', 'mark', (list.selection.length > 0 ? true : false)); } // start timer for message preview (wait for double click) @@ -2121,6 +2153,32 @@ function rcube_webmail() $(row.obj).removeClass('unroot'); }; + // copy selected messages to the specified mailbox + this.copy_messages = function(mbox) + { + // exit if current or no mailbox specified or if selection is empty + if (!mbox || mbox == this.env.mailbox || (!this.env.uid && (!this.message_list || !this.message_list.get_selection().length))) + return; + + var add_url = '&_target_mbox='+urlencode(mbox)+'&_from='+(this.env.action ? this.env.action : ''); + var a_uids = new Array(); + + if (this.env.uid) + a_uids[0] = this.env.uid; + else + { + var selection = this.message_list.get_selection(); + var id; + for (var n=0; n | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + +// only process ajax requests +if (!$OUTPUT->ajax_call) + return; + +// count messages before changing anything +$old_count = $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL'); +$old_pages = ceil($old_count / $IMAP->page_size); + +// move messages +if (!empty($_POST['_uid']) && !empty($_POST['_target_mbox'])) { + $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST)))); + $target = get_input_value('_target_mbox', RCUBE_INPUT_POST); + $mbox = get_input_value('_mbox', RCUBE_INPUT_POST); + + $copied = $IMAP->copy_message($uids, $target, $mbox); + + if (!$copied) { + // send error message + if ($_POST['_from'] != 'show') + $OUTPUT->command('list_mailbox'); + $OUTPUT->show_message('errorcopying', 'error'); + $OUTPUT->send(); + exit; + } + + rcmail_send_unread_count($target, true); + + $OUTPUT->command('set_quota', rcmail_quota_content()); +} +// unknown action or missing query param +else { + exit; +} + +// send response +$OUTPUT->send(); + +?> diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 09a24924b..e8600ef55 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -130,7 +130,8 @@ if (empty($RCMAIL->action) || $RCMAIL->action == 'list') $OUTPUT->set_env('junk_mailbox', $CONFIG['junk_mbox']); if (!$OUTPUT->ajax_call) - $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', 'movingmessage'); + $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', + 'movingmessage', 'copyingmessage', 'copy', 'move'); $OUTPUT->set_pagetitle(rcmail_localize_foldername($mbox_name)); } @@ -1457,7 +1458,6 @@ function rcmail_send_mdn($uid, &$smtp_error) return false; } - function rcmail_search_filter($attrib) { global $OUTPUT, $CONFIG; @@ -1490,6 +1490,7 @@ function rcmail_search_filter($attrib) return $out; } + // register UI objects $OUTPUT->add_handlers(array( 'mailboxlist' => 'rcmail_mailbox_list', -- cgit v1.2.3