incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtu...@apache.org
Subject svn commit: r430906 - /incubator/xap/trunk/src/xap/Xap.js
Date Fri, 11 Aug 2006 21:54:57 GMT
Author: mturyn
Date: Fri Aug 11 14:54:57 2006
New Revision: 430906

URL: http://svn.apache.org/viewvc?rev=430906&view=rev
Log:
Halfway to producing another way of specifying sessions:  with a function call on Xap before
we start creating them (with a function call changed from scanPage() to createAllPredefinedSession()).

Modified:
    incubator/xap/trunk/src/xap/Xap.js

Modified: incubator/xap/trunk/src/xap/Xap.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/Xap.js?rev=430906&r1=430905&r2=430906&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/Xap.js (original)
+++ incubator/xap/trunk/src/xap/Xap.js Fri Aug 11 14:54:57 2006
@@ -141,31 +141,74 @@
 Xap.APPLICATION_SOURCE_ATTRIBUTE__NAME = "xapSrc" ;
 Xap.APPLICATION_TOOLKIT_ATTRIBUTE__NAME = "xapToolkit" ;
 
-Xap.scanPage = function(){
+Xap.xapletCount = 0 ;
+
+
+Xap.scanPage= function(){
 	var allPossibleContainerNodes = Xap._findAppElements() ;
 	if( !window.xapSessionIds){
 		window.xapSessionIds = new Array( 0 ) ;
 	}
+	// information may already be here from a script in the html file:
+	if( !Xap.predefinedSessions){
+	// ...or not:
+		Xap.predefinedSessions = new Array( 0 ) ;
+	}
 	for (var i =0; i<allPossibleContainerNodes.length; i++){
+		var thisSessionsParameters = new Object() ;
 		var element = allPossibleContainerNodes[i] ; 	
 		if( !element.getAttribute ){
 			continue;
 		}
-		var thisElementsAppName = null ;		
-		thisElementsAppName = element.getAttribute(Xap.APPLICATION_ID_ATTRIBUTE__NAME);
-		if(!thisElementsAppName){
-			continue;
-		}
+		// The HTML DOM node from which we're getting all these attributes....
+		thisSessionsParameters.htmlElement = element ;	
+
 		// What's the XAL file?---required
-		var src = element.getAttribute(Xap.APPLICATION_SOURCE_ATTRIBUTE__NAME);	
-		// What's the toolkit?---dojo?---defaults to zimbra if null
-		var toolkit = element.getAttribute(Xap.APPLICATION_TOOLKIT_ATTRIBUTE__NAME);
+		thisSessionsParameters.xapSrc = element.getAttribute(Xap.APPLICATION_SOURCE_ATTRIBUTE__NAME);

+		if(! thisSessionsParameters.xapSrc  ){
+			continue ;
+		}
+
+
+		// What's the i.d.?---if none passed in, generate one:	
+		thisSessionsParameters.xapId = element.getAttribute(Xap.APPLICATION_ID_ATTRIBUTE__NAME);
+		var passedInId = true ;
+
+		if(! thisSessionsParameters.xapId  ){
+			passedInId = false ;
+			thisSessionsParameters.xapId = "xaplet_"+ (++Xap.xapletCount) ;
+		}
+	
+		// What's the toolkit?---dojo?---defaults to zimbra if null	
+		thisSessionsParameters.xapToolkit = element.getAttribute(Xap.APPLICATION_TOOLKIT_ATTRIBUTE__NAME);
+		
 		// what's the load context for plugin.xml or its equivalent?---default to boot context:
-		var context = Xap._sourceRootDir ;
+		thisSessionsParameters.xapContext = Xap._sourceRootDir ;
 		if( element.getAttribute(Xap.APPLICATION_CONTEXT_ATTRIBUTE__NAME)){
-			context = element.getAttribute(Xap.APPLICATION_CONTEXT_ATTRIBUTE__NAME) ;
+			thisSessionsParameters.xapContext  = element.getAttribute(Xap.APPLICATION_CONTEXT_ATTRIBUTE__NAME)
;
 		};
 		
+		Xap.predefinedSessions.push(thisSessionsParameters) ;
+		
+	}
+}
+
+
+/**
+ * Uses the data gathered into Xap.predefinedSessions to create them:
+**/ 
+Xap.createAllPredefinedSessions = function(){
+	// Gather any information on sessions found in the page
+	Xap.scanPage() ;
+	
+	for( var j=0; j<Xap.predefinedSessions.length; ++j ){
+		var thisSessionDef = Xap.predefinedSessions[j] ;
+		var thisElementsAppName = thisSessionDef.xapId ;
+		var src = thisSessionDef.xapSrc ;	
+		var toolkit = thisSessionDef.xapToolkit ;
+		var context = thisSessionDef.xapContext ;		
+		var element = thisSessionDef.htmlElement ;				
+
 		var session = Xap.createSession(context, src, toolkit , element);
 		// these might be handy to keep around:
 		session[Xap.APPLICATION_ID_ATTRIBUTE__NAME] = thisElementsAppName ;
@@ -177,10 +220,7 @@
 		if (window[thisElementsAppName]==null){
 			window[thisElementsAppName]= session;
 			window.xapSessionIds.push( thisElementsAppName ) ;
-		}
-		
-		
-		else{
+		} else{
 			//TODO throw some error?
 		}
 	}
@@ -188,6 +228,22 @@
 
 
 
+
+Xap.defineSession = function(src, xapletName,elementId,context,toolkit){
+
+	if( !Xap.predefinedSessions){
+		Xap.predefinedSessions = new Array( 0 ) ;
+	}
+	var newSess = new Object() ;
+	newSess.xapId = xapletName ;
+	newSess.xapContext = context ;	
+	newSess.xapSrc = src  ;
+	newSess.xapToolkit =  toolkit ;
+	newSess.htmlElement = document.getElementId(elementId) ;
+
+
+	Xap.predefinedSessions.push(newSess) ;
+}
 
 
 



Mime
View raw message