- Make nextmatch refresh more intelligently

- Call nextmatch refresh() from etemplate2.refresh()
- Add autorefresh preference (in column selection)
This commit is contained in:
Nathan Gray 2013-02-25 20:35:17 +00:00
parent e38ab3715e
commit 643b120195
2 changed files with 85 additions and 31 deletions

View File

@ -269,8 +269,30 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], {
refresh: function(_row_ids, _type) {
if (typeof _type == 'undefined') _type = 'edit';
if (typeof _row_ids == 'string') _rowids = [_row_ids];
// ToDo: use given context, to be more smart about what to change
this.applyFilters();
// Use jsapi data module to update
var uid = app + "::" + id;
switch(_type)
{
case "update":
if(!egw().dataRefreshUID(uid))
{
// Could not update just that row
this.applyFilters();
}
break;
case "delete":
// Blank the row
egw().dataStoreUID(uid,null);
// Stop caring about this ID
egw().dataUnregisterUID(uid);
break;
case "add":
default:
// Trigger refresh
this.applyFilters();
break;
}
},
/**
@ -744,6 +766,16 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], {
select.set_select_options(columns);
select.set_value(columns_selected);
var autoRefresh = et2_createWidget("select", {"empty_label":"Refresh"}, this);
autoRefresh.set_id("nm_autorefresh");
autoRefresh.set_select_options({
'': "off",
30: "30 seconds",
60: "1 Minute",
300: "5 Minutes"
});
autoRefresh.set_value(this._get_autorefresh());
var defaultCheck = et2_createWidget("checkbox", {}, this);
defaultCheck.set_id('as_default');
defaultCheck.set_label(this.egw().lang("As default"));
@ -799,6 +831,9 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], {
self.dataview.updateColumns();
// Auto refresh
self._set_autorefresh(autoRefresh.get_value());
// Set default?
if(defaultCheck.get_value() == "true")
{
@ -819,6 +854,9 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], {
.append(cancelButton.getDOMNode())
.appendTo(this.innerDiv);
// Add autorefresh
this.selectPopup.append(autoRefresh.getSurroundings().getDOMNode(autoRefresh.getDOMNode()));
// Add default checkbox for admins
var apps = this.egw().user('apps');
if(apps['admin'])
@ -836,6 +874,42 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], {
.css("left", s_position.left + this.div.width() - this.selectPopup.width());
},
/**
* Set the auto-refresh time period, and starts the timer if not started
*
* @param time int Refresh period, in seconds
*/
_set_autorefresh: function(time) {
// Store preference
var refresh_preference = this.options.template + "_autorefresh";
var app = this.options.template.split(".");
this.egw().set_preference(app[0],refresh_preference,time);
// Start / update timer
var self = this;
if (this._autorefresh_timer)
{
window.clearInterval(this._autorefresh_timer);
delete this._autorefresh_timer;
}
if(time > 0)
{
this._autorefresh_timer = setInterval(function() {self.refresh();}, time * 1000);
}
},
/**
* Get the auto-refresh timer
*
* @return int Refresh period, in secods
*/
_get_autorefresh: function() {
var refresh_preference = this.options.template + "_autorefresh";
var app = this.options.template.split(".");
return this.egw().preference(refresh_preference,app[0]);
console.log(this);
},
/**
* When the template attribute is set, the nextmatch widget tries to load
* that template and to fetch the grid which is inside of it. It then calls
@ -881,6 +955,9 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], {
this.sortBy(this.options.settings.order,
this.options.settings.sort == "ASC", false);
}
// Start auto-refresh
this._set_autorefresh(this._get_autorefresh());
}
},

View File

@ -497,35 +497,12 @@ etemplate2.prototype.refresh = function(msg, app, id, type)
$j(msg_widget.getDOMNode()).parents().show();
}
// Use jsapi data module to update
var uid = app + "::" + id;
var update = false;
switch(type)
{
case "update":
if(!egw(app).dataRefreshUID(uid))
{
// Could not update just that row
this.widgetContainer.iterateOver(function(_widget) {
// Trigger refresh
_widget.applyFilters();
}, this, et2_nextmatch);
}
break;
case "delete":
// Blank the row
egw().dataStoreUID(uid,null);
// Stop caring about this ID
egw().dataUnregisterUID(uid);
break;
case "add":
default:
this.widgetContainer.iterateOver(function(_widget) {
// Trigger refresh
_widget.applyFilters();
}, this, et2_nextmatch);
break;
}
// Refresh nextmatches
this.widgetContainer.iterateOver(function(_widget) {
// Trigger refresh
_widget.refresh(id,type);
}, this, et2_nextmatch);
}
// Some static things to make getting into widget context a little easier //