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/10/17 18:49:09 UTC

svn commit: r465000 - in /incubator/xap/trunk: WebContent/examples/widgets/ src/xap/bridges/dojo/ src/xap/widgets/dojo/

Author: mturyn
Date: Tue Oct 17 11:49:07 2006
New Revision: 465000

URL: http://svn.apache.org/viewvc?view=rev&rev=465000
Log:
Better inheritance---barely any code left in the password field widget and bridge.

Modified:
    incubator/xap/trunk/WebContent/examples/widgets/passwordField.html
    incubator/xap/trunk/WebContent/examples/widgets/passwordField.xal
    incubator/xap/trunk/WebContent/examples/widgets/textField.html
    incubator/xap/trunk/src/xap/bridges/dojo/PasswordFieldBridge.js
    incubator/xap/trunk/src/xap/bridges/dojo/TextFieldBridge.js
    incubator/xap/trunk/src/xap/widgets/dojo/PasswordField.js
    incubator/xap/trunk/src/xap/widgets/dojo/TextField.js

Modified: incubator/xap/trunk/WebContent/examples/widgets/passwordField.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/widgets/passwordField.html?view=diff&rev=465000&r1=464999&r2=465000
==============================================================================
--- incubator/xap/trunk/WebContent/examples/widgets/passwordField.html (original)
+++ incubator/xap/trunk/WebContent/examples/widgets/passwordField.html Tue Oct 17 11:49:07 2006
@@ -3,7 +3,7 @@
 <html>
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-    <title>Button</title>
+    <title>Password field</title>
 
 	<style type="text/css">
       <!--
@@ -19,7 +19,21 @@
 	</script>    
 	
 	<script language="JavaScript" type="text/javascript" src="../../xapcore.js"></script>
-   <script language="JavaScript" type="text/javascript" src="AttributeTester.js"></script>
+   	<script language="JavaScript" type="text/javascript" src="AttributeTester.js"></script>
+
+    <!--  script language="JavaScript">
+   		Xap._sourceRootDir = "../../" ; 	
+		Xap.addDebuggables(	
+							"xap.widgets.dojo.PasswordField",
+							"xap.widgets.dojo.TextField",							
+							"xap.bridges.dojo.PasswordFieldBridge",
+							"xap.bridges.dojo.TextFieldBridge",							
+							"xap.bridges.dojo.DojoWidgetBridge"																
+							) ;
+		Xap._loadDebuggables() ;
+	</script -->
+    
+
     
  </head>
   

Modified: incubator/xap/trunk/WebContent/examples/widgets/passwordField.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/widgets/passwordField.xal?view=diff&rev=465000&r1=464999&r2=465000
==============================================================================
--- incubator/xap/trunk/WebContent/examples/widgets/passwordField.xal (original)
+++ incubator/xap/trunk/WebContent/examples/widgets/passwordField.xal Tue Oct 17 11:49:07 2006
@@ -14,16 +14,38 @@
 	
 		<xal:passwordField width="200px" text="A text field"
 		id="testComponent" onEdit="mco:attributeSetter.reportEvent(event)"
+		onTextChange="mco:attributeSetter.reportEvent(event)"
 		/>
 		
 		
-		<!-- button specific properties -->
+		<!-- text/password-field specific properties -->
 		<xal:button width="200px" height="25px" 
 			text="text -> 'some new text'"
 			onCommand="mco:attributeSetter.setAttribute(testComponent,
 				'text','some new text')"/>
+
+		<xal:button width="200px" height="25px" 
+			text="Limit to 8 chars."
+			onCommand="mco:attributeSetter.setAttribute(testComponent,
+				'maxLength','8')"/>			
 				
-		
+		<xal:button width="200px" height="25px" 
+			text="...255 chars."
+			onCommand="mco:attributeSetter.setAttribute(testComponent,
+				'maxLength','255')"/>								
+		<xal:button width="200px" height="25px" 
+			text="Selectability ON"
+			onCommand="mco:attributeSetter.setAttribute(testComponent,
+				'selectable', 'true')"/>
+		<xal:button width="200px" height="25px" 
+			text="Selectability OFF" 
+			onCommand="mco:attributeSetter.setAttribute(testComponent,
+				'selectable','false')"/>
+				
+		<xal:button width="200px" height="25px" 
+			text="Toggle editability"
+			onCommand="mco:attributeSetter.toggleBooleanAttribute(testComponent,
+				'editable')"/>				
 		
 		<!--standard test things -->
 		

