Skip to content

Commit

Permalink
Cleaned up widget code
Browse files Browse the repository at this point in the history
Added a check in updateRendering to check if there is a callback present.
  • Loading branch information
Rvthof committed Jul 9, 2015
1 parent 75e4e5b commit 7d3f120
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 69 deletions.
20 changes: 4 additions & 16 deletions src/DynamicImage/widget/DynamicImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,18 @@ define([
// _TemplatedMixin will create our dom node using this HTML template.
templateString: widgetTemplate,

// Parameters configured in the Modeler.
mfToExecute: "",
messageString: "",
backgroundColor: "",

// Internal variables. Non-primitives created in the prototype are shared between all widget instances.
_handles: null,
_contextObj: null,
_contextContext: null,
_alertDiv: null,

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

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

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

// mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
applyContext: function (context, callback) {
console.log(this.id + ".applyContext");
this._contextContext = context;
if (context && !!context.getTrackId()) {
var obj = context.getTrackObject();
if (obj !== null) {
Expand Down Expand Up @@ -139,8 +126,9 @@ define([
if (!loaded) {
this._setToDefaultImage();
}

callback();

if (callback)
callback();
},

_loadImagefromUrl : function(url) {
Expand Down
28 changes: 4 additions & 24 deletions src/DynamicImage/widget/MobileDynamicImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,20 @@ define([
// _TemplatedMixin will create our dom node using this HTML template.
templateString: widgetTemplate,

// Parameters configured in the Modeler.
mfToExecute: "",
messageString: "",
backgroundColor: "",

// Internal variables. Non-primitives created in the prototype are shared between all widget instances.
_handles: null,
_contextObj: null,
_contextContext: null,
_alertDiv: null,
_contexContext: null,

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

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

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

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

// mxui.widget._WidgetBase.enable is called when the widget should enable editing. Implement to enable editing if widget is input widget.
enable: function () {},

// mxui.widget._WidgetBase.enable is called when the widget should disable editing. Implement to disable editing if widget is input widget.
disable: function () {},

// mxui.widget._WidgetBase.resize is called when the page"s layout is recalculated. Implement to do sizing calculations. Prefer using CSS instead.
resize: function (box) {},

// mxui.widget._WidgetBase.uninitialize is called when the widget is destroyed. Implement to do special tear-down work.
uninitialize: function () {
console.log(this.id + ".uninitialize");
try {
Expand Down Expand Up @@ -151,7 +130,8 @@ define([
this._setToDefaultImage();
}

callback();
if (callback)
callback();
},

_loadImagefromUrl : function(url) {
Expand Down
31 changes: 4 additions & 27 deletions src/DynamicImage/widget/MobileStaticImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,25 @@ define([
// _TemplatedMixin will create our dom node using this HTML template.
templateString: widgetTemplate,

// Parameters configured in the Modeler.
mfToExecute: "",
messageString: "",
backgroundColor: "",

// Internal variables. Non-primitives created in the prototype are shared between all widget instances.
_handles: null,
_contextObj: null,
_alertDiv: null,

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

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

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

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

// mxui.widget._WidgetBase.enable is called when the widget should enable editing. Implement to enable editing if widget is input widget.
enable: function () {},

// mxui.widget._WidgetBase.enable is called when the widget should disable editing. Implement to disable editing if widget is input widget.
disable: function () {},

// mxui.widget._WidgetBase.resize is called when the page"s layout is recalculated. Implement to do sizing calculations. Prefer using CSS instead.
resize: function (box) {},

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

// Rerender the interface.
_updateRendering: function (callback) {
if (this.imageurl !== '') {
this.imageNode.src = this.imageurl;
} else {
this.imageNode.src = this.defaultImage;
}
callback();

if (callback)
callback();
},

// Reset subscriptions.
Expand Down
6 changes: 4 additions & 2 deletions src/DynamicImage/widget/StaticImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ define([

postCreate: function () {
console.log(this.id + ".postCreate");
this._updateRendering(function(){});
this._updateRendering();
},

update: function (obj, callback) {
Expand All @@ -55,7 +55,9 @@ define([
} else {
this.imageNode.src = this.defaultImage;
}
callback();

if (callback)
callback();
},

// Reset subscriptions.
Expand Down
Binary file modified test/widgets/DynamicImage.mpk
Binary file not shown.

0 comments on commit 7d3f120

Please sign in to comment.