Skip to content

Commit 3fafcd4

Browse files
author
Jelte Lagendijk
committed
Cleanup widget code
1 parent 3afebd8 commit 3fafcd4

File tree

5 files changed

+57
-79
lines changed

5 files changed

+57
-79
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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
22
"name": "MicroflowTimer",
3-
"version": "2.2.1",
3+
"version": "2.3.0",
44
"description": "",
55
"license": "",
66
"author": "",
77
"private": true,
8-
"dependencies": {
9-
},
8+
"dependencies": {},
109
"devDependencies": {
1110
"grunt": "0.4.5",
1211
"grunt-contrib-clean": "^0.6.0",
@@ -31,4 +30,4 @@
3130
"scripts": {
3231
"test": "grunt test"
3332
}
34-
}
33+
}
Lines changed: 43 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
/*jslint white:true, nomen: true, plusplus: true */
2-
/*global mx, define, require, browser, devel, console */
3-
/*mendix */
4-
5-
// Required module list. Remove unnecessary modules, you can always get them back from the boilerplate.
61
require([
7-
'dojo/_base/declare', 'mxui/widget/_WidgetBase',
8-
'mxui/dom', 'dojo/dom', 'dojo/query', 'dojo/dom-prop', 'dojo/dom-geometry', 'dojo/dom-class', 'dojo/dom-style', 'dojo/dom-construct', 'dojo/_base/array', 'dojo/_base/lang', 'dojo/text'
9-
], function (declare, _WidgetBase, dom, dojoDom, domQuery, domProp, domGeom, domClass, domStyle, domConstruct, dojoArray, lang, text) {
10-
'use strict';
11-
12-
// Declare widget's prototype.
13-
return declare('MicroflowTimer.widget.MicroflowTimer', [_WidgetBase], {
2+
"dojo/_base/declare",
3+
"mxui/widget/_WidgetBase",
4+
"dojo/_base/lang"
5+
], function (declare, _WidgetBase, lang) {
6+
"use strict";
147

8+
// Declare widget"s prototype.
9+
return declare("MicroflowTimer.widget.MicroflowTimer", [_WidgetBase], {
1510

1611
// Parameters configured in the Modeler.
1712
interval: 30000,
@@ -23,17 +18,11 @@ require([
2318
_handle: null,
2419
_contextObj: null,
2520
_timer: null,
26-
_blocked : null,
21+
_timeout: null,
2722
_timerStarted: false,
2823

29-
// dijit._WidgetBase.postCreate is called after constructing the widget. Implement to do extra setup work.
30-
postCreate: function () {
31-
console.log(this.id + '.postCreate');
32-
},
33-
34-
// mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
3524
update: function (obj, callback) {
36-
console.log(this.id + '.update');
25+
logger.debug(this.id + ".update");
3726

3827
this._contextObj = obj;
3928
if (!this._timerStarted) {
@@ -43,76 +32,65 @@ require([
4332
callback();
4433
},
4534

46-
// mxui.widget._WidgetBase.enable is called when the widget should enable editing. Implement to enable editing if widget is input widget.
47-
enable: function () {
48-
49-
},
50-
51-
// mxui.widget._WidgetBase.enable is called when the widget should disable editing. Implement to disable editing if widget is input widget.
52-
disable: function () {
53-
54-
},
55-
56-
// mxui.widget._WidgetBase.resize is called when the page's layout is recalculated. Implement to do sizing calculations. Prefer using CSS instead.
57-
resize: function (box) {
58-
59-
},
35+
resize: function (box) {},
6036

61-
// mxui.widget._WidgetBase.uninitialize is called when the widget is destroyed. Implement to do special tear-down work.
6237
uninitialize: function () {
63-
// Clean up listeners, helper objects, etc. There is no need to remove listeners added with this.connect / this.subscribe / this.own.
6438
this._stopTimer();
6539
},
6640

6741
_runTimer: function () {
68-
console.log(this.id + '._runTimer', this.interval);
42+
logger.debug(this.id + "._runTimer", this.interval);
6943
if (this.microflow !== "" && this._contextObj) {
7044
this._timerStarted = true;
7145
if (this.once) {
72-
setTimeout(lang.hitch(this, this._execMf), this.interval);
46+
this._timeout = setTimeout(lang.hitch(this, this._execMf), this.interval);
7347
} else {
7448
if (this.startatonce) {
75-
this._execMf([this._contextObj.getGuid()], this.microflow);
49+
this._execMf();
7650
}
7751
this._timer = setInterval(lang.hitch(this, this._execMf), this.interval);
7852
}
7953
}
8054
},
8155

8256
_stopTimer: function () {
83-
console.log(this.id + '._stopTimer');
57+
logger.debug(this.id + "._stopTimer");
8458
if (this._timer !== null) {
59+
logger.debug(this.id + "._stopTimer timer cleared");
8560
clearInterval(this._timer);
8661
this._timer = null;
8762
}
63+
if (this._timeout !== null) {
64+
logger.debug(this.id + "._stopTimer timeout cleared");
65+
clearTimeout(this._timeout);
66+
this._timeout = null;
67+
}
8868
},
8969

9070
_execMf: function () {
91-
console.log(this.id + '._execMf');
92-
93-
var self = this,
94-
guids = [this._contextObj.getGuid()],
95-
mf = this.microflow;
96-
mx.data.action({
97-
params: {
98-
applyto: "selection",
99-
actionname: mf,
100-
guids: guids
101-
},
102-
store: {
103-
caller: this.mxform
104-
},
105-
callback: function (result) {
106-
if (!result) {
107-
console.log('stopping timer');
108-
self._stopTimer();
109-
//this._blocked = false;
110-
}
111-
},
112-
error: function (error) {
113-
console.warn('Error executing mf: ', error);
114-
}
115-
});
71+
logger.debug(this.id + "._execMf");
72+
73+
if (this._contextObj && this.microflow !== "") {
74+
mx.data.action({
75+
params: {
76+
applyto: "selection",
77+
actionname: this.microflow,
78+
guids: [this._contextObj.getGuid()]
79+
},
80+
store: {
81+
caller: this.mxform
82+
},
83+
callback: lang.hitch(this, function (result) {
84+
if (!result) {
85+
logger.debug(this.id + "._execMf callback, stopping timer");
86+
this._stopTimer();
87+
}
88+
}),
89+
error: function (error) {
90+
console.warn("Error executing mf: ", error);
91+
}
92+
});
93+
}
11694
}
11795
});
11896
});

src/package.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="MicroflowTimer" version="2.2.1" xmlns="http://www.mendix.com/clientModule/1.0/">
4-
<widgetFiles>
5-
<widgetFile path="MicroflowTimer/MicroflowTimer.xml"/>
6-
</widgetFiles>
7-
<files>
8-
<file path="MicroflowTimer/widget/"/>
9-
</files>
10-
</clientModule>
3+
<clientModule name="MicroflowTimer" version="2.3.0" xmlns="http://www.mendix.com/clientModule/1.0/">
4+
<widgetFiles>
5+
<widgetFile path="MicroflowTimer/MicroflowTimer.xml"/>
6+
</widgetFiles>
7+
<files>
8+
<file path="MicroflowTimer/widget/"/>
9+
</files>
10+
</clientModule>
1111
</package>

test/widgets/MicroflowTimer.mpk

-554 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)