Skip to content

Commit 03a1bc3

Browse files
author
Jelte Lagendijk
committed
Update codestyle & fix update method (#5)
1 parent f799cbc commit 03a1bc3

File tree

7 files changed

+84
-65
lines changed

7 files changed

+84
-65
lines changed

.jshintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"undef" : true,
1010
"globals" : {
1111
"mendix" : false,
12-
"mx" : false
12+
"mx" : false,
13+
"logger" : false
1314
},
1415

1516
// Relaxing

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "CustomString",
3-
"version": "2.1.1",
3+
"version": "2.2.0",
44
"description": "Create a string with a microflow",
55
"license": "",
66
"author": "",

src/CustomString/widget/CustomString.js

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ define([
2121
"dijit/_TemplatedMixin",
2222
"dojo/_base/array",
2323
"dojo/_base/lang",
24-
"mxui/dom",
24+
"mxui/dom",
2525
"dojo/text!CustomString/widget/template/CustomString.html"
2626
], function(declare, _WidgetBase, _TemplatedMixin, dojoArray, dojoLang, dom, widgetTemplate) {
2727
"use strict";
@@ -42,31 +42,35 @@ define([
4242

4343
// dojo.declare.constructor is called to construct the widget instance. Implement to initialize non-primitive properties.
4444
constructor: function() {
45+
logger.level(logger.DEBUG);
4546
this._handles = [];
4647
},
4748

4849
// dijit._WidgetBase.postCreate is called after constructing the widget. Implement to do extra setup work.
4950
postCreate: function() {
51+
logger.debug(this.id + ".postCreate");
5052
this._setupEvents();
5153
},
5254

5355
// mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
5456
update: function(obj, callback) {
57+
logger.debug(this.id + ".update");
5558
this._contextObj = obj;
56-
57-
if(this._contextObj)
58-
{
59+
60+
if (this._contextObj) {
5961
this._resetSubscriptions();
60-
this._updateRendering();
62+
this._updateRendering(callback);
63+
} else if (this._render){
64+
this._render(callback);
65+
} else {
66+
this._runCallback(callback);
6167
}
62-
callback();
6368
},
64-
69+
6570
// Attach events to HTML dom elements
6671
_setupEvents: function() {
67-
72+
logger.debug(this.id + "._setupEvents");
6873
this.connect(this.customString, "click", function(e) {
69-
7074
// If a microflow has been set execute the microflow on a click.
7175
if (this.mfToExecute !== "") {
7276
mx.data.action({
@@ -75,9 +79,9 @@ define([
7579
actionname: this.mfToExecute,
7680
guids: [ this._contextObj.getGuid() ]
7781
},
78-
store: {
79-
caller: this.mxform
80-
},
82+
store: {
83+
caller: this.mxform
84+
},
8185
callback: function(obj) {
8286
//TODO what to do when all is ok!
8387
},
@@ -88,36 +92,53 @@ define([
8892
}
8993
});
9094
},
91-
_updateRendering : function () {
92-
mx.data.action({
93-
params : {
94-
actionname : this.sourceMF,
95-
applyto : "selection",
96-
guids : [this._contextObj.getGuid()]
97-
98-
},
99-
callback : dojoLang.hitch(this, this._processSourceMFCallback),
100-
error : dojoLang.hitch(this, function(error) {
101-
alert(error.description);
102-
}),
103-
onValidation : dojoLang.hitch(this, function(validations) {
104-
alert("There were " + validations.length + " validation errors");
105-
})
106-
});
107-
},
108-
109-
_processSourceMFCallback: function(returnedString) {
95+
_updateRendering : function (callback) {
96+
logger.debug(this.id + "._updateRendering");
97+
mx.data.action({
98+
params : {
99+
actionname : this.sourceMF,
100+
applyto : "selection",
101+
guids : [this._contextObj.getGuid()]
102+
103+
},
104+
callback : dojoLang.hitch(this, this._processSourceMFCallback, callback),
105+
error : dojoLang.hitch(this, function(error) {
106+
alert(error.description);
107+
this._runCallback(callback);
108+
}),
109+
onValidation : dojoLang.hitch(this, function(validations) {
110+
alert("There were " + validations.length + " validation errors");
111+
this._runCallback(callback);
112+
})
113+
});
114+
},
115+
116+
117+
_processSourceMFCallback: function (callback, returnedString) {
118+
logger.debug(this.id + "._processSourceMFCallback");
110119
this.customString.innerHTML = this.checkString(returnedString, this.renderHTML);
120+
this._runCallback(callback);
121+
},
122+
123+
124+
_runCallback: function (callback) {
125+
logger.debug(this.id + "._runCallback");
126+
if (typeof callback === "function") {
127+
callback();
128+
}
111129
},
112130

113131
checkString : function (string, htmlBool) {
114-
if(string.indexOf("<script") > -1 || !htmlBool)
115-
string = dom.escapeString(string);
116-
return string;
117-
},
132+
logger.debug(this.id + ".checkString");
133+
if (string.indexOf("<script") > -1 || !htmlBool) {
134+
string = dom.escapeString(string);
135+
}
136+
return string;
137+
},
118138

119139
// Reset subscriptions.
120140
_resetSubscriptions: function() {
141+
logger.debug(this.id + "._resetSubscriptions");
121142
// Release handles on previous object, if any.
122143
if (this._handles) {
123144
dojoArray.forEach(this._handles, function (handle) {
@@ -126,7 +147,7 @@ define([
126147
this._handles = [];
127148
}
128149

129-
// When a mendix object exists create subscribtions.
150+
// When a mendix object exists create subscribtions.
130151
if (this._contextObj) {
131152
var objectHandle = this.subscribe({
132153
guid: this._contextObj.getGuid(),
@@ -135,7 +156,7 @@ define([
135156
})
136157
});
137158

138-
this._handles = [ objectHandle];
159+
this._handles = [objectHandle];
139160
}
140161
}
141162
});

src/CustomString/widget/CustomStringNoContext.js

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,48 @@
11

22
// Required module list. Remove unnecessary modules, you can always get them back from the boilerplate.
33
require([
4-
'dojo/_base/declare',
5-
'dojo/_base/lang',
6-
'CustomString/widget/CustomString'
4+
"dojo/_base/declare",
5+
"dojo/_base/lang",
6+
"CustomString/widget/CustomString"
77
], function (declare, dojoLang,_customStringNoContextWidget) {
8-
8+
99
// Declare widget's prototype.
1010
return declare("CustomString.widget.CustomStringNoContext", [ _customStringNoContextWidget ], {
1111

1212
// dijit._WidgetBase.postCreate is called after constructing the widget. Implement to do extra setup work.
1313
postCreate: function() {
14+
logger.debug(this.id + ".postCreate");
1415
this._setupEvents();
15-
this._render();
1616
},
1717

18-
// mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
19-
20-
// Attach events to HTML dom elements
18+
// Attach events to HTML dom elements
2119
_setupEvents: function() {
22-
if(this.mfToExecute){
23-
this.connect(this.customString, "click", this._executeMicroflow)};
20+
logger.debug(this.id + "._setupEvents");
21+
if (this.mfToExecute) {
22+
this.connect(this.customString, "click", this._executeMicroflow);
23+
}
2424
},
25-
26-
27-
_render : function () {
28-
mx.data.action({
25+
26+
_render : function (callback) {
27+
logger.debug(this.id + "._render");
28+
mx.data.action({
2929
params : {
3030
actionname : this.sourceMF
31-
},
32-
callback : dojoLang.hitch(this, this._processSourceMFCallback),
31+
},
32+
callback : dojoLang.hitch(this, this._processSourceMFCallback, callback),
3333
error : dojoLang.hitch(this, function(error) {
3434
alert(error.description);
35+
this._runCallback(callback);
3536
}),
3637
onValidation : dojoLang.hitch(this, function(validations) {
3738
alert("There were " + validations.length + " validation errors");
39+
this._runCallback(callback);
3840
})
3941
});
4042
},
4143

4244
_executeMicroflow: function () {
45+
logger.debug(this.id + "._executeMicroflow");
4346
if (this.mfToExecute) {
4447
mx.data.action({
4548
store: {
@@ -48,17 +51,11 @@ require([
4851
params: {
4952
actionname: this.mfToExecute
5053
},
51-
callback: function () {
52-
// ok
53-
},
54-
error: function () {
55-
// error
56-
}
57-
54+
callback: function () {}, // ok
55+
error: function () {} // error
5856
});
5957
}
60-
},
61-
58+
}
6259

6360
});
6461
});

src/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="CustomString" version="2.1.1" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="CustomString" version="2.2.0" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="CustomString/CustomString.xml"/>
66
<widgetFile path="CustomString/CustomStringNoContext.xml"/>

test/CustomStringTest.mpr.bak

-772 KB
Binary file not shown.

test/widgets/CustomString.mpk

123 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)