mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-08 00:54:50 +01:00
Implement getState() & setState() towards a more universal favorites, but still more to do:
- Need to get favorite widget to use setState() - Move much code out of etemplate2 widgets into a higher level
This commit is contained in:
parent
9cba54fb63
commit
87936488bf
@ -948,9 +948,9 @@ class etemplate_widget_nextmatch extends etemplate_widget
|
||||
if(!$registry) $registry = egw_link::get_registry($app,'index');
|
||||
foreach($filters as $name => $filter)
|
||||
{
|
||||
$href = egw::link('/index.php', (array)$registry + array('favorite'=>$name),$app);
|
||||
$href = "javascript:app.$app.setState(" . json_encode($filter['filter']) . ');';
|
||||
$html .= "<li id='$name' class='ui-menu-item' role='menuitem'>\n";
|
||||
$html .= "<a href=\"$href\" class='ui-corner-all' tabindex='-1'>";
|
||||
$html .= "<a href='$href' class='ui-corner-all' tabindex='-1'>";
|
||||
$html .= "<div class='" . ($name == $default_filter ? 'ui-icon ui-icon-heart' : 'sideboxstar') . "'></div>".
|
||||
$filter['name'] .($filter['group'] != false ? " ♦" :"");
|
||||
$html .= "</a></li>\n";
|
||||
@ -969,7 +969,7 @@ class etemplate_widget_nextmatch extends etemplate_widget
|
||||
* @param $app Current application, needed to save preference
|
||||
* @param $name String Name of the favorite
|
||||
* @param $action String add or delete
|
||||
* @param $group int|String ID of the group to create the favorite for, or All for all users
|
||||
* @param $group int|String ID of the group to create the favorite for, or 'all' for all users
|
||||
* @param $filters Array of key => value pairs for the filter
|
||||
*
|
||||
* @return boolean Success
|
||||
|
@ -177,6 +177,81 @@ var AppJS = Class.extend(
|
||||
nm.getInstanceManager().submit();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the application's state to the given state.
|
||||
*
|
||||
* While not pretending to implement the history API, it is patterned similarly
|
||||
* @link http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html
|
||||
*
|
||||
* The default implementation works with the favorites to apply filters to a nextmatch.
|
||||
*
|
||||
*
|
||||
* @param {object} state description
|
||||
*/
|
||||
setState: function(state)
|
||||
{
|
||||
// State should be an object, not a string, but we'll try
|
||||
if(typeof state == "string")
|
||||
{
|
||||
if(state.indexOf('{') != -1 || state =='null')
|
||||
{
|
||||
state = JSON.parse(state);
|
||||
}
|
||||
}
|
||||
if(typeof state != "object")
|
||||
{
|
||||
egw.debug('error', 'Unable to set state to %o, needs to be an object',state);
|
||||
return;
|
||||
}
|
||||
if(state == null)
|
||||
{
|
||||
state = {};
|
||||
}
|
||||
|
||||
// Try and find a nextmatch widget, and set its filters
|
||||
var nextmatched = false;
|
||||
var et2 = etemplate2.getByApplication(this.appname);
|
||||
for(var i = 0; i < et2.length; i++)
|
||||
{
|
||||
et2[i].widgetContainer.iterateOver(function(_widget) {
|
||||
// Apply
|
||||
_widget.activeFilters = state;
|
||||
_widget.applyFilters();
|
||||
nextmatched = true;
|
||||
}, this, et2_nextmatch);
|
||||
}
|
||||
|
||||
// No nextmatch? Try a redirect to list
|
||||
if(!nextmatched)
|
||||
{
|
||||
egw.open('',this.appname,'list',{'state': state},this.appname);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve the current state of the application for future restoration
|
||||
*
|
||||
* The state can be anything, as long as it's an object. The contents are
|
||||
* application specific. The default implementation finds a nextmatch and
|
||||
* returns its value.
|
||||
*
|
||||
* @return {object} Value of a nextmatch
|
||||
*/
|
||||
getState: function()
|
||||
{
|
||||
var state = {};
|
||||
|
||||
// Try and find a nextmatch widget, and set its filters
|
||||
var et2 = etemplate2.getByApplication(this.appname);
|
||||
for(var i = 0; i < et2.length; i++)
|
||||
{
|
||||
et2.widgetContainer.iterateOver(function(_widget) {
|
||||
state = _widget.getValue();
|
||||
}, this, et2_nextmatch);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user