Skip to content

Commit 401337b

Browse files
author
Jelte Lagendijk
committed
Fix MX6 deprecations, add development files & bump version for App Store
1 parent 9a49515 commit 401337b

File tree

8 files changed

+213
-20
lines changed

8 files changed

+213
-20
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ test/javasource/
22
test/deployment/
33
test/.classpath
44
test/.project
5-
*.mws
65
*.launch
76
*.tmp
87
*.lock
8+
.idea/
9+
10+
*DS_Store*
11+
node_modules/
12+
dist/

Gruntfile.js

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
'use strict';
2+
3+
var path = require('path'),
4+
mendixApp = require('node-mendix-modeler-path'),
5+
base64 = require('node-base64-image'),
6+
fs = require('fs'),
7+
xml2js = require('xml2js'),
8+
parser = new xml2js.Parser(),
9+
builder = new xml2js.Builder(),
10+
shelljs = require('shelljs');
11+
12+
// In case you seem to have trouble starting Mendix through `grunt start-mendix`, you might have to set the path to the Mendix application.
13+
// If it works, leave MODELER_PATH at null
14+
var MODELER_PATH = null;
15+
var MODELER_ARGS = '/file:{path}';
16+
17+
var TEST_PATH = path.join(shelljs.pwd(), './test/FormatString.mpr');
18+
19+
module.exports = function (grunt) {
20+
var pkg = grunt.file.readJSON("package.json");
21+
grunt.verbose;
22+
grunt.initConfig({
23+
watch: {
24+
autoDeployUpdate: {
25+
"files": [ "./src/**/*" ],
26+
"tasks": [ "newer:copy", "compress" ],
27+
options: {
28+
debounceDelay: 250,
29+
livereload: true
30+
}
31+
}
32+
},
33+
compress: {
34+
makezip: {
35+
options: {
36+
archive: "./dist/" + pkg.name + ".mpk",
37+
mode: "zip"
38+
},
39+
files: [{
40+
expand: true,
41+
date: new Date(),
42+
store: false,
43+
cwd: "./src",
44+
src: ["**/*"]
45+
}]
46+
}
47+
},
48+
copy: {
49+
deployment: {
50+
files: [
51+
{ dest: "./test/deployment/web/widgets", cwd: "./src/", src: ["**/*"], expand: true }
52+
]
53+
},
54+
mpks: {
55+
files: [
56+
{ dest: "./test/widgets", cwd: "./dist/", src: [ pkg.name + ".mpk"], expand: true }
57+
]
58+
}
59+
},
60+
clean: {
61+
build: [
62+
"./dist/" + pkg.name + "/*",
63+
"./test/deployment/web/widgets/" + pkg.name + "/*",
64+
"./test/widgets/" + pkg.name + ".mpk"
65+
]
66+
}
67+
});
68+
69+
grunt.loadNpmTasks("grunt-contrib-compress");
70+
grunt.loadNpmTasks("grunt-contrib-clean");
71+
grunt.loadNpmTasks("grunt-contrib-watch");
72+
grunt.loadNpmTasks("grunt-contrib-copy");
73+
grunt.loadNpmTasks("grunt-newer");
74+
75+
grunt.registerTask("start-mendix", function () {
76+
var done = this.async(),
77+
testProjectPath = TEST_PATH !== null ? TEST_PATH : path.join(shelljs.pwd(), '/test/Test.mpr');
78+
79+
if (MODELER_PATH !== null || (mendixApp.err === null && mendixApp.output !== null && mendixApp.output.cmd && mendixApp.output.arg)) {
80+
grunt.util.spawn({
81+
cmd: MODELER_PATH || mendixApp.output.cmd,
82+
args: [
83+
(MODELER_PATH !== null ? MODELER_ARGS : mendixApp.output.arg).replace('{path}', testProjectPath)
84+
]
85+
}, function () {
86+
done();
87+
});
88+
} else {
89+
console.error('Cannot start Modeler, see error:');
90+
console.log(mendixApp.err);
91+
done();
92+
}
93+
});
94+
95+
grunt.registerTask("generate-icon", function () {
96+
var iconPath = path.join(shelljs.pwd(), '/ico.png'),
97+
widgetXml = path.join(shelljs.pwd(), '/src/', pkg.name, '/', pkg.name+'.xml'),
98+
options = {localFile: true, string: true},
99+
done = this.async();
100+
101+
grunt.log.writeln('Processing icon');
102+
103+
if (!grunt.file.exists(iconPath) || !grunt.file.exists(widgetXml)) {
104+
grunt.log.error("can't generate icon");
105+
return done();
106+
}
107+
108+
base64.base64encoder(iconPath, options, function (err, image) {
109+
if (!err) {
110+
var xmlOld = grunt.file.read(widgetXml);
111+
parser.parseString(xmlOld, function (err, result) {
112+
if (!err) {
113+
if (result && result.widget && result.widget.icon) {
114+
result.widget.icon[0] = image;
115+
}
116+
var xmlString = builder.buildObject(result);
117+
grunt.file.write(widgetXml, xmlString);
118+
done();
119+
}
120+
});
121+
}
122+
});
123+
});
124+
125+
grunt.registerTask(
126+
"default",
127+
"Watches for changes and automatically creates an MPK file, as well as copying the changes to your deployment folder",
128+
[ "watch" ]
129+
);
130+
131+
grunt.registerTask(
132+
"clean build",
133+
"Compiles all the assets and copies the files to the build directory.",
134+
[ "clean", "compress", "copy" ]
135+
);
136+
137+
grunt.registerTask(
138+
"build",
139+
[ "clean build" ]
140+
);
141+
};

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "FormatString",
3+
"version": "5.2.0",
4+
"description": "This widget adds a user-defined string to your page, taking object attributes as input parameters.",
5+
"private": true,
6+
"dependencies": {},
7+
"devDependencies": {
8+
"grunt": "0.4.5",
9+
"grunt-contrib-clean": "^0.6.0",
10+
"grunt-contrib-compress": "^0.14.0",
11+
"grunt-contrib-copy": "^0.8.2",
12+
"grunt-contrib-watch": "^0.6.1",
13+
"grunt-newer": "^1.1.1",
14+
"node-base64-image": "^0.1.0",
15+
"node-mendix-modeler-path": "https://github.com/JelteMX/node-mendix-modeler-path/archive/v1.0.0.tar.gz",
16+
"shelljs": "^0.5.3",
17+
"xml2js": "^0.4.15"
18+
},
19+
"repository": {
20+
"type": "git",
21+
"url": "http://github.com/mendix/FormatString"
22+
},
23+
"engines": {
24+
"node": ">=0.12.0"
25+
},
26+
"scripts": {
27+
"test": "grunt test"
28+
}
29+
}

