mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-04-13 10:38:20 +02:00
reorganized egw.link methods to call each other (and not dublicate code), using mime-registry to open files, todo: special download url of eg. filesystem stream wrapper
This commit is contained in:
parent
aa7a14c670
commit
2e8d60d5a0
@ -678,7 +678,7 @@ var et2_link = et2_valueWidget.extend([et2_IDetachedDOM], {
|
|||||||
this.set_title(this.link, _value.title);
|
this.set_title(this.link, _value.title);
|
||||||
var self = this;
|
var self = this;
|
||||||
this.link.unbind()
|
this.link.unbind()
|
||||||
.click( function(){self.egw().open(_value.id, _value.app, "edit", _value.extra);});
|
.click( function(){self.egw().open(_value, "", "edit");});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -819,17 +819,19 @@ var et2_link_string = et2_valueWidget.extend([et2_IDetachedDOM], {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_add_link: function(_link_data) {
|
_add_link: function(_link_data) {
|
||||||
|
/* RB: seems not used anymore: Nathan?
|
||||||
if(!_link_data.title) {
|
if(!_link_data.title) {
|
||||||
// No callback yet, need something to do with it
|
// No callback yet, need something to do with it
|
||||||
var title = this.egw().link_title(_link_data.app, _link_data.id);
|
var title = this.egw().link_title(_link_data.app, _link_data.id);
|
||||||
// Need to set it to something, or call to text() will return current value
|
// Need to set it to something, or call to text() will return current value
|
||||||
if(title == null || title == false) _link_data.title = "";
|
if(title == null || title == false) _link_data.title = "";
|
||||||
}
|
}*/
|
||||||
var self = this;
|
var self = this;
|
||||||
var link = $j(document.createElement("li"))
|
var link = $j(document.createElement("li"))
|
||||||
.appendTo(this.list)
|
.appendTo(this.list)
|
||||||
.addClass("et2_link")
|
.addClass("et2_link")
|
||||||
.click( function(){self.egw().open(_link_data.id, _link_data.app, "edit", _link_data.extra);});
|
.click( function(){self.egw().open(_link_data, "", "edit");});
|
||||||
|
|
||||||
if(_link_data.title) link.text(_link_data.title);
|
if(_link_data.title) link.text(_link_data.title);
|
||||||
|
|
||||||
// Now that link is created, get title from server & update
|
// Now that link is created, get title from server & update
|
||||||
@ -915,7 +917,7 @@ var et2_link_list = et2_link_string.extend({
|
|||||||
$j(document.createElement("td"))
|
$j(document.createElement("td"))
|
||||||
.appendTo(row)
|
.appendTo(row)
|
||||||
.addClass(columns[i])
|
.addClass(columns[i])
|
||||||
.click( function(){self.egw().open(_link_data.id, _link_data.app, "edit", _link_data.extra);})
|
.click( function(){self.egw().open(_link_data, "", "edit");})
|
||||||
.text(_link_data[columns[i]]);
|
.text(_link_data[columns[i]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,25 +58,55 @@ egw.extend('links', egw.MODULE_GLOBAL, function() {
|
|||||||
* - egw.open(123,'addressbook','view') opens addressbook view for entry 123 (showing linked infologs)
|
* - 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'
|
* - egw.open('','addressbook','view_list',{ search: 'Becker' }) opens list of addresses containing 'Becker'
|
||||||
*
|
*
|
||||||
* @param string|int id either just the id or "app:id" if app==""
|
* @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 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 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 object|string extra extra url parameters to append as object or string
|
||||||
* @param string target target of window to open
|
* @param string target target of window to open
|
||||||
*/
|
*/
|
||||||
open: function(id, app, type, extra, target)
|
open: function(id_data, app, type, extra, target)
|
||||||
{
|
{
|
||||||
if (typeof link_registry != 'object')
|
if (typeof link_registry != 'object')
|
||||||
{
|
{
|
||||||
alert('egw.open() link registry is NOT defined!');
|
alert('egw.open() link registry is NOT defined!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var id;
|
||||||
if (!app)
|
if (!app)
|
||||||
|
{
|
||||||
|
if (typeof id_data != 'object')
|
||||||
{
|
{
|
||||||
var app_id = id.split(':',2);
|
var app_id = id.split(':',2);
|
||||||
app = app_id[0];
|
app = app_id[0];
|
||||||
id = app_id[1];
|
id = app_id[1];
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
app = id_data.app;
|
||||||
|
id = id_data.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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' && typeof url.mime_popup != 'undefined')
|
||||||
|
{
|
||||||
|
popup = url.mime_popup;
|
||||||
|
delete url.mime_popup;
|
||||||
|
params = url;
|
||||||
|
url = '/index.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (!app || typeof link_registry[app] != 'object')
|
if (!app || typeof link_registry[app] != 'object')
|
||||||
{
|
{
|
||||||
alert('egw.open() app "'+app+'" NOT defined in link registry!');
|
alert('egw.open() app "'+app+'" NOT defined in link registry!');
|
||||||
@ -90,9 +120,8 @@ egw.extend('links', egw.MODULE_GLOBAL, function() {
|
|||||||
alert('egw.open() type "'+type+'" is NOT defined in link registry for app "'+app+'"!');
|
alert('egw.open() type "'+type+'" is NOT defined in link registry for app "'+app+'"!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var url = this.webserverUrl+'/index.php';
|
url = '/index.php';
|
||||||
var delimiter = '?';
|
params = app_registry[type];
|
||||||
var params = app_registry[type];
|
|
||||||
if (type == 'view' || type == 'edit') // add id parameter for type view or edit
|
if (type == 'view' || type == 'edit') // add id parameter for type view or edit
|
||||||
{
|
{
|
||||||
params[app_registry[type+'_id']] = id;
|
params[app_registry[type+'_id']] = id;
|
||||||
@ -103,39 +132,18 @@ egw.extend('links', egw.MODULE_GLOBAL, function() {
|
|||||||
params[app_registry.add_app] = app_id[0];
|
params[app_registry.add_app] = app_id[0];
|
||||||
params[app_registry.add_id] = app_id[1];
|
params[app_registry.add_id] = app_id[1];
|
||||||
}
|
}
|
||||||
for(var attr in params)
|
|
||||||
|
if (typeof extra == 'string')
|
||||||
{
|
{
|
||||||
url += delimiter+attr+'='+encodeURIComponent(params[attr]);
|
url += '?'+extra;
|
||||||
delimiter = '&';
|
|
||||||
}
|
}
|
||||||
if (typeof extra == 'object')
|
else if (typeof extra == 'object')
|
||||||
{
|
{
|
||||||
for(var attr in extra)
|
$j.extend(params, extra);
|
||||||
{
|
|
||||||
url += delimiter+attr+'='+encodeURIComponent(extra[attr]);
|
|
||||||
}
|
}
|
||||||
|
popup = app_registry[type+'_popup'];
|
||||||
}
|
}
|
||||||
else if (typeof extra == 'string')
|
this.call_link(this.link(url, params), target, popup);
|
||||||
{
|
|
||||||
url += delimiter + extra;
|
|
||||||
}
|
|
||||||
if (typeof app_registry[type+'_popup'] == 'undefined')
|
|
||||||
{
|
|
||||||
if (target)
|
|
||||||
{
|
|
||||||
window.open(url, target);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
egw_appWindowOpen(app, url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var w_h = app_registry[type+'_popup'].split('x');
|
|
||||||
if (w_h[1] == 'egw_getWindowOuterHeight()') w_h[1] = egw_getWindowOuterHeight();
|
|
||||||
egw_openWindowCentered2(url, target, w_h[0], w_h[1], 'yes', app, false);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -177,6 +185,83 @@ egw.extend('links', egw.MODULE_GLOBAL, function() {
|
|||||||
return typeof reg[_name] == 'undefined' ? false : reg[_name];
|
return typeof reg[_name] == 'undefined' ? false : reg[_name];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get mime-type information from app-registry
|
||||||
|
*
|
||||||
|
* @param string _type
|
||||||
|
* @return array with values for keys 'menuaction', 'mime_id' (path) or 'mime_url' and options 'mime_popup' and other values to pass one
|
||||||
|
*/
|
||||||
|
get_mime_info: function(_type)
|
||||||
|
{
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get handler (link-data) for given path and mime-type
|
||||||
|
*
|
||||||
|
* @param string|object _path vfs path or object with attr path or id, app2 and id2 (path=/apps/app2/id2/id)
|
||||||
|
* @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)
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
case 'mime_id':
|
||||||
|
data[mime_info.mime_id] = path;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
data[attr] = mime_info[attr];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var data = '/webdav.php' + path;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list of link-aware apps the user has rights to use
|
* Get list of link-aware apps the user has rights to use
|
||||||
*
|
*
|
||||||
@ -247,14 +332,13 @@ egw.extend('links', egw.MODULE_GLOBAL, function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// link is not necessary an url, it can also be a menuaction!
|
// link is not necessary an url, it can also be a menuaction!
|
||||||
if (url.indexOf('/') == -1 &&
|
if (url.indexOf('/') == -1 && url.split('.').length >= 3 &&
|
||||||
url.split('.').length >= 3 &&
|
!(url.indexOf('mailto:') == 0 || url.indexOf('/index.php') == 0 || url.indexOf('://') != -1))
|
||||||
url.indexOf('mailto:') == -1 ||
|
|
||||||
url.indexOf('://') == -1)
|
|
||||||
{
|
{
|
||||||
url = "/index.php?menuaction="+url;
|
url = "/index.php?menuaction="+url;
|
||||||
}
|
}
|
||||||
if (url[0] == '/') // link relative to eGW
|
// 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;
|
url = this.webserverUrl + url;
|
||||||
}
|
}
|
||||||
@ -287,20 +371,10 @@ egw.extend('links', egw.MODULE_GLOBAL, function() {
|
|||||||
var app = window.egw_appName;
|
var app = window.egw_appName;
|
||||||
if (app != 'login' && app != 'logout') _url = app+'/'+_url;
|
if (app != 'login' && app != 'logout') _url = app+'/'+_url;
|
||||||
}
|
}
|
||||||
// append the url to the webserver url, but avoid more then one slash between the parts of the url
|
// append the url to the webserver url, if not already contained or empty
|
||||||
var webserver_url = this.webserverUrl;
|
if (this.webserverUrl && this.webserverUrl != '/' && _url.indexOf(this.webserverUrl+'/') != 0)
|
||||||
// patch inspired by vladimir kolobkov -> we should not try to match the webserver url against the url without '/' as delimiter,
|
|
||||||
// as webserver_url may be part of _url (as /egw is part of phpgwapi/js/egw_instant_load.html)
|
|
||||||
if ((_url[0] != '/' || webserver_url != '/') && (!webserver_url || _url.indexOf(webserver_url+'/') == -1))
|
|
||||||
{
|
{
|
||||||
if(_url[0] != '/' && webserver_url.lastIndexOf('/') != webserver_url.length-1)
|
_url = this.webserverUrl + _url;
|
||||||
{
|
|
||||||
_url = webserver_url +'/'+ _url;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_url = webserver_url + _url;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var vars = {};
|
var vars = {};
|
||||||
|
Loading…
Reference in New Issue
Block a user