Modified: incubator/xap/trunk/WebContent/examples/widgets/textField.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/widgets/textField.html?view=diff&rev=465000&r1=464999&r2=465000
==============================================================================
--- incubator/xap/trunk/WebContent/examples/widgets/textField.html (original)
+++ incubator/xap/trunk/WebContent/examples/widgets/textField.html Tue Oct 17 11:49:07 2006
@@ -21,7 +21,7 @@
 	<script language="JavaScript" type="text/javascript" src="../../xapcore.js"></script>
    <script language="JavaScript" type="text/javascript" src="AttributeTester.js"></script>
     
-    <script languag="JavaScript">
+    <!--  script language="JavaScript">
    		Xap._sourceRootDir = "../../" ; 	
 		Xap.addDebuggables(		
 							"xap.widgets.dojo.TextField",
@@ -29,7 +29,7 @@
 							"xap.bridges.dojo.DojoWidgetBridge"																
 							) ;
 		Xap._loadDebuggables() ;
-	</script>
+	</script -->
     
  </head>
   

Modified: incubator/xap/trunk/src/xap/bridges/dojo/PasswordFieldBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/dojo/PasswordFieldBridge.js?view=diff&rev=465000&r1=464999&r2=465000
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/PasswordFieldBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/PasswordFieldBridge.js Tue Oct 17 11:49:07 2006
@@ -23,7 +23,7 @@
 
 Xap.provide("xap.bridges.dojo.PasswordFieldBridge"); 
 
-Xap.require("xap.bridges.dojo.DojoWidgetBridge");
+Xap.require("xap.bridges.dojo.TextFieldBridge");
 Xap.require("xap.widgets.dojo.PasswordField"); 
 Xap.require("xap.session.ClientEvent"); 
 
@@ -34,55 +34,24 @@
  */
  
 xap.bridges.dojo.PasswordFieldBridge= function() {
-	xap.bridges.dojo.DojoWidgetBridge.call(this);
+	xap.bridges.dojo.TextFieldBridge.call(this);
 }
 
 
 Xap.setupClassAsSubclassOf(
 				"xap.bridges.dojo.PasswordFieldBridge",
-				"xap.bridges.dojo.DojoWidgetBridge"						
+				"xap.bridges.dojo.TextFieldBridge"						
 );
 
 
 
-xap.bridges.dojo.PasswordFieldBridge.prototype.init = function() {
-	this.superclass.init.call(this);
-	
-	//add listener last so we don't fire for the initial set
-	dojo.event.connect(this.getPeer(), "onblur",this,"onblur");	
-}
-
 xap.bridges.dojo.PasswordFieldBridge.prototype.getPeerString = function(){
     return "PasswordField" ;
 }
 
- 
-/**
- * 
- * 
- * Attribute definitions
- * 
- */ 
+
  
  
-/**
- * No new dynamic attributes
- */
-xap.bridges.dojo.PasswordFieldBridge.prototype.getNewAllowedAttributes = function(){
-	return ["text"];
-}	
-
-xap.bridges.dojo.PasswordFieldBridge.prototype.setTextAttribute = function( value ){
-	this.getPeer().setText(value);
-}	
-
-xap.bridges.dojo.PasswordFieldBridge.prototype.onblur = function( ){
-	var text = this.getPeer().getText();
-	this.writeBackAttribute("text",text);
-	var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
-	clientEvent.text = text;
-	this.fireEvent("onEdit",null,null,clientEvent);
-}	
 
 
 

Modified: incubator/xap/trunk/src/xap/bridges/dojo/TextFieldBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/dojo/TextFieldBridge.js?view=diff&rev=465000&r1=464999&r2=465000
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/TextFieldBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/TextFieldBridge.js Tue Oct 17 11:49:07 2006
@@ -36,6 +36,7 @@
  
 xap.bridges.dojo.TextFieldBridge= function() {
 	xap.bridges.dojo.DojoWidgetBridge.call(this);
+	this.lastText = "" ;
 }
 
 
