From 342c020822f3543968b367ae66ec850c2cd9d6bf Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 31 Aug 2010 21:22:43 +0000 Subject: [PATCH] added support for specifying a dojo.data-style query to select options in the filtering select to 'disable'. disabling greys the background and prevents selection of the items in question git-svn-id: svn://svn.open-ils.org/ILS/trunk@17416 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../js/dojo/openils/widget/FilteringTreeSelect.js | 40 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js b/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js index ac5fe1af4..1833f9570 100644 --- a/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js +++ b/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js @@ -24,6 +24,7 @@ if(!dojo._hasResource["openils.widget.FilteringTreeSelect"]){ parentField : 'parent', labelAttr : 'name', childField : 'children', + disableQuery : null, tree : null, startup : function() { @@ -44,6 +45,33 @@ if(!dojo._hasResource["openils.widget.FilteringTreeSelect"]){ this.store = new dojo.data.ItemFileReadStore({data:storeData}); } this.inherited(arguments); + + if(this.dataList.length > 0 && this.disableQuery) + this._setDisabled(); + }, + + _setDisabled : function() { + + // tag disabled items + this.store.fetch({ + query : this.disableQuery, + onItem : function(item) { item._disabled = 'true'; } + }); + + // disallow selecting of disabled items + var self = this; + dojo.connect(this, 'onChange', + function(ident) { + if(!ident) return; + self.store.fetchItemByIdentity({ + identity : ident, + onItem : function(item) { + if(item._disabled == 'true') + self.attr('value', ''); + } + }); + } + ); }, // Compile the tree down to a depth-first list of dojo data items @@ -52,18 +80,24 @@ if(!dojo._hasResource["openils.widget.FilteringTreeSelect"]){ var storeItem = node.toStoreItem(); storeItem._depth = depth++; this.dataList.push(storeItem); + for(var i in node[this.childField]()) this._makeNodeList(node[this.childField]()[i], depth); }, // For each item, find the depth at display time by searching up the tree. _getMenuLabelFromItem : function(item) { + + var style = 'padding-left:'+ (item._depth * this.defaultPad) +'px;'; + + if(item._disabled == 'true') // TODO: external CSS + style += 'background-color:#CCC;cursor:wait'; + return { html: true, - label: '
' + - this.store.getValue(item, this.labelAttr) + '
' + label: '
' + this.store.getValue(item, this.labelAttr) + '
' } - } + }, } ); } -- 2.11.0