incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmarga...@apache.org
Subject svn commit: r486795 - in /incubator/xap/trunk/src/xap/bridges/xap: ListBoxBridge.js XapComboBoxBridge.js
Date Wed, 13 Dec 2006 18:54:16 GMT
Author: jmargaris
Date: Wed Dec 13 10:54:14 2006
New Revision: 486795

URL: http://svn.apache.org/viewvc?view=rev&rev=486795
Log:
Michael's changes plus a couple of fixes

Modified:
    incubator/xap/trunk/src/xap/bridges/xap/ListBoxBridge.js
    incubator/xap/trunk/src/xap/bridges/xap/XapComboBoxBridge.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=486795&r1=486794&r2=486795
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/xap/ListBoxBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/xap/ListBoxBridge.js Wed Dec 13 10:54:14 2006
@@ -41,41 +41,35 @@
 
 
 xap.bridges.xap.ListBoxBridge.prototype.init = function() {
+	// Keep us from firing events first off:
+	var initialDisabledState = this._disabled ;
+	this._disabled = true ;
+
 	xap.bridges.dojo.DojoWidgetBridge.prototype.init.call(this);
 	
-	var eventNames = xap.bridges.xap.ListBoxBridge.selectEventNames	 ;
-	// Make sure there's something to connect-to:
-	for(var jj=0; jj<eventNames.length; ++jj){
-		var name = eventNames[jj] ;
-		if (typeof this.getPeer().select[name] == "undefined" ){
-			this.getPeer().select[name]=function(event){} ;	
-		}
-	}
-
-	//add listeners last so we don't fire for the initial set
-	dojo.event.connect(this.getPeer().select, "onchange",this,"onChange");	
-	dojo.event.connect(this.getPeer().select, "onmouseup",this,"onMouseup");	
-	dojo.event.connect(this.getPeer().select, "onkeydown",this,"onKeyDown");	
-}
-
-//xap.bridges.xap.ListBoxBridge.prototype.getPeerOnCommandEvent = function(){
-//	return "onSelect" ;
-//}
+	
+	// Make sure there's something for onChange to connect-to:
+	if (typeof this.getPeer().select.onchange == "undefined" ){
+			this.getPeer().select.onchange=function(event){} ;	
+	}
+	
+	dojo.event.connect(this.getPeer().select,"onchange",this,"onChange") ;	
 
-xap.bridges.xap.ListBoxBridge.prototype.onChange = function(event){
-	this._onSelectOrChange(event) ;
-	var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
-	clientEvent.originalEvent = event ;
-	this.fireEvent("onCommand",null,null,clientEvent);
+	// Now we'll pass on events....
+	//this._initted = true ;
+	this._disabled = initialDisabledState ;
 }
 
 
