Author: croberts Date: 2011-08-15 14:55:24 +0000 (Mon, 15 Aug 2011) New Revision: 4925
Modified: trunk/wooly/resources/mootools.js Log: Adding "select filtered" functionality to the large select widget.
Modified: trunk/wooly/resources/mootools.js =================================================================== --- trunk/wooly/resources/mootools.js 2011-08-15 14:54:37 UTC (rev 4924) +++ trunk/wooly/resources/mootools.js 2011-08-15 14:55:24 UTC (rev 4925) @@ -1850,7 +1850,8 @@ 'selected': 'Selected:', 'unselected': 'Unselected:', 'selectall': 'Select all', - 'selectnone': 'Select none', + 'selectedfiltered':'Select filtered', + 'selectnone': 'Clear', 'filter': 'Filter', 'in': 'in', 'out': 'out', @@ -1886,12 +1887,12 @@ this.showunselected, this.options.datasrc.getChildren().length - this.numselected); ul.grab(this.unselectedbtn); + + this.selectFilteredBtn = this.makebtn(this.options.labels.selectedfiltered, + this.selectFiltered, + ''); + ul.grab(this.selectFilteredBtn);
- this.selectAllBtn = this.makebtn(this.options.labels.selectall, - this.selectAll, - ''); - ul.grab(this.selectAllBtn); - this.selectNoneBtn = this.makebtn(this.options.labels.selectnone, this.selectNone, ''); @@ -1902,6 +1903,7 @@ // that filters based on what's been entered in the textfield filterbox_container = new Element('div', {'class': 'mtms_filterbox'}); this.filterbox = new Element('input', { + 'id':'filterbox', 'events': { 'keyup': function(evt){ if(this.options.case_sensitive){ @@ -1986,7 +1988,7 @@ this.fireEvent('rebuild', [this.options.datasrc.getChildren()]); this.update(0); }, - + // list is the list of option dom elements from the select elem // test is a function that gets used in the filter filter: function(list, test, reset){ @@ -1998,7 +2000,26 @@ this.filterbox.value = ""; } this.fireEvent('rebuild', [results]); + return results; //returning in the even that someone wants to do a filter(...).each() }, + + selectFiltered:function() { + var filter_by_text = ""; + if(this.options.case_sensitive){ + filter_by_text = function(item){ return item.text.contains($('filterbox').value)}; + } else { + filter_by_text = function(item){ return item.text.toLowerCase().contains($('filterbox').value.toLowerCase()) }; + } + results = this.filter(this.options.datasrc.getChildren(), filter_by_text, false); + results.each( + function(item){ + item.selected = true; + } + ); + this.fireEvent('rebuild', [results]); + this.update(this.options.datasrc.getChildren().length); + }, + update: function(numselected){ var total = this.options.datasrc.getChildren().length; this.totalbtn.getElement('span').set('text', total);
cumin-developers@lists.fedorahosted.org