From 53363be626f10bb074a803e8d60a1f0954e00d7a Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Mon, 20 Apr 2015 14:31:21 +0000 Subject: [PATCH] Implement mail integration to an existing ticket --- mail/inc/class.mail_integration.inc.php | 9 ++- mail/inc/class.mail_ui.inc.php | 1 + mail/js/app.js | 76 +++++++++++++++++-- mail/lang/egw_de.lang | 1 + mail/lang/egw_en.lang | 1 + .../default/integration_to_entry_dialog.xet | 12 +++ 6 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 mail/templates/default/integration_to_entry_dialog.xet diff --git a/mail/inc/class.mail_integration.inc.php b/mail/inc/class.mail_integration.inc.php index 54535569b5..2ad5559529 100644 --- a/mail/inc/class.mail_integration.inc.php +++ b/mail/inc/class.mail_integration.inc.php @@ -50,6 +50,7 @@ class mail_integration { * 'message' => string, * 'date' => string, * 'subject' => string, + * 'entry_id => string // Id of the app entry which mail content will append to * ) * * @param string $_to_emailAddress @@ -65,7 +66,10 @@ class mail_integration { { // App name which is called for integration $app = isset($GLOBALS['egw_info']['user']['apps'][$_GET['app']])? $_GET['app'] : null; - + + // preset app entry id, selected by user from app_entry_dialog + $app_entry_id = $_GET['entry_id']; + // Set the date if (!$_date) { @@ -276,7 +280,8 @@ class mail_integration { 'attachments' => $data_attachments, 'message' => $data_message, 'date' => $mailcontent['date'], - 'subject' => $mailcontent['subject'] + 'subject' => $mailcontent['subject'], + 'entry_id' => $app_entry_id )); } } diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index aed7fbab2b..a5fa6fcc6b 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -1249,6 +1249,7 @@ class mail_ui 'icon' => 'tracker/navbar', 'onExecute' => 'javaScript:app.mail.mail_integrate', 'popup' => egw_link::get_registry('tracker', 'add_popup'), + 'mail_import' => $GLOBALS['egw']->hooks->single(array('location' => 'mail_import'),'tracker'), 'allowOnMultiple' => false, ), 'calendar' => array( diff --git a/mail/js/app.js b/mail/js/app.js index 01d3dcdbf5..beb491143a 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -2624,14 +2624,14 @@ app.classes.mail = AppJS.extend( mail_integrate: function(_action, _elems) { var app = _action.id; + var w_h = ['750','580']; // define a default wxh if there's no popup size registered - if (typeof _action.data != 'undefined' && typeof _action.data.popup != 'undefined') + var add_as_new = true; + + if (typeof _action.data != 'undefined' ) { - w_h = _action.data.popup.split('x'); - } - else // define a default wxh if there's no popup size registered - { - var w_h = ['750','580']; + if (typeof _action.data.popup != 'undefined') w_h = _action.data.popup.split('x'); + if (typeof _action.data.mail_import != 'undefined') var mail_import_hook = _action.data.mail_import; } if (typeof _elems == 'undefined' || _elems.length==0) @@ -2650,8 +2650,70 @@ app.classes.mail = AppJS.extend( } } } + var url = window.egw_webserverUrl+ '/index.php?menuaction=mail.mail_integration.integrate&rowid=' + _elems[0].id + '&app='+app; - egw_openWindowCentered(url,'import_mail_'+_elems[0].id,w_h[0],w_h[1]); + + /** + * Checks the application entry existance and offers user + * to select desire app id to append mail content into it, + * or add the mail content as a new app entry + * + * @param {string} _title select app entry title + * @param {string} _appName app to be integrated + * @param {string} _appCheckCallback registered mail_import hook method + * for check app entry existance + */ + check_app_entry = function (_title, _appName, _appCheckCallback) + { + var data = egw.dataGetUIDdata(_elems[0].id); + var subject = (data && typeof data.data != 'undefined')? data.data.subject : ''; + egw.json(_appCheckCallback, subject,function(_entryId){ + + // if there's no entry saved already + // open dialog in order to select one + if (!_entryId) + { + var buttons = [ + {text: 'Append', id: 'append', image: 'check', default:true}, + {text: 'Add as new', id: 'new', image: 'check'}, + {text: 'Cancel', id: 'cancel', image: 'check'} + ]; + et2_createWidget("dialog", + { + callback: function(_buttons, _value) + { + if (_buttons == 'cancel') return; + if (_buttons == 'append' && _value) + { + url += '&entry_id=' + _value.id; + } + egw_openWindowCentered(url,'import_mail_'+_elems[0].id,w_h[0],w_h[1]); + }, + title: egw.lang(_title), + buttons: buttons||et2_dialog.BUTTONS_OK_CANCEL, + value:{ + content:{ + appName:_appName // appName to search on its list later + }}, + template: egw.webserverUrl+'/mail/templates/default/integration_to_entry_dialog.xet' + },et2_dialog._create_parent('mail')); + } + else // there is an entry saved related to this mail's subject + { + egw_openWindowCentered(url,'import_mail_'+_elems[0].id,w_h[0],w_h[1]); + } + },this,true,this).sendRequest(); + } + + if (mail_import_hook && typeof mail_import_hook.app_entry_method != 'undefined') + { + check_app_entry('Select '+ app + ' entry', app, mail_import_hook.app_entry_method); + } + else + { + egw_openWindowCentered(url,'import_mail_'+_elems[0].id,w_h[0],w_h[1]); + } + }, /** diff --git a/mail/lang/egw_de.lang b/mail/lang/egw_de.lang index 79f500b313..538c98ee4e 100644 --- a/mail/lang/egw_de.lang +++ b/mail/lang/egw_de.lang @@ -370,6 +370,7 @@ saving of message %1 failed. destination folder %2 does not exist. mail de Speic saving of message %1 succeeded. check folder %2. mail de Speichern der Nachricht %1 war erfolgreich. Prüfen Sie den Ziel Ordner %2 saving the rule failed: mail de Speichern der Regel ist fehlgeschlagen: select all mail de Alle Auswählen +select an existing entry in order to append mail content to it mail de Bestehendes Ticket auswählen, zu dem die Mail als Kommentar hinzugefügt werden soll. select file to attach to message mail de Wählen Sie die Dateien aus, die Sie an diese Nachricht anhängen möchten. select file to import into folder mail de Wählen Sie ein E-Mail als Datei aus, damit Sie in ein Ordner importiert werden kann. select file(s) from vfs mail de Dateien aus dem EGroupware Dateimanager anhängen. diff --git a/mail/lang/egw_en.lang b/mail/lang/egw_en.lang index b5e2a2aa01..c55737a1be 100644 --- a/mail/lang/egw_en.lang +++ b/mail/lang/egw_en.lang @@ -370,6 +370,7 @@ saving of message %1 failed. destination folder %2 does not exist. mail en Savin saving of message %1 succeeded. check folder %2. mail en Saving of message %1 succeeded. Check Folder %2. saving the rule failed: mail en Saving the rule failed: select all mail en Select all +select an existing entry in order to append mail content to it mail en Select an existing entry in order to append mail content to it select file to attach to message mail en Select file to attach to message select file to import into folder mail en Select file to import into Folder select file(s) from vfs mail en Select file(s) from VFS diff --git a/mail/templates/default/integration_to_entry_dialog.xet b/mail/templates/default/integration_to_entry_dialog.xet new file mode 100644 index 0000000000..ca05c67523 --- /dev/null +++ b/mail/templates/default/integration_to_entry_dialog.xet @@ -0,0 +1,12 @@ + + + + + +