forked from extern/egroupware
- 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
This commit is contained in:
parent
596f252eb7
commit
3bbc6a6962
@ -598,11 +598,11 @@ class nextmatch_widget
|
|||||||
* @param string $prefix='' prefix for ids
|
* @param string $prefix='' prefix for ids
|
||||||
* @param array &$action_links=array() on return all first-level actions plus the ones with enabled='javaScript:...'
|
* @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 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
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function egw_actions(array $actions=null, $template_name='', $prefix='', array &$action_links=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 "<p>".__METHOD__."(\$actions, '$template_name', '$prefix', \$action_links, $max_length) \$actions="; _debug_array($actions);
|
//echo "<p>".__METHOD__."(\$actions, '$template_name', '$prefix', \$action_links, $max_length) \$actions="; _debug_array($actions);
|
||||||
// default icons for some common actions
|
// default icons for some common actions
|
||||||
@ -611,11 +611,13 @@ class nextmatch_widget
|
|||||||
'edit' => 'edit',
|
'edit' => 'edit',
|
||||||
'open' => 'edit', // does edit if possible, otherwise view
|
'open' => 'edit', // does edit if possible, otherwise view
|
||||||
'add' => 'new',
|
'add' => 'new',
|
||||||
|
'new' => 'new',
|
||||||
'delete' => 'delete',
|
'delete' => 'delete',
|
||||||
'cat' => 'attach', // add as category icon to api
|
'cat' => 'attach', // add as category icon to api
|
||||||
'document' => 'etemplate/merge',
|
'document' => 'etemplate/merge',
|
||||||
'print'=> 'print',
|
'print'=> 'print',
|
||||||
'copy' => 'copy',
|
'copy' => 'copy',
|
||||||
|
'move' => 'move',
|
||||||
);
|
);
|
||||||
|
|
||||||
$first_level = !$action_links; // add all first level actions
|
$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
|
// in case it's only selectbox id => label pairs
|
||||||
if (!is_array($action)) $action = array('caption' => $action);
|
if (!is_array($action)) $action = array('caption' => $action);
|
||||||
|
if ($default_attrs) $action += $default_attrs;
|
||||||
|
|
||||||
if (!$first_level && $n == $max_length && count($actions) > $max_length)
|
if (!$first_level && $n == $max_length && count($actions) > $max_length)
|
||||||
{
|
{
|
||||||
@ -643,10 +646,11 @@ class nextmatch_widget
|
|||||||
}
|
}
|
||||||
$action['id'] = $prefix.$id;
|
$action['id'] = $prefix.$id;
|
||||||
|
|
||||||
// set some default onExecute
|
// set certain enable functions
|
||||||
foreach(array(
|
foreach(array(
|
||||||
'enableClass' => 'javaScript:nm_enableClass',
|
'enableClass' => 'javaScript:nm_enableClass',
|
||||||
'disableClass' => 'javaScript:nm_not_disableClass',
|
'disableClass' => 'javaScript:nm_not_disableClass',
|
||||||
|
'enableId' => 'javaScript:nm_enableId',
|
||||||
) as $attr => $check)
|
) as $attr => $check)
|
||||||
{
|
{
|
||||||
if (isset($action[$attr]) && !isset($action['enabled']))
|
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
|
// link or popup action
|
||||||
if ($action['url'])
|
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'])
|
if ($action['popup'])
|
||||||
{
|
{
|
||||||
list($action['data']['width'],$action['data']['height']) = explode('x',$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';
|
$action['data']['nm_action'] = 'location';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($action['egw_open'])
|
||||||
// add sub-menues
|
|
||||||
if ($action['children'])
|
|
||||||
{
|
{
|
||||||
$action['children'] = self::egw_actions($action['children'], $template_name, $action['prefix'], $action_links, $max_length, $action['onExecute']);
|
$action['data']['nm_action'] = 'egw_open';
|
||||||
unset($action['prefix']);
|
|
||||||
unset($action['onExecute']);
|
|
||||||
}
|
}
|
||||||
if ($onExecute && !isset($action['onExecute'])) $action['onExecute'] = $onExecute;
|
|
||||||
|
|
||||||
static $egw_action_supported = array( // attributes supported by egw_action
|
static $egw_action_supported = array( // attributes supported by egw_action
|
||||||
'id','caption','iconUrl','type','default','onExecute','group',
|
'id','caption','iconUrl','type','default','onExecute','group',
|
||||||
|
@ -145,6 +145,14 @@ function nm_action(_action, _senders)
|
|||||||
egw_openWindowCentered2(url,target,_action.data.width,_action.data.height);
|
egw_openWindowCentered2(url,target,_action.data.width,_action.data.height);
|
||||||
break;
|
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':
|
case 'open_popup':
|
||||||
// open div styled as popup contained in current form and named action.id+'_popup'
|
// open div styled as popup contained in current form and named action.id+'_popup'
|
||||||
if (typeof nm_popup_action == 'undefined')
|
if (typeof nm_popup_action == 'undefined')
|
||||||
@ -208,6 +216,22 @@ function nm_enableClass(_action, _senders, _target)
|
|||||||
return $(_target.iface.getDOMNode()).hasClass(_action.data.enableClass);
|
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)
|
* Callback to check if a certain field (_action.data.fieldId) is (not) equal to given value (_action.data.fieldValue)
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user