diff --git a/ShowByCondition/src/ShowByCondition/widget/ShowByCondition.js b/ShowByCondition/src/ShowByCondition/widget/ShowByCondition.js index 82b77ee..1cf2312 100644 --- a/ShowByCondition/src/ShowByCondition/widget/ShowByCondition.js +++ b/ShowByCondition/src/ShowByCondition/widget/ShowByCondition.js @@ -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 : @@ -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. @@ -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) { @@ -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() { diff --git a/ShowByCondition/test/Widget/ShowByCondition.mpk b/ShowByCondition/test/Widget/ShowByCondition.mpk index c86ff6e..31ced26 100644 Binary files a/ShowByCondition/test/Widget/ShowByCondition.mpk and b/ShowByCondition/test/Widget/ShowByCondition.mpk differ