diff --git a/src/TreeView/widget/Commons.js b/src/TreeView/widget/Commons.js index 74b4d9d..cba401f 100644 --- a/src/TreeView/widget/Commons.js +++ b/src/TreeView/widget/Commons.js @@ -1,12 +1,12 @@ define([ "dojo/_base/declare", "dojo/data/util/simpleFetch", -], function(declare) { +], function (declare) { "use strict"; var Commons = declare("TreeView.widget.Commons", null, { //MX5 hack - fixObjProps : function(widget, props) { + fixObjProps: function (widget, props) { logger.debug("TreeView.widget.Commons.fixObjProps"); var args = {}; @@ -29,7 +29,7 @@ define([ } }, - getEnumMap : function(classname, attrname) { + getEnumMap: function (classname, attrname) { logger.debug("TreeView.widget.Commons.getEnumMap"); var meta = mx.meta.getEntity(classname); @@ -48,15 +48,15 @@ define([ * @param {[type]} data [datamap object to be attached to the domnode] * @return {[type]} node [description] */ - renderLabel : function(name, close, data) { + renderLabel: function (name, close, data) { logger.debug("TreeView.widget.Commons.renderLabel"); var n = mxui.dom.create( "span", - {"class": "gv_label"}, + { "class": "gv_label" }, mxui.dom.create( "span", - {"class": "gv_label_name"}, + { "class": "gv_label_name" }, name ? name : "" ) ); @@ -64,7 +64,7 @@ define([ if (close) { dojo.place(mxui.dom.create( "span", - {"class": "gv_label_close"}, + { "class": "gv_label_close" }, "x" ), n); } @@ -73,7 +73,7 @@ define([ return n; }, - getAttributeType : function(classnameOrObject, attr) { + getAttributeType: function (classnameOrObject, attr) { logger.debug("TreeView.widget.Commons.getAttributeType"); var parts = attr.split("/"); @@ -93,7 +93,7 @@ define([ return false; }, - getObjectAttr : function(object, attr, renderValue) { + getObjectAttr: function (object, attr, renderValue) { logger.debug("TreeView.widget.Commons.getObjectAttr"); if (!object || !attr) { @@ -156,7 +156,7 @@ define([ throw "GridCommons.getObjectAttr: Failed to retrieve attribute '" + attr + "'"; }, - objectToGuid : function(thing) { + objectToGuid: function (thing) { logger.debug("TreeView.widget.Commons.objectToGuid"); if (!thing) { @@ -181,7 +181,7 @@ define([ * @param {Function} callback [callback function] * @return {[type]} [description] */ - store : function(object, attr, value, mode, commit, callback) { + store: function (object, attr, value, mode, commit, callback) { logger.debug("TreeView.widget.Commons.store"); var res = false; @@ -192,7 +192,7 @@ define([ var cb = function () { left -= 1; if (left < 1) { - mendix.lang.nullExec(callback); + callback && callback(); } }; @@ -231,10 +231,10 @@ define([ } switch (mode) { - case "add" : + case "add": res = object.addReferences(attr, guids); break; - case "rem" : + case "rem": res = object.removeReferences(attr, guids); break; default: @@ -263,7 +263,7 @@ define([ mxobj: object, error: this.error, callback: function () { - mendix.lang.nullExec(callback); + callback && callback(); } }); } @@ -277,7 +277,7 @@ define([ * @param {[type]} event [description] * @param {[type]} map of className -> function(node, event) -> boolean. (If false, further event are stopped) */ - liveConnect : function(widget, node, event, map) { + liveConnect: function (widget, node, event, map) { logger.debug("TreeView.widget.Commons.liveConnect"); if (!node) { @@ -314,11 +314,11 @@ define([ * @param {[type]} message [description] * @param {Function} callback [description] */ - confirm : function(message, callback, yescaption, nocaption) { + confirm: function (message, callback, yescaption, nocaption) { logger.debug("TreeView.widget.Commons.confirm"); if (!message) { - mendix.lang.nullExec(callback); + callback && callback(); return; } @@ -330,7 +330,7 @@ define([ }); }, - mf : function(mfname, data, callback, context, mfNeedsList, progressMessage) { + mf: function (mfname, data, callback, context, mfNeedsList, progressMessage) { logger.debug("TreeView.widget.Commons.mf"); //firing on multiple items? wait for all items to finish @@ -379,7 +379,7 @@ define([ } }, - configError : function(widget, msg) { + configError: function (widget, msg) { logger.debug("TreeView.widget.Commons.configError"); msg = "Configuration error in " + widget.id + ": " + msg; @@ -390,7 +390,7 @@ define([ throw msg; }, - error : function(e) { + error: function (e) { logger.debug("TreeView.widget.Commons.error"); console.error(e); @@ -400,7 +400,7 @@ define([ /** * splits the given properties up to objects in target per index. First property indicates targetobjects name */ - splitPropsTo : function(widget, propnames, target) { + splitPropsTo: function (widget, propnames, target) { logger.debug("TreeView.widget.Commons.splitPropsTo"); var props = propnames.split(","); @@ -436,13 +436,13 @@ define([ * @param {[function(object, guid)]} cb to be invoked when resolved [description] * @return {[type]} [description] */ - normalizeContext : function(data, cb) { + normalizeContext: function (data, cb) { logger.debug("TreeView.widget.Commons.normalizeContext"); //Nothing if (data == null) { cb(null, null); - } else if (typeof(data) != "object" && /^\d+$/.test(data)) { //GUid only + } else if (typeof (data) != "object" && /^\d+$/.test(data)) { //GUid only mx.data.get({ guid: data, callback: function (mxobj) { diff --git a/src/TreeView/widget/Commons/RelatedDataset.js b/src/TreeView/widget/Commons/RelatedDataset.js index 641ad23..12208ce 100644 --- a/src/TreeView/widget/Commons/RelatedDataset.js +++ b/src/TreeView/widget/Commons/RelatedDataset.js @@ -1,7 +1,7 @@ define([ "dojo/_base/declare", "TreeView/widget/Commons" -], function(declare, Commons) { +], function (declare, Commons) { "use strict" return declare("TreeView.widget.Commons.RelatedDataset", null, { @@ -40,7 +40,7 @@ define([ this.widget.connect(this.widget, "update", dojo.hitch(this, function (data, cb) { this.contextGuid = data && data.getGuid ? data.getGuid() : data; this.fetchLabels(); - mendix.lang.nullExec(cb); + cb && cb(); })); }, @@ -53,7 +53,7 @@ define([ }, getValue: function (item, _) { - if (typeof (item) == "object"){ + if (typeof (item) == "object") { return item.get(this.relnameattr); } else if (/^\d+$/.test(item)) { var obj = this.existingLabelsById[item]; //assuming guid @@ -69,7 +69,7 @@ define([ }, fetchLabels: function () { - if (this.contextGuid == null || this._fetchingLabels){ + if (this.contextGuid == null || this._fetchingLabels) { return; } this.hasData = false; @@ -98,12 +98,12 @@ define([ this.existingLabels[label.toLowerCase()] = obj; this.existingLabelsById[value] = obj; - return {value: value, label: label}; + return { value: value, label: label }; }, this); this._fetchingLabels = false; - if (this.relnewitemcaption){ + if (this.relnewitemcaption) { this.existingOptions.splice(0, 0, { value: "new", label: this.relnewitemcaption, @@ -136,9 +136,9 @@ define([ callback: dojo.hitch(this, function (label) { var cb = callback ? dojo.hitch(this, callback, { - value: label.getGuid(), - label: labelname - }) + value: label.getGuid(), + label: labelname + }) : null; if (this.relcontextassoc) @@ -163,7 +163,7 @@ define([ fetchItemByIdentity: function (args) { //TODO: check and error handling - if (!this.existingLabelsById){ + if (!this.existingLabelsById) { args.onItem.call(args.scope, null); } else { args.onItem.call(args.scope, this.existingLabelsById[args.identity]); @@ -173,10 +173,11 @@ define([ /* Simplefetch api */ _fetchItems: function (query, resultcallback) { var results = []; - if (this.existingLabels != null){ - for (var key in this.existingLabels){ - if (key.indexOf(query.query.name.toLowerCase()) === 0){ - results.push(this.existingLabels[key]);} + if (this.existingLabels != null) { + for (var key in this.existingLabels) { + if (key.indexOf(query.query.name.toLowerCase()) === 0) { + results.push(this.existingLabels[key]); + } } } resultcallback(results, query); diff --git a/src/TreeView/widget/GridView.js b/src/TreeView/widget/GridView.js index 881aa53..45fed5d 100644 --- a/src/TreeView/widget/GridView.js +++ b/src/TreeView/widget/GridView.js @@ -12,7 +12,7 @@ require([ "TreeView/widget/Commons/RelatedDataset", "TreeView/widget/Commons/SearchControl", "dojo/NodeList-traverse" -], function(declare, _WidgetBase, Commons, ColHead, Record, Action, ColRenderer, Condition, Filter, FilterManager, RelatedDataset, SearchControl) { +], function (declare, _WidgetBase, Commons, ColHead, Record, Action, ColRenderer, Condition, Filter, FilterManager, RelatedDataset, SearchControl) { "use strict"; return declare("TreeView.widget.GridView", _WidgetBase, { @@ -135,9 +135,9 @@ require([ condclass: "", /* context applied */ - _contextSubscription : null, + _contextSubscription: null, - constructor : function() { + constructor: function () { logger.debug("TreeView.widget.GridView.constructor"); this.records = []; @@ -151,7 +151,7 @@ require([ this.actionsByName = {}; }, - postCreate : function() { + postCreate: function () { logger.debug("TreeView.widget.GridView.postCreate"); Commons.fixObjProps(this, ["blaat0", "blaat2", "blaat3", "blaat4", "blaat7", "blaat8"]); @@ -171,21 +171,21 @@ require([ if (this.refreshonclass) { this.subscribe({ - "entity" : this.entity, - callback : dojo.hitch(this, function() { + "entity": this.entity, + callback: dojo.hitch(this, function () { this.fetchAll(); }) }); } if (this.searchenabled) { this.searchControl = new SearchControl({ - searchplaceholder : this.searchplaceholder, - labelentity : this.labelentity, - labelcontextassoc : this.labelcontextassoc, - labelitemassoc : this.labelitemassoc, - labelnameattr : this.labelnameattr, - dataset : !this.searchlabeldataset ? null : this.dataset[this.searchlabeldataset], - realtime : this.realtimesearch + searchplaceholder: this.searchplaceholder, + labelentity: this.labelentity, + labelcontextassoc: this.labelcontextassoc, + labelitemassoc: this.labelitemassoc, + labelnameattr: this.labelnameattr, + dataset: !this.searchlabeldataset ? null : this.dataset[this.searchlabeldataset], + realtime: this.realtimesearch }, this); dojo.place(this.searchControl.domNode, this.searchbarNode); @@ -194,15 +194,15 @@ require([ this._setupFilters(); //triggers data retrieval as well! - if (this.defaultsortcolumn < 0 || this.defaultsortcolumn >= this.colheads.length || !this.colheads[this.defaultsortcolumn].getSortAttr()){ - if (!this.datasourcemf){ + if (this.defaultsortcolumn < 0 || this.defaultsortcolumn >= this.colheads.length || !this.colheads[this.defaultsortcolumn].getSortAttr()) { + if (!this.datasourcemf) { this.configError("Invalid default sort column. The column does not exists or no sort attribute has been defined"); } } //listening formloader if (this.listenchannel) { - this.connect(this, "onSelect", function(item) { - dojo.publish(this.uniqueid + "/"+this.listenchannel+"/context", [!item ? null : item.data()]); + this.connect(this, "onSelect", function (item) { + dojo.publish(this.uniqueid + "/" + this.listenchannel + "/context", [!item ? null : item.data()]); }); } this.setCurrentSortColumn(this.defaultsortcolumn); @@ -213,7 +213,7 @@ require([ /** called by mxclient whenever context is replaced */ - update : function(obj, cb) { + update: function (obj, cb) { logger.debug("TreeView.widget.GridView.update"); //use the new context @@ -225,27 +225,27 @@ require([ //reload this.resetAndFetchAll(dojo.hitch(this, this.updateSelectionFromContext)); - mendix.lang.nullExec(cb); + cb && cb(); }, resize: function () { // stub function }, - suspended : function() { + suspended: function () { this._suspended = true; }, - resumed : function() { + resumed: function () { this._suspended = false; this.resetAndFetchAll(dojo.hitch(this, this.updateSelectionFromContext)); }, - isSuspended : function() { + isSuspended: function () { return this._suspended; }, - uninitialize : function() { + uninitialize: function () { logger.debug("TreeView.widget.GridView.uninitialize"); if (this.searchControl) { @@ -255,42 +255,42 @@ require([ this.filterManager.free(); } - dojo.forEach(this.columns, function(column) { + dojo.forEach(this.columns, function (column) { column.free(); }); - dojo.forEach(this.actions, function(action) { + dojo.forEach(this.actions, function (action) { action.free(); }); - dojo.forEach(this.records, function(record) { + dojo.forEach(this.records, function (record) { record.free(); }); }, - _setupEvents : function() { + _setupEvents: function () { logger.debug("TreeView.widget.GridView._setupEvents"); var lc = Commons.liveConnect; lc(this, this.gridNode, "onclick", { - "gv_multiselect_checkbox" : this.multiSelectClick, - "gv_label_close" : this.labelClick, - "gv_label_name" : this.labelClick, - "gv_column_wrapper" : this.columnClick, - "gv_cell" : function(node, e) { + "gv_multiselect_checkbox": this.multiSelectClick, + "gv_label_close": this.labelClick, + "gv_label_name": this.labelClick, + "gv_column_wrapper": this.columnClick, + "gv_cell": function (node, e) { this.grabFocus(); this.setSelection(this.getRowForNode(node)); if (this.singleclickdefaultaction) { this.invokeDefaultAction(node, e); } }, - "gv_th" : function(node, e) { + "gv_th": function (node, e) { this.setCurrentSortColumn(this.getIndex(node) - 1); } }); if (!this.singleclickdefaultaction) { lc(this, this.gridNode, "ondblclick", { - "gv_cell" : function(target, e) { + "gv_cell": function (target, e) { this.invokeDefaultAction(target, e); } }); @@ -298,8 +298,8 @@ require([ var currentcolhover = 0; lc(this, this.gridNode, "onmouseover", { - "gv_row" : this.onRowMouseOver, - "gv_th" : function(target, e) { + "gv_row": this.onRowMouseOver, + "gv_th": function (target, e) { dojo.removeClass(target.parentNode.childNodes[currentcolhover], "gv_sort_hover"); currentcolhover = this.getIndex(target); dojo.addClass(target, "gv_sort_hover"); @@ -307,12 +307,12 @@ require([ }); lc(this, this.gridNode, "onmouseout", { - "gv_th" : function(target) { + "gv_th": function (target) { dojo.removeClass(target, "gv_sort_hover"); } }); - this.connect(this.gridNode, "onmouseout", function(e) { + this.connect(this.gridNode, "onmouseout", function (e) { var target = e.target; //TODO: this can be done more efficient by using onmouseleave and now isDescendant. //Not yet supported by webkit though @@ -326,7 +326,7 @@ require([ this.connect(this.pagingNode, "onclick", this.pagingClick); }, - _setupLayout : function() { + _setupLayout: function () { logger.debug("TreeView.widget.GridView._setupLayout"); dojo.addClass(this.domNode, "gv_grid"); @@ -334,39 +334,39 @@ require([ dojo.addClass(this.domNode, "gv_floating_grid"); } - this.headerNode = mxui.dom.create("div", {"class" : "gv_header"}); + this.headerNode = mxui.dom.create("div", { "class": "gv_header" }); - this.gridNode = mxui.dom.create(this.showasdiv ? "div" : "table", {"class": "gv_table"}); + this.gridNode = mxui.dom.create(this.showasdiv ? "div" : "table", { "class": "gv_table" }); - this.headerRow = mxui.dom.create(this.showasdiv ? "div" : "tr", {"class":"gv_headrow"}, mxui.dom.create(this.showasdiv ? "div" : "th", { "class" : "gv_multiselect_column_head gv_th gv_th_0"})); - var header = mxui.dom.create(this.showasdiv ? "div" : "thead", {"class":"gv_gridhead"}, this.headerRow); + this.headerRow = mxui.dom.create(this.showasdiv ? "div" : "tr", { "class": "gv_headrow" }, mxui.dom.create(this.showasdiv ? "div" : "th", { "class": "gv_multiselect_column_head gv_th gv_th_0" })); + var header = mxui.dom.create(this.showasdiv ? "div" : "thead", { "class": "gv_gridhead" }, this.headerRow); dojo.addClass(this.domNode, this.colheaderenabled ? "gv_columnheaders" : "gv_nocolumnheaders"); dojo.addClass(this.domNode, this.allowmultiselect ? "gv_multiselect_enabled" : "gv_multiselect_disabled"); dojo.place(header, this.gridNode, "first"); - this.footerNode = mxui.dom.create("div", {"class" : "gv_footer"}); - this.pagingNode = mxui.dom.create("div", {"class" : "gv_paging"}); + this.footerNode = mxui.dom.create("div", { "class": "gv_footer" }); + this.pagingNode = mxui.dom.create("div", { "class": "gv_paging" }); dojo.place(this.pagingNode, this.footerNode); - this.searchbarNode = mxui.dom.create("div", {"class" : "gv_searchnode"}); + this.searchbarNode = mxui.dom.create("div", { "class": "gv_searchnode" }); dojo.place(this.searchbarNode, this.headerNode); dojo.place(this.headerNode, this.domNode); - dojo.place(this.gridNode, this.domNode); + dojo.place(this.gridNode, this.domNode); dojo.place(this.footerNode, this.domNode); - dojo.attr(this.gridNode, { - tabindex : this.tabindex, - focusindex : 0 + dojo.attr(this.gridNode, { + tabindex: this.tabindex, + focusindex: 0 }); mxui.wm.focus.addBox(this.gridNode); this.grabFocus(); }, - _setupColumns : function() { + _setupColumns: function () { logger.debug("TreeView.widget.GridView._setupColumns"); var data = []; @@ -377,27 +377,27 @@ require([ this.colheads.push(colhead); } - dojo.forEach(this.colheads, function(colhead) { + dojo.forEach(this.colheads, function (colhead) { colhead.setup(this.headerNode); }, this); }, - _setupDatasets : function() { + _setupDatasets: function () { logger.debug("TreeView.widget.GridView._setupDatasets"); this.dataset = {}; var data = []; this.splitPropsTo("relname,rellabel,relnewitemcaption,relentity,relcontextassoc,relitemassocref,relitemassocrefset,relnameattr,relconstraint", data); - dojo.forEach(data, function(item) { + dojo.forEach(data, function (item) { if (this.dataset[item.relname]) - this.configError("Related dataset \"" + item.relname + "\" is defined twice!"); + this.configError("Related dataset \"" + item.relname + "\" is defined twice!"); var r = new RelatedDataset(item, this); this.dataset[item.relname] = r; this.addToSchema((item.relitemassocref || item.relitemassocrefset) + "/" + item.relnameattr); }, this); }, - _setupActions : function() { + _setupActions: function () { logger.debug("TreeView.widget.GridView._setupActions"); var data = []; @@ -413,13 +413,13 @@ require([ this.actionsByName[action.actname] = action; } - dojo.forEach(this.actions, function(action) { + dojo.forEach(this.actions, function (action) { action.setup(this.headerNode); action.updateToSelection(); }, this); }, - _setupConditions : function() { + _setupConditions: function () { logger.debug("TreeView.widget.GridView._setupConditions"); var data = []; @@ -435,7 +435,7 @@ require([ } }, - _setupFilters: function() { + _setupFilters: function () { logger.debug("TreeView.widget.GridView._setupFilters"); var data = []; @@ -443,7 +443,7 @@ require([ var fm = this.filterManager = new FilterManager(this); - this.filters = dojo.map(data, function(d) { + this.filters = dojo.map(data, function (d) { return new Filter(d, fm); }, this); @@ -452,7 +452,7 @@ require([ } }, - _setupRendering : function() { + _setupRendering: function () { logger.debug("TreeView.widget.GridView._setupRendering"); var data = []; @@ -480,15 +480,15 @@ require([ } }, - getContextGUID : function() { + getContextGUID: function () { return this.contextGUID; }, - getContextObject : function() { + getContextObject: function () { return this.contextObject; }, - listenToContext : function() { + listenToContext: function () { logger.debug("TreeView.widget.GridView.listenToContext"); //if reload on context change is enabled, reload as soon as the context object is altered @@ -500,7 +500,7 @@ require([ if (this.contextGUID) { this._contextSubscription = mx.data.subscribe({ guid: this.contextGUID, - callback : dojo.hitch(this, function() { + callback: dojo.hitch(this, function () { if (!this._iscallingdatasource) { this.resetAndFetchAll(dojo.hitch(this, this.updateSelectionFromContext)); } @@ -510,44 +510,44 @@ require([ } }, - saveAndFireSelection : function(item) { + saveAndFireSelection: function (item) { logger.debug("TreeView.widget.GridView.saveAndFireSelection"); this.updatePaging(); //update selected items label if (this.selectionref || this.selectionrefset) { - mx.data.save({ - mxobj : this.contextObject, - callback : dojo.hitch(this, this.onSelect, item), - error : this.showError + mx.data.commit({ + mxobj: this.contextObject, + callback: dojo.hitch(this, this.onSelect, item), + error: this.showError }, this); } else { this.onSelect(item); } }, - hasSelection : function() { + hasSelection: function () { logger.debug("TreeView.widget.GridView.hasSelection"); return this._multiSelection.length > 0; }, - hasMultiSelection : function() { + hasMultiSelection: function () { return this._multiSelection.length > 1; }, - getSelection : function() { + getSelection: function () { return this._multiSelection; }, - getLastSelection : function() { - return (this.hasSelection() ? this._multiSelection[this._multiSelection.length -1] : null); + getLastSelection: function () { + return (this.hasSelection() ? this._multiSelection[this._multiSelection.length - 1] : null); }, - withSelection : function(scope, cb) { + withSelection: function (scope, cb) { dojo.forEach(this._multiSelection, cb, scope); }, - addToSelection : function(item, noevents) { + addToSelection: function (item, noevents) { logger.debug("TreeView.widget.GridView.addToSelection"); item.checkbox.checked = true; @@ -564,16 +564,16 @@ require([ if (noevents !== true) { if (this.selectionref) - Commons.store(this.contextObject, this.selectionref, item.guid); + Commons.store(this.contextObject, this.selectionref, item.guid); if (this.selectionrefset) - Commons.store(this.contextObject, this.selectionrefset, item.guid, "add"); + Commons.store(this.contextObject, this.selectionrefset, item.guid, "add"); this.saveAndFireSelection(item); } }, - removeFromSelection : function(item, noevents) { + removeFromSelection: function (item, noevents) { logger.debug("TreeView.widget.GridView.removeFromSelection"); dojo.removeClass(item.domNode, "gv_selected"); @@ -594,9 +594,9 @@ require([ var lastitem = this.getLastSelection(); - if(noevents !== true) { + if (noevents !== true) { if (this.selectionref) { - Commons.store(this.contextObject, this.selectionref, lastitem ? lastitem.guid : null); + Commons.store(this.contextObject, this.selectionref, lastitem ? lastitem.guid : null); } if (this.selectionrefset) { @@ -607,7 +607,7 @@ require([ } }, - setSelection : function(item) { + setSelection: function (item) { logger.debug("TreeView.widget.GridView.setSelection"); //the same selection? @@ -617,7 +617,7 @@ require([ this._inMultiSelectMode = false; - while(this.hasSelection()) { + while (this.hasSelection()) { this.removeFromSelection(this.getLastSelection(), true); } @@ -626,7 +626,7 @@ require([ } if (this.selectionref) { - Commons.store(this.contextObject, this.selectionref, item && item.guid); + Commons.store(this.contextObject, this.selectionref, item && item.guid); } if (this.selectionrefset) { @@ -638,7 +638,7 @@ require([ } }, - multiSelectClick : function(node, e) { + multiSelectClick: function (node, e) { logger.debug("TreeView.widget.GridView.multiSelectClick"); var record = this.getRowForNode(node); @@ -654,7 +654,7 @@ require([ return false; //no propagation }, - getRecordByGuid : function(guid) { + getRecordByGuid: function (guid) { logger.debug("TreeView.widget.GridView.getRecordByGuid"); for (var i = 0; i < this.records.length; i++) { @@ -666,20 +666,20 @@ require([ }, /** tries to read the selection data from the context object, and apply it*/ - updateSelectionFromContext : function() { + updateSelectionFromContext: function () { logger.debug("TreeView.widget.GridView.updateSelectionFromContext"); var guids = []; if (this.selectionref) { - this.contextObject.fetch(this.selectionref, function(value) { + this.contextObject.fetch(this.selectionref, function (value) { if (value) { guids.push(value); } }); } if (this.selectionrefset) { - this.contextObject.fetch(this.selectionrefset, function(value) { + this.contextObject.fetch(this.selectionrefset, function (value) { if (value) { guids.push(value); } @@ -700,7 +700,7 @@ require([ }, /** tries to reapply the current selection, otherwise, selects the first record */ - reapplySelection : function() { + reapplySelection: function () { logger.debug("TreeView.widget.GridView.reapplySelection"); var selected = false; @@ -710,9 +710,9 @@ require([ //In multi selection, re-select selection if visible, leave the rest as is. if (this._inMultiSelectMode) { - guids = dojo.map(this._multiSelection, function(item) { return item.guid;}); + guids = dojo.map(this._multiSelection, function (item) { return item.guid; }); - dojo.forEach(this.records, function(item) { + dojo.forEach(this.records, function (item) { var idx = dojo.indexOf(guids, item.guid); if (idx > -1) { item.checkbox.checked = true; @@ -728,7 +728,7 @@ require([ this.removeFromSelection(this._multiSelection[i], true); } - dojo.forEach(this.records, function(record) { + dojo.forEach(this.records, function (record) { if (dojo.indexOf(guids, record.guid) > -1) { this.addToSelection(record); selected = true; @@ -741,15 +741,15 @@ require([ } }, - onSelect : function(selection) { + onSelect: function (selection) { //stub method to connect events to }, - onDefaultAction : function(selection) { + onDefaultAction: function (selection) { //stub, this method is invoked when a row is doubleclicked/ return is pressed }, - resetAndFetchAll : function(cb) { + resetAndFetchAll: function (cb) { logger.debug("TreeView.widget.GridView.resetAndFetchAll"); if (!this.isSuspended()) { @@ -758,11 +758,11 @@ require([ } }, - fetchAll : function(cb) { + fetchAll: function (cb) { logger.debug("TreeView.widget.GridView.fetchAll"); if (!this.contextGUID || this.isSuspended()) { - mendix.lang.nullExec(cb); + cb && cb(); } else if (this.datasourcemf != "") { this.fetchFromMicroflowDatasource(cb); } else { @@ -770,7 +770,7 @@ require([ } }, - fetchFromMicroflowDatasource : function(cb) { + fetchFromMicroflowDatasource: function (cb) { logger.debug("TreeView.widget.GridView.fetchFromMicroflowDatasource"); var contextObject = this.contextObject; @@ -786,48 +786,48 @@ require([ var self = this; - mx.data.save({ - mxobj : contextObject, - callback : function(){ + mx.data.commit({ + mxobj: contextObject, + callback: function () { self._iscallingdatasource = true; mx.data.action({ - params : { - actionname : self.datasourcemf, - applyto : "selection", - guids : ["" + contextObject.getGuid()] + params: { + actionname: self.datasourcemf, + applyto: "selection", + guids: ["" + contextObject.getGuid()] }, - callback : function (objlist, xhr) { + callback: function (objlist, xhr) { var count = contextObject.get(self.datasourcecountattr); self.processData(cb, objlist, count); //The refresh instruction that are responded to the datasource mf are processed later than the callback (this callback) with the results itself. So schedule async and hope for the best. (otherwise looping will occur) - setTimeout(function() { + setTimeout(function () { self._iscallingdatasource = false; }, 1); }, - error : function(e) { + error: function (e) { self._iscallingdatasource = false; self.showError(e); } }); }, - error : function (e) { + error: function (e) { self.showError(e); } }, this); }, - fetchFromDatabaseDatasource : function(cb) { + fetchFromDatabaseDatasource: function (cb) { logger.debug("TreeView.widget.GridView.fetchFromDatabaseDatasource"); var xpath = this.buildXpath(); var args = { - xpath : xpath, - filter : this.enableschema ? this._schema : {}, - callback : dojo.hitch(this, this.processData, cb), - count : true, - error : this.showError + xpath: xpath, + filter: this.enableschema ? this._schema : {}, + callback: dojo.hitch(this, this.processData, cb), + count: true, + error: this.showError }; //sorting @@ -839,26 +839,26 @@ require([ } if (!sortCol.getSortAttr()) { - this.configError("No sortable column : " + this.currentSortColumn + " ("+ sortCol.data.colheadcaption + ")"); + this.configError("No sortable column : " + this.currentSortColumn + " (" + sortCol.data.colheadcaption + ")"); } - args.filter.sort = [[ sortCol.getSortAttr(), sortdir]]; + args.filter.sort = [[sortCol.getSortAttr(), sortdir]]; args.filter.offset = this.curpage * this.pagesize; - args.filter.amount = this.pagesize; + args.filter.amount = this.pagesize; //perform the get mx.data.get(args); }, - buildXpath : function () { + buildXpath: function () { logger.debug("TreeView.widget.GridView.buildXpath"); var xpath = "//" + this.entity + (this.constraint ? this.constraint.replace(/\[\%CurrentObject\%\]/gi, this.contextGUID) : ""); if (this.searchControl) { if (!this.searchAttrs) { - this.searchAttrs = dojo.map(dojo.filter(this.columns, function(column) { + this.searchAttrs = dojo.map(dojo.filter(this.columns, function (column) { return column.columnissearchattr && column.columnattr; - }), function(column) { + }), function (column) { return column.columnattr; }); } @@ -874,20 +874,20 @@ require([ return xpath; }, - processData : function(cb, data, count) { + processData: function (cb, data, count) { logger.debug("TreeView.widget.GridView.processData"); - this.count = (dojo.isObject(count) ? count.count : count)*1; //Mx 3 returns primitive, Mx 4 an aggregate object + this.count = (dojo.isObject(count) ? count.count : count) * 1; //Mx 3 returns primitive, Mx 4 an aggregate object this.updatePaging(); - dojo.forEach(this.records, function(record){ + dojo.forEach(this.records, function (record) { record.free(); }); this.records = []; // TODO check scoping - var handleElem = function(data) { + var handleElem = function (data) { var r = new Record(data, this); this.records.push(r); r.setup(this.gridNode); @@ -906,7 +906,7 @@ require([ this.reapplySelection(); }, - updatePaging : function() { + updatePaging: function () { logger.debug("TreeView.widget.GridView.updatePaging"); dojo.empty(this.pagingNode); @@ -923,40 +923,40 @@ require([ if (this.count > this.pagesize || this.curpage > 0) { //show prev btn? if (this.curpage > 0) { - dojo.place(mxui.dom.create("a", { "class" : "gv_btn_prev"}, "<"), this.pagingNode); + dojo.place(mxui.dom.create("a", { "class": "gv_btn_prev" }, "<"), this.pagingNode); } //page 1 - dojo.place(mxui.dom.create("a", { "class" : "gv_btn_page " + (0 === this.curpage ? "gv_btn_page_active" : "")}, "1"), this.pagingNode); + dojo.place(mxui.dom.create("a", { "class": "gv_btn_page " + (0 === this.curpage ? "gv_btn_page_active" : "") }, "1"), this.pagingNode); //paging skipper? if (this.curpage > PAGERSIZE) { - dojo.place(mxui.dom.create("a", { "class" : "gv_btn_paging_spacer"}, ".."), this.pagingNode); + dojo.place(mxui.dom.create("a", { "class": "gv_btn_paging_spacer" }, ".."), this.pagingNode); } - for (var i = Math.max(this.curpage - PAGERSIZE + 1, 1); i < Math.min(this.curpage + PAGERSIZE , lastpage); i++) { - dojo.place(mxui.dom.create("a", { "class" : "gv_btn_page " + (i === this.curpage ? "gv_btn_page_active" : "")}, "" + (i + 1)), this.pagingNode); + for (var i = Math.max(this.curpage - PAGERSIZE + 1, 1); i < Math.min(this.curpage + PAGERSIZE, lastpage); i++) { + dojo.place(mxui.dom.create("a", { "class": "gv_btn_page " + (i === this.curpage ? "gv_btn_page_active" : "") }, "" + (i + 1)), this.pagingNode); } //paging skipper? if (this.curpage < lastpage - PAGERSIZE) { - dojo.place(mxui.dom.create("a", { "class" : "gv_btn_paging_spacer"}, ".."), this.pagingNode); + dojo.place(mxui.dom.create("a", { "class": "gv_btn_paging_spacer" }, ".."), this.pagingNode); } //last page - dojo.place(mxui.dom.create("a", { "class" : "gv_btn_page " + (lastpage === this.curpage ? "gv_btn_page_active" : "")}, "" + (lastpage + 1)), this.pagingNode); + dojo.place(mxui.dom.create("a", { "class": "gv_btn_page " + (lastpage === this.curpage ? "gv_btn_page_active" : "") }, "" + (lastpage + 1)), this.pagingNode); //show next btn? if (this.curpage < lastpage) { - dojo.place(mxui.dom.create("a", { "class" : "gv_btn_next"}, ">"), this.pagingNode); + dojo.place(mxui.dom.create("a", { "class": "gv_btn_next" }, ">"), this.pagingNode); } } if (this.count === 0) { - dojo.place(mxui.dom.create("span", {"class" : "gv_empty_message"}, this.emptymessage), this.pagingNode); + dojo.place(mxui.dom.create("span", { "class": "gv_empty_message" }, this.emptymessage), this.pagingNode); } else if (this.showtotals) { - dojo.place(mxui.dom.create("span", {"class" : "gv_paging_totals"}, ( + dojo.place(mxui.dom.create("span", { "class": "gv_paging_totals" }, ( this.itemcountmessage || (this._multiSelection.length > 1 ? "{1} of {0} item(s) selected." : "{0} item(s) in total")).replace("{0}", this.count).replace("{1}", this._multiSelection.length) @@ -964,7 +964,7 @@ require([ } }, - pagingClick : function(e) { + pagingClick: function (e) { logger.debug("TreeView.widget.GridView.pagingClick"); if (dojo.hasClass(e.target, "gv_btn_prev")) { @@ -980,12 +980,12 @@ require([ this.fetchAll(); }, - prevPage : function() { + prevPage: function () { logger.debug("TreeView.widget.GridView.prevPage"); if (this.curpage > 0) { this.curpage -= 1; - this.fetchAll(function() { + this.fetchAll(function () { //select last item when going to previous page if (!this._inMultiSelectMode) { if (this.gridNode.childNodes.length > 1) { @@ -998,12 +998,12 @@ require([ } }, - nextPage : function() { + nextPage: function () { logger.debug("TreeView.widget.GridView.nextPage"); - if (this.curpage < Math.ceil(this.count / this.pagesize) -1) { + if (this.curpage < Math.ceil(this.count / this.pagesize) - 1) { this.curpage += 1; - this.fetchAll(function() { + this.fetchAll(function () { if (!this._inMultiSelectMode) { this.selectFirstItem(); } @@ -1011,7 +1011,7 @@ require([ } }, - selectFirstItem : function() { + selectFirstItem: function () { logger.debug("TreeView.widget.GridView.selectFirstItem"); if (this.gridNode.childNodes.length > 1) { @@ -1021,7 +1021,7 @@ require([ } }, - setDefaultSelection: function(){ + setDefaultSelection: function () { logger.debug("TreeView.widget.GridView.setDefaultSelection"); if (this.selectfirstrow) { @@ -1029,7 +1029,7 @@ require([ } }, - grabStartupFocus : function() { + grabStartupFocus: function () { logger.debug("TreeView.widget.GridView.grabStartupFocus"); if (this.searchenabled) { mxui.wm.focus.put(this.searchControl.searchInput.textbox); @@ -1038,7 +1038,7 @@ require([ } }, - grabFocus : function() { + grabFocus: function () { logger.debug("TreeView.widget.GridView.grabFocus"); if (mxui.wm.focus.get() !== this.gridNode) { @@ -1046,17 +1046,17 @@ require([ } }, - getIndex : function(node) { + getIndex: function (node) { logger.debug("TreeView.widget.GridView.getIndex"); return typeof node.cellIndex === "number" ? node.cellIndex : dojo.query(node.parentNode).children().indexOf(node); }, - keypress : function(e) { + keypress: function (e) { logger.debug("TreeView.widget.GridView.keypress"); var record = this.getLastSelection(), //this.getRowForNode(e.target); - handled = false; + handled = false; if (record) { handled = true; switch (e.keyCode) { @@ -1075,7 +1075,7 @@ require([ case dojo.keys.ENTER: this.invokeDefaultAction(); break; - case dojo.keys.DOWN_ARROW : + case dojo.keys.DOWN_ARROW: var next = this.getRowForNode(record.domNode.nextElementSibling); if (next) { if (!this._inMultiSelectMode) { @@ -1086,7 +1086,7 @@ require([ this.nextPage(); } break; - case dojo.keys.UP_ARROW : + case dojo.keys.UP_ARROW: var prev = this.getRowForNode(record.domNode.previousElementSibling); if (prev) { if (!this._inMultiSelectMode) { @@ -1111,7 +1111,7 @@ require([ } }, - invokeDefaultAction : function() { + invokeDefaultAction: function () { logger.debug("TreeView.widget.GridView.invokeDefaultAction"); for (var i = 0, a = null; a = this.actions[i++];) { @@ -1121,7 +1121,7 @@ require([ } }, - onRowMouseOver : function(target, e) { + onRowMouseOver: function (target, e) { if (target !== this._hoveredRow) { this._hoveredRow && dojo.removeClass(this._hoveredRow, "gv_row_hover"); dojo.addClass(target, "gv_row_hover"); @@ -1133,7 +1133,7 @@ require([ return false; //stop further events }, - getRowForNode : function (node) { + getRowForNode: function (node) { logger.debug("TreeView.widget.GridView.getRowForNode"); if (!node) { @@ -1145,7 +1145,7 @@ require([ return this.getRowForNode(node.parentNode); }, - labelClick : function(node) { + labelClick: function (node) { logger.debug("TreeView.widget.GridView.labelClick"); var isClose = dojo.hasClass(node, "gv_label_close"); @@ -1154,9 +1154,9 @@ require([ //assuming dataset: { owner: record, guid : guid, dataset: this.columneditdataset, colindex: this.colindex } var data = mxui.dom.data(node, "data"); var record = data.owner; - var guid = data.guid; + var guid = data.guid; var dataset = this.dataset[data.dataset]; - var rnd = this.columns[data.colindex]; + var rnd = this.columns[data.colindex]; if (!(record && guid && dataset && rnd)) { this.showError("Unable to handle labelclick!"); } @@ -1173,16 +1173,16 @@ require([ } }, - columnClick : function(node) { + columnClick: function (node) { logger.debug("TreeView.widget.GridView.columnClick"); var col = mxui.dom.data(node, "colindex"), - record = this.getRowForNode(node); + record = this.getRowForNode(node); this.columns[col].invokeAction(record); }, - setCurrentSortColumn : function(index) { + setCurrentSortColumn: function (index) { logger.debug("TreeView.widget.GridView.setCurrentSortColumn"); if (this.colheads[index].getSortAttr()) { @@ -1195,19 +1195,19 @@ require([ } else { if (this.currentSortColumn > -1) { - dojo.removeClass(this.headerRow.childNodes[this.currentSortColumn +1], "gv_sortcolumn gv_sort_up gv_sort_down"); + dojo.removeClass(this.headerRow.childNodes[this.currentSortColumn + 1], "gv_sortcolumn gv_sort_up gv_sort_down"); } this.currentSortColumn = index; this.sortInverted = false; } - dojo.addClass(colnode, "gv_sortcolumn " + ("asc" === this.colheads[index].getSortDir() ^ this.sortInverted ? "gv_sort_up" : "gv_sort_down")); + dojo.addClass(colnode, "gv_sortcolumn " + ("asc" === this.colheads[index].getSortDir() ^ this.sortInverted ? "gv_sort_up" : "gv_sort_down")); this.resetAndFetchAll(); } }, - verifyDatasourceSettings : function() { + verifyDatasourceSettings: function () { logger.debug("TreeView.widget.GridView.verifyDatasourceSettings"); if (this.datasourcemf) { @@ -1237,21 +1237,21 @@ require([ } }, - _schema : null, - addToSchema : function( attr) { + _schema: null, + addToSchema: function (attr) { logger.debug("TreeView.widget.GridView.addToSchema"); if (!attr) { return; } if (!this._schema) { - this._schema = { references : {}, attributes : [] }; + this._schema = { references: {}, attributes: [] }; } if (attr.indexOf("/") > -1) { var parts = attr.split("/"); if (!(parts[0] in this._schema.references)) { - this._schema.references[parts[0]] = { attributes : []}; + this._schema.references[parts[0]] = { attributes: [] }; } if (parts.length > 2) { @@ -1262,25 +1262,25 @@ require([ } }, - showError : function(e) { + showError: function (e) { logger.debug("TreeView.widget.GridView.showError"); Commons.error(e, this); }, - mf : function(mf, data, callback) { + mf: function (mf, data, callback) { logger.debug("TreeView.widget.GridView.mf"); Commons.mf(mf, data, callback, this); }, - configError : function(msg) { + configError: function (msg) { logger.debug("TreeView.widget.GridView.configError"); Commons.configError(this, msg); }, - splitPropsTo : function(props, target) { + splitPropsTo: function (props, target) { logger.debug("TreeView.widget.GridView.splitPropsTo"); Commons.splitPropsTo(this, props, target); diff --git a/src/TreeView/widget/TreeView.js b/src/TreeView/widget/TreeView.js index 095b406..ac2921f 100644 --- a/src/TreeView/widget/TreeView.js +++ b/src/TreeView/widget/TreeView.js @@ -7,12 +7,11 @@ require([ "TreeView/widget/TreeView/GraphNode", "TreeView/widget/Commons/Action", "dojo/NodeList-traverse" -], function(declare, _WidgetBase, Commons, ColRenderer, Edge, GraphNode, Action) { +], function (declare, _WidgetBase, Commons, ColRenderer, Edge, GraphNode, Action) { "use strict"; - var _Scriptable = mxui.mixin._Scriptable; - return declare("TreeView.widget.TreeView", [_WidgetBase, _Scriptable], { + return declare("TreeView.widget.TreeView", [_WidgetBase], { root: null, //render node dict: null, //guid -> GraphNode types: null, //type definitions : entityName -> config @@ -112,31 +111,31 @@ require([ this.xsettings = []; }, - postCreate: function() { + postCreate: function () { Commons.fixObjProps(this, ["blaat4", "blaat", "blaat2", "blaat3", "blaat5"]); this.splitPropsTo("xentity,xburstattr,sortattr,sortdir,entityclazz,entitystyle,entitychannel", this.xsettings); for (var i = 0; i < this.xsettings.length; i++) { var x = this.xsettings[i]; x.entitystyle = x.entitystyle.split(/\||\n/).join(";"); - x.filter = {references: {}, attributes: []}; + x.filter = { references: {}, attributes: [] }; this.addToSchema(x.xentity, x.xburstattr); this.addToSchema(x.xentity, x.sortattr); if (x.entitychannel) { var onSelectHandler = - this.connect(this, "onSelect", dojo.hitch(this, function (channel, entity, selection) { - if (selection != null && selection.isA(entity)) { - // KVL: This used to use this.getContent() as the first part, but that no longer exists. - // Not sure what the alternative is, so we might want to look into that... - dojo.publish("/" + channel + "/context", [selection.data()]); - } else { - // KVL: This used to use this.getContent() as the first part, but that no longer exists. - // Not sure what the alternative is, so we might want to look into that... - dojo.publish("/" + channel + "/context", [null]); - } - }, x.entitychannel, x.xentity)); + this.connect(this, "onSelect", dojo.hitch(this, function (channel, entity, selection) { + if (selection != null && selection.isA(entity)) { + // KVL: This used to use this.getContent() as the first part, but that no longer exists. + // Not sure what the alternative is, so we might want to look into that... + dojo.publish("/" + channel + "/context", [selection.data()]); + } else { + // KVL: This used to use this.getContent() as the first part, but that no longer exists. + // Not sure what the alternative is, so we might want to look into that... + dojo.publish("/" + channel + "/context", [null]); + } + }, x.entitychannel, x.xentity)); } } @@ -144,7 +143,6 @@ require([ this.selectionrefs = this.selectionref.split(";"); } - this.offerInterface("close"); this._setupTypes(); @@ -182,7 +180,7 @@ require([ this.selectFirstItem(); } - mendix.lang.nullExec(cb); + cb && cb(); }, @@ -230,9 +228,9 @@ require([ logger.debug("TreeView.widget.TreeView._setupLayout"); dojo.addClass(this.domNode, "gg_tree"); - this.headerNode = mxui.dom.create("div", {"class": "gg_header"}); + this.headerNode = mxui.dom.create("div", { "class": "gg_header" }); - this.treeNode = mxui.dom.create("ul", {"class": "gg_children gg_root_wrapper"}); + this.treeNode = mxui.dom.create("ul", { "class": "gg_children gg_root_wrapper" }); if (this.hiderootnode) { dojo.addClass(this.treeNode, "gg_hiddenroot"); } @@ -401,14 +399,12 @@ require([ saveAndFireSelection: function (item) { logger.debug("TreeView.widget.TreeView.saveAndFireSelection"); - mx.data.save({ + mx.data.commit({ mxobj: this.getContextObject(), callback: this.onSelect, error: this.showError }, this); - mx.data.objectUpdateNotification(this.getContextObject()); - this.onSelect(item); }, @@ -740,10 +736,10 @@ require([ case dojo.keys.ENTER: this.invokeDefaultAction(); break; - case dojo.keys.DOWN_ARROW : + case dojo.keys.DOWN_ARROW: if (e.ctrlKey == true) { //TODO: swap - } else { + } else { //next one is a child var fc = this._getRenderNodeForNode(this.findNextNode(sel.domNode, "gg_node", this.treeNode)); @@ -752,7 +748,7 @@ require([ } } break; - case dojo.keys.UP_ARROW : + case dojo.keys.UP_ARROW: if (e.ctrlKey == true) { //TODO: swap } else { @@ -786,7 +782,7 @@ require([ this.itemIndent(this.getSelection(), false); //TODO } break; - default : + default: if (e.charCode == dojo.keys.SPACE) { sel.setCollapsed(!sel.collapsed); } else { @@ -863,7 +859,7 @@ require([ logger.debug("TreeView.widget.TreeView.startDrag"); //tmp node for drag an drop operations - this.dnd.tmpnode = mxui.dom.create("li", {"class": "gg_node gg_anchor"}, mxui.dom.create("div", {"class": "gg_anchor_inner"})); + this.dnd.tmpnode = mxui.dom.create("li", { "class": "gg_node gg_anchor" }, mxui.dom.create("div", { "class": "gg_anchor_inner" })); var current = this.dnd.current = this._getRenderNodeForNode(target); this.setSelection(current); @@ -873,7 +869,7 @@ require([ return false; } - var avatar = this.dnd.avatar = mxui.dom.create("div", {"class": "gg_avatar"}, dojo.clone(current.rowNode)); //TODO: make beter avatar + var avatar = this.dnd.avatar = mxui.dom.create("div", { "class": "gg_avatar" }, dojo.clone(current.rowNode)); //TODO: make beter avatar //hooray, we can start thedrag // console.log("start drag"); @@ -1155,11 +1151,11 @@ require([ //determine drop target var t = null; - if (target.isEdge){ + if (target.isEdge) { t = target.parent.graphNode._data; - } else if (pos == "before" || pos == "after"){ + } else if (pos == "before" || pos == "after") { t = target.parent.graphNode._data - } else{ + } else { t = target.graphNode._data; //new parent } @@ -1167,18 +1163,20 @@ require([ if (!copy) { var assoc1 = item.type; if (assoc1.assoctype == "fromparent") { - if (assoc1.isRefset){ - o.removeReferences(assoc1.assoc, [i.getGuid()]);} - else{ + if (assoc1.isRefset) { + o.removeReferences(assoc1.assoc, [i.getGuid()]); + } + else { o.set(assoc1.assoc, ""); -} + } actions.push([assoc1.dropmf, o]); //otherwise o might never know that a child was removed } else { //from child - if (assoc1.isRefset){ + if (assoc1.isRefset) { i.removeReferences(assoc1.assoc, [o.getGuid()]); - }else{ - i.set(assoc1.assoc, "");} + } else { + i.set(assoc1.assoc, ""); + } //actions.push([assoc.dropmf, i]); //MWE: I guess this is not needed, since a drop mf is most likely already fired for i, and this might confuse the logic. } @@ -1193,7 +1191,7 @@ require([ //reference set (was already removed from orig parent in step 0) if (assoc.isRefset) { t.addReferences(assoc.assoc, [i.getGuid()]); - } else{ //normal reference + } else { //normal reference t.set(assoc.assoc, i.getGuid()); } } else { //assoc stored in child @@ -1228,7 +1226,8 @@ require([ if (pos == "last") { nidx = (target.isEdge ? target.parent : target).findMaxIndex() + 14056; } else { - nidx = (target.isEdge ? target.parent : target).findMinIndex() - 4313;} + nidx = (target.isEdge ? target.parent : target).findMinIndex() - 4313; + } } if (isNaN(nidx)) { @@ -1328,7 +1327,7 @@ require([ var parts = attr.split("/"); if (!(parts[0] in t.filter.references)) { - t.filter.references[parts[0]] = {attributes: []}; + t.filter.references[parts[0]] = { attributes: [] }; } if (parts.length > 2) { @@ -1415,7 +1414,7 @@ require([ } } - if (dojo.hasClass(cur, clazz)){ + if (dojo.hasClass(cur, clazz)) { return cur; } return null; @@ -1449,14 +1448,14 @@ require([ }; var fc = findChild(node); - if (fc){ + if (fc) { return fc; } var cur = node; while (cur != limitNode && cur != null) { var n = cur.nextElementSibling; - if (n != null && dojo.hasClass(n, clazz) && dojo.style(n, "display") != "none"){ + if (n != null && dojo.hasClass(n, clazz) && dojo.style(n, "display") != "none") { return n; } cur = cur.parentNode; diff --git a/src/TreeView/widget/TreeView/GraphNode.js b/src/TreeView/widget/TreeView/GraphNode.js index bb3489a..dfb42cc 100644 --- a/src/TreeView/widget/TreeView/GraphNode.js +++ b/src/TreeView/widget/TreeView/GraphNode.js @@ -5,7 +5,7 @@ define([ "dojo/_base/declare", "TreeView/widget/TreeView/RenderNode" -], function(declare, RenderNode) { +], function (declare, RenderNode) { "use strict"; return declare("TreeView.widget.TreeView.GraphNode", null, { @@ -50,9 +50,9 @@ define([ this._subscription = mx.data.subscribe({ guid: this.guid, callback: dojo.hitch(this, function (thing) { - if (dojo.isObject(thing)){ + if (dojo.isObject(thing)) { this.updateWithRefs(thing); - }else{ + } else { mx.data.get({ guid: thing, error: this.tree.showError, @@ -146,7 +146,7 @@ define([ var nocreate = false; if (type != this.tree._currentLoadingRel && isChild && type.constraint.length) { var xsettings = this.tree.getXsettings(type.parententity) - if (xsettings != null && xsettings.xburstattr){ + if (xsettings != null && xsettings.xburstattr) { nocreate = true; } } @@ -184,7 +184,7 @@ define([ if (newburst != this._burst) { this._burst = newburst; dojo.forEach(this.children, function (edgeSet) { - if (edgeSet){ + if (edgeSet) { edgeSet.knowsChildren = false; } }); @@ -210,7 +210,7 @@ define([ forNodes: function (func) { logger.debug("TreeView.widget.GraphNode.forNodes"); var l = this.nodes.length; - for (var i = 0; i < l; i++){ + for (var i = 0; i < l; i++) { func.call(this, this.nodes[i]); } }, @@ -275,10 +275,10 @@ define([ logger.debug("TreeView.widget.GraphNode.ensureChildren"); var c = this.children[type.index]; if (c.knowsChildren) { - mendix.lang.nullExec(callback); + callback && callback(); } else if (c._retrieving) { if (callback) { - c._afterChildrenCb.push(callback); + c._afterChildrenCb.push(callback); } } else { c._retrieving = true; @@ -312,7 +312,7 @@ define([ //1. mark edges from here in here invalid var edges = this.tree.getChildEdges(this)[rel.index]; - for (var childguid in edges){ + for (var childguid in edges) { edges[childguid]._valid = false; } diff --git a/src/TreeView/widget/TreeView/RenderEdge.js b/src/TreeView/widget/TreeView/RenderEdge.js index f853eb2..c12502c 100644 --- a/src/TreeView/widget/TreeView/RenderEdge.js +++ b/src/TreeView/widget/TreeView/RenderEdge.js @@ -4,7 +4,7 @@ define([ "dojo/_base/declare", "TreeView/widget/TreeView/RenderNode" -], function(declare, RenderNode) { +], function (declare, RenderNode) { "use strict"; return declare("TreeView.widget.TreeView.RenderEdge", null, { @@ -25,14 +25,14 @@ define([ this.tree = this.parent.tree; this.children = []; - var childNode = this.childNode = mxui.dom.create("ul", {"class": "gg_assoc_children gg_assoc_" + type.assoc.replace(".", "_")}); - var wrapperNode = this.domNode = mxui.dom.create("li", {"class": "gg_assoc_wrapper " + type.assocclazz}); + var childNode = this.childNode = mxui.dom.create("ul", { "class": "gg_assoc_children gg_assoc_" + type.assoc.replace(".", "_") }); + var wrapperNode = this.domNode = mxui.dom.create("li", { "class": "gg_assoc_wrapper " + type.assocclazz }); this.visible = type.showassocname; if (this.visible) { var fold = this.foldNode = mxui.dom.create("span", {}); - var caption = mxui.dom.create("span", {"class": "gg_assoc_title gg_assoc_" + type.assoc.replace(".", "_")}, type.assoccaption); - var div = new mxui.dom.create("div", {"class": "gg_row", "style": type.assocstyle}, fold, caption); + var caption = mxui.dom.create("span", { "class": "gg_assoc_title gg_assoc_" + type.assoc.replace(".", "_") }, type.assoccaption); + var div = new mxui.dom.create("div", { "class": "gg_row", "style": type.assocstyle }, fold, caption); dojo.place(div, wrapperNode); dojo.addClass(childNode, "gg_assoc_wrapped"); @@ -102,7 +102,7 @@ define([ break; } - if (!found){ + if (!found) { new RenderNode(this.tree.dict[childguid], this.parent, this.type); } } @@ -118,7 +118,7 @@ define([ dojo.style(this.childNode, "display", "none"); if (this.foldNode) //if wrapper node not visible, there is no foldnode.. dojo.attr(this.foldNode, "class", "gg_assocfold gg_fold gg_folded"); - mendix.lang.nullExec(cb); + cb && cb(); } //expand @@ -140,19 +140,19 @@ define([ this.updateFoldVisibility(); - mendix.lang.nullExec(cb); + cb && cb(); })); } } else - mendix.lang.nullExec(cb); + cb && cb(); }, updateFoldVisibility: function () { logger.debug("TreeView.widget.TreeView.RenderEdge.updateFoldVisibility"); if (this.foldNode) { - if (this.children.length == 0){ + if (this.children.length == 0) { dojo.style(this.foldNode, "visibility", "hidden"); } else { dojo.style(this.foldNode, "visibility", ""); @@ -168,16 +168,16 @@ define([ free: function () { logger.debug("TreeView.widget.TreeView.RenderEdge.free"); - if (this._destroyed){ + if (this._destroyed) { return; } this._destroyed = true; - for (var i = this.children.length - 1; i >= 0; i--){ + for (var i = this.children.length - 1; i >= 0; i--) { this.children[i].free(); } - if (this.domNode){ + if (this.domNode) { dojo.destroy(this.domNode); } } diff --git a/src/TreeView/widget/TreeView/RenderNode.js b/src/TreeView/widget/TreeView/RenderNode.js index 314e163..80f15fb 100644 --- a/src/TreeView/widget/TreeView/RenderNode.js +++ b/src/TreeView/widget/TreeView/RenderNode.js @@ -2,7 +2,7 @@ define([ "dojo/_base/declare", "TreeView/widget/TreeView/RenderEdge" -], function(declare, RenderEdge) { +], function (declare, RenderEdge) { "use strict"; return declare("TreeView.widget.TreeView.RenderNode", null, { @@ -34,14 +34,14 @@ define([ this.canHazChildren = this.graphNode.getChildTypes().length > 0; - this.foldNode = mxui.dom.create("span", {"class": "gg_nodefold gg_fold " + (this.canHazChildren ? "gg_folded" : "gg_nofold")}); + this.foldNode = mxui.dom.create("span", { "class": "gg_nodefold gg_fold " + (this.canHazChildren ? "gg_folded" : "gg_nofold") }); this.dataNode = mxui.dom.create("span", { "class": "gg_data", "style": this.graphNode.xsettings.entitystyle }); - this.childNode = mxui.dom.create("ul", {"class": "gg_children"}); - this.rowNode = mxui.dom.create("div", {"class": "gg_row"}, this.foldNode, this.dataNode); - this.domNode = mxui.dom.create("li", {"class": "gg_node " + this.graphNode.xsettings.entityclazz}, this.rowNode, this.childNode); + this.childNode = mxui.dom.create("ul", { "class": "gg_children" }); + this.rowNode = mxui.dom.create("div", { "class": "gg_row" }, this.foldNode, this.dataNode); + this.domNode = mxui.dom.create("li", { "class": "gg_node " + this.graphNode.xsettings.entityclazz }, this.rowNode, this.childNode); mxui.dom.data(this.domNode, "ggdata", this); @@ -73,11 +73,11 @@ define([ graphNode.nodes.push(this); - if (this.tree.expandall > this.depth){ + if (this.tree.expandall > this.depth) { this.setCollapsed(false); - }else if (this.tree.prefetch == true) { + } else if (this.tree.prefetch == true) { dojo.forEach(this.graphNode.getChildTypes(), function (type) { - if (!graphNode.children[type.index].knowsChildren){ + if (!graphNode.children[type.index].knowsChildren) { graphNode.ensureChildren(type, dojo.hitch(this, function () { this.children[type.index].placeChildren(); this.children[type.index].updateFoldVisibility(); @@ -95,12 +95,12 @@ define([ getVisibleParent: function () { logger.debug("TreeView.widget.TreeView.RenderNode.getVisibleParent"); - if (this.parent == null){ + if (this.parent == null) { return null; } var e = this.getEdge(); - if (e.visible){ + if (e.visible) { return e; } return this.parent; @@ -121,7 +121,7 @@ define([ logger.debug("TreeView.widget.TreeView.RenderNode.getChildCount"); var res = 0; dojo.forEach(this.children, function (edge) { - if (edge){ + if (edge) { res += edge.children.length; } }); @@ -131,7 +131,7 @@ define([ updateFoldVisibility: function () { logger.debug("TreeView.widget.TreeView.RenderNode.updateFoldVisibility"); if (this.foldNode) { - if (!this.hasVisibleEdge && this.getChildCount() == 0){ + if (!this.hasVisibleEdge && this.getChildCount() == 0) { dojo.style(this.foldNode, "visibility", "hidden"); } else { dojo.style(this.foldNode, "visibility", ""); @@ -143,8 +143,8 @@ define([ logger.debug("TreeView.widget.TreeView.RenderNode.findMaxIndex"); var max = -100000; dojo.forEach(this.children, function (edge) { - if (edge){ - for (var j = 0, c = null; c = edge.children[j++];){ + if (edge) { + for (var j = 0, c = null; c = edge.children[j++];) { max = Math.max(max, c.graphNode.getSortIndex()); } } @@ -156,8 +156,8 @@ define([ logger.debug("TreeView.widget.TreeView.RenderNode.findMinIndex"); var min = 100000; dojo.forEach(this.children, function (edge) { - if (edge){ - for (var j = 0, c = null; c = edge.children[j++];){ + if (edge) { + for (var j = 0, c = null; c = edge.children[j++];) { min = Math.min(min, c.graphNode.getSortIndex()); } } @@ -168,7 +168,7 @@ define([ setCollapsed: function (newvalue, cb) { logger.debug("TreeView.widget.TreeView.RenderNode.setCollapsed"); if (newvalue == this.collapsed) { - mendix.lang.nullExec(cb); + cb && cb(); return; } @@ -176,7 +176,7 @@ define([ if (this.collapsed) { dojo.style(this.childNode, "display", "none"); //TODO: anim dojo.attr(this.foldNode, "class", "gg_nodefold gg_fold " + (this.canHazChildren ? "gg_folded" : "gg_nofold")); - mendix.lang.nullExec(cb); + cb && cb(); } else { dojo.attr(this.foldNode, "class", "gg_nodefold gg_fold gg_loading"); @@ -188,7 +188,7 @@ define([ this.updateFoldVisibility(); - mendix.lang.nullExec(cb); + cb && cb(); }); var left = 0; @@ -218,9 +218,9 @@ define([ for (var i = 0, col = null; col = this.tree.columns[i]; i++) { if (col.appliesTo(this)) { - var span = mxui.dom.create("span", {"class": "gg_column gg_column_" + i}); + var span = mxui.dom.create("span", { "class": "gg_column gg_column_" + i }); this._colNodes.push(span); - this.dataNode.appendChild(mxui.dom.create("span", {"class": "gg_column_wrapper"}, span)); //wrapper column for hovers and such + this.dataNode.appendChild(mxui.dom.create("span", { "class": "gg_column_wrapper" }, span)); //wrapper column for hovers and such col.setupNode(span); } @@ -230,7 +230,7 @@ define([ draw: function (firstTime) { logger.debug("TreeView.widget.TreeView.RenderNode.draw"); var curCol = 0; - for (var i = 0, col = null; col = this.tree.columns[i]; i++){ + for (var i = 0, col = null; col = this.tree.columns[i]; i++) { if (col.appliesTo(this)) { col.render(this, this._colNodes[curCol], firstTime); curCol += 1; @@ -244,7 +244,7 @@ define([ return; this._destroyed = true; - if (this.tree.getSelection() == this){ + if (this.tree.getSelection() == this) { this.tree.setSelection(this.parent ? this.parent : null); } @@ -254,9 +254,9 @@ define([ } }); - if (this.parent){ + if (this.parent) { this.getEdge().remove(this); //this will destroy the domNode as well - } else if (this.domNode){ + } else if (this.domNode) { dojo.destroy(this.domNode); } }