From 3bbc6a6962fb8273980f73e0be55ccea1c000eb5 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 2 Jun 2011 20:03:34 +0000 Subject: [PATCH] - egw_open nm_action using new clientside link registry - enabling/disabling actions based on row-id matching a regular expression - children/submenus inherit 'url','popup','nm_action','onExecute','type','egw_open' attributes --- etemplate/inc/class.nextmatch_widget.inc.php | 32 +++++++++++++------- etemplate/js/nextmatch_action.js | 24 +++++++++++++++ 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/etemplate/inc/class.nextmatch_widget.inc.php b/etemplate/inc/class.nextmatch_widget.inc.php index e23d22f021..88c0b00d56 100644 --- a/etemplate/inc/class.nextmatch_widget.inc.php +++ b/etemplate/inc/class.nextmatch_widget.inc.php @@ -598,11 +598,11 @@ class nextmatch_widget * @param string $prefix='' prefix for ids * @param array &$action_links=array() on return all first-level actions plus the ones with enabled='javaScript:...' * @param int $max_length=self::DEFAULT_MAX_MENU_LENGTH automatic pagination, not for first menu level! - * @param string $onExecute='' default onExecute + * @param array $default_attrs=null default attributes * @return array */ public static function egw_actions(array $actions=null, $template_name='', $prefix='', array &$action_links=array(), - $max_length=self::DEFAULT_MAX_MENU_LENGTH, $onExecute='') + $max_length=self::DEFAULT_MAX_MENU_LENGTH, array $default_attrs=null) { //echo "

".__METHOD__."(\$actions, '$template_name', '$prefix', \$action_links, $max_length) \$actions="; _debug_array($actions); // default icons for some common actions @@ -611,11 +611,13 @@ class nextmatch_widget 'edit' => 'edit', 'open' => 'edit', // does edit if possible, otherwise view 'add' => 'new', + 'new' => 'new', 'delete' => 'delete', 'cat' => 'attach', // add as category icon to api 'document' => 'etemplate/merge', 'print'=> 'print', 'copy' => 'copy', + 'move' => 'move', ); $first_level = !$action_links; // add all first level actions @@ -627,6 +629,7 @@ class nextmatch_widget { // in case it's only selectbox id => label pairs if (!is_array($action)) $action = array('caption' => $action); + if ($default_attrs) $action += $default_attrs; if (!$first_level && $n == $max_length && count($actions) > $max_length) { @@ -643,10 +646,11 @@ class nextmatch_widget } $action['id'] = $prefix.$id; - // set some default onExecute + // set certain enable functions foreach(array( 'enableClass' => 'javaScript:nm_enableClass', 'disableClass' => 'javaScript:nm_not_disableClass', + 'enableId' => 'javaScript:nm_enableId', ) as $attr => $check) { if (isset($action[$attr]) && !isset($action['enabled'])) @@ -695,10 +699,21 @@ class nextmatch_widget } } + // add sub-menues + if ($action['children']) + { + static $inherit_attrs = array('url','popup','nm_action','onExecute','type','egw_open'); + $action['children'] = self::egw_actions($action['children'], $template_name, $action['prefix'], $action_links, $max_length, + array_intersect_key($action, array_flip($inherit_attrs))); + + unset($action['prefix']); + $action = array_diff_key($action, array_flip($inherit_attrs)); + } + // link or popup action if ($action['url']) { - $action['url'] = egw::link('/index.php',$action['url']); + $action['url'] = egw::link('/index.php',str_replace('$action',$id,$action['url'])); if ($action['popup']) { list($action['data']['width'],$action['data']['height']) = explode('x',$action['popup']); @@ -710,15 +725,10 @@ class nextmatch_widget $action['data']['nm_action'] = 'location'; } } - - // add sub-menues - if ($action['children']) + if ($action['egw_open']) { - $action['children'] = self::egw_actions($action['children'], $template_name, $action['prefix'], $action_links, $max_length, $action['onExecute']); - unset($action['prefix']); - unset($action['onExecute']); + $action['data']['nm_action'] = 'egw_open'; } - if ($onExecute && !isset($action['onExecute'])) $action['onExecute'] = $onExecute; static $egw_action_supported = array( // attributes supported by egw_action 'id','caption','iconUrl','type','default','onExecute','group', diff --git a/etemplate/js/nextmatch_action.js b/etemplate/js/nextmatch_action.js index 8b7af67aba..ef7e6ba5d9 100644 --- a/etemplate/js/nextmatch_action.js +++ b/etemplate/js/nextmatch_action.js @@ -145,6 +145,14 @@ function nm_action(_action, _senders) egw_openWindowCentered2(url,target,_action.data.width,_action.data.height); break; + case 'egw_open': + var params = _action.data.egw_open.split('-'); // type-appname-idNum (idNum is part of id split by :), eg. "edit-infolog" + console.log(params); + var egw_open_id = _senders[0].id; + if (typeof params[2] != 'undefined') egw_open_id = egw_open_id.split(':')[params[2]]; + egw_open(egw_open_id,params[1],params[0],params[3]); + break; + case 'open_popup': // open div styled as popup contained in current form and named action.id+'_popup' if (typeof nm_popup_action == 'undefined') @@ -208,6 +216,22 @@ function nm_enableClass(_action, _senders, _target) return $(_target.iface.getDOMNode()).hasClass(_action.data.enableClass); } +/** + * Enable an _action, if it matches a given regular expresstion in _action.data.enableId + * + * @param _action egwAction object, we use _action.data.enableId to check + * @param _senders array of egwActionObject objects + * @param _target egwActionObject object, get's called for every object in _senders + * @returns boolean true if _target.id matches _action.data.enableId + */ +function nm_enableId(_action, _senders, _target) +{ + if (typeof _action.data.enableId == 'string') + _action.data.enableId = new RegExp(_action.data.enableId); + + return _target.id.match(_action.data.enableId); +} + /** * Callback to check if a certain field (_action.data.fieldId) is (not) equal to given value (_action.data.fieldValue) *