Skip to content

Added the possibility to set a refresh time #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/CustomString/CustomString.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<category>Behavior</category>
<description>The microflow to execute on click.</description>
<returnType type="Boolean" />
</property>
<property key="refreshTime" type="integer" required="true" defaultValue="0">
<caption>Refresh Time</caption>
<category>Behavior</category>
<description>The microflow will be re-executed and after (x) milliseconds.</description>
</property>
</properties>
</widget>
Expand Down
6 changes: 6 additions & 0 deletions src/CustomString/CustomStringNoContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
<description>The microflow to execute on click.</description>
<returnType type="Boolean" />
</property>
<property key="refreshTime" type="integer" required="true" defaultValue="0">
<caption>Refresh Time</caption>
<category>Behavior</category>
<description>The microflow will be re-executed and after (x) milliseconds.</description>
</property>

</properties>
</widget>

41 changes: 33 additions & 8 deletions src/CustomString/widget/CustomString.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
}
},

Expand Down Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down
Binary file modified test/CustomStringTest.mpr
Binary file not shown.
Binary file modified test/widgets/CustomString.mpk
Binary file not shown.