From 5cadd29d587bb50f19f8ac38d406a5d29003f7b1 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 13 Sep 2011 18:23:43 +0000 Subject: [PATCH] Basic egw.link_title(_app,_id,_callback,_context) method. Plan is to run a clientside cache and own queue for link_titles, as server can query titles for N id's for a given app more effiently then N separeate queries. --- .../inc/class.etemplate_widget_link.inc.php | 28 ++++++++++++++----- phpgwapi/js/jsapi/egw.js | 18 ++++++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/etemplate/inc/class.etemplate_widget_link.inc.php b/etemplate/inc/class.etemplate_widget_link.inc.php index 19d8859f44..40e4fe690d 100644 --- a/etemplate/inc/class.etemplate_widget_link.inc.php +++ b/etemplate/inc/class.etemplate_widget_link.inc.php @@ -95,6 +95,20 @@ error_log("$app, $pattern, $options"); $response->data($links); } + /** + * Return title for a given app/id pair + * + * @param string $app + * @param string|int $id + * @return string|boolean string with title, boolean false of permission denied or null if not found + */ + public static function ajax_link_title($app,$id) + { + $title = egw_link::title($app, $id); + error_log(__METHOD__."('$app', '$id') = ".array2string($title)); + egw_json_response::get()->data($title); + } + /** * Create links */ @@ -103,13 +117,13 @@ error_log("$app, $pattern, $options"); foreach($links as &$link) { if($link['app'] == egw_link::VFS_APPNAME) { if (is_dir($GLOBALS['egw_info']['server']['temp_dir']) && is_writable($GLOBALS['egw_info']['server']['temp_dir'])) - { - $path = $GLOBALS['egw_info']['server']['temp_dir'] . '/' . $link['id']; - } - else - { - $path = $link['id'].'+'; - } + { + $path = $GLOBALS['egw_info']['server']['temp_dir'] . '/' . $link['id']; + } + else + { + $path = $link['id'].'+'; + } $link['tmp_name'] = $path; $link['id'] = $link; } diff --git a/phpgwapi/js/jsapi/egw.js b/phpgwapi/js/jsapi/egw.js index a5c5895dc7..cd4e99a67e 100644 --- a/phpgwapi/js/jsapi/egw.js +++ b/phpgwapi/js/jsapi/egw.js @@ -750,6 +750,24 @@ else delete this.jsonq_queue[uid]; } + }, + + /** + * Query a title of _app/_id + * + * @param string _app + * @param string|int _id + * @param function _callback optinal callback, required if for responses from the server + * @param object _context context for the callback + * @return string|boolean|null string with title if it exist in local cache or null if not + */ + link_title: function(_app, _id, _callback, _context) + { + if (typeof _callback == 'function') + { + this.jsonq(_app+'.etemplate_widget_link.ajax_link_title', [_app, _id], _callback, _context); + } + return null; } }; }