+xap.bridges.xap.ListBoxBridge.prototype.onChange = function(event,eventType){
 
-
-xap.bridges.xap.ListBoxBridge.prototype._onSelectOrChange = function(event){
+	if(this._disabled){
+		return ;
+	}
 
 	// Default:
 	var select = this.getPeer().select ;
+
 	if(event && event.originalTarget){
 		select = event.originalTarget ;
 	}
@@ -83,18 +77,51 @@
 	// These might two arrays, or two strings:
 	var valtext = this.getPeer().getTextValuePairs(select) ; 
 
-	this.writeBackAttribute("text", valtext.text ) ;
-	this.writeBackAttribute("value", valtext.value ) ;
+	if( valtext.text ){
+		this.writeBackAttribute("text", valtext.text ) ;
+	}
+	if( valtext.value ){
+		this.writeBackAttribute("value", valtext.value ) ;
+	}
+	
+	var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
+	clientEvent.originalEvent = event ;
+
+	clientEvent.value = valtext.value ; ;
+	clientEvent.text = valtext.text ;
+	this.fireEvent("onStateChange",null,null,clientEvent);	
+	
+}
+
+
+xap.bridges.xap.ListBoxBridge.prototype.onSelectItem = function(event,eventType){
+
+	if(this._disabled){
+		return ;
+	}
+
+	// Default:
+	var optionItem = event.originalTarget ;
+	if( !optionItem ){
+		return ;
+	}
+
+	var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
+	clientEvent.originalEvent = event ;
+
+	clientEvent.value = optionItem.value ; ;
+	clientEvent.text = optionItem.text ;
+	this.fireEvent("onSelect",null,null,clientEvent);	
+	
 }
 
+
 // The events associated with list items.
-//TODO: See if we can safely discard any of the following events---	// can they all induce
a change in the selected status of an option item?
+//TODO: See if we can safely discard any of the following events---	
+// can they all induce a change in the "selected" status of an option item?
 xap.bridges.xap.ListBoxBridge.itemEventNames 
 	=["onmousedown","onmouseup","onkeypress","onkeydown","onkeyup"] ;
 	
-//more?	
-xap.bridges.xap.ListBoxBridge.selectEventNames 
-	=["onmousedown","onkeydown","onchange"] ;
 
 xap.bridges.xap.ListBoxBridge.prototype.addChild = function(childHandler) {
 	
@@ -102,16 +129,6 @@
 	var childPeer = childHandler.getPeer();
 	childPeer.setDetail(elementListItem.getAttribute('text'),  elementListItem.getAttribute('value'));
 	
-//Deprecated	this.getPeer().setOnStateChange(this, 'fireEvent', 'onChange')	
-	
-// Hard to find a good point in the list item bridge creation to do this,
-// so do it here---need it to write back changes in "selected" status;
-// this isn't so bad, since isolated listbox items are useless.
-     var option = this.getPeer().domNode ;
-     var eventNames = xap.bridges.xap.ListBoxBridge.itemEventNames ;
-     for(var jj=0; jj<eventNames.length ; ++jj){
-     	dojo.event.connect(option,eventNames[jj],childHandler,"onChange") ;
-     }
 	
 	var peer = this.getPeer() ;
 	peer.addChild(childPeer);
@@ -135,18 +152,17 @@
 		}		
 	
 	}
+
 	
-//	
-//	if (this._setEventOnce) {
-//		this.getPeer().setOnStateChange(this, 'fireEvent', 'onStateChange');
-//		this._setEventOnce = false;
-//	}
-	
-	// If this is a combo box child, it must have a default value---
-	// use the first option if there is none selected yet:
-	if( this.isChildOfComboBox && !this.getPeer().select.value){
-		this.getPeer().select.selectedIndex = 0 ;
-	}
+// Hard to find a good point in the list item bridge creation to do this,
+// so do it here---need it to write back changes in "selected" status;
+// this isn't so bad, since isolated listbox items are useless.
+// As usual, put this last to avoid hearing "adding item" events on first display.
+//	var option = this.getPeer().domNode ;
+//	var eventNames = xap.bridges.xap.ListBoxBridge.itemEventNames ;
+//	for(var jj=0; jj<eventNames.length ; ++jj){
+//		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
@@ -254,7 +270,15 @@
 	this.getPeer().setVisible(pszVisible);
 }
 
+xap.bridges.xap.ListBoxBridge.prototype.onMouseDown = function(event){
+	xap.bridges.dojo.DojoWidgetBridge.prototype.onMouseDown.call(this,event) ;
+	this.onSelectItem(event) ;
+}
 
+xap.bridges.xap.ListBoxBridge.prototype.onKeyPress = function(event){
+	xap.bridges.dojo.DojoWidgetBridge.prototype.onKeyPress.call(this,event) ;
+	this.onSelectItem(event) ;
+}
 
 
 xap.bridges.xap.ListBoxBridge.prototype.fakeDomEvent = function(){	
@@ -262,21 +286,8 @@
 }	
 
 
-xap.bridges.xap.ListBoxBridge.prototype.onKeyUp = function(event){
-	var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
-	clientEvent.originalEvent = event ;
-	this.fireEvent("onKeyUp",null,null,clientEvent);
-}
-xap.bridges.xap.ListBoxBridge.prototype.onKeyDown = function(event){
-	var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
-	clientEvent.originalEvent = event ;
-	this.fireEvent("onKeyDown",null,null,clientEvent);
-}
-xap.bridges.xap.ListBoxBridge.prototype.onMouseUp = function(event){
-	var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
-	clientEvent.originalEvent = event ;
-	this.fireEvent("onMouseUp",null,null,clientEvent);
-}
+
+
 
 
 

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=486795&r1=486794&r2=486795
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/xap/XapComboBoxBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/xap/XapComboBoxBridge.js Wed Dec 13 10:54:14 2006
@@ -43,10 +43,14 @@
 //	return "onSelect" ;
 //}
 //
