You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by mt...@apache.org on 2006/08/01 21:28:04 UTC

svn commit: r427739 - in /incubator/xap/trunk: WebContent/examples/basic/datePicker.html WebContent/examples/basic/datePicker.xal src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js src/xap/bridges/basic/DatePickerBridge.js

Author: mturyn
Date: Tue Aug  1 14:28:04 2006
New Revision: 427739

URL: http://svn.apache.org/viewvc?rev=427739&view=rev
Log:
Now, "onXXX" events from the peer are by default translated into aBridge.fireEvent("onXXX") calls.

Modified:
    incubator/xap/trunk/WebContent/examples/basic/datePicker.html
    incubator/xap/trunk/WebContent/examples/basic/datePicker.xal
    incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js
    incubator/xap/trunk/src/xap/bridges/basic/DatePickerBridge.js

Modified: incubator/xap/trunk/WebContent/examples/basic/datePicker.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/basic/datePicker.html?rev=427739&r1=427738&r2=427739&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/basic/datePicker.html (original)
+++ incubator/xap/trunk/WebContent/examples/basic/datePicker.html Tue Aug  1 14:28:04 2006
@@ -12,7 +12,7 @@
 	<!-- Keep dojo from trying to scan this whole page for dojoType'd tags: -->
 	<script type="text/javascript">
 		djConfig = {
-			parseWidgets: false
+			parseWidgets: true
 		};
 	</script>    
 	
@@ -46,7 +46,7 @@
 		// including the object dojo.widget needed to create one
 		dojo.require("dojo.widget.*");   
 		dojo.require("dojo.event.*");            
-		dojo.require("dojo.widget.Button");  	                                          
+		dojo.require("dojo.widget.DatePicker");  	                                          
  	</script>
 
 	<script language="JavaScript" src="datePicker.js"> </script>
@@ -56,32 +56,34 @@
  
  
  </head>
- 
- <body onLoad="Xap.scanPage();if(xap.showStatus){xap.showStatus();};">
+  
+ <body onload="divv=document.getElementById('dp') ;dojo.widget.createWidget('datepicker',{widgetId:'dp'},divv);Xap.scanPage();if(xap.showStatus){xap.showStatus();}; ">
 	<script type="text/javascript">
 		DBG = new AjxDebug( AjxDebug.NONE, null, false ); 
 	</script>
-	<h1>Wrapped DIV managed by a xaplet embedded in another table cell:</h1>
+	<h1>A Dojo "DatePicker" wrapped by an AbstractBlackBoxWidgetBridge subclass, managed by a xaplet in a different cell.</h1>
 	
 	<table id="bigtable" border="4px" borderColor="#8866AA" width="80%" height="80%"
 		style="left:10%;top:10%"
 		cellpadding="20em" cellspacing="2px"
 		>
 		<tr><th width="30%">0.</th><th>1.</th></tr>
-		<tr><td><td/><td/></tr>
+		<tr><td>This is put here by plain old Dojo.<div  id="dp"/><td/><td></td></tr>
 		<tr><td id="xapStat"></td>		
 			<td><div context="../../"  id="applicationHome"
 				appName="MyApp" src="datePicker.xal" toolkit="dojo">This cell is the xap ClientSession "MyApp"'s home-base.</div>
 			</td>
 		</tr>
-		<tr><td  height="5em" id="targetNode" valign="top" align="left"/><td></td></tr>
+		<tr><td>This DatePicker was put here via a xap application:<div  height="5em" id="targetNode" valign="top" align="left"/></div></td><td></td></tr>
 		<tr><td height="30px" bgColor="#FFFFee"><strong>Try changing the year.</strong></td><td id="mouseOverDisplayer"/><td/></tr>
 	</table>
 
 
 	<!-- MyApp as the app name is a top-level alias for session
 	as this event handler illustrates -->	
-	<button onclick="alert(MyApp.getDocumentContainer().getUiDocument().toXml());">hello</button>
+	<button onclick="alert(MyApp.getDocumentContainer().getUiDocument().toXml());Xap.getAllDependencies('xap')">hello</button>
+	
+
 	<div id="foot">FOOTER TEXT</dev>
 
 

Modified: incubator/xap/trunk/WebContent/examples/basic/datePicker.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/basic/datePicker.xal?rev=427739&r1=427738&r2=427739&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/basic/datePicker.xal (original)
+++ incubator/xap/trunk/WebContent/examples/basic/datePicker.xal Tue Aug  1 14:28:04 2006
@@ -17,7 +17,12 @@
 				width="90px"
 				x="10px"
 				y="10px"
-				onCommand="javascript:alert('Year changed, event \'onIncrementYear\' triggered the code that created this box.')"
+				onIncrementDate="javascript:alert('Changed, event \'onIncrementDate\' triggered the DEFAULT code that created this box.')"
+				onIncrementWeek="javascript:alert('Changed, event \'onIncrementWeek\' triggered the DEFAULT code that created this box.')"
+				onIncrementMonth="javascript:alert('Changed, event \'onIncrementMonth\' triggered the DEFAULT code that created this box.')"
+				onIncrementYear="javascript:alert('Changed, event \'onIncrementYear\' triggered the NON-DEFAULT code that created this box.')"
+				onClick="javascript:alert('Changed, event \'onClick\' triggered the DEFAULT code that created this box.')"
+				onSetDate="javascript:alert('Changed, event \'onSetDate\' triggered the DEFAULT code that created this box.')"
 		/>	
    	</xm:append> 	  	
 

