Skip to content

Commit b18e57c

Browse files
author
Jelte Lagendijk
committed
Fix #14 update method rewritten
1 parent cb1950c commit b18e57c

4 files changed

Lines changed: 28 additions & 14 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "formatstring",
3-
"version": "5.3.0",
3+
"version": "5.4.0",
44
"description": "This widget adds a user-defined string to your page, taking object attributes as input parameters.",
55
"license": "",
66
"author": "",

src/formatstring/widget/formatstring.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ define([
6767
logger.debug(this.id + ".update");
6868
this._contextObj = obj;
6969
this._resetSubscriptions();
70-
this._loadData();
7170

72-
callback();
71+
this._loadData(callback);
7372
},
7473

7574
_setupEvents: function () {
@@ -79,7 +78,7 @@ define([
7978
}
8079
},
8180

82-
_loadData: function () {
81+
_loadData: function (callback) {
8382
logger.debug(this.id + "._loadData");
8483
this.replaceattributes = [];
8584
var referenceAttributeList = [],
@@ -88,6 +87,8 @@ define([
8887
value = null;
8988

9089
if (!this._contextObj) {
90+
logger.debug(this.id + "._loadData empty context");
91+
mendix.lang.nullExec(callback);
9192
return;
9293
}
9394

@@ -108,16 +109,18 @@ define([
108109

109110
if (referenceAttributeList.length > 0) {
110111
//if we have reference attributes, we need to fetch them
111-
this._fetchReferences(referenceAttributeList, numberlist);
112+
this._fetchReferences(referenceAttributeList, numberlist, callback);
112113
} else {
113-
this._buildString();
114+
this._buildString(callback);
114115
}
115116
},
116117

117118
// The fetch referencse is an async action, we use dojo.hitch to create a function that has values of the scope of the for each loop we are in at that moment.
118-
_fetchReferences: function (list, numberlist) {
119+
_fetchReferences: function (list, numberlist, callback) {
119120
logger.debug(this.id + "._fetchReferences");
120121

122+
var l = list.length;
123+
121124
var callbackfunction = function (data, obj) {
122125
logger.debug(this.id + "._fetchReferences get callback");
123126
var value = this._fetchAttr(obj, data.split[2], data.renderAsHTML, data.oldnumber, data.emptyReplacement, data.decimalPrecision, data.groupDigits);
@@ -126,7 +129,13 @@ define([
126129
variable: data.listObj.variablename,
127130
value: value
128131
});
129-
this._buildString();
132+
133+
l--;
134+
if (l <= 0) {
135+
this._buildString(callback);
136+
} else {
137+
this._buildString();
138+
}
130139
};
131140

132141
for (var i = 0; i < list.length; i++) {
@@ -162,7 +171,7 @@ define([
162171
variable: listObj.variablename,
163172
value: ""
164173
});
165-
this._buildString();
174+
this._buildString(callback);
166175
}
167176
}
168177
},
@@ -212,7 +221,7 @@ define([
212221

213222

214223
// _buildString also does _renderString because of callback from fetchReferences is async.
215-
_buildString: function (message) {
224+
_buildString: function (callback) {
216225
logger.debug(this.id + "._buildString");
217226
var str = this.displaystr,
218227
settings = null,
@@ -222,11 +231,10 @@ define([
222231
settings = this.replaceattributes[attr];
223232
str = str.split("${" + settings.variable + "}").join(settings.value);
224233
}
225-
226-
this._renderString(str);
234+
this._renderString(str, callback);
227235
},
228236

229-
_renderString: function (msg) {
237+
_renderString: function (msg, callback) {
230238
logger.debug(this.id + "._renderString");
231239
var div = null;
232240

@@ -236,6 +244,11 @@ define([
236244
});
237245
div.innerHTML = msg;
238246
this.domNode.appendChild(div);
247+
248+
if (callback && typeof callback === "function") {
249+
logger.debug(this.id + "._renderString callback");
250+
callback();
251+
}
239252
},
240253

241254
_checkString: function (string, renderAsHTML) {
@@ -361,4 +374,5 @@ define([
361374
}
362375
});
363376
});
377+
364378
require(["formatstring/widget/formatstring"]);

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="formatstring" version="5.3.0" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="formatstring" version="5.4.0" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="formatstring/formatstring.xml"/>
66
</widgetFiles>

test/widgets/FormatString.mpk

102 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)