@@ -47,7 +48,7 @@
 
 
 xap.bridges.dojo.TextFieldBridge.prototype.init = function() {
-	this.superclass.init.call(this);
+	xap.bridges.dojo.DojoWidgetBridge.prototype.init.call(this);
 	
 	//add listener last so we don't fire for the initial set
 	dojo.event.connect(this.getPeer(), "onkeyup",this,"onTextChange");	
@@ -75,17 +76,22 @@
 }	
 
 xap.bridges.dojo.TextFieldBridge.prototype.setTextAttribute = function( value ){
+	this.lastText = value ;
 	this.getPeer().setText(value);
 }	
 
 xap.bridges.dojo.TextFieldBridge.prototype.onTextChange = function( event ){
-	var text = this.getPeer().getText();
-	var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
-	clientEvent.text = text;
-	clientEvent.originalEvent = event ;
-	// Probably shouldn't alter element on every keystroke:
-	//this.writeBackAttribute(xap.xml.XmlTokens.TEXT,newText);	
-	this.fireEvent("onTextChange",null,null,clientEvent);
+	var text = this.getPeer().getText() ;
+	// When text field size is limited, get a keyup even if there's been no 
+	// change, so we'll have to chack that there has been:
+	if ( text != this.lastText ){
+		this.lastText = text ;
+		var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
+		clientEvent.text = text;
+		clientEvent.originalEvent = event ;
+		this.lastKeyCode = event.keyCode ;	
+		this.fireEvent("onTextChange",null,null,clientEvent);
+	}
 }	
 
 /**
@@ -94,7 +100,6 @@
  * Problem:  This doesn't work under IE
 **/ 
 xap.bridges.dojo.TextFieldBridge.prototype.onEdit= function(event ){
-//	var oldText = this.getElement().getAttribute(xap.xml.XmlTokens.TEXT) ;
 	var newText = this.getPeer().getText();
 
 	var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
@@ -116,6 +121,7 @@
 	if (text && text.length> nMax){
 		// For the benefit of the onEdit event later on:
 		var newText = text.substring(0,nMax) ;
+		this.lastText = newText ;
 		// Trimmed so let the document know about that:
 		var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());	
 		clientEvent.text = newText;
@@ -138,12 +144,12 @@
 	}
 	if ( bSelectable == "false" ){
 		dojo.html.disableSelection(this.getPeer().domNode); 
-		// TODO: Move this to css a.s.a.p:
-		this.getPeer().domNode.style.fontWeight = "bold" ;
+		// TODO: Move this to css a.s.a.p.:
+		//this.getPeer().domNode.style.fontWeight = "bold" ;
 	} else {
 		dojo.html.enableSelection(this.getPeer().domNode); 
-		// TODO: Move this to css a.s.a.p:
-		this.getPeer().domNode.style.fontWeight = "normal" ;		
+		// TODO: Move this to css as soon as might be possible:
+		//this.getPeer().domNode.style.fontWeight = "normal" ;		
 	}
 	this.writeBackAttribute("selectable",bSelectable);	
 }	
@@ -156,14 +162,14 @@
 	this.getPeer().setReadOnly( bReadonly ) ;
 	this.writeBackAttribute("editable",bWritable);
 
-	// TODO: Move this to css a.s.a.p:
-	if( bReadonly == "true"){
-		this.setBackgroundColorAttribute("#ccccdd") ;
-		this.getPeer().domNode.style.borderStyle = "ridge" ;
-	} else {
-		this.setBackgroundColorAttribute("#ffffee") ;	
-		this.getPeer().domNode.style.borderStyle = "inset" ;		 
-	}	
+	// TODO: Move this to css a.s.a.p.:
+//	if( bReadonly == "true"){
+//		this.setBackgroundColorAttribute("#eeeeee") ;
+//		this.getPeer().domNode.style.borderStyle = "ridge" ;
+//	} else {
+//		this.setBackgroundColorAttribute("#ffffee") ;	
+//		this.getPeer().domNode.style.borderStyle = "inset" ;		 
+//	}	
 	
 }	
 

Modified: incubator/xap/trunk/src/xap/widgets/dojo/PasswordField.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/dojo/PasswordField.js?view=diff&rev=465000&r1=464999&r2=465000
==============================================================================
--- incubator/xap/trunk/src/xap/widgets/dojo/PasswordField.js (original)
+++ incubator/xap/trunk/src/xap/widgets/dojo/PasswordField.js Tue Oct 17 11:49:07 2006
@@ -4,36 +4,27 @@
 Xap.provide("xap.widgets.dojo.PasswordField");
 
 dojo.require("dojo.widget.*");
-dojo.require("dojo.widget.HtmlWidget");
+dojo.require("xap.widgets.dojo.TextField");
 dojo.require("dojo.dom");
 dojo.require("dojo.html");
 dojo.require("dojo.style");
 dojo.require("dojo.event");
 
+
 dojo.widget.tags.addParseTreeHandler("dojo:PasswordField");
 
 xap.widgets.dojo.PasswordField = function(){
-	dojo.widget.HtmlWidget.call(this);
+	xap.widgets.dojo.TextField.call(this);
+	// These will override the equivalent fields 
+	// that would otherwise be picked up in extend:
+	this.templateString ="<input type=\"password\" dojoAttachEvent=\"onchange;onkeyup;\"></input>" ;
+	this.widgetType = "PasswordField" ;
 }
 dojo.inherits(xap.widgets.dojo.PasswordField, dojo.widget.HtmlWidget);
 
