Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"undef" : true,
"globals" : {
"mendix" : false,
"mx" : false,
"logger" : false
"mx" : false
},

// Relaxing
Expand Down
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated on 2016-02-09 using generator-mendix 1.3.3 :: git+https://github.com/mendix/generator-mendix.git
// Generated on 2016-04-06 using generator-mendix 1.3.3 :: git+https://github.com/mendix/generator-mendix.git
/*jshint -W069*/
/*global module*/
"use strict";
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "DynamicImage",
"version": "4.2.0",
"version": "4.3.0",
"description": "",
"license": "",
"author": "",
"private": true,
"dependencies": {},
"dependencies": {
},
"devDependencies": {
"grunt": "0.4.5",
"grunt-contrib-clean": "^0.6.0",
Expand All @@ -25,9 +26,9 @@
"generatorVersion": "1.3.3",
"paths": {
"testProjectFolder": "./test/",
"testProjectFileName": "DynamicImageWidget.mpr"
"testProjectFileName": "Test.mpr"
},
"scripts": {
"test": "grunt test"
}
}
}
8 changes: 4 additions & 4 deletions src/DynamicImage/widget/DynamicImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ define([
} else {
mx.data.get({
guid : this.mxcontext.getTrackId(),
callback : function(obj) {
callback : lang.hitch(this, function(obj) {
this._contextObj = obj;
this._updateRendering(callback);
}
})
}, this);
}
},
Expand Down Expand Up @@ -70,7 +70,7 @@ define([
targetObj = this._contextObj.get(this.imageattr.split("/")[0]);
if (/\d+/.test(targetObj)) { //guid only
loaded = true;
this.setToDefaultImage();
this._setToDefaultImage();
mx.data.get({ //fetch the object first
guid : targetObj,
nocache : true,
Expand All @@ -83,7 +83,7 @@ define([
}
}
}
this.connect(this.imageNode, "onclick", this.execclick);
this.connect(this.imageNode, "onclick", this._execClick);
} catch (err) {
console.warn(this.id +".setDataobject: error while loading image" + err);
loaded = false;
Expand Down
196 changes: 4 additions & 192 deletions src/DynamicImage/widget/MobileDynamicImage.js
Original file line number Diff line number Diff line change
@@ -1,200 +1,12 @@

define([
"dojo/_base/declare", "mxui/widget/_WidgetBase", "dijit/_TemplatedMixin",
"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", "dojo/html", "dojo/_base/event",
"dojo/text!DynamicImage/widget/template/DynamicImage.html"
], function (declare, _WidgetBase, _TemplatedMixin, dom, dojoDom, domQuery, domProp, domGeom, domClass, domStyle, domConstruct, dojoArray, lang, text, html, event, widgetTemplate) {
"dojo/_base/declare", "DynamicImage/widget/DynamicImage"
], function (declare, DynamicImage) {
"use strict";

// Declare widget"s prototype.
return declare("DynamicImage.widget.MobileDynamicImage", [_WidgetBase, _TemplatedMixin], {

// _TemplatedMixin will create our dom node using this HTML template.
templateString: widgetTemplate,

_handles: null,
_contextObj: null,
_contexContext: null,

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

postCreate: function () {
logger.debug(this.id + ".postCreate");
this._updateRendering();
},

update: function (obj, callback) {
logger.debug(this.id + ".update");
this._contextObj = obj;
if (obj !== null) {
this._resetSubscriptions();
this._updateRendering(callback);
} else {
mx.data.get({
guid : this.mxcontext.getTrackId(),
callback : function(obj) {
this._contextObj = obj;
this._updateRendering(callback);
}
}, this);
}
},

uninitialize: function () {
logger.debug(this.id + ".uninitialize");
try {
if (this._handles) {
this._handles.forEach(function (handle, i) {
this.unsubscribe(handle);
});
this._handles = [];
}
} catch (e) {
console.warn("Unitialize of Dynamic Image Viewer failed");
}
},

// Rerender the interface.
_updateRendering: function (callback) {
logger.debug(this.id + "._updateRendering");

var targetObj,
loaded = false;

if (this._contextObj !== null) {
try {
if (this.imageattr !== "") {
if (this.imageattr.indexOf("/") === -1) {
loaded = this._loadImagefromUrl(this._contextObj.get(this.imageattr));
} else {
targetObj = this._contextObj.get(this.imageattr.split("/")[0]);
if (/\d+/.test(targetObj)) { //guid only
loaded = true;
this.setToDefaultImage();
mx.data.get({ //fetch the object first
guid : targetObj,
nocache : true,
callback : function(obj) {
this._loadImagefromUrl(obj.get(this.imageattr.split("/")[2]));
}
}, this);
} else if (targetObj !== null) {
loaded = this._loadImagefromUrl(targetObj.attributes[ this.imageattr.split("/")[2]].value);
}
}
}
this.connect(this.imageNode, "onclick", this.execclick);
} catch (err) {
console.warn(this.id +".setDataobject: error while loading image" + err);
loaded = false;
}
} else {
console.warn(this.id + ".setDataobject: received null object");
}

if (!loaded) {
this._setToDefaultImage();
}

if (callback)
callback();
},

_loadImagefromUrl : function(url) {
logger.debug(this.id + "._loadImagefromUrl");

if (url !== "" && typeof url !== "undefined" && url !== null) {
this.imageNode.onerror = lang.hitch(this, this._setToDefaultImage);
this.imageNode.onload = lang.hitch(this, this._resizeImage);
this.imageNode.src = this.pathprefix + url + this.pathpostfix;
if (this.tooltipattr) {
this.imageNode.title = this._contextObj.get(this.tooltipattr);
}
return true;
}
return false;
},

_resizeImage: function() {
logger.debug(this.id + "._resizeImage");
var origw, origh, factorw, factorh, factor;
origw = this.imageNode.width;
origh = this.imageNode.height;
if (origw > 0 && origh > 0) {//only apply if an valid image has been loaded
factorw = this.width / origw;
factorh = this.height / origh;
factor = (factorw < factorh ? factorw : factorh);
if (factor < 1) {//check prevents upscaling
domStyle.add(this.imageNode, "width", (factor * origw) + "px");
domStyle.add(this.imageNode, "height", (factor * origh) + "px");
}
}
},

_setToDefaultImage : function() {
logger.debug(this.id + "._setToDefaultImage");
if (this.imageNode) {
this.imageNode.onerror = null; //do not catch exceptions when loading default
this.imageNode.src = this.defaultImage;
}
},

_execClick : function(index) {
if (this._contextObj !== null && this.imageNode) {
if (this.clickmicroflow !== "") {
mx.data.action({
params : {
applyto : "selection",
actionname : this.clickmicroflow,
guids : [this._contextObj.getGuid()]
},
store: {
caller: this.mxform
},
callback : function(obj) {
},
error : function(error) {
console.error(this.id + "error: XAS error executing microflow");
}
});
}
if (this.linkattr !== "") {
var url = this._contextObj.get(this.linkattr);
if (url !== "" && url !== undefined && url !== null) {
window.open(url, this.linktarget);
}
}
}
},

// Reset subscriptions.
_resetSubscriptions: function () {
logger.debug(this.id + "._resetSubscriptions");
var _objectHandle = null;

// Release handles on previous object, if any.
if (this._handles) {
this._handles.forEach(function (handle, i) {
mx.data.unsubscribe(handle);
});
this._handles = [];
}

// When a mendix object exists create subscribtions.
if (this._contextObj) {
_objectHandle = this.subscribe({
guid: this._contextObj.getGuid(),
callback: lang.hitch(this, function (guid) {
this._updateRendering();
})
});
this._handles = [_objectHandle];
}
}
});
return declare("DynamicImage.widget.MobileDynamicImage", [DynamicImage]);

});
require(["DynamicImage/widget/MobileDynamicImage"], function () {
"use strict";
Expand Down
Binary file modified test/widgets/DynamicImage.mpk
Binary file not shown.