diff --git a/src/CustomString/CustomString.xml b/src/CustomString/CustomString.xml index f73de26..fab64d6 100644 --- a/src/CustomString/CustomString.xml +++ b/src/CustomString/CustomString.xml @@ -22,6 +22,11 @@ Behavior The microflow to execute on click. + + + Refresh Time + Behavior + The microflow will be re-executed and after (x) milliseconds. diff --git a/src/CustomString/CustomStringNoContext.xml b/src/CustomString/CustomStringNoContext.xml index 1b7b8d9..351d470 100644 --- a/src/CustomString/CustomStringNoContext.xml +++ b/src/CustomString/CustomStringNoContext.xml @@ -23,6 +23,12 @@ The microflow to execute on click. + + Refresh Time + Behavior + The microflow will be re-executed and after (x) milliseconds. + + diff --git a/src/CustomString/widget/CustomString.js b/src/CustomString/widget/CustomString.js index e03d13b..3700076 100644 --- a/src/CustomString/widget/CustomString.js +++ b/src/CustomString/widget/CustomString.js @@ -35,11 +35,13 @@ define([ // Parameters configured in the Modeler. sourceMF: "", renderHTML: "", + refreshTime: 0, // Internal variables. Non-primitives created in the prototype are shared between all widget instances. _handles: null, _contextObj: null, _alertDiv: null, + _widgetIsDestroyed: false, // dojo.declare.constructor is called to construct the widget instance. Implement to initialize non-primitive properties. constructor: function() { @@ -56,15 +58,19 @@ define([ // mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data. update: function(obj, callback) { logger.debug(this.id + ".update"); - this._contextObj = obj; + // Do not update the widget if it does not exist anymore. + if (!this._widgetIsDestroyed){ + this._contextObj = obj; + + if (this._contextObj) { + this._resetSubscriptions(); + this._updateRendering(callback); + } else if (this._render){ + this._render(callback); + } else { + mendix.lang.nullExec(callback); + } - if (this._contextObj) { - this._resetSubscriptions(); - this._updateRendering(callback); - } else if (this._render){ - this._render(callback); - } else { - mendix.lang.nullExec(callback); } }, @@ -123,6 +129,10 @@ define([ logger.debug(this.id + "._processSourceMFCallback"); html.set(this.customString, this.checkString(returnedString, this.renderHTML)); mendix.lang.nullExec(callback); + + if (this.refreshTime !== null && this.refreshTime > 0){ + setTimeout(dojoLang.hitch(this, this.update, this._contextObj, callback), this.refreshTime); + } }, checkString : function (string, htmlBool) { @@ -133,6 +143,21 @@ define([ } return string; }, + + uninitialize : function () { + logger.debug(this.id + ".uninitialize"); + + + this._widgetIsDestroyed = true; + + if (this._handles) { + dojoArray.forEach(this._handles, function (handle) { + mx.data.unsubscribe(handle); + }); + this._handles = []; + } + }, + // Reset subscriptions. _resetSubscriptions: function() { diff --git a/test/CustomStringTest.mpr b/test/CustomStringTest.mpr index d7c1f96..a053a7c 100644 Binary files a/test/CustomStringTest.mpr and b/test/CustomStringTest.mpr differ diff --git a/test/widgets/CustomString.mpk b/test/widgets/CustomString.mpk index dca7624..ab033aa 100644 Binary files a/test/widgets/CustomString.mpk and b/test/widgets/CustomString.mpk differ