Skip to content

Commit 82e7ab5

Browse files
author
Jelte Lagendijk
committed
Cleanup
1 parent d4eeb57 commit 82e7ab5

File tree

3 files changed

+27
-63
lines changed

3 files changed

+27
-63
lines changed

src/CustomString/widget/CustomString.js

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
Describe your widget here.
1515
*/
1616

17-
// Required module list. Remove unnecessary modules, you can always get them back from the boilerplate.
1817
define([
1918
"dojo/_base/declare",
2019
"mxui/widget/_WidgetBase",
@@ -24,12 +23,11 @@ define([
2423
"dojo/html",
2524
"mxui/dom",
2625
"dojo/text!CustomString/widget/template/CustomString.html"
27-
], function(declare, _WidgetBase, _TemplatedMixin, dojoArray, dojoLang, html, dom, widgetTemplate) {
26+
], function(declare, _WidgetBase, _TemplatedMixin, dojoArray, lang, html, dom, widgetTemplate) {
2827
"use strict";
2928

30-
// Declare widget's prototype.
3129
return declare("CustomString.widget.CustomString", [ _WidgetBase, _TemplatedMixin ], {
32-
// _TemplatedMixin will create our dom node using this HTML template.
30+
3331
templateString: widgetTemplate,
3432

3533
// Parameters configured in the Modeler.
@@ -41,19 +39,16 @@ define([
4139
_contextObj: null,
4240
_alertDiv: null,
4341

44-
// dojo.declare.constructor is called to construct the widget instance. Implement to initialize non-primitive properties.
4542
constructor: function() {
4643
logger.level(logger.DEBUG);
4744
this._handles = [];
4845
},
4946

50-
// dijit._WidgetBase.postCreate is called after constructing the widget. Implement to do extra setup work.
5147
postCreate: function() {
5248
logger.debug(this.id + ".postCreate");
5349
this._setupEvents();
5450
},
5551

56-
// mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
5752
update: function(obj, callback) {
5853
logger.debug(this.id + ".update");
5954
this._contextObj = obj;
@@ -64,29 +59,24 @@ define([
6459
} else if (this._render){
6560
this._render(callback);
6661
} else {
67-
mendix.lang.nullExec(callback);
62+
this._executeCallback(callback, "update");
6863
}
6964
},
7065

71-
// Attach events to HTML dom elements
7266
_setupEvents: function() {
7367
logger.debug(this.id + "._setupEvents");
7468
this.connect(this.customString, "click", function(e) {
7569
// If a microflow has been set execute the microflow on a click.
7670
if (this.mfToExecute !== "") {
77-
mx.data.action({
71+
mx.ui.action(this.mfToExecute, {
7872
params: {
7973
applyto: "selection",
80-
actionname: this.mfToExecute,
8174
guids: [ this._contextObj.getGuid() ]
8275
},
83-
store: {
84-
caller: this.mxform
85-
},
8676
callback: function(obj) {
8777
//TODO what to do when all is ok!
8878
},
89-
error: dojoLang.hitch(this, function(error) {
79+
error: lang.hitch(this, function(error) {
9080
console.log(this.id + ": An error occurred while executing microflow: " + error.description);
9181
})
9282
}, this);
@@ -96,33 +86,27 @@ define([
9686

9787
_updateRendering : function (callback) {
9888
logger.debug(this.id + "._updateRendering");
99-
mx.data.action({
100-
params : {
101-
actionname : this.sourceMF,
89+
mx.ui.action(this.sourceMF, {
90+
params: {
10291
applyto : "selection",
10392
guids : [this._contextObj.getGuid()]
104-
10593
},
106-
store: {
107-
caller: this.mxform
108-
},
109-
callback : dojoLang.hitch(this, this._processSourceMFCallback, callback),
110-
error : dojoLang.hitch(this, function(error) {
94+
callback : lang.hitch(this, this._processSourceMFCallback, callback),
95+
error : lang.hitch(this, function(error) {
11196
alert(error.description);
112-
mendix.lang.nullExec(callback);
97+
this._executeCallback(callback, "_updateRendering error");
11398
}),
114-
onValidation : dojoLang.hitch(this, function(validations) {
99+
onValidation : lang.hitch(this, function(validations) {
115100
alert("There were " + validations.length + " validation errors");
116-
mendix.lang.nullExec(callback);
101+
this._executeCallback(callback, "_updateRendering onValidation");
117102
})
118-
});
103+
}, this);
119104
},
120105

121-
122106
_processSourceMFCallback: function (callback, returnedString) {
123107
logger.debug(this.id + "._processSourceMFCallback");
124108
html.set(this.customString, this.checkString(returnedString, this.renderHTML));
125-
mendix.lang.nullExec(callback);
109+
this._executeCallback(callback, "_processSourceMFCallback");
126110
},
127111

128112
checkString : function (string, htmlBool) {
@@ -134,32 +118,27 @@ define([
134118
return string;
135119
},
136120

137-
// Reset subscriptions.
138121
_resetSubscriptions: function() {
139122
logger.debug(this.id + "._resetSubscriptions");
140-
// Release handles on previous object, if any.
141-
if (this._handles) {
142-
dojoArray.forEach(this._handles, function (handle) {
143-
mx.data.unsubscribe(handle);
144-
});
145-
this._handles = [];
146-
}
123+
this.unsubscribeAll();
147124

148-
// When a mendix object exists create subscribtions.
149125
if (this._contextObj) {
150-
var objectHandle = this.subscribe({
126+
this.subscribe({
151127
guid: this._contextObj.getGuid(),
152-
callback: dojoLang.hitch(this, function(guid) {
128+
callback: lang.hitch(this, function(guid) {
153129
this._updateRendering();
154130
})
155131
});
132+
}
133+
},
156134

157-
this._handles = [objectHandle];
135+
_executeCallback: function (cb, from) {
136+
logger.debug(this.id + "._executeCallback" + (from ? " from " + from : ""));
137+
if (cb && typeof cb === "function") {
138+
cb();
158139
}
159140
}
160141
});
161142
});
162143

163-
require(["CustomString/widget/CustomString"], function() {
164-
"use strict";
165-
});
144+
require(["CustomString/widget/CustomString"]);

src/CustomString/widget/CustomStringNoContext.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ require([
2525

2626
_render : function (callback) {
2727
logger.debug(this.id + "._render");
28-
mx.data.action({
29-
params : {
30-
actionname : this.sourceMF
31-
},
32-
store: {
33-
caller: this.mxform
34-
},
28+
mx.ui.action(this.sourceMF, {
3529
callback : dojoLang.hitch(this, this._processSourceMFCallback, callback),
3630
error : dojoLang.hitch(this, function(error) {
3731
alert(error.description);
@@ -41,22 +35,13 @@ require([
4135
alert("There were " + validations.length + " validation errors");
4236
mendix.lang.nullExec(callback);
4337
})
44-
});
38+
}, this);
4539
},
4640

4741
_executeMicroflow: function () {
4842
logger.debug(this.id + "._executeMicroflow");
4943
if (this.mfToExecute) {
50-
mx.data.action({
51-
store: {
52-
caller: this.mxform
53-
},
54-
params: {
55-
actionname: this.mfToExecute
56-
},
57-
callback: function () {}, // ok
58-
error: function () {} // error
59-
});
44+
mx.ui.action(this.mfToExecute, {}, this);
6045
}
6146
}
6247

test/widgets/CustomString.mpk

-893 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)