From 845a1ec3e73e7e7e6632fc673f0d67b4ac0cacb7 Mon Sep 17 00:00:00 2001 From: nathangray Date: Thu, 19 Jan 2017 09:36:38 -0700 Subject: [PATCH] Added a checkbox for 'save as infolog' when merging multiple contacts into an email document. --- addressbook/js/app.js | 40 ++++++++++++++++++ .../templates/default/mail_merge_dialog.xet | 21 ++++++++++ api/src/Contacts/Merge.php | 41 +++++++++++++++++++ api/src/Mail.php | 3 ++ mail/inc/class.mail_compose.inc.php | 13 ++++++ 5 files changed, 118 insertions(+) create mode 100644 addressbook/templates/default/mail_merge_dialog.xet diff --git a/addressbook/js/app.js b/addressbook/js/app.js index 371151cba3..a98a6be50b 100644 --- a/addressbook/js/app.js +++ b/addressbook/js/app.js @@ -815,6 +815,46 @@ app.classes.addressbook = AppJS.extend( return false; }, + /** + * Merge the selected contacts into the target document. + * + * Normally we let the framework handle this, but in addressbook we want to + * interfere and customize things a little to ask about saving to infolog. + * + * @param {egwAction} action - The document they clicked + * @param {egwActionObject[]} selected - Rows selected + */ + merge_mail: function merge_mail(action, selected, target) + { + // Special processing for email documents - ask about infolog + if(action && action.data && selected.length > 1) + { + var callback = function(button, value) { + if(button == et2_dialog.OK_BUTTON) + { + var _action = jQuery.extend(true, {}, action); + if(value.infolog) + { + _action.data.menuaction += '&to_app=infolog'; + } + nm_action(_action, selected, target); + } + }; + et2_createWidget("dialog",{ + callback: callback, + title: action.caption, + buttons: et2_dialog.BUTTONS_OK_CANCEL, + type: et2_dialog.QUESTION_MESSAGE, + template: egw.webserverUrl+'/addressbook/templates/default/mail_merge_dialog.xet' + }); + } + else + { + // Normal processing for only one contact selected + return nm_action(action, selected, target); + } + }, + /** * Retrieve the current state of the application for future restoration * diff --git a/addressbook/templates/default/mail_merge_dialog.xet b/addressbook/templates/default/mail_merge_dialog.xet new file mode 100644 index 0000000000..7be0540b40 --- /dev/null +++ b/addressbook/templates/default/mail_merge_dialog.xet @@ -0,0 +1,21 @@ + + + + + + diff --git a/api/src/Contacts/Merge.php b/api/src/Contacts/Merge.php index 119dbcb310..de626b6bee 100644 --- a/api/src/Contacts/Merge.php +++ b/api/src/Contacts/Merge.php @@ -256,4 +256,45 @@ class Merge extends Api\Storage\Merge $GLOBALS['egw']->framework->render(ob_get_clean()); } + + /** + * Get insert-in-document action with optional default document on top + * + * Overridden from parent to change the insert-in-email actions so we can + * have a custom action handler. + * + * @param string $dirs Directory(s comma or space separated) to search + * @param int $group see nextmatch_widget::egw_actions + * @param string $caption ='Insert in document' + * @param string $prefix ='document_' + * @param string $default_doc ='' full path to default document to show on top with action == 'document'! + * @param int|string $export_limit =null export-limit, default $GLOBALS['egw_info']['server']['export_limit'] + * @return array see nextmatch_widget::egw_actions + */ + public static function document_action($dirs, $group=0, $caption='Insert in document', $prefix='document_', $default_doc='', + $export_limit=null) + { + $actions = parent::document_action($dirs, $group, $caption, $prefix, $default_doc, $export_limit); + + // Change merge into email actions so we can customize them + static::customise_mail_actions($actions); + + return $actions; + } + + protected static function customise_mail_actions(&$action) + { + if(strpos($action['egw_open'], 'edit-mail') === 0) + { + unset($action['confirm_multiple']); + $action['onExecute'] = 'javaScript:app.addressbook.merge_mail'; + } + else if ($action['children']) + { + foreach($action['children'] as &$child) + { + static::customise_mail_actions($child); + } + } + } } diff --git a/api/src/Mail.php b/api/src/Mail.php index 5cbc381c33..d6d5de2709 100644 --- a/api/src/Mail.php +++ b/api/src/Mail.php @@ -6824,6 +6824,9 @@ class Mail $sendOK = true; try { $mailObject->send(); + $message_id = $mailObject->getHeader('Message-ID'); + $id = $this->appendMessage($_folder, $mailObject->getRaw(), ''); + $importID = $id->current(); } catch(Exception $e) { $sendOK = false; diff --git a/mail/inc/class.mail_compose.inc.php b/mail/inc/class.mail_compose.inc.php index 8c25ba8825..6dd1223d46 100644 --- a/mail/inc/class.mail_compose.inc.php +++ b/mail/inc/class.mail_compose.inc.php @@ -3520,6 +3520,19 @@ class mail_compose array((int)$contact_id, ''), $folder,$merged_mail_id ); + + // Also save as infolog + if($merged_mail_id && $_REQUEST['to_app'] && isset($GLOBALS['egw_info']['user']['apps'][$_REQUEST['to_app']])) + { + $rowid = mail_ui::generateRowID($this->mail_bo->profileID, $folder, $merged_mail_id, true); + $data = mail_integration::get_integrate_data($rowid); + if($data && $_REQUEST['to_app'] == 'infolog') + { + $bo = new infolog_bo(); + $entry = $bo->import_mail($data['addresses'],$data['subject'],$data['message'],$data['attachments'],$data['date']); + $bo->write($entry); + } + } } catch (Exception $e) {