Move initialisation for egw_actions stuff into static method of nextmatch_widget, it get called now from:

- etemplate::show_grid() 
- addressbook_ui::view() to load JS stuff before header get generated
This commit is contained in:
Ralf Becker 2011-05-02 13:34:59 +00:00
parent dfd160f11b
commit 1e8de99ed7
3 changed files with 64 additions and 46 deletions

View File

@ -1999,6 +1999,9 @@ class addressbook_ui extends addressbook_bo
$GLOBALS['egw_info']['flags']['currentid'] = $content['id'];
// Load JS for infolog actions
egw_framework::validate_file('.','index','infolog');
// Load egw_action stuff for infolog, required before etemplate::exec() because it loads stuff into HTML header
nextmatch_widget::init_egw_actions();
$this->tmpl->exec('addressbook.addressbook_ui.view',$content,$sel_options,$readonlys,array('id' => $content['id']));
$GLOBALS['egw']->hooks->process(array(

View File

@ -953,52 +953,10 @@ class etemplate extends boetemplate
$html = html::div($html,$div_style);
}
// initialise egw_actions for nextmatch widget, if egwGridView_grid CSS class set
if ($options[3] == 'egwGridView_grid')
{
// Load some JS files needed for the egw_action framework
egw_framework::includeCSS('/phpgwapi/js/egw_action/test/skins/dhtmlxmenu_egw.css');
egw_framework::validate_file('dhtmlxtree','dhtmlxMenu/codebase/dhtmlxcommon');
egw_framework::validate_file('dhtmlxtree','dhtmlxMenu/codebase/dhtmlxmenu');
egw_framework::validate_file('dhtmlxtree','dhtmlxMenu/codebase/ext/dhtmlxmenu_ext');
egw_framework::validate_file('egw_action','egw_action');
egw_framework::validate_file('egw_action','egw_action_common');
egw_framework::validate_file('egw_action','egw_action_popup');
egw_framework::validate_file('egw_action','egw_menu');
egw_framework::validate_file('egw_action','egw_menu_dhtmlx');
egw_framework::validate_file('.', 'nextmatch_action', 'etemplate');
// JS action objects generated for this widget are prefixed with the
// prefix given here
$prefix = "egw_";
$action_links = array();
$html .= '
<script type="text/javascript">
$(document).ready(function() {
// Initialize the action manager and add some actions to it
'.$prefix.'actionManager = new egwActionManager();
'.$prefix.'objectManager = new egwActionObjectManager("", '.$prefix.'actionManager);
'.$prefix.'actionManager.updateActions('.str_replace('},',"},\n",
json_encode(nextmatch_widget::egw_actions($content['_actions'], $this->name, '', $action_links))).');
'.$prefix.'actionManager.setDefaultExecute("javaScript:nm_action");
var actionLinks = ['.($content['_actions'] ? '"'.implode('","', isset($content['_action_links']) ?
$content['_action_links'] : $action_links).'"' : '').'];
// Create a new action object for each table row
// TODO: only apply function to outer level
$("table.egwGridView_grid>tbody>tr").each(function(index, elem)
{
// Create a new action object
var obj = '.$prefix.'objectManager.addObject(elem.id, new nextmatchRowAOI(elem));
obj.updateActionLinks(actionLinks);
});
});
</script>';
$html .= nextmatch_widget::init_egw_actions($content['_actions'], $content['action_links'], $this->name);
}
return "\n\n<!-- BEGIN grid $grid[name] -->\n$html<!-- END grid $grid[name] -->\n\n";

View File

@ -60,9 +60,10 @@
* 'actions' => // I array with actions, see nextmatch_widget::egw_actions
* 'action_links' => // I array with enabled actions or ones which should be checked if they are enabled
* optional, default id of all first level actions plus the ones with enabled='javaScript:...'
* 'action' => // O string selected action
* 'selected' => // O array with selected id's
* 'checkboxes' => // 0 array with checkbox id as key and boolean checked value
* 'select_all' => // 0 boolean value of select_all checkbox, reference to above value for key 'select_all'
* 'checkboxes' => // O array with checkbox id as key and boolean checked value
* 'select_all' => // O boolean value of select_all checkbox, reference to above value for key 'select_all'
* );
*/
class nextmatch_widget
@ -804,6 +805,62 @@ class nextmatch_widget
return $cat_actions;
}
/**
* Return HTML to initialise actions, if called without arguments only CSS and JS get loaded
*
* Gets called from etemplate::show_grid() and addressbook_ui::view (without arguments).
*
* @param array $actions=null
* @param array $action_links=null
* @param string $template_name='' name of the template, used as default for app name of images
* @param string $prefix='egw_' JS action objects generated for this widget are prefixed with given prefix
*/
public static function init_egw_actions(array $actions=null, $action_links=null, $template_name='', $prefix='egw_')
{
// Load some JS files needed for the egw_action framework
egw_framework::includeCSS('/phpgwapi/js/egw_action/test/skins/dhtmlxmenu_egw.css');
egw_framework::validate_file('dhtmlxtree','dhtmlxMenu/codebase/dhtmlxcommon');
egw_framework::validate_file('dhtmlxtree','dhtmlxMenu/codebase/dhtmlxmenu');
egw_framework::validate_file('dhtmlxtree','dhtmlxMenu/codebase/ext/dhtmlxmenu_ext');
egw_framework::validate_file('egw_action','egw_action');
egw_framework::validate_file('egw_action','egw_action_common');
egw_framework::validate_file('egw_action','egw_action_popup');
egw_framework::validate_file('egw_action','egw_menu');
egw_framework::validate_file('egw_action','egw_menu_dhtmlx');
egw_framework::validate_file('.', 'nextmatch_action', 'etemplate');
if ($actions)
{
if (!is_array($action_links)) $action_links = array();
return '
<script type="text/javascript">
$(document).ready(function() {
// Initialize the action manager and add some actions to it
'.$prefix.'actionManager = new egwActionManager();
'.$prefix.'objectManager = new egwActionObjectManager("", '.$prefix.'actionManager);
'.$prefix.'actionManager.updateActions('.str_replace('},',"},\n",
json_encode(self::egw_actions($actions, $template_name, '', $action_links))).');
'.$prefix.'actionManager.setDefaultExecute("javaScript:nm_action");
var actionLinks = ["'.implode('","', $action_links).'"];
// Create a new action object for each table row
// TODO: only apply function to outer level
$("table.egwGridView_grid>tbody>tr").each(function(index, elem)
{
// Create a new action object
var obj = '.$prefix.'objectManager.addObject(elem.id, new nextmatchRowAOI(elem));
obj.updateActionLinks(actionLinks);
});
});
</script>';
}
}
/**
* Calling our callback
*