Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Bugfix/async commons getobjectattr (#38)
Browse files Browse the repository at this point in the history
* Bugfix commons getObjectAttr

* Add return

* Fix method call

* Make render columns async

* dojo.hitch -> lang.hitch

* Replace moved dojo functions

* Cleanup

* Fix microflows

* Bump version
  • Loading branch information
JelteMX authored Aug 10, 2017
1 parent 95f4c34 commit 995935a
Show file tree
Hide file tree
Showing 21 changed files with 373 additions and 206 deletions.
9 changes: 7 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"globals" : {
"mendix" : false,
"mx" : false,
"logger" : false
"logger" : false,
"mxui" : false
},

// Relaxing
Expand All @@ -19,5 +20,9 @@
// Environments
"browser" : true,
"devel" : true,
"dojo" : true
"dojo" : true,
"-W083" : true,
"-W084" : true,
"-W030" : true,
"-W116" : true
}
Binary file modified dist/TreeView.mpk
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "TreeView",
"version": "4.4.0",
"version": "4.5.0",
"description": "",
"license": "",
"author": "",
Expand Down
84 changes: 79 additions & 5 deletions src/TreeView/widget/Commons.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
define([
"dojo/_base/declare",
"dojo/_base/lang",
"dojo/data/util/simpleFetch",
], function (declare) {
], function (declare, lang) {
"use strict";

var Commons = declare("TreeView.widget.Commons", null, {
Expand Down Expand Up @@ -133,11 +134,10 @@ define([
return this.getObjectAttr(tmp, parts[2], renderValue);
}

//console && console.warn && console.warn("Commons.getObjectAttr failed to retrieve " + attr );
console && console.warn && console.warn("Commons.getObjectAttr failed to retrieve " + attr );
//This happens if no retrieve schema was used :-(.
return "";
}

}

//objects can be returned in X different ways, sometime just a guid, sometimes its an object...
Expand All @@ -156,6 +156,69 @@ define([
throw "GridCommons.getObjectAttr: Failed to retrieve attribute '" + attr + "'";
},

getObjectAttrAsync: function (object, attr, renderValue, cb) {
logger.debug("TreeView.widget.Commons.getObjectAttrAsync");

if (!object || !attr) {
return cb("");
}

if (attr.indexOf("/") == -1) {
if (renderValue) {
return cb(mx.parser && mx.parser.formatAttribute ? mx.parser.formatAttribute(object, attr) : mxui.html.renderValue(object, attr)); //mxui.html.rendervalue moved in 5.~7.
}
return cb(object.get(attr));
}
var parts = attr.split("/");
if (parts.length == 3) {
var child = object.getReference(parts[0]);

if (!child) {
return cb("");
}

//Fine, we have an object
if (dojo.isObject(child)) {
child = object.getChild(parts[0]); //Get child only works if child was not a guid but object
return cb(this.getObjectAttr(child, parts[2], renderValue));
}

//Try to retrieve guid in syc
else {
//..but, there is a guid...
mx.data.get({
guid: child,
noCache: false,
callback: lang.hitch(this, function (obj) { //async = false option would be nice!
if (obj != null) {//callback was invoked in sync :)
return this.getObjectAttrAsync(obj, parts[2], renderValue, cb);
}

console && console.warn && console.warn("Commons.getObjectAttr failed to retrieve " + attr );
//This happens if no retrieve schema was used :-(.
return cb("");
})
});
return;
}
}

//objects can be returned in X different ways, sometime just a guid, sometimes its an object...
if (parts.length == 2) {
var result = object.getReferences(parts[0]); //incase of of a get object, return the Guids (but sometimes getAttribute gives the object...)
if (!result || result.length == 0) {
return cb("");
}
if (result.guid) {
return cb(result.guid);
}
if (/\d+/.test(result)) {
return cb(result);
}
}
throw "GridCommons.getObjectAttr: Failed to retrieve attribute '" + attr + "'";
},

objectToGuid: function (thing) {
logger.debug("TreeView.widget.Commons.objectToGuid");

Expand Down Expand Up @@ -353,7 +416,7 @@ define([
throw "Multiple selection found, but microflow supports only one argument!";
}

mx.ui.action(mfname, {
var mfObject = {
params: {
applyto: "selection",
guids: guids
Expand All @@ -372,7 +435,18 @@ define([
}
},
async: !!progressMessage
});
};

if (!mx.version || mx.version && parseInt(mx.version.split(".")[0]) < 7) {
// < Mendix 7
mfObject.store = {
caller: this.mxform
};
} else {
mfObject.origin = this.mxform;
}

mx.ui.action(mfname, mfObject, this);
}
},

Expand Down
20 changes: 11 additions & 9 deletions src/TreeView/widget/Commons/Action.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
define([
"dojo/_base/declare",
"dojo/_base/lang",
"dojo/dom-style",
"TreeView/widget/Commons",
"TreeView/widget/Commons/Dropdown",
], function(declare, Commons, DropDown) {
], function(declare, lang, domStyle, Commons, DropDown) {
"use strict"

return declare("TreeView.widget.Commons.Action", null, {
Expand Down Expand Up @@ -32,7 +34,7 @@ define([
this.tree = tree;
dojo.mixin(this, args);

this.tree.connect(this.tree, "onSelect", dojo.hitch(this, this.updateToSelection));
this.tree.connect(this.tree, "onSelect", lang.hitch(this, this.updateToSelection));
},

assignRefToSelection : function(item) {
Expand All @@ -45,7 +47,7 @@ define([

this.dataset.getAssoc(), item, "add", false,
//callback
dojo.hitch(this, function() {
lang.hitch(this, function() {
this.invokeOnSelection();

this.mxbutton.set("value", null);
Expand All @@ -67,7 +69,7 @@ define([
}

this.mxbutton = new DropDown({
onChange : dojo.hitch(this, this.assignRefToSelection),
onChange : lang.hitch(this, this.assignRefToSelection),
sticky : false,
label : this.dataset.rellabel,
dataset : this.dataset,
Expand All @@ -81,7 +83,7 @@ define([
this.mxbutton = new mxui.widget._Button({
caption : this.actbuttoncaption,
iconUrl : this.actbuttonimage,
onClick : dojo.hitch(this, this.invokeOnSelection),
onClick : lang.hitch(this, this.invokeOnSelection),
type : "button",
cssclass : this.actclassname,
//title : column.help, //TODO:?
Expand All @@ -92,7 +94,7 @@ define([
}

if (this.actonselect) {
this.tree.connect(this.tree, "onSelect", dojo.hitch(this, this.invokeOnSelection));
this.tree.connect(this.tree, "onSelect", lang.hitch(this, this.invokeOnSelection));
}
},

Expand Down Expand Up @@ -132,7 +134,7 @@ define([
if (!this.mxbutton._destroyed) {//MWE: wtf?
this.mxbutton.set("disabled", !enable);
if (this.actautohide){
dojo.style(this.mxbutton.domNode, "display", enable ? "inline-block" : "none");
domStyle.set(this.mxbutton.domNode, "display", enable ? "inline-block" : "none");
} else {
(enable ? dojo.removeClass : dojo.addClass)(this.mxbutton.domNode, "gv_button_disabled");
}
Expand All @@ -152,7 +154,7 @@ define([

//invoke on the root object
else if (this.actnoselectionmf) {
Commons.confirm(this.actconfirmtext, dojo.hitch(this, function() {
Commons.confirm(this.actconfirmtext, lang.hitch(this, function() {
Commons.mf(this.actnoselectionmf, this.tree.getContextObject(), null, this.tree, false, this.actprogressmsg);
}));
}
Expand All @@ -164,7 +166,7 @@ define([



Commons.confirm(this.actconfirmtext, dojo.hitch(this, function() {
Commons.confirm(this.actconfirmtext, lang.hitch(this, function() {
//if a new item is added, suggest it as new selection
delete this._recordSelectionSuggestion;
this.tree._recordSelectionSuggestion = true;
Expand Down
12 changes: 7 additions & 5 deletions src/TreeView/widget/Commons/Checkbox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
define([
"dojo/_base/declare",
], function(declare) {
"dojo/_base/lang",
"dojo/dom-attr",
], function(declare, lang, attr) {
"use strict"

return declare("TreeView.widget.Commons.Checkbox", null, {
Expand All @@ -18,12 +20,12 @@ define([
type: "checkbox"
});

dojo.attr(this.checkbox, "checked", this.value);
dojo.attr(this.checkbox, "readonly", this.readOnly);
dojo.attr(this.checkbox, "disabled", this.readOnly);
attr.set(this.checkbox, "checked", this.value);
attr.set(this.checkbox, "readonly", this.readOnly);
attr.set(this.checkbox, "disabled", this.readOnly);

if (!this.readOnly){
this._clickSubscription = dojo.connect(this.checkbox, "onchange", dojo.hitch(this, this.change));
this._clickSubscription = dojo.connect(this.checkbox, "onchange", lang.hitch(this, this.change));
}

dojo.addClass(this.checkbox, "gv_checkbox " + this.className);
Expand Down
Loading

0 comments on commit 995935a

Please sign in to comment.