-dojo.lang.extend(xap.widgets.dojo.PasswordField, {
-
-	templateString: '<input type="password" dojoAttachEvent="onblur"></input>',
-	templateCssPath: null ,
-	widgetType: "PasswordField",
-	isContainer: false,
-	
-	//hook for attach event
-	onblur: function(){
-	},
-	
-	setText: function( text ){
-		this.domNode.value = text;
-	},
-	
-	getText: function(){
-		return this.domNode.value;
-	}
-}
-);
\ No newline at end of file
+// As noted above, the templateString and widgetType have
+// already been set for this constructore, so they won't
+// be reset by the ones for TextField when we mix it in:				
+dojo.lang.extend(xap.widgets.dojo.PasswordField, 
+					new xap.widgets.dojo.TextField()
+				) ;
\ No newline at end of file

Modified: incubator/xap/trunk/src/xap/widgets/dojo/TextField.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/dojo/TextField.js?view=diff&rev=465000&r1=464999&r2=465000
==============================================================================
--- incubator/xap/trunk/src/xap/widgets/dojo/TextField.js (original)
+++ incubator/xap/trunk/src/xap/widgets/dojo/TextField.js Tue Oct 17 11:49:07 2006
@@ -1,7 +1,7 @@
 //IMPORTANT move this to some shared area
 dojo.widget.manager.registerWidgetPackage("xap.widgets.dojo");
 
-Xap.provide("xap.widgets.dojo.TextField");
+dojo.provide("xap.widgets.dojo.TextField");
 
 dojo.require("dojo.widget.*");
 dojo.require("dojo.widget.HtmlWidget");
@@ -17,57 +17,62 @@
 }
 dojo.inherits(xap.widgets.dojo.TextField, dojo.widget.HtmlWidget);
 
-dojo.lang.extend(xap.widgets.dojo.TextField, {
 
-	templateString: '<input type="text" dojoAttachEvent="onblur"></input>',
-	templateCssPath: null ,
-	widgetType: "TextField",
-	isContainer: false,
-	isRichText:false,
+xap.widgets.dojo.TextField.getMixinObject = function(){
+	var toMixIn  = 
+	{
+	
+		templateString: '<input type="text"  dojoAttachEvent="onkeyup;onchange;"></input>',
+		templateCssPath: null ,
+		widgetType: "TextField",
+		isContainer: false,
+		isRichText:false,
+		
+	
+		setText: function( text ){
+			this.domNode.value = text;
+		},
+		
+		getText: function(){
+			return this.domNode.value;
+		},
+		
+		setRichText: function( bRich ){
+			this._isRichText = bRich ;
+		},
+		
+		isRichText: function(){
+			return this._isRichText ;
+		},	
+	
+		setMaxLength: function( nMax ){
+			this.domNode.maxLength = nMax ;
+		},
+		
+		getMaxLength: function(){
+			return this.domNode.maxLength ;
+		},
+		
+		setReadOnly: function( bNonWritable ){
+			 var val = ""+bNonWritable ;
+			 var newVal = (val=="true")?true:false ;
+			 this.domNode.readOnly = newVal ;
+			 // Move this to css a.s.a.p:
+			 if( newVal=="true"){
+				this.domNode.style.backgroundColor= "#bbbbbb" ;
+			 } else {
+				this.domNode.style.backgroundColor= "#FFFFFF" ;		 
+			 }
+		},
+		
+		isReadOnly: function(){
+			return this.domNode.readOnly ;
+		}
 	
-	//hook for attach event
-	onblur: function(){
-	},
-	
-	setText: function( text ){
-		this.domNode.value = text;
-	},
-	
-	getText: function(){
-		return this.domNode.value;
-	},
-	
-	setRichText: function( bRich ){
-		this._isRichText = bRich ;
-	},
-	
-	isRichText: function(){
-		return this._isRichText ;
-	},	
-
-	setMaxLength: function( nMax ){
-		this.domNode.maxLength = nMax ;
-	},
-	
-	getMaxLength: function(){
-		return this.domNode.maxLength ;
-	},
-	
-	setReadOnly: function( bNonWritable ){
-		 var val = ""+bNonWritable ;
-		 var newVal = (val=="true")?true:false ;
-		 this.domNode.readOnly = newVal ;
-		 // Move this to css a.s.a.p:
-		 if( newVal=="true"){
-			this.domNode.style.backgroundColor= "#bbbbbb" ;
-		 } else {
-			this.domNode.style.backgroundColor= "#FFFFFF" ;		 
-		 }
-	},
-	
-	isReadOnly: function(){
-		return this.domNode.readOnly ;
-	}
+	} ;
 	
+	return toMixIn ;
 }
-);
\ No newline at end of file
+
+
+dojo.lang.extend(xap.widgets.dojo.TextField, xap.widgets.dojo.TextField.getMixinObject());