Skip to content

Commit 7d3f120

Browse files
committed
Cleaned up widget code
Added a check in updateRendering to check if there is a callback present.
1 parent 75e4e5b commit 7d3f120

5 files changed

Lines changed: 16 additions & 69 deletions

File tree

src/DynamicImage/widget/DynamicImage.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,18 @@ define([
2929
// _TemplatedMixin will create our dom node using this HTML template.
3030
templateString: widgetTemplate,
3131

32-
// Parameters configured in the Modeler.
33-
mfToExecute: "",
34-
messageString: "",
35-
backgroundColor: "",
36-
37-
// Internal variables. Non-primitives created in the prototype are shared between all widget instances.
3832
_handles: null,
3933
_contextObj: null,
40-
_contextContext: null,
41-
_alertDiv: null,
4234

43-
// dojo.declare.constructor is called to construct the widget instance. Implement to initialize non-primitive properties.
4435
constructor: function () {
4536
this._handles = [];
4637
},
4738

48-
// dijit._WidgetBase.postCreate is called after constructing the widget. Implement to do extra setup work.
4939
postCreate: function () {
5040
console.log(this.id + ".postCreate");
51-
this._updateRendering(function(){});
41+
this._updateRendering();
5242
},
5343

54-
// mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
5544
update: function (obj, callback) {
5645
console.log(this.id + ".update");
5746
this._contextObj = obj;
@@ -63,10 +52,8 @@ define([
6352
}
6453
},
6554

66-
// mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
6755
applyContext: function (context, callback) {
6856
console.log(this.id + ".applyContext");
69-
this._contextContext = context;
7057
if (context && !!context.getTrackId()) {
7158
var obj = context.getTrackObject();
7259
if (obj !== null) {
@@ -139,8 +126,9 @@ define([
139126
if (!loaded) {
140127
this._setToDefaultImage();
141128
}
142-
143-
callback();
129+
130+
if (callback)
131+
callback();
144132
},
145133

146134
_loadImagefromUrl : function(url) {

src/DynamicImage/widget/MobileDynamicImage.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,20 @@ define([
3030
// _TemplatedMixin will create our dom node using this HTML template.
3131
templateString: widgetTemplate,
3232

33-
// Parameters configured in the Modeler.
34-
mfToExecute: "",
35-
messageString: "",
36-
backgroundColor: "",
37-
38-
// Internal variables. Non-primitives created in the prototype are shared between all widget instances.
3933
_handles: null,
4034
_contextObj: null,
41-
_contextContext: null,
42-
_alertDiv: null,
35+
_contexContext: null,
4336

4437
// dojo.declare.constructor is called to construct the widget instance. Implement to initialize non-primitive properties.
4538
constructor: function () {
4639
this._handles = [];
4740
},
4841

49-
// dijit._WidgetBase.postCreate is called after constructing the widget. Implement to do extra setup work.
5042
postCreate: function () {
5143
console.log(this.id + ".postCreate");
52-
this._updateRendering(function(){});
44+
this._updateRendering();
5345
},
5446

55-
// mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
5647
update: function (obj, callback) {
5748
console.log(this.id + ".update");
5849
this._contextObj = obj;
@@ -64,10 +55,8 @@ define([
6455
}
6556
},
6657

67-
// mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
6858
applyContext: function (context, callback) {
6959
console.log(this.id + ".applyContext");
70-
this._contextContext = context;
7160
if (context && !!context.getTrackId()) {
7261
var obj = context.getTrackObject();
7362
if (obj !== null) {
@@ -85,16 +74,6 @@ define([
8574
}
8675
},
8776

88-
// mxui.widget._WidgetBase.enable is called when the widget should enable editing. Implement to enable editing if widget is input widget.
89-
enable: function () {},
90-
91-
// mxui.widget._WidgetBase.enable is called when the widget should disable editing. Implement to disable editing if widget is input widget.
92-
disable: function () {},
93-
94-
// mxui.widget._WidgetBase.resize is called when the page"s layout is recalculated. Implement to do sizing calculations. Prefer using CSS instead.
95-
resize: function (box) {},
96-
97-
// mxui.widget._WidgetBase.uninitialize is called when the widget is destroyed. Implement to do special tear-down work.
9877
uninitialize: function () {
9978
console.log(this.id + ".uninitialize");
10079
try {
@@ -151,7 +130,8 @@ define([
151130
this._setToDefaultImage();
152131
}
153132

154-
callback();
133+
if (callback)
134+
callback();
155135
},
156136

157137
_loadImagefromUrl : function(url) {

src/DynamicImage/widget/MobileStaticImage.js

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,25 @@ define([
2929
// _TemplatedMixin will create our dom node using this HTML template.
3030
templateString: widgetTemplate,
3131

32-
// Parameters configured in the Modeler.
33-
mfToExecute: "",
34-
messageString: "",
35-
backgroundColor: "",
36-
37-
// Internal variables. Non-primitives created in the prototype are shared between all widget instances.
3832
_handles: null,
3933
_contextObj: null,
40-
_alertDiv: null,
4134

42-
// dojo.declare.constructor is called to construct the widget instance. Implement to initialize non-primitive properties.
4335
constructor: function () {
4436
this._handles = [];
4537
},
4638

47-
// dijit._WidgetBase.postCreate is called after constructing the widget. Implement to do extra setup work.
4839
postCreate: function () {
4940
console.log(this.id + ".postCreate");
50-
this._updateRendering(function(){});
41+
this._updateRendering();
5142
},
5243

53-
// mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
5444
update: function (obj, callback) {
5545
console.log(this.id + ".update");
5646
this._contextObj = obj;
5747
this._resetSubscriptions();
5848
this._updateRendering(callback);
5949
},
6050

61-
// mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
6251
applyContext: function (context, callback) {
6352
console.log(this.id + ".applyContext");
6453
this._contextContext = context;
@@ -79,28 +68,16 @@ define([
7968
}
8069
},
8170

82-
// mxui.widget._WidgetBase.enable is called when the widget should enable editing. Implement to enable editing if widget is input widget.
83-
enable: function () {},
84-
85-
// mxui.widget._WidgetBase.enable is called when the widget should disable editing. Implement to disable editing if widget is input widget.
86-
disable: function () {},
87-
88-
// mxui.widget._WidgetBase.resize is called when the page"s layout is recalculated. Implement to do sizing calculations. Prefer using CSS instead.
89-
resize: function (box) {},
90-
91-
// mxui.widget._WidgetBase.uninitialize is called when the widget is destroyed. Implement to do special tear-down work.
92-
uninitialize: function () {
93-
// Clean up listeners, helper objects, etc. There is no need to remove listeners added with this.connect / this.subscribe / this.own.
94-
},
95-
9671
// Rerender the interface.
9772
_updateRendering: function (callback) {
9873
if (this.imageurl !== '') {
9974
this.imageNode.src = this.imageurl;
10075
} else {
10176
this.imageNode.src = this.defaultImage;
10277
}
103-
callback();
78+
79+
if (callback)
80+
callback();
10481
},
10582

10683
// Reset subscriptions.

src/DynamicImage/widget/StaticImage.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ define([
3838

3939
postCreate: function () {
4040
console.log(this.id + ".postCreate");
41-
this._updateRendering(function(){});
41+
this._updateRendering();
4242
},
4343

4444
update: function (obj, callback) {
@@ -55,7 +55,9 @@ define([
5555
} else {
5656
this.imageNode.src = this.defaultImage;
5757
}
58-
callback();
58+
59+
if (callback)
60+
callback();
5961
},
6062

6163
// Reset subscriptions.

test/widgets/DynamicImage.mpk

-1.07 KB
Binary file not shown.

0 commit comments

Comments
 (0)