incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtu...@apache.org
Subject svn commit: r487727 - in /incubator/xap/trunk/src/xap: bridges/xap/ListBoxBridge.js bridges/xap/XapComboBoxBridge.js widgets/ListBox.js widgets/ListItem.js
Date Sat, 16 Dec 2006 00:14:27 GMT
Author: mturyn
Date: Fri Dec 15 16:14:27 2006
New Revision: 487727

URL: http://svn.apache.org/viewvc?view=rev&rev=487727
Log:
Make sure that the element element 'value' and 'text' attributes are updated immediately after
a list item has been added to a listbox, and after a listbox has been added to a combobox.

This functionality was formerly handled with an onChange event at startup, which latter was
deemed undesirable.

Modified:
    incubator/xap/trunk/src/xap/bridges/xap/ListBoxBridge.js
    incubator/xap/trunk/src/xap/bridges/xap/XapComboBoxBridge.js
    incubator/xap/trunk/src/xap/widgets/ListBox.js
    incubator/xap/trunk/src/xap/widgets/ListItem.js

Modified: incubator/xap/trunk/src/xap/bridges/xap/ListBoxBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/xap/ListBoxBridge.js?view=diff&rev=487727&r1=487726&r2=487727
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/xap/ListBoxBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/xap/ListBoxBridge.js Fri Dec 15 16:14:27 2006
@@ -90,7 +90,7 @@
 	clientEvent.value = valtext.value ; ;
 	clientEvent.text = valtext.text ;
 	this.fireEvent("onStateChange",null,null,clientEvent);	
-	
+
 }
 
 
@@ -164,13 +164,27 @@
 //		dojo.event.connect(option,eventNames[jj],childHandler,"onChange") ;
 //	}	
 
-	// We should always use "onChange" to reset values
-	// to make sure values are propagated upwards if this
-	// is pwned by a ComboBoxBridge
-	this.onChange( this.fakeDomEvent() ) ;
+}
+
+// Adjust world to changes from adding a new option list item:
+xap.bridges.xap.ListBoxBridge.prototype.childAdded  = function(anEvent){
+
+	this.superclass.childAdded.call(this,anEvent) ;
 
+	// These might two arrays, or two strings:;
+	// the getPeer() should be fine, since we've
+	// just added a child and not thrown an error:
+	var valtext = this.getPeer().getTextValuePairs(this.getPeer().select) ; 
+
+	if( valtext.text ){
+		this.writeBackAttribute("text", valtext.text ) ;
+	}
+	if( valtext.value ){
+		this.writeBackAttribute("value", valtext.value ) ;
+	}
 }
 
+
 xap.bridges.xap.ListBoxBridge.prototype.removeChild = function( childHandler ){
 	var peer = this.getPeer() ;
 	peer.removeChild(childHandler.getPeer());
@@ -178,8 +192,9 @@
 	// See addChild() above:
 	if(this.isChildOfComboBox){
 		// ComboBox "size" is always 1, so list isn't displayed
-		// until we might want it to be:
+		// until top is clicked
 		peer.size = 1 ;
+		
 	} else {
 		// ListBox "size" is always at least 2, so the 
 		// list is always displayed---though not necesarily all at

Modified: incubator/xap/trunk/src/xap/bridges/xap/XapComboBoxBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/xap/XapComboBoxBridge.js?view=diff&rev=487727&r1=487726&r2=487727
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/xap/XapComboBoxBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/xap/XapComboBoxBridge.js Fri Dec 15 16:14:27 2006
@@ -73,10 +73,12 @@
 	
 
 	if( this._childHandler ){
+	// If we're swapping listboxes in and out, disconnect the unlinked one's events:
 		dojo.event.disconnect(this._childHandler,"onChange",this,"onChange") ;
-		dojo.event.disconnect(this._childHandler,"onKeyDown",this,"onKeyDown") ;
-		dojo.event.disconnect(this._childHandler,"onMouseUp",this,"onMouseUp") ;		
-		
+-		dojo.event.disconnect(this._childHandler,"onKeyDown",this,"onKeyDown") ;
+-		dojo.event.disconnect(this._childHandler,"onMouseUp",this,"onMouseUp") ;
+		dojo.event.connect(childHandler,"childAdded",this,"listboxAddedOrRemovedChild") ;
+		dojo.event.connect(childHandler,"removeChild",this,"listboxAddedOrRemovedChild") ;
 	}
 
 	childHandler.isChildOfComboBox = true;
@@ -107,19 +109,49 @@
 		this._childListbox.select.style.height = "100%" ;
 	}
 
-	
 
 	// Notice events in the child:
 	dojo.event.connect(childHandler,"onChange",this,"onChange") ;
+	dojo.event.connect(childHandler,"childAdded",this,"listboxAddedOrRemovedChild") ;
+	dojo.event.connect(childHandler,"removeChild",this,"listboxAddedOrRemovedChild") ;
+
 }
 
 
