incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtu...@apache.org
Subject svn commit: r463821 - /incubator/xap/trunk/src/xap/bridges/dojo/TextFieldBridge.js
Date Fri, 13 Oct 2006 20:56:47 GMT
Author: mturyn
Date: Fri Oct 13 13:56:47 2006
New Revision: 463821

URL: http://svn.apache.org/viewvc?view=rev&rev=463821
Log:
1.) Separated "selectable" from "editable".
2.) Improved "onEdit" and "onTextChange".

Modified:
    incubator/xap/trunk/src/xap/bridges/dojo/TextFieldBridge.js

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=463821&r1=463820&r2=463821
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/TextFieldBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/TextFieldBridge.js Fri Oct 13 13:56:47 2006
@@ -26,6 +26,7 @@
 Xap.require("xap.bridges.dojo.DojoWidgetBridge");
 Xap.require("xap.widgets.dojo.TextField"); 
 Xap.require("xap.session.ClientEvent"); 
+Xap.require("dojo.html") ;
 
  /**
  * @fileoverview
@@ -49,8 +50,8 @@
 	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");	
-	dojo.event.connect(this.getPeer(), "onkeyup",this,"onTextChange");		
+	dojo.event.connect(this.getPeer(), "onkeyup",this,"onTextChange");	
+	dojo.event.connect(this.getPeer(), "onchange",this,"onEdit");			
 }
 
 xap.bridges.dojo.TextFieldBridge.prototype.getPeerString = function(){
@@ -77,56 +78,50 @@
 	this.getPeer().setText(value);
 }	
 
-xap.bridges.dojo.TextFieldBridge.prototype.onblur = function( ){
-	// Only do the rest if read-only:	
-	if( this.getPeer().isReadOnly() ){
-		return ;
-	}
+xap.bridges.dojo.TextFieldBridge.prototype.onTextChange = function( event ){
 	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);
+	clientEvent.originalEvent = event ;
+	// Probably shouldn't alter element on every keystroke:
+	//this.writeBackAttribute(xap.xml.XmlTokens.TEXT,newText);	
+	this.fireEvent("onTextChange",null,null,clientEvent);
 }	
 
 /**
- * Fires an onTextChange() iff the field has lost focus
+ * Fires an onEvent() iff the field has lost focus
  * and there has been a change in the text:
+ * Problem:  This doesn't work under IE
 **/ 
-xap.bridges.dojo.TextFieldBridge.prototype.onTextChange = function( kbdEvent ){
-	// Only do the rest if not read-only:	
-	if( this.getPeer().isReadOnly() ){
-		return false;
-	}
-	var oldText = this.getElement().getAttribute(xap.xml.XmlTokens.TEXT) ;
+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());
 
-	// fire an onTextChange() iff there's been a change:
-	if( oldText != newText ){
-		// I don't think we should change the element on
-		// every keystroke:
-		//this.writeBackAttribute(xap.xml.XmlTokens.TEXT,newText);
-		clientEvent.text = newText;
-		clientEvent.originalEvent = kbdEvent ;
-		this.fireEvent("onTextChange",null,null,clientEvent);
-	}
+	this.writeBackAttribute(xap.xml.XmlTokens.TEXT,newText);
+	clientEvent.text = newText;
+	clientEvent.originalEvent = event ;
+	this.fireEvent("onEdit",null,null,clientEvent);
+
 	return false ;	
 }
 
 
-
-
-
 xap.bridges.dojo.TextFieldBridge.prototype.setMaxLengthAttribute = function( nMax ){
 	this.getPeer().setMaxLength( nMax ) ;
 
 	// Trim text down, if needed:	
 	var text = this.getPeer().getText();
 	if (text && text.length> nMax){
-		text = text.substring(0,nMax) ;
-		this.setTextAttribute(text) ;	
+		// For the benefit of the onEdit event later on:
+		var newText = text.substring(0,nMax) ;
+		// Trimmed so let the document know about that:
+		var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());	
+		clientEvent.text = newText;
+		this.setTextAttribute(newText) ;
+		this.writeBackAttribute(xap.xml.XmlTokens.TEXT,newText);	
+		this.fireEvent("onEdit",null,null,clientEvent) ;
 	}
 }	
 
@@ -136,13 +131,23 @@
 }
 
 
-xap.bridges.dojo.TextFieldBridge.prototype.setSelectableAttribute = function( bWritable ){
-	this.setEditableAttribute(bWritable) ;
+xap.bridges.dojo.TextFieldBridge.prototype.setSelectableAttribute = function( bSelectable
){
+	if( this.getPeer().isReadOnly() ){
+		//ineditability trumps selectability setting:
+		return ;
+	}
+	if ( bSelectable == "false" ){
+		dojo.html.disableSelection(this.getPeer().domNode); 
+		// 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" ;		
+	}
+	this.writeBackAttribute("selectable",bSelectable);	
 }	
 
-xap.bridges.dojo.TextFieldBridge.prototype.getSelectableAttribute = function( ){
-	return (this.getEditableAttribute()=="false")?"false":"true" ;
-}
 
 xap.bridges.dojo.TextFieldBridge.prototype.setEditableAttribute = function( bWritable ){
 //alert("About to handle setEditableAttribute("+bWritable+").");
@@ -150,8 +155,7 @@
 	var bReadonly = (bWritable=="false")?"true":"false" ;
 	this.getPeer().setReadOnly( bReadonly ) ;
 	this.writeBackAttribute("editable",bWritable);
-	this.writeBackAttribute("selectable",bWritable);
-	
+
 	// TODO: Move this to css a.s.a.p:
 	if( bReadonly == "true"){
 		this.setBackgroundColorAttribute("#ccccdd") ;
@@ -164,12 +168,6 @@
 }	
 
 
-// The peer thinks in terms of "readOnly" or not, we set using the opposite sense,
-// as "editable"=="non-readOnly":
-
-xap.bridges.dojo.TextFieldBridge.prototype.getEditableAttribute = function( ){
-	return ""+ !Boolean(this.getPeer().getReadOnly()) ;
-}
 
 
 



Mime
View raw message