From 60edb83929c599b88ee5eb24c782b2ead1b52334 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 27 Apr 2011 16:54:35 +0000 Subject: [PATCH] enable via a class and no more need to set enabled='javascript:nm...' for enableClass or disableClass --- etemplate/inc/class.nextmatch_widget.inc.php | 19 ++++++++++++++++--- etemplate/js/nextmatch_action.js | 13 +++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/etemplate/inc/class.nextmatch_widget.inc.php b/etemplate/inc/class.nextmatch_widget.inc.php index 34969e94b8..1f3ef9c082 100644 --- a/etemplate/inc/class.nextmatch_widget.inc.php +++ b/etemplate/inc/class.nextmatch_widget.inc.php @@ -486,8 +486,10 @@ class nextmatch_widget $name = is_object($extension_data['template']) ? $extension_data['template']->name : $extension_data['template']; list($app) = explode('.',$name); $definition = $GLOBALS['egw_info']['user']['preferences'][$app]['nextmatch-export-definition']; - if(!$value['no_csv_export'] && ($definition || !is_array($value['csv_fields']))) { - if($GLOBALS['egw_info']['user']['apps']['importexport'] && ($definition || $value['csv_fields'])) { + if(!$value['no_csv_export'] && ($definition || !is_array($value['csv_fields']))) + { + if($GLOBALS['egw_info']['user']['apps']['importexport'] && ($definition || $value['csv_fields']) && is_object($nextmatch)) + { $nextmatch->set_cell_attribute('export', 'onclick', "egw_openWindowCentered2('". egw::link('/index.php', array( 'menuaction' => 'importexport.importexport_export_ui.export_dialog', @@ -512,7 +514,6 @@ class nextmatch_widget $value['rows']['_actions'] =& $value['actions']; $value['rows']['_action_links'] =& $value['action_links']; $value['rows']['_row_id'] =& $value['row_id']; - $value['action'] = $value['selected'] = $value['select_all'] = null; // nothing yet return False; // NO extra Label } @@ -591,6 +592,18 @@ class nextmatch_widget if (!is_array($action)) $action = array('caption' => $action); $action['id'] = $prefix.$id; + // set some default onExecute + foreach(array( + 'enableClass' => 'javaScript:nm_enableClass', + 'disableClass' => 'javaScript:nm_not_disableClass', + ) as $attr => $check) + { + if (isset($action[$attr]) && !isset($action['enabled'])) + { + $action['enabled'] = $check; + } + } + // add all first level actions plus ones with enabled = 'javaScript:...' to action_links if ($first_level || substr($action['enabled'],0,11) == 'javaScript:') { diff --git a/etemplate/js/nextmatch_action.js b/etemplate/js/nextmatch_action.js index 2697300215..af951ba436 100644 --- a/etemplate/js/nextmatch_action.js +++ b/etemplate/js/nextmatch_action.js @@ -183,6 +183,19 @@ function nm_not_disableClass(_action, _senders, _target) return !$(_target.iface.getDOMNode()).hasClass(_action.data.disableClass); } +/** + * Callback to check if all of _senders rows have enableClass set + * + * @param _action egwAction object, we use _action.data.enableClass to check + * @param _senders array of egwActionObject objects + * @param _target egwActionObject object, get's called for every object in _senders + * @returns boolean true if none has disableClass, false otherwise + */ +function nm_enableClass(_action, _senders, _target) +{ + return $(_target.iface.getDOMNode()).hasClass(_action.data.enableClass); +} + /** * Callback to check if a certain field (_action.data.fieldId) is (not) equal to given value (_action.data.fieldValue) *