2012-03-01 17:24:29 +01:00
|
|
|
/**
|
2012-03-28 14:37:03 +02:00
|
|
|
* EGroupware clientside API: link-registry, link-titles, generation links
|
2012-03-01 17:24:29 +01:00
|
|
|
*
|
|
|
|
* @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$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
egw_core;
|
|
|
|
*/
|
2021-06-05 20:39:39 +02:00
|
|
|
import './egw_core.js';
|
2012-03-01 17:24:29 +01:00
|
|
|
|
2013-07-22 21:20:13 +02:00
|
|
|
/**
|
|
|
|
* @augments Class
|
|
|
|
*/
|
2014-10-09 11:34:24 +02:00
|
|
|
egw.extend('links', egw.MODULE_GLOBAL, function()
|
|
|
|
{
|
|
|
|
"use strict";
|
2012-03-01 17:24:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Link registry
|
2013-12-12 04:43:17 +01:00
|
|
|
*
|
2012-03-01 17:24:29 +01:00
|
|
|
* @access: private, use egw.open() or egw.set_link_registry()
|
|
|
|
*/
|
2014-11-18 13:55:32 +01:00
|
|
|
var link_registry = undefined;
|
2012-03-01 17:24:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Local cache for link-titles
|
2013-12-12 04:43:17 +01:00
|
|
|
*
|
2012-03-01 17:24:29 +01:00
|
|
|
* @access private, use egw.link_title(_app, _id[, _callback, _context])
|
|
|
|
*/
|
|
|
|
var title_cache = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queue for link_title requests
|
2013-12-12 04:43:17 +01:00
|
|
|
*
|
2012-03-01 17:24:29 +01:00
|
|
|
* @access private, use egw.link_title(_app, _id[, _callback, _context])
|
|
|
|
* @var object _app._id.[{callback: _callback, context: _context}[, ...]]
|
|
|
|
*/
|
|
|
|
var title_queue = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uid of active jsonq request, to not start an other one, as we get notified
|
|
|
|
* before it's actually send to the server via our link_title_before_send callback.
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
var title_uid = null;
|
|
|
|
|
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* Check if $app is in the registry and has an entry for $name
|
|
|
|
*
|
2014-10-09 11:34:24 +02:00
|
|
|
* @param {string} _app app-name
|
|
|
|
* @param {string} _name name / key in the registry, eg. 'view'
|
|
|
|
* @return {boolean|string} false if $app is not registered, otherwise string with the value for $name
|
2013-07-22 21:20:13 +02:00
|
|
|
* @memberOf egw
|
2012-03-01 17:24:29 +01:00
|
|
|
*/
|
|
|
|
link_get_registry: function(_app, _name)
|
|
|
|
{
|
2012-03-28 14:37:03 +02:00
|
|
|
if (typeof link_registry != 'object')
|
|
|
|
{
|
|
|
|
alert('egw.open() link registry is NOT defined!');
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-01 17:24:29 +01:00
|
|
|
if (typeof link_registry[_app] == 'undefined')
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var reg = link_registry[_app];
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
// some defaults (we set them directly in the registry, to do this only once)
|
|
|
|
if (typeof reg[_name] == 'undefined')
|
|
|
|
{
|
|
|
|
switch(_name)
|
|
|
|
{
|
|
|
|
case 'name':
|
|
|
|
reg.name = _app;
|
|
|
|
break;
|
|
|
|
case 'icon':
|
|
|
|
var app_data = this.app(_app);
|
2013-12-12 04:43:17 +01:00
|
|
|
if (typeof app_data != 'undefined' &&
|
2013-10-10 18:15:46 +02:00
|
|
|
typeof app_data.icon != 'undefined' && app_data.icon != null)
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
|
|
|
reg.icon = (typeof app_data.icon_app != 'undefined' ? app_data.icon_app : _app)+'/'+app_data.icon;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reg.icon = _app+'/navbar';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-04-04 21:17:07 +02:00
|
|
|
if (reg && typeof _name == 'undefined')
|
|
|
|
{
|
|
|
|
// No key requested, return the whole thing
|
|
|
|
return reg;
|
|
|
|
}
|
2012-03-01 17:24:29 +01:00
|
|
|
return typeof reg[_name] == 'undefined' ? false : reg[_name];
|
|
|
|
},
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2012-03-21 17:02:50 +01:00
|
|
|
/**
|
|
|
|
* Get mime-type information from app-registry
|
|
|
|
*
|
2015-03-25 18:48:24 +01:00
|
|
|
* We prefer a full match over a wildcard like 'text/*' (written as regualr expr. "/^text\\//"
|
|
|
|
*
|
2014-10-09 11:34:24 +02:00
|
|
|
* @param {string} _type
|
|
|
|
* @return {object} with values for keys 'menuaction', 'mime_id' (path) or 'mime_url' and options 'mime_popup' and other values to pass one
|
2012-03-21 17:02:50 +01:00
|
|
|
*/
|
|
|
|
get_mime_info: function(_type)
|
|
|
|
{
|
2015-03-25 18:48:24 +01:00
|
|
|
var wildcard_mime;
|
2012-03-21 17:02:50 +01:00
|
|
|
for(var app in link_registry)
|
|
|
|
{
|
|
|
|
var reg = link_registry[app];
|
|
|
|
if (typeof reg.mime != 'undefined')
|
|
|
|
{
|
|
|
|
for(var mime in reg.mime)
|
|
|
|
{
|
|
|
|
if (mime == _type) return reg.mime[_type];
|
2015-03-25 18:48:24 +01:00
|
|
|
if (mime[0] == '/' && _type.match(new RegExp(mime.substring(1, mime.length-1), 'i')))
|
|
|
|
{
|
|
|
|
wildcard_mime = reg.mime[mime];
|
|
|
|
}
|
2012-03-21 17:02:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-25 18:48:24 +01:00
|
|
|
return wildcard_mime ? wildcard_mime : null;
|
2012-03-21 17:02:50 +01:00
|
|
|
},
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2012-03-21 17:02:50 +01:00
|
|
|
/**
|
|
|
|
* Get handler (link-data) for given path and mime-type
|
|
|
|
*
|
2015-05-01 12:52:24 +02:00
|
|
|
* @param {string|object} _path vfs path, egw_link::set_data() id or
|
|
|
|
* object with attr path, optinal download_url or id, app2 and id2 (path=/apps/app2/id2/id)
|
2014-10-09 11:34:24 +02:00
|
|
|
* @param {string} _type mime-type, if not given in _path object
|
|
|
|
* @return {string|object} string with EGw relative link, array with get-parameters for '/index.php' or null (directory and not filemanager access)
|
2012-03-21 17:02:50 +01:00
|
|
|
*/
|
|
|
|
mime_open: function(_path, _type)
|
|
|
|
{
|
|
|
|
var path;
|
|
|
|
if (typeof _path == 'object')
|
|
|
|
{
|
|
|
|
if (typeof _path.path == 'undefined')
|
|
|
|
{
|
|
|
|
path = '/apps/'+_path.app2+'/'+_path.id2+'/'+_path.id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path = _path.path;
|
|
|
|
}
|
|
|
|
if (typeof _path.type == 'string')
|
|
|
|
{
|
|
|
|
_type = _path.type;
|
|
|
|
}
|
2015-03-25 18:48:24 +01:00
|
|
|
}
|
|
|
|
else if(_path[0] != '/')
|
|
|
|
{
|
|
|
|
|
2012-03-21 17:02:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path = _path;
|
|
|
|
}
|
|
|
|
var mime_info = this.get_mime_info(_type);
|
|
|
|
if (mime_info)
|
|
|
|
{
|
|
|
|
var data = {};
|
|
|
|
for(var attr in mime_info)
|
|
|
|
{
|
|
|
|
switch(attr)
|
|
|
|
{
|
|
|
|
case 'mime_url':
|
|
|
|
data[mime_info.mime_url] = 'vfs://default' + path;
|
|
|
|
break;
|
2015-03-25 18:48:24 +01:00
|
|
|
case 'mime_data':
|
|
|
|
break;
|
|
|
|
case 'mime_type':
|
|
|
|
data[mime_info.mime_type] = _type;
|
|
|
|
break;
|
2015-08-26 19:08:37 +02:00
|
|
|
case 'mime_id':
|
|
|
|
data[mime_info.mime_id] = path;
|
|
|
|
break;
|
2012-03-21 17:02:50 +01:00
|
|
|
default:
|
|
|
|
data[attr] = mime_info[attr];
|
|
|
|
}
|
|
|
|
}
|
2015-03-25 18:48:24 +01:00
|
|
|
// if mime_info did NOT define mime_url attribute, we use a WebDAV url drived from path
|
|
|
|
if (typeof mime_info.mime_url == 'undefined')
|
|
|
|
{
|
2015-05-01 12:52:24 +02:00
|
|
|
data.url = typeof _path == 'object' && _path.download_url ? _path.download_url : '/webdav.php' + path;
|
2015-03-25 18:48:24 +01:00
|
|
|
}
|
2012-03-21 17:02:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-01 12:52:24 +02:00
|
|
|
var data = typeof _path == 'object' && _path.download_url ? _path.download_url : '/webdav.php' + path;
|
2012-03-21 17:02:50 +01:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
},
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
/**
|
|
|
|
* Get list of link-aware apps the user has rights to use
|
|
|
|
*
|
2014-10-09 11:34:24 +02:00
|
|
|
* @param {string} _must_support capability the apps need to support, eg. 'add', default ''=list all apps
|
|
|
|
* @return {object} with app => title pairs
|
2012-03-01 17:24:29 +01:00
|
|
|
*/
|
|
|
|
link_app_list: function(_must_support)
|
|
|
|
{
|
|
|
|
var apps = [];
|
|
|
|
for (var type in link_registry)
|
|
|
|
{
|
|
|
|
var reg = link_registry[type];
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
if (typeof _must_support != 'undefined' && _must_support && typeof reg[_must_support] == 'undefined') continue;
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
var app_sub = type.split('-');
|
|
|
|
if (this.app(app_sub[0]))
|
|
|
|
{
|
|
|
|
apps.push({"type": type, "label": this.lang(this.link_get_registry(type,'name'))});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// sort labels (caseinsensitive) alphabetic
|
2013-12-12 04:43:17 +01:00
|
|
|
apps = apps.sort(function(_a,_b) {
|
|
|
|
var al = _a.label.toUpperCase();
|
|
|
|
var bl = _b.label.toUpperCase();
|
2012-03-01 17:24:29 +01:00
|
|
|
return al == bl ? 0 : (al > bl ? 1 : -1);
|
|
|
|
});
|
|
|
|
// create sorted associative array / object
|
|
|
|
var sorted = {};
|
|
|
|
for(var i = 0; i < apps.length; ++i)
|
|
|
|
{
|
|
|
|
sorted[apps[i].type] = apps[i].label;
|
|
|
|
}
|
|
|
|
return sorted;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set link registry
|
2013-12-12 04:43:17 +01:00
|
|
|
*
|
2014-10-09 11:34:24 +02:00
|
|
|
* @param {object} _registry whole registry or entries for just one app
|
|
|
|
* @param {string} _app
|
2015-02-02 20:49:18 +01:00
|
|
|
* @param {boolean} _need_clone _images need to be cloned, as it is from different window context
|
|
|
|
* and therefore will be inaccessible in IE, after that window is closed
|
2012-03-01 17:24:29 +01:00
|
|
|
*/
|
2015-02-02 20:49:18 +01:00
|
|
|
set_link_registry: function (_registry, _app, _need_clone)
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
|
|
|
if (typeof _app == 'undefined')
|
|
|
|
{
|
2015-02-02 20:49:18 +01:00
|
|
|
link_registry = _need_clone ? jQuery.extend(true, {}, _registry) : _registry;
|
2012-03-01 17:24:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-02 20:49:18 +01:00
|
|
|
link_registry[_app] = _need_clone ? jQuery.extend(true, {}, _registry) : _registry;
|
2012-03-01 17:24:29 +01:00
|
|
|
}
|
|
|
|
},
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
/**
|
|
|
|
* Generate a url which supports url or cookies based sessions
|
|
|
|
*
|
|
|
|
* Please note, the values of the query get url encoded!
|
|
|
|
*
|
2015-05-01 12:52:24 +02:00
|
|
|
* @param {string} _url a url relative to the egroupware install root, it can contain a query too or
|
|
|
|
* full url containing a schema and "://"
|
2014-10-09 11:34:24 +02:00
|
|
|
* @param {object|string} _extravars query string arguements as string or array (prefered)
|
2012-03-01 17:24:29 +01:00
|
|
|
* if string is used ambersands in vars have to be already urlencoded as '%26', function ensures they get NOT double encoded
|
2014-10-09 11:34:24 +02:00
|
|
|
* @return {string} generated url
|
2012-03-01 17:24:29 +01:00
|
|
|
*/
|
|
|
|
link: function(_url, _extravars)
|
|
|
|
{
|
2015-09-10 17:17:48 +02:00
|
|
|
if (_url.substr(0,4) == 'http' && _url.indexOf('://') <= 5)
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
2015-05-01 12:52:24 +02:00
|
|
|
// already a full url (eg. download_url of vfs), nothing to do
|
2012-03-01 17:24:29 +01:00
|
|
|
}
|
2015-05-01 12:52:24 +02:00
|
|
|
else
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
2015-05-01 12:52:24 +02:00
|
|
|
if (_url[0] != '/')
|
|
|
|
{
|
|
|
|
alert("egw.link('"+_url+"') called with url starting NOT with a slash!");
|
|
|
|
var app = window.egw_appName;
|
|
|
|
if (app != 'login' && app != 'logout') _url = app+'/'+_url;
|
|
|
|
}
|
|
|
|
// append the url to the webserver url, if not already contained or empty
|
|
|
|
if (this.webserverUrl && this.webserverUrl != '/' && _url.indexOf(this.webserverUrl+'/') != 0)
|
|
|
|
{
|
|
|
|
_url = this.webserverUrl + _url;
|
|
|
|
}
|
2012-03-01 17:24:29 +01:00
|
|
|
}
|
|
|
|
var vars = {};
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
// check if the url already contains a query and ensure that vars is an array and all strings are in extravars
|
|
|
|
var url_othervars = _url.split('?',2);
|
|
|
|
_url = url_othervars[0];
|
|
|
|
var othervars = url_othervars[1];
|
|
|
|
if (_extravars && typeof _extravars == 'object')
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery.extend(vars, _extravars);
|
2012-03-01 17:24:29 +01:00
|
|
|
_extravars = othervars;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-06 16:04:26 +01:00
|
|
|
if (!_extravars) _extravars = '';
|
|
|
|
if (othervars) _extravars += (_extravars?'&':'')+othervars;
|
2012-03-01 17:24:29 +01:00
|
|
|
}
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
// parse extravars string into the vars array
|
|
|
|
if (_extravars)
|
|
|
|
{
|
|
|
|
_extravars = _extravars.split('&');
|
|
|
|
for(var i=0; i < _extravars.length; ++i)
|
|
|
|
{
|
|
|
|
var name_val = _extravars[i].split('=',2);
|
|
|
|
var name = name_val[0];
|
2013-04-09 18:17:43 +02:00
|
|
|
var val = name_val[1] || '';
|
2012-03-01 17:24:29 +01:00
|
|
|
if (val.indexOf('%26') != -1) val = val.replace(/%26/g,'&'); // make sure to not double encode &
|
|
|
|
if (name.lastIndexOf('[]') == name.length-2)
|
|
|
|
{
|
|
|
|
name = name.substr(0,name.length-2);
|
|
|
|
if (typeof vars[name] == 'undefined') vars[name] = [];
|
|
|
|
vars[name].push(val);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vars[name] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
// if there are vars, we add them urlencoded to the url
|
|
|
|
var query = [];
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
for(var name in vars)
|
|
|
|
{
|
2013-12-12 04:43:17 +01:00
|
|
|
var val = vars[name] || ''; // fix error for eg. null, which is an object!
|
2012-03-01 17:24:29 +01:00
|
|
|
if (typeof val == 'object')
|
|
|
|
{
|
|
|
|
for(var i=0; i < val.length; ++i)
|
|
|
|
{
|
|
|
|
query.push(name+'[]='+encodeURIComponent(val[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
query.push(name+'='+encodeURIComponent(val));
|
|
|
|
}
|
|
|
|
}
|
2013-11-26 23:23:08 +01:00
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
return query.length ? _url+'?'+query.join('&') : _url;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query a title of _app/_id
|
2013-12-12 04:43:17 +01:00
|
|
|
*
|
2014-03-20 10:40:37 +01:00
|
|
|
* @param {string} _app
|
2014-10-09 11:34:24 +02:00
|
|
|
* @param {string|number} _id
|
2014-03-20 10:40:37 +01:00
|
|
|
* @param {function} _callback optinal callback, required if for responses from the server
|
|
|
|
* @param {object} _context context for the callback
|
|
|
|
* @param {boolean} _force_reload true load again from server, even if already cached
|
2014-10-09 11:34:24 +02:00
|
|
|
* @return {string|boolean|null} string with title if it exist in local cache or null if not
|
2012-03-01 17:24:29 +01:00
|
|
|
*/
|
2014-03-20 10:40:37 +01:00
|
|
|
link_title: function(_app, _id, _callback, _context, _force_reload)
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
|
|
|
// check if we have a cached title --> return it direct
|
2014-03-20 10:40:37 +01:00
|
|
|
if (typeof title_cache[_app] != 'undefined' && typeof title_cache[_app][_id] != 'undefined' && _force_reload !== true)
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
|
|
|
if (typeof _callback == 'function')
|
|
|
|
{
|
|
|
|
_callback.call(_context, title_cache[_app][_id]);
|
|
|
|
}
|
|
|
|
return title_cache[_app][_id];
|
|
|
|
}
|
|
|
|
// no callback --> return null
|
|
|
|
if (typeof _callback != 'function')
|
|
|
|
{
|
|
|
|
return null; // not found in local cache and cant do a synchronious request
|
|
|
|
}
|
|
|
|
// queue the request
|
|
|
|
if (typeof title_queue[_app] == 'undefined')
|
|
|
|
{
|
|
|
|
title_queue[_app] = {};
|
|
|
|
}
|
|
|
|
if (typeof title_queue[_app][_id] == 'undefined')
|
|
|
|
{
|
|
|
|
title_queue[_app][_id] = [];
|
|
|
|
}
|
|
|
|
title_queue[_app][_id].push({callback: _callback, context: _context});
|
|
|
|
// if there's no active jsonq request, start a new one
|
|
|
|
if (title_uid == null)
|
|
|
|
{
|
2016-05-04 21:07:54 +02:00
|
|
|
title_uid = this.jsonq('EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link_titles',[{}], this.link_title_callback, this, this.link_title_before_send);
|
2012-03-01 17:24:29 +01:00
|
|
|
}
|
|
|
|
},
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
/**
|
|
|
|
* Callback to add all current title requests
|
2013-12-12 04:43:17 +01:00
|
|
|
*
|
2014-10-09 11:34:24 +02:00
|
|
|
* @param {object} _params of parameters, only first parameter is used
|
2012-03-01 17:24:29 +01:00
|
|
|
*/
|
|
|
|
link_title_before_send: function(_params)
|
|
|
|
{
|
|
|
|
// add all current title-requests
|
|
|
|
for(var app in title_queue)
|
|
|
|
{
|
|
|
|
for(var id in title_queue[app])
|
|
|
|
{
|
2013-10-10 12:49:41 +02:00
|
|
|
if (typeof _params[0][app] == 'undefined')
|
|
|
|
{
|
|
|
|
_params[0][app] = [];
|
|
|
|
}
|
2012-03-01 17:24:29 +01:00
|
|
|
_params[0][app].push(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
title_uid = null; // allow next request to jsonq
|
|
|
|
},
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
/**
|
|
|
|
* Callback for server response
|
2013-12-12 04:43:17 +01:00
|
|
|
*
|
2014-10-09 11:34:24 +02:00
|
|
|
* @param {object} _response _app => _id => title
|
2012-03-01 17:24:29 +01:00
|
|
|
*/
|
|
|
|
link_title_callback: function(_response)
|
|
|
|
{
|
|
|
|
if (typeof _response != 'object')
|
|
|
|
{
|
|
|
|
throw "Wrong parameter for egw.link_title_callback!";
|
|
|
|
}
|
|
|
|
for(var app in _response)
|
|
|
|
{
|
2013-12-12 04:43:17 +01:00
|
|
|
if (typeof title_cache[app] != 'object')
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
|
|
|
title_cache[app] = {};
|
|
|
|
}
|
|
|
|
for (var id in _response[app])
|
|
|
|
{
|
|
|
|
var title = _response[app][id];
|
|
|
|
// cache locally
|
|
|
|
title_cache[app][id] = title;
|
|
|
|
// call callbacks waiting for title of app/id
|
2016-01-07 01:49:59 +01:00
|
|
|
if(typeof title_queue[app] !== 'undefined' &&
|
|
|
|
typeof title_queue[app][id] !== "undefined"
|
2016-01-06 21:33:38 +01:00
|
|
|
)
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
2013-03-13 20:31:06 +01:00
|
|
|
for(var i=0; i < title_queue[app][id].length; ++i)
|
|
|
|
{
|
|
|
|
var callback = title_queue[app][id][i];
|
|
|
|
callback.callback.call(callback.context, title);
|
|
|
|
}
|
2016-01-07 01:49:59 +01:00
|
|
|
delete title_queue[app][id];
|
2012-03-01 17:24:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-22 21:20:13 +02:00
|
|
|
},
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2013-07-22 21:20:13 +02:00
|
|
|
/**
|
|
|
|
* Create quick add selectbox
|
2013-12-12 04:43:17 +01:00
|
|
|
*
|
2014-10-09 11:34:24 +02:00
|
|
|
* @param {DOMnode} _parent parent to create selectbox in
|
2013-07-22 21:20:13 +02:00
|
|
|
*/
|
|
|
|
link_quick_add: function(_parent)
|
|
|
|
{
|
2013-08-01 11:54:09 +02:00
|
|
|
// check if quick-add selectbox is alread there, only create it again if not
|
|
|
|
if (document.getElementById('quick_add_selectbox')) return;
|
|
|
|
|
|
|
|
var select = jQuery(document.createElement('select')).attr('id', 'quick_add_selectbox');
|
2013-07-22 21:20:13 +02:00
|
|
|
jQuery(typeof _parent == 'string' ? '#'+_parent : _parent).append(select);
|
2013-12-12 04:43:17 +01:00
|
|
|
|
2013-07-22 21:20:13 +02:00
|
|
|
var self = this;
|
|
|
|
// bind change handler
|
|
|
|
select.change(function(){
|
2015-03-18 11:36:47 +01:00
|
|
|
if (this.value) self.open('', this.value, 'add', {}, undefined, this.value, true);
|
2013-07-22 21:20:13 +02:00
|
|
|
this.value = '';
|
|
|
|
});
|
|
|
|
// need to load common translations for app-names
|
2014-01-09 16:32:07 +01:00
|
|
|
this.langRequire(window, [{app: 'common', lang: this.preference('lang')}], function(){
|
2013-07-22 21:20:13 +02:00
|
|
|
select.append(jQuery(document.createElement('option')).attr('value', '').text(self.lang('Add')+' ...'));
|
|
|
|
var apps = self.link_app_list('add');
|
|
|
|
for(var app in apps)
|
|
|
|
{
|
2021-03-30 18:12:29 +02:00
|
|
|
if(egw.link_get_registry(app, 'no_quick_add'))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2014-10-21 15:51:37 +02:00
|
|
|
var option = jQuery(document.createElement('option')).attr('value', app)
|
|
|
|
.text(self.lang(self.link_get_registry(app,'entry') || apps[app]));
|
2013-07-22 21:20:13 +02:00
|
|
|
select.append(option);
|
|
|
|
}
|
|
|
|
});
|
2012-03-01 17:24:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|