From 643b1201954d7ad31bc61bb2e1607a95caae0d9b Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 25 Feb 2013 20:35:17 +0000 Subject: [PATCH] - Make nextmatch refresh more intelligently - Call nextmatch refresh() from etemplate2.refresh() - Add autorefresh preference (in column selection) --- etemplate/js/et2_extension_nextmatch.js | 81 ++++++++++++++++++++++++- etemplate/js/etemplate2.js | 35 ++--------- 2 files changed, 85 insertions(+), 31 deletions(-) diff --git a/etemplate/js/et2_extension_nextmatch.js b/etemplate/js/et2_extension_nextmatch.js index af79e0ba6a..4b21f122c4 100644 --- a/etemplate/js/et2_extension_nextmatch.js +++ b/etemplate/js/et2_extension_nextmatch.js @@ -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()); } }, diff --git a/etemplate/js/etemplate2.js b/etemplate/js/etemplate2.js index 2f7955a159..fb9674b38b 100644 --- a/etemplate/js/etemplate2.js +++ b/etemplate/js/etemplate2.js @@ -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 //