Modified: incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js?rev=427739&r1=427738&r2=427739&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js Tue Aug  1 14:28:04 2006
@@ -87,8 +87,18 @@
 }
 
 xap.bridges.basic.AbstractBlackBoxWidgetBridge.FUNCTION="function" ; 
+
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.ON="on" ;
+
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.s_IsFunction = function(aMember){
+	var typ =  typeof aMember ;
+	var eqq =  (typ== xap.bridges.basic.AbstractBlackBoxWidgetBridge.FUNCTION) ;
+	return eqq ;
+}
+
+
 xap.bridges.basic.AbstractBlackBoxWidgetBridge.interfaceMethods = 
-	{attributeSet:null,getEventSource:null,getEventTrigger:null,getDisplayDomNode:null,getRootDomNode:null} ;
+	{attributeSet:null,getEventTriggers:null,getDisplayDomNode:null,getRootDomNode:null} ;
 	
 xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.createPeer = function() {
 	var parent = this.getElement().getParent();
@@ -115,14 +125,23 @@
 			if(!this[meth] ){
 				throw new xap.util.Exception("Source object does not have member \""+ meth+"\".") ;
 			}
-			if( typeof this[meth] !=xap.bridges.basic.AbstractBlackBoxWidgetBridge.FUNCTION){
+			if( !xap.bridges.basic.AbstractBlackBoxWidgetBridge.s_IsFunction(this[meth]) ){
 				throw new xap.util.Exception("Source object member \""+ meth+"\" is not a function.") ;
 			}
 		}
 		
 		// O.K., this is an object we can use as a  bridge---go on:		
 		//var peer = this._peer ;  //We've got one already.
-		dojo.event.connect(this.getEventSource(),this.getEventTrigger(), this,"_onCommandEvent");				
+		var triggers = this.getEventTriggers() ;
+		// We now have a hash table containing a set of strings (triggers) pointing to 
+		// objects, like "[Foobar.]onBaz"--->aFoobarInstance
+		for(var  aKey in triggers){
+			var source = triggers[aKey] ;
+			var triggerPieces = aKey.split(".") ;
+			// handles both "foo" and "Me.foo"
+			var trigger  = triggerPieces[triggerPieces.length - 1] ;
+			dojo.event.connect(source,trigger, this,trigger);				
+		}
 	} else {
 		xap.bridges.basic.AbstractBlackBoxWidgetBridge.s_log.error("Bogus parent peer:" + parentPeer );
 	}
@@ -140,4 +159,42 @@
 }
 
 
+/**
+ *		Default behavior:  transfer all "onXXX" methods to the bridge:
+ **/ 
+ xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.onFuncMapper = new Object() ;
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.getEventTriggers = function () {
+	if(! this.eventTriggers ){
+		var triggerMap = new Object() ;
+		// Let's transfer all the "onXXX" methods over to the xal app:
+		for(var keyy in this._peer){
+			var member = this._peer[keyy] ;
+			if( !xap.bridges.basic.AbstractBlackBoxWidgetBridge.s_IsFunction(member) ){
+				continue ;
+			}
+			if(  keyy.substring(0,2)==xap.bridges.basic.AbstractBlackBoxWidgetBridge.ON){
+				triggerMap[keyy] = this._peer ;
+				// Create the callback for this "on..." method, if we don't have it:
+				if( !this[keyy]){
+					// This is the only way I could think of (that worked) to
+					// get the name of the event into the callback definition, so
+					// "onBlur"  --> this.fireEvent("onBlur")
+					this[keyy] = eval(  this.getStringForFireEventMethodString(keyy)	) ;
+				}
+			}
+		}
+		this.eventTriggers  = triggerMap ;
+	}
+	return  this.eventTriggers ;
+};
+
+// "Evil, be thou my good."---Marlowe's "Faust"
+// In the lack of a robust context-passing mechanism,
+// this is the only way I could think of to get the name of
+// the event into the function:
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.getStringForFireEventMethodString = function(keyy){
+	return " function(){\n"
+				+"this.fireEvent(\""+keyy+"\") ;\n"
+				+"		}"
+}
 

Modified: incubator/xap/trunk/src/xap/bridges/basic/DatePickerBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/basic/DatePickerBridge.js?rev=427739&r1=427738&r2=427739&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/basic/DatePickerBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/basic/DatePickerBridge.js Tue Aug  1 14:28:04 2006
@@ -65,7 +65,6 @@
 
 	xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.createPeer.call(this);
 	
-
 };
 
 
@@ -73,12 +72,7 @@
 xap.bridges.basic.DatePickerBridge.prototype.attributeSet = function () {
 	//TO_DO anything useful here?  format-string?
 };
-xap.bridges.basic.DatePickerBridge.prototype.getEventSource = function () {
-	return this._peer;
-};
-xap.bridges.basic.DatePickerBridge.prototype.getEventTrigger = function () {
-	return "onIncrementYear";
-};
+
 
 xap.bridges.basic.DatePickerBridge.prototype.getRootDomNode= function () {
 	return this._peer.domNode ;
@@ -89,4 +83,10 @@
 	return this.getRootDomNode() ;
 }
 
+
+
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.onIncrementYear = function(){
+	this.fireEvent("onIncrementYear") ;
+	var bkpt = true ;
+}