+xap.bridges.xap.XapComboBoxBridge.prototype.listboxAddedOrRemovedChild  = function(anEvent){
+	// These should be two strings, since the child 
+	// should be a single-valued list box.
+	// The getPeer() should be fine, since we've
+	// just added a child and not thrown an error:
+	var select = this._childListbox.select ;
+	// Also:  there must be a selected value for a combobox; if
+	// there is none such yet, choose the first one by default:
+	if( select.selectedIndex == -1 && select.options.length > 0 ){
+		select.selectedIndex = 0 ;
+	}
+
+	var valtext 
+		= this._childListbox.getTextValuePairs(select) ; 
+
+	if( valtext.text ){
+		this.writeBackAttribute("text", valtext.text ) ;
+	}
+	if( valtext.value ){
+		this.writeBackAttribute("value", valtext.value ) ;
+	}
+}
+
 xap.bridges.xap.XapComboBoxBridge.prototype.onChange = function(event){
 	if(this._disabled || !this._childListbox){
 		return ;
 	}
-	var valueAndText = this._childListbox.getTextValuePairs(event.originalTarget) ;	
-	if(valueAndText.value){
+	var valueAndText = this._childListbox.getTextValuePairs(event.originalTarget) ;
+	var hasValue = 	(valueAndText.value)?true:false ;
+	// Deal with IE case:
+	if( !window.netscape &&valueAndText.value == "null" ){
+		hasValue = false ;
+	}
+	if(hasValue){
 		this.writeBackAttribute("value", valueAndText.value );	
 	}
 	if(valueAndText.text){
@@ -131,8 +163,6 @@
 	clientEvent.text = valueAndText.text ;	
 	this.fireEvent("onCommand",null,null,clientEvent);		
 }
-
-
 
 
 

Modified: incubator/xap/trunk/src/xap/widgets/ListBox.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/ListBox.js?view=diff&rev=487727&r1=487726&r2=487727
==============================================================================
--- incubator/xap/trunk/src/xap/widgets/ListBox.js (original)
+++ incubator/xap/trunk/src/xap/widgets/ListBox.js Fri Dec 15 16:14:27 2006
@@ -42,23 +42,21 @@
 		},
 
 		addChild: function(child) { /* elementListItem */
-			
 			this.select.appendChild(child.domNode);
 			//alert('adding an option');
 			if( this.multiselect){
 				++this.select.size ;
 			}
-			
 		},
 		removeChild: function(child) {
 			
 			//this.select.removeChild(child.domNode);
-
-
 			var options = this.select.options
 			
 			for (var i = 0; i < options.length; i++) {
 				if (options[i] == child.domNode){
+
+
 					options[i] = null;
 				}
 				/* IE doesn't update the page with dom node removal so we have to do this*/
@@ -132,7 +130,7 @@
 			}
 			result={text:null, value:null} ;
 			if( !select.multiple ){
-				var val = select.value || "";
+				var val = select.value ;
 				if( val ){
 					result.value = val ;	
 					if( select.selectedIndex != -1 ){

Modified: incubator/xap/trunk/src/xap/widgets/ListItem.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/ListItem.js?view=diff&rev=487727&r1=487726&r2=487727
==============================================================================
--- incubator/xap/trunk/src/xap/widgets/ListItem.js (original)
+++ incubator/xap/trunk/src/xap/widgets/ListItem.js Fri Dec 15 16:14:27 2006
@@ -30,6 +30,7 @@
 		isSelected: function(){
 			return this.domNode.selected?true:false ;
 		},
+		
 		handler: null
 	}
 );



Mime
View raw message