Skip to content

Commit

Permalink
Added resetSubscriptions and updateRendering
Browse files Browse the repository at this point in the history
Added two functions: resetSubscriptions and updateRendering. The widget
now refreshes on every refresh of your entity.
  • Loading branch information
remcos committed Jun 13, 2016
1 parent 5114071 commit 4da4b58
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 24 deletions.
73 changes: 49 additions & 24 deletions ShowByCondition/src/ShowByCondition/widget/ShowByCondition.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
Default
========================
@file : Default.js
@version : 1
@file : ShowByCondition.js
@version : 1.2
@author : Remco
@date : Fri, 22 Jan 2016 12:45:23 GMT
@date : Mon, 13 Jun 2016
@copyright :
@license :
Expand All @@ -21,7 +21,8 @@ define([
"dojo/NodeList-traverse",
"mxui/widget/_WidgetBase",
"mxui/dom",
], function(declare, NodeList, _WidgetBase, dom) {
"dojo/_base/lang",
], function(declare, NodeList, _WidgetBase, dom, lang) {
"use strict";

// Declare widget's prototype.
Expand All @@ -41,6 +42,7 @@ define([
// dijit._WidgetBase.postCreate is called after constructing the widget. Implement to do extra setup work.
postCreate: function() {
logger.debug(this.id + ".postCreate");
this.domNode.parentElement.style.display = "none";
},

setParentDisplay : function(display) {
Expand All @@ -53,28 +55,51 @@ 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.domNode.parentElement.style.display = "none";
this.contextGUID = obj.getGuid();

if (this.contextGUID) {
if (this.microflowName != '') {
mx.data.action({
params: {
applyto: "selection",
actionname: this.microflowName,
guids: [this.contextGUID]
},
callback: dojo.hitch(this, function (result) {
this.setParentDisplay(result);
}),
error: function(error) {
alert(error.description);
}
}, this);
}
}
this._contextObj = obj;
this._resetSubscriptions();
this._updateRendering();
callback();
},

// Rerender the interface.
        _updateRendering: function () {
if (this.microflowName != '') {
mx.data.action({
params: {
applyto: "selection",
actionname: this.microflowName,
guids: [this._contextObj.getGuid()]
},
callback: dojo.hitch(this, function (result) {
this.setParentDisplay(result);
}),
error: function(error) {
alert(error.description);
}
}, this);
}
        },
        // Reset subscriptions.
        _resetSubscriptions: function () {
            var _objectHandle = null;
            // Release handles on previous object, if any.
            if (this._handles) {
                this._handles.forEach(function (handle, i) {
                    mx.data.unsubscribe(handle);
                });
                this._handles = [];
            }
            // When a mendix object exists create subscribtions.
            if (this._contextObj) {
                _objectHandle = this.subscribe({
                    guid: this._contextObj.getGuid(),
                    callback: lang.hitch(this, function (guid) {
                        this._updateRendering();
                    })
                });
                this._handles = [_objectHandle];
            }
        },

// mxui.widget._WidgetBase.uninitialize is called when the widget is destroyed. Implement to do special tear-down work.
uninitialize: function() {
Expand Down
Binary file modified ShowByCondition/test/Widget/ShowByCondition.mpk
Binary file not shown.

0 comments on commit 4da4b58

Please sign in to comment.