diff --git a/mail/inc/class.mail_compose.inc.php b/mail/inc/class.mail_compose.inc.php
index 0030efe102..d9fcdc9aa6 100644
--- a/mail/inc/class.mail_compose.inc.php
+++ b/mail/inc/class.mail_compose.inc.php
@@ -179,7 +179,8 @@ class mail_compose
'group' => $group,
'checkbox' => true,
'hint' => 'check to save as trackerentry on send',
- 'onExecute' => 'javaScript:app.mail.compose_setToggle'
+ 'onExecute' => 'javaScript:app.mail.compose_setToggle',
+ 'mail_import' => Api\Hooks::single(array('location' => 'mail_import'),'tracker'),
),
'to_calendar' => array(
'caption' => 'Calendar',
@@ -3158,6 +3159,7 @@ class mail_compose
{
foreach(array('to_infolog','to_tracker','to_calendar') as $app_key)
{
+ $entryid = $_formData['to_integrate_ids'][0][$app_key];
if ($_formData[$app_key] == 'on')
{
$app_name = substr($app_key,3);
@@ -3169,11 +3171,7 @@ class mail_compose
$eml_fp = fopen($eml, 'w');
stream_copy_to_stream($mail->getRaw(), $eml_fp);
fclose($eml_fp);
-
- // Open the app called for integration in a popup
- // and store the mail raw data as egw_data, in order to
- // be stored from registered app method later
- Framework::popup(Egw::link('/index.php', array(
+ $target = array(
'menuaction' => $hook['menuaction'],
'egw_data' => Link::set_data(null,'mail_integration::integrate',array(
$mailaddresses,
@@ -3184,7 +3182,12 @@ class mail_compose
$eml,
$_formData['serverID']),true),
'app' => $app_name
- )),'_blank',$hook['popup']);
+ );
+ if ($entryid) $target['entry_id'] = $entryid;
+ // Open the app called for integration in a popup
+ // and store the mail raw data as egw_data, in order to
+ // be stored from registered app method later
+ Framework::popup(Egw::link('/index.php', $target),'_blank',$hook['popup']);
}
}
}
diff --git a/mail/js/app.js b/mail/js/app.js
index 90178343cc..61d2b4609c 100644
--- a/mail/js/app.js
+++ b/mail/js/app.js
@@ -2861,8 +2861,6 @@ app.classes.mail = AppJS.extend(
var app = _action.id;
var w_h = ['750','580']; // define a default wxh if there's no popup size registered
- var add_as_new = true;
-
if (typeof _action.data != 'undefined' )
{
if (typeof _action.data.popup != 'undefined' && _action.data.popup) w_h = _action.data.popup.split('x');
@@ -2888,61 +2886,13 @@ app.classes.mail = AppJS.extend(
var url = window.egw_webserverUrl+ '/index.php?menuaction=mail.mail_integration.integrate&rowid=' + _elems[0].id + '&app='+app;
- /**
- * 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)
+ if (mail_import_hook && typeof mail_import_hook.app_entry_method != 'undefined')
{
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);
+ this.integrate_checkAppEntry('Select '+ app + ' entry', app, subject, url, mail_import_hook.app_entry_method, function (args){
+ egw_openWindowCentered(args.url+ (args.entryid ?'&entry_id=' + args.entryid: ''),'import_mail_'+_elems[0].id,w_h[0],w_h[1]);
+ });
}
else
{
@@ -2951,6 +2901,60 @@ app.classes.mail = AppJS.extend(
},
+ /**
+ * 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} _subject
+ * @param {string} _url
+ * @param {string} _appCheckCallback registered mail_import hook method
+ * @param {function} _execCallback function to get called on dialog actions
+ */
+ integrate_checkAppEntry: function (_title, _appName, _subject ,_url, _appCheckCallback, _execCallback)
+ {
+ var subject = _subject || '';
+ var execCallback = _execCallback;
+ 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)
+ {
+ _entryId = _value.id;
+ }
+ execCallback.call(this,{entryid:_entryId,url:_url});
+ },
+ 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
+ {
+ execCallback.call(this,{entryid:_entryId,url:_url});
+ }
+ },this,true,this).sendRequest();
+ },
+
/**
* mail_getFormData
*
@@ -4978,10 +4982,13 @@ app.classes.mail = AppJS.extend(
/**
* Set the relevant widget to toolbar actions and submit
*
- * @param {type} _action toolbar action
+ * @param {object|boolean} _action toolbar action or boolean value to stop extra call on
+ * compose_integrated_submit
*/
compose_submitAction: function (_action)
{
+ if (this.compose_integrate_submit() && _action) return false;
+
if (this.mailvelope_editor)
{
var self = this;
@@ -5003,6 +5010,55 @@ app.classes.mail = AppJS.extend(
this.et2._inst.submit(null,null,true);
},
+ /**
+ * This function runs before client submit (send) mail to server
+ * and takes care of mail integration modules to popup entry selection
+ * dialog to give user a choice to which entry of selected app the compose
+ * should be integereated.
+ *
+ * @returns {Boolean} return true if to_tracker is checked otherwise false
+ */
+ compose_integrate_submit: function (_integIndex)
+ {
+ if (_integIndex == false) return false;
+ var index = _integIndex || 0;
+ var integApps = ['to_tracker', 'to_infolog', 'to_calendar'];
+ var subject = this.et2.getWidgetById('subject');
+ var toolbar = this.et2.getWidgetById('composeToolbar');
+ var to_integrate_ids = this.et2.getWidgetById('to_integrate_ids');
+ var integWidget= {};
+ var self = this;
+
+ integWidget = this.et2.getWidgetById(integApps[index]);
+ if (toolbar.options.actions[integApps[index]] &&
+ typeof toolbar.options.actions[integApps[index]]['mail_import'] != 'undefined' &&
+ typeof toolbar.options.actions[integApps[index]]['mail_import']['app_entry_method'] != 'unefined')
+ {
+ var mail_import_hook = toolbar.options.actions[integApps[index]]['mail_import']['app_entry_method'];
+ if (integWidget.get_value() == 'on')
+ {
+ this.integrate_checkAppEntry(egw.lang('Select %1 entry',integApps[index]), integApps[index].substr(3), subject.get_value(), '', mail_import_hook , function (args){
+ var value = {};
+ value[integApps[index]] = args.entryid;
+ var oldValue = to_integrate_ids.get_value()[0];
+ to_integrate_ids.set_value(jQuery.extend(value,oldValue));
+ index = index
+