src/formatstring/widget/formatstring.js

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,26 @@
22
/*global mx, define, require, browser, devel, console */
33
/*mendix */
44

5-
define('formatstring/widget/formatstring', ['dojo/_base/declare', 'mxui/widget/_WidgetBase', 'dijit/_TemplatedMixin',
6-
'mxui/dom', 'dojo/dom', 'dojo/dom-class', 'dojo/_base/lang', 'dojo/text', 'dojo/json',
7-
'dojo/_base/kernel', 'dojo/_base/xhr', 'dojo/text!formatstring/lib/timeLanguagePack.json', 'dojo/text!formatstring/widget/template/formatstring.html'
5+
define([
6+
'dojo/_base/declare',
7+
'mxui/widget/_WidgetBase',
8+
'dijit/_TemplatedMixin',
9+
'mxui/dom',
10+
'dojo/dom',
11+
'dojo/dom-class',
12+
'dojo/_base/lang',
13+
'dojo/text',
14+
'dojo/json',
15+
'dojo/_base/kernel',
16+
'dojo/_base/xhr',
17+
'dojo/text!formatstring/lib/timeLanguagePack.json',
18+
'dojo/text!formatstring/widget/template/formatstring.html'
819
], function (declare, _WidgetBase, _TemplatedMixin, dom, dojoDom, domClass, lang, text, json, dojo, xhr, languagePack, widgetTemplate) {
920
'use strict';
1021

1122
return declare('formatstring.widget.formatstring', [_WidgetBase, _TemplatedMixin], {
1223
templateString: widgetTemplate,
13-
24+
1425
_wgtNode: null,
1526
_contextGuid: null,
1627
_contextObj: null,
@@ -19,11 +30,11 @@ define('formatstring/widget/formatstring', ['dojo/_base/declare', 'mxui/widget/_
1930
attributeList: null,
2031

2132
postCreate: function () {
22-
this._timeData = json.parse(languagePack);
23-
24-
this._setupEvents();
2533

34+
this._timeData = json.parse(languagePack);
35+
this._setupEvents();
2636
this.attributeList = this.notused;
37+
2738
},
2839

2940
update: function (obj, callback) {
@@ -47,10 +58,11 @@ define('formatstring/widget/formatstring', ['dojo/_base/declare', 'mxui/widget/_
4758
numberlist = [],
4859
i = null,
4960
value = null;
50-
51-
if (!this._contextObj)
52-
return;
53-
61+
62+
if (!this._contextObj) {
63+
return;
64+
}
65+
5466
for (i = 0; i < this.attributeList.length; i++) {
5567
if (this._contextObj.get(this.attributeList[i].attrs) !== null) {
5668
value = this._fetchAttr(this._contextObj, this.attributeList[i].attrs, this.attributeList[i].renderHTML, i,
@@ -104,6 +116,9 @@ define('formatstring/widget/formatstring', ['dojo/_base/declare', 'mxui/widget/_
104116
listObj: listObj,
105117
split: split,
106118
renderAsHTML: renderAsHTML,
119+
emptyReplacement: emptyReplacement,
120+
decimalPrecision: decimalPrecision,
121+
groupDigits: groupDigits,
107122
oldnumber: oldnumber
108123
};
109124

@@ -129,10 +144,11 @@ define('formatstring/widget/formatstring', ['dojo/_base/declare', 'mxui/widget/_
129144
var returnvalue = "",
130145
options = {},
131146
numberOptions = null;
132-
133-
// Referenced object might be empty, can't fetch an attr on empty
134-
if (!obj)
135-
return emptyReplacement;
147+
148+
// Referenced object might be empty, can't fetch an attr on empty
149+
if (!obj) {
150+
return emptyReplacement;
151+
}
136152

137153
if (obj.isDate(attr)) {
138154
if (this.attributeList[i].datePattern !== '') {
@@ -145,7 +161,7 @@ define('formatstring/widget/formatstring', ['dojo/_base/declare', 'mxui/widget/_
145161
} else if (obj.isEnum(attr)) {
146162
returnvalue = this._checkString(obj.getEnumCaption(attr, obj.get(attr)), renderAsHTML);
147163

148-
} else if (obj.isNumeric(attr) || obj.isCurrency(attr) || obj.getAttributeType(attr) == 'AutoNumber') {
164+
} else if (obj.isNumeric(attr) || obj.isCurrency(attr) || obj.getAttributeType(attr) === 'AutoNumber') {
149165
numberOptions = {};
150166
numberOptions.places = decimalPrecision;
151167
if (groupDigits) {
@@ -195,7 +211,7 @@ define('formatstring/widget/formatstring', ['dojo/_base/declare', 'mxui/widget/_
195211

196212
_checkString: function (string, renderAsHTML) {
197213
if (string.indexOf("<script") > -1 || !renderAsHTML) {
198-
string = dom.escapeHTML(string);
214+
string = dom.escapeString(string);
199215
}
200216
return string;
201217
},
@@ -265,13 +281,16 @@ define('formatstring/widget/formatstring', ['dojo/_base/declare', 'mxui/widget/_
265281

266282
if (this.onclickmf) {
267283
mx.data.action({
284+
store: {
285+
caller: this.mxform
286+
},
268287
params: {
269288
actionname: this.onclickmf,
270289
applyto: 'selection',
271290
guids: [this._contextObj.getGuid()]
272291
},
273292
callback: function () {
274-
// ok
293+
// ok
275294
},
276295
error: function () {
277296
// error

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

test/FormatString.mpr

-2 KB
Binary file not shown.

test/FormatString.mpr.bak

614 KB
Binary file not shown.

test/widgets/FormatString.mpk

550 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)