diff --git a/.jshintrc b/.jshintrc index f73b569..2714f03 100644 --- a/.jshintrc +++ b/.jshintrc @@ -9,8 +9,7 @@ "undef" : true, "globals" : { "mendix" : false, - "mx" : false, - "logger" : false + "mx" : false }, // Relaxing diff --git a/Gruntfile.js b/Gruntfile.js index c12ddb9..b5e38a0 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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"; diff --git a/package.json b/package.json index 2abecde..ed473bd 100644 --- a/package.json +++ b/package.json @@ -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", @@ -25,9 +26,9 @@ "generatorVersion": "1.3.3", "paths": { "testProjectFolder": "./test/", - "testProjectFileName": "DynamicImageWidget.mpr" + "testProjectFileName": "Test.mpr" }, "scripts": { "test": "grunt test" } -} \ No newline at end of file +} diff --git a/src/DynamicImage/widget/DynamicImage.js b/src/DynamicImage/widget/DynamicImage.js index 989b80b..5d68610 100644 --- a/src/DynamicImage/widget/DynamicImage.js +++ b/src/DynamicImage/widget/DynamicImage.js @@ -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); } }, @@ -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, @@ -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; diff --git a/src/DynamicImage/widget/MobileDynamicImage.js b/src/DynamicImage/widget/MobileDynamicImage.js index 816bbd6..a2ca5ad 100644 --- a/src/DynamicImage/widget/MobileDynamicImage.js +++ b/src/DynamicImage/widget/MobileDynamicImage.js @@ -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"; diff --git a/test/widgets/DynamicImage.mpk b/test/widgets/DynamicImage.mpk index 0db054f..d4d0b97 100644 Binary files a/test/widgets/DynamicImage.mpk and b/test/widgets/DynamicImage.mpk differ