2012-03-28 14:37:03 +02:00
|
|
|
/**
|
|
|
|
* EGroupware clientside API: opening of windows, popups or application entries
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Andreas Stöckel (as AT stylite.de)
|
|
|
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
egw_core;
|
|
|
|
egw_links;
|
|
|
|
*/
|
|
|
|
|
2013-08-16 11:16:40 +02:00
|
|
|
/**
|
|
|
|
* @augments Class
|
|
|
|
*/
|
2012-03-28 14:37:03 +02:00
|
|
|
egw.extend('open', egw.MODULE_WND_LOCAL, function(_egw, _wnd) {
|
2014-01-13 18:37:46 +01:00
|
|
|
|
|
|
|
|
2013-10-07 12:09:08 +02:00
|
|
|
/**
|
|
|
|
* Magic handling for mailto: uris using mail application.
|
2014-01-13 18:37:46 +01:00
|
|
|
*
|
2013-10-07 12:09:08 +02:00
|
|
|
* We check for open compose windows and add the address in as specified in
|
|
|
|
* the URL. If there are no open compose windows, a new one is opened. If
|
|
|
|
* there are more than one open compose window, we prompt for which one to
|
|
|
|
* use.
|
2014-01-13 18:37:46 +01:00
|
|
|
*
|
2013-10-07 12:09:08 +02:00
|
|
|
* The user must have set the 'Open EMail addresses in external mail program' preference
|
|
|
|
* to No, otherwise the browser will handle it.
|
2014-01-13 18:37:46 +01:00
|
|
|
*
|
2013-10-07 12:09:08 +02:00
|
|
|
* @param {String} uri
|
|
|
|
*/
|
|
|
|
function mailto(uri)
|
|
|
|
{
|
|
|
|
// Parse uri into a map
|
2014-01-13 18:37:46 +01:00
|
|
|
var match = [], index;
|
|
|
|
var mailto = uri.match(/^mailto:([^?]+)/) || [];
|
|
|
|
var hashes = uri.slice(uri.indexOf('?') + 1).split('&');
|
|
|
|
for(var i = 0; i < hashes.length; i++)
|
2013-10-07 12:09:08 +02:00
|
|
|
{
|
2014-01-13 18:37:46 +01:00
|
|
|
index = hashes[i].split('=');
|
|
|
|
match.push(index[0]);
|
|
|
|
match[index[0]] = index[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
var content = {
|
|
|
|
to: mailto[1] || [],
|
|
|
|
cc: match['cc'] || [],
|
|
|
|
bcc: match['bcc'] || [],
|
2013-10-07 12:09:08 +02:00
|
|
|
}
|
2014-01-13 18:37:46 +01:00
|
|
|
|
2013-10-07 12:09:08 +02:00
|
|
|
// Get open compose windows
|
|
|
|
var compose = egw.getOpenWindows("mail", /^compose_/);
|
|
|
|
if(compose.length == 0)
|
|
|
|
{
|
|
|
|
// No compose windows, might be no mail app.js
|
|
|
|
// We really want to use mail_compose() here
|
|
|
|
egw.open('','mail','add',{'preset[mailto]': uri},'compose__','mail')
|
|
|
|
}
|
|
|
|
if(compose.length == 1)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
var popup = egw.open_link('',compose[0],'100x100','mail');
|
|
|
|
popup.app.mail.setCompose(compose[0], content);
|
|
|
|
} catch(e) {
|
|
|
|
// Looks like a leftover window that wasn't removed from the list
|
|
|
|
egw.debug("warn", e.message);
|
|
|
|
popup.close();
|
|
|
|
egw.windowClosed("mail",popup);
|
|
|
|
window.setTimeout(function() {
|
|
|
|
egw.open_link(uri);
|
|
|
|
console.debug("Trying again with ", uri);
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(compose.length > 1)
|
|
|
|
{
|
|
|
|
// Need to prompt
|
|
|
|
var prompt = $j(document.createElement('ul'));
|
|
|
|
for(var i = 0; i < compose.length; i++)
|
|
|
|
{
|
|
|
|
var w = window.open('',compose[i],'100x100');
|
|
|
|
if(w.closed) continue;
|
2013-10-10 11:37:21 +02:00
|
|
|
w.blur();
|
2013-10-07 12:09:08 +02:00
|
|
|
var title = w.document.title || egw.lang("compose");
|
|
|
|
$j("<li data-window = '" + compose[i] + "'>"+ title + "</li>")
|
|
|
|
.click(function() {
|
|
|
|
var w = egw.open_link('',$j(this).attr("data-window"),'100x100','mail');
|
|
|
|
w.app.mail.setCompose(w.name, content);
|
|
|
|
prompt.dialog("close");
|
|
|
|
})
|
|
|
|
.appendTo(prompt);
|
|
|
|
}
|
|
|
|
_wnd.setTimeout(function() {
|
|
|
|
this.focus();
|
|
|
|
}, 200);
|
|
|
|
var _buttons = {};
|
|
|
|
_buttons[egw.lang("cancel")] = function() {
|
|
|
|
$j(this).dialog("close");
|
|
|
|
};
|
|
|
|
prompt.dialog({
|
|
|
|
buttons: _buttons
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-01-13 18:37:46 +01:00
|
|
|
|
2012-03-28 14:37:03 +02:00
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* View an EGroupware entry: opens a popup of correct size or redirects window.location to requested url
|
2014-01-13 18:37:46 +01:00
|
|
|
*
|
|
|
|
* Examples:
|
2012-03-28 14:37:03 +02:00
|
|
|
* - egw.open(123,'infolog') or egw.open('infolog:123') opens popup to edit or view (if no edit rights) infolog entry 123
|
|
|
|
* - egw.open('infolog:123','timesheet','add') opens popup to add new timesheet linked to infolog entry 123
|
|
|
|
* - egw.open(123,'addressbook','view') opens addressbook view for entry 123 (showing linked infologs)
|
|
|
|
* - egw.open('','addressbook','view_list',{ search: 'Becker' }) opens list of addresses containing 'Becker'
|
2014-01-13 18:37:46 +01:00
|
|
|
*
|
2012-03-28 14:37:03 +02:00
|
|
|
* @param string|int|object id_data either just the id or if app=="" "app:id" or object with all data
|
|
|
|
* to be able to open files you need to give: (mine-)type, path or id, app2 and id2 (path=/apps/app2/id2/id"
|
|
|
|
* @param string app app-name or empty (app is part of id)
|
|
|
|
* @param string type default "edit", possible "view", "view_list", "edit" (falls back to "view") and "add"
|
|
|
|
* @param object|string extra extra url parameters to append as object or string
|
|
|
|
* @param string target target of window to open
|
2013-09-02 15:25:00 +02:00
|
|
|
* @param string target_app target application to open in that tab
|
2013-08-16 11:16:40 +02:00
|
|
|
* @memberOf egw
|
2012-03-28 14:37:03 +02:00
|
|
|
*/
|
2013-09-02 15:25:00 +02:00
|
|
|
open: function(id_data, app, type, extra, target, target_app)
|
2012-03-28 14:37:03 +02:00
|
|
|
{
|
2014-01-21 10:21:46 +01:00
|
|
|
// Log for debugging purposes - special log tag 'navigation' always
|
|
|
|
// goes in user log, if user log is enabled
|
|
|
|
egw.debug("navigation",
|
|
|
|
"egw.open(id_data=%o, app=%s, type=%s, extra=%o, target=%s, target_app=%s)",
|
|
|
|
id_data,app,type,extra,target,target_app
|
|
|
|
);
|
|
|
|
|
2012-03-28 14:37:03 +02:00
|
|
|
var id;
|
2012-04-25 18:23:27 +02:00
|
|
|
if(typeof target === 'undefined')
|
|
|
|
{
|
|
|
|
target = '_blank';
|
|
|
|
}
|
2012-03-28 14:37:03 +02:00
|
|
|
if (!app)
|
|
|
|
{
|
|
|
|
if (typeof id_data != 'object')
|
|
|
|
{
|
2012-05-17 11:26:25 +02:00
|
|
|
var app_id = id_data.split(':',2);
|
2012-03-28 14:37:03 +02:00
|
|
|
app = app_id[0];
|
|
|
|
id = app_id[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
app = id_data.app;
|
|
|
|
id = id_data.id;
|
2013-12-07 00:12:05 +01:00
|
|
|
if(typeof id_data.type != 'undefined')
|
|
|
|
{
|
|
|
|
type = id_data.type;
|
|
|
|
}
|
2012-03-28 14:37:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (app != 'file')
|
|
|
|
{
|
2012-05-17 11:26:25 +02:00
|
|
|
id = id_data;
|
2012-03-28 14:37:03 +02:00
|
|
|
id_data = { 'id': id, 'app': app, 'extra': extra };
|
|
|
|
}
|
|
|
|
var url;
|
|
|
|
var popup;
|
|
|
|
var params;
|
|
|
|
if (app == 'file')
|
|
|
|
{
|
|
|
|
url = this.mime_open(id_data);
|
|
|
|
if (typeof url == 'object')
|
|
|
|
{
|
|
|
|
if(typeof url.mime_popup != 'undefined')
|
|
|
|
{
|
|
|
|
popup = url.mime_popup;
|
|
|
|
delete url.mime_popup;
|
|
|
|
}
|
2012-03-28 15:01:37 +02:00
|
|
|
if(typeof url.mime_target != 'undefined')
|
|
|
|
{
|
|
|
|
target = url.mime_target;
|
|
|
|
delete url.mime_target;
|
|
|
|
}
|
2012-03-28 14:37:03 +02:00
|
|
|
params = url;
|
|
|
|
url = '/index.php';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var app_registry = this.link_get_registry(app);
|
2014-01-13 18:37:46 +01:00
|
|
|
|
2012-03-28 14:37:03 +02:00
|
|
|
if (!app || !app_registry)
|
|
|
|
{
|
|
|
|
alert('egw.open() app "'+app+'" NOT defined in link registry!');
|
2014-01-13 18:37:46 +01:00
|
|
|
return;
|
2012-03-28 14:37:03 +02:00
|
|
|
}
|
|
|
|
if (typeof type == 'undefined') type = 'edit';
|
|
|
|
if (type == 'edit' && typeof app_registry.edit == 'undefined') type = 'view';
|
|
|
|
if (typeof app_registry[type] == 'undefined')
|
|
|
|
{
|
|
|
|
alert('egw.open() type "'+type+'" is NOT defined in link registry for app "'+app+'"!');
|
2014-01-13 18:37:46 +01:00
|
|
|
return;
|
2012-03-28 14:37:03 +02:00
|
|
|
}
|
|
|
|
url = '/index.php';
|
2014-01-20 10:48:17 +01:00
|
|
|
// Copy, not get a reference, or we'll change the registry
|
|
|
|
params = jQuery.extend({},app_registry[type]);
|
2012-03-28 14:37:03 +02:00
|
|
|
if (type == 'view' || type == 'edit') // add id parameter for type view or edit
|
|
|
|
{
|
|
|
|
params[app_registry[type+'_id']] = id;
|
|
|
|
}
|
|
|
|
else if (type == 'add' && id) // add add_app and app_id parameters, if given for add
|
|
|
|
{
|
|
|
|
var app_id = id.split(':',2);
|
|
|
|
params[app_registry.add_app] = app_id[0];
|
|
|
|
params[app_registry.add_id] = app_id[1];
|
|
|
|
}
|
2014-01-13 18:37:46 +01:00
|
|
|
|
2012-03-28 14:37:03 +02:00
|
|
|
if (typeof extra == 'string')
|
|
|
|
{
|
|
|
|
url += '?'+extra;
|
|
|
|
}
|
|
|
|
else if (typeof extra == 'object')
|
|
|
|
{
|
|
|
|
$j.extend(params, extra);
|
|
|
|
}
|
|
|
|
popup = app_registry[type+'_popup'];
|
|
|
|
}
|
2013-09-02 15:25:00 +02:00
|
|
|
return this.open_link(this.link(url, params), target, popup, target_app);
|
2012-03-28 14:37:03 +02:00
|
|
|
},
|
2014-01-13 18:37:46 +01:00
|
|
|
|
2012-03-28 14:37:03 +02:00
|
|
|
/**
|
|
|
|
* Open a link, which can be either a menuaction, a EGroupware relative url or a full url
|
2014-01-13 18:37:46 +01:00
|
|
|
*
|
2012-03-28 14:37:03 +02:00
|
|
|
* @param string _link menuaction, EGroupware relative url or a full url (incl. "mailto:" or "javascript:")
|
2013-08-20 20:01:49 +02:00
|
|
|
* @param string _target optional target / window name
|
2012-03-28 14:37:03 +02:00
|
|
|
* @param string _popup widthxheight, if a popup should be used
|
2013-08-20 20:01:49 +02:00
|
|
|
* @param string _target_app app-name for opener
|
2012-03-28 14:37:03 +02:00
|
|
|
*/
|
2013-08-20 20:01:49 +02:00
|
|
|
open_link: function(_link, _target, _popup, _target_app)
|
2012-03-28 14:37:03 +02:00
|
|
|
{
|
2014-01-21 10:21:46 +01:00
|
|
|
// Log for debugging purposes - don't use navigation here to avoid
|
|
|
|
// flooding log with details already captured by egw.open()
|
|
|
|
egw.debug("log",
|
|
|
|
"egw.open_link(_link=%s, _target=%s, _popup=%s, _target_app=%s)",
|
|
|
|
_link,_target,_popup,_target_app
|
|
|
|
);
|
|
|
|
|
2012-03-28 14:37:03 +02:00
|
|
|
var url = _link;
|
|
|
|
if (url.indexOf('javascript:') == 0)
|
|
|
|
{
|
|
|
|
eval(url.substr(11));
|
|
|
|
return;
|
|
|
|
}
|
2013-10-07 12:09:08 +02:00
|
|
|
if (url.indexOf('mailto:') == 0)
|
|
|
|
{
|
|
|
|
return mailto(url);
|
|
|
|
}
|
2012-03-28 14:37:03 +02:00
|
|
|
// link is not necessary an url, it can also be a menuaction!
|
|
|
|
if (url.indexOf('/') == -1 && url.split('.').length >= 3 &&
|
|
|
|
!(url.indexOf('mailto:') == 0 || url.indexOf('/index.php') == 0 || url.indexOf('://') != -1))
|
|
|
|
{
|
|
|
|
url = "/index.php?menuaction="+url;
|
|
|
|
}
|
|
|
|
// append the url to the webserver url, if not already contained or empty
|
|
|
|
if (url[0] == '/' && this.webserverUrl && this.webserverUrl != '/' && url.indexOf(this.webserverUrl+'/') != 0)
|
|
|
|
{
|
|
|
|
url = this.webserverUrl + url;
|
|
|
|
}
|
|
|
|
if (_popup)
|
|
|
|
{
|
|
|
|
var w_h = _popup.split('x');
|
|
|
|
if (w_h[1] == 'egw_getWindowOuterHeight()') w_h[1] = egw_getWindowOuterHeight();
|
2013-10-05 11:38:22 +02:00
|
|
|
var popup_window = _wnd.egw_openWindowCentered2(url, _target, w_h[0], w_h[1], false, _target_app, true);
|
2014-01-13 18:37:46 +01:00
|
|
|
|
2013-10-05 11:28:12 +02:00
|
|
|
// Remember which windows are open
|
2013-10-10 11:37:21 +02:00
|
|
|
egw().storeWindow(_target_app, popup_window);
|
2014-01-13 18:37:46 +01:00
|
|
|
|
2013-10-05 11:38:22 +02:00
|
|
|
return popup_window;
|
2012-03-28 14:37:03 +02:00
|
|
|
}
|
2013-07-15 18:03:37 +02:00
|
|
|
else if (typeof _wnd.egw_link_handler == 'function' && (typeof _target == 'undefined' || _target =='_self' || typeof this.link_app_list()[_target] != "undefined"))
|
2013-06-12 18:56:12 +02:00
|
|
|
{
|
2013-07-15 18:03:37 +02:00
|
|
|
if(_target == '_self')
|
|
|
|
{
|
|
|
|
// '_self' isn't allowed, but we can handle it
|
|
|
|
_target = undefined;
|
|
|
|
}
|
2013-06-12 18:56:12 +02:00
|
|
|
// Use framework's link handler, if present
|
|
|
|
return _wnd.egw_link_handler(url,_target);
|
|
|
|
}
|
2013-09-02 15:25:00 +02:00
|
|
|
else if (_target == '_self')
|
|
|
|
{
|
|
|
|
_wnd.location.href = url;
|
|
|
|
}
|
2012-03-28 14:37:03 +02:00
|
|
|
else
|
|
|
|
{
|
2012-12-04 01:13:12 +01:00
|
|
|
return _wnd.open(url, _target);
|
2012-03-28 14:37:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2013-10-07 12:09:08 +02:00
|
|
|
|
|
|
|
// Add protocol handler as an option if mail handling is not forced so mail can handle mailto:
|
|
|
|
/* Not working consistantly yet
|
|
|
|
$j(function() {
|
|
|
|
try {
|
|
|
|
if(egw.user('apps').mail && (egw.preference('force_mailto','addressbook')||true) != '0')
|
|
|
|
{
|
|
|
|
var params = egw.link_get_registry('mail','add');
|
|
|
|
if(params)
|
|
|
|
{
|
|
|
|
params['preset[mailto]'] = ''; // %s, but egw.link will encode it
|
|
|
|
navigator.registerProtocolHandler("mailto",egw.link('/index.php', params)+'%s', egw.lang('mail'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
});
|
|
|
|
*/
|