-//xap.bridges.xap.XapComboBoxBridge.prototype.init = function(){
-//	xap.bridges.dojo.DojoWidgetBridge.prototype.init.call(this) ;
-//	this.autoAttachBridgeEventsToPeerEvents() ;
-//}
+xap.bridges.xap.XapComboBoxBridge.prototype.init = function(){
+	// Keep us from firing events first off:
+	var initialDisabledState = this._disabled ;
+	this._disabled = true ;
+
+	xap.bridges.dojo.DojoWidgetBridge.prototype.init.call(this);
+	this._disabled = initialDisabledState ;
+}
 
 
 xap.bridges.xap.XapComboBoxBridge.prototype.getNewAllowedAttributes = function() {
@@ -66,6 +70,7 @@
 }
 
 xap.bridges.xap.XapComboBoxBridge.prototype.addChild = function(childHandler) {
+	
 
 	if( this._childHandler ){
 		dojo.event.disconnect(this._childHandler,"onChange",this,"onChange") ;
@@ -106,33 +111,30 @@
 
 	// Notice events in the child:
 	dojo.event.connect(childHandler,"onChange",this,"onChange") ;
-	dojo.event.connect(childHandler,"onKeyUp",this,"onKeyUp") ;
-	dojo.event.connect(childHandler,"onKeyDown",this,"onKeyDown") ;
-	dojo.event.connect(childHandler,"onMouseUp",this,"onMouseUp") ;
 }
 
 
 xap.bridges.xap.XapComboBoxBridge.prototype.onChange = function(event){
-	this._onSelectOrChange(event) ;
+	if(this._disabled || !this._childListbox){
+		return ;
+	}
+	var valueAndText = this._childListbox.getTextValuePairs(event.originalTarget) ;	
+	if(valueAndText.value){
+		this.writeBackAttribute("value", valueAndText.value );	
+	}
+	if(valueAndText.text){
+		this.writeBackAttribute("text", valueAndText.text);
+	}
 	var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
-	clientEvent.originalEvent = event ;	
+	clientEvent.originalEvent = event ;
+	clientEvent.value = valueAndText.value ; ;
+	clientEvent.text = valueAndText.text ;	
 	this.fireEvent("onCommand",null,null,clientEvent);		
 }
 
 
 
-xap.bridges.xap.XapComboBoxBridge.prototype._onSelectOrChange = function(event){
 
-// These already should have been set, since the
-// basic dojo "connect" connects _after_ the
-// connected-to function---in this case, the child
-// listbox's handler's "onChange".  If we had wanted
-// the opposite behaviour, we'd have used "connectBefore"
-// in addChild above.
-	var xapNode = this._childHandler.getElement() ;
-	this.writeBackAttribute("value", xapNode.getAttribute("value"));	
-	this.writeBackAttribute("text", xapNode.getAttribute("text"));
-}
 
 xap.bridges.xap.XapComboBoxBridge.prototype.setColorAttribute = function(value){
 	this.getPeer().setColor( value ) ;
@@ -204,24 +206,6 @@
 	}	
 }
 
-
-
-
-xap.bridges.xap.XapComboBoxBridge.prototype.onKeyUp = function(event){
-	var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
-	clientEvent.originalEvent = event ;
-	this.fireEvent("onKeyUp",null,null,clientEvent);
-}
-xap.bridges.xap.XapComboBoxBridge.prototype.onKeyDown = function(event){
-	var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
-	clientEvent.originalEvent = event ;
-	this.fireEvent("onKeyDown",null,null,clientEvent);
-}
-xap.bridges.xap.XapComboBoxBridge.prototype.onMouseUp = function(event){
-	var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
-	clientEvent.originalEvent = event ;
-	this.fireEvent("onMouseUp",null,null,clientEvent);
-}
 
 
 



Mime
View raw message