[richfaces-svn-commits] JBoss Rich Faces SVN: r14660 - in branches/community/3.3.X/ui/inplaceInput/src/main: resources/org/richfaces/renderkit/html/scripts and 1 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Jun 18 13:50:41 EDT 2009


Author: konstantin.mishin
Date: 2009-06-18 13:50:41 -0400 (Thu, 18 Jun 2009)
New Revision: 14660

Modified:
   branches/community/3.3.X/ui/inplaceInput/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java
   branches/community/3.3.X/ui/inplaceInput/src/main/resources/org/richfaces/renderkit/html/scripts/inplaceinput.js
   branches/community/3.3.X/ui/inplaceInput/src/main/templates/inplaceinput.jspx
Log:
RF-7397

Modified: branches/community/3.3.X/ui/inplaceInput/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java
===================================================================
--- branches/community/3.3.X/ui/inplaceInput/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java	2009-06-18 12:02:43 UTC (rev 14659)
+++ branches/community/3.3.X/ui/inplaceInput/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java	2009-06-18 17:50:41 UTC (rev 14660)
@@ -108,47 +108,14 @@
 	return false;
     }
 
-    public String encodeScriptAttributes(FacesContext context, UIComponent component) {
-    	StringBuilder attributes = new StringBuilder();
-    	attributes.append("var attributes = ");
-    	
-    	ScriptOptions options = new ScriptOptions(component);
-    	
+    public String getDefaultLabel(FacesContext context, UIComponent component) {
     	String defaultLabel = (String)component.getAttributes().get("defaultLabel");
-
     	if (defaultLabel == null || defaultLabel.trim().equals("")) {
-	    defaultLabel = EMPTY_DEFAULT_LABEL;
+    		defaultLabel = EMPTY_DEFAULT_LABEL;
     	}
-    	
-    	options.addOption("defaultLabel", defaultLabel);
-    	options.addOption("showControls");
-    	options.addOption("editEvent");
-    	options.addOption("selectOnEdit");
-    	options.addOption("verticalPosition", component.getAttributes().get("controlsVerticalPosition"));
-    	options.addOption("horizontalPosition", component.getAttributes().get("controlsHorizontalPosition"));
-    	options.addOption("inputWidth");
-    	options.addOption("minInputWidth");
-    	options.addOption("maxInputWidth");
-    	attributes.append(options.toScript());
-    	  	
-    	return attributes.toString();
+    	return defaultLabel;
     }
-      
-    public String encodeScriptEvents(FacesContext context, UIComponent component) {
-    	StringBuilder events = new StringBuilder();
-    	
-    	events.append("var events = ");
-    	ScriptOptions options = new ScriptOptions(component);
-    	options.addEventHandler("oneditactivation");
-    	options.addEventHandler("onviewactivation");
-    	options.addEventHandler("oneditactivated");
-    	options.addEventHandler("onviewactivated");
-    	options.addEventHandler("onchange");
-    	events.append(options.toScript());
-    	
-    	return events.toString();
-    }
-        
+    
     public String getAsEventHandler(FacesContext context, UIComponent component, String attributeName) {
 	JSFunctionDefinition script = getUtils().getAsEventHandler(context, component, attributeName, null);  
 	return ScriptUtils.toScript(script);

Modified: branches/community/3.3.X/ui/inplaceInput/src/main/resources/org/richfaces/renderkit/html/scripts/inplaceinput.js
===================================================================
--- branches/community/3.3.X/ui/inplaceInput/src/main/resources/org/richfaces/renderkit/html/scripts/inplaceinput.js	2009-06-18 12:02:43 UTC (rev 14659)
+++ branches/community/3.3.X/ui/inplaceInput/src/main/resources/org/richfaces/renderkit/html/scripts/inplaceinput.js	2009-06-18 17:50:41 UTC (rev 14660)
@@ -8,15 +8,21 @@
 
 Richfaces.InplaceInput.prototype = {
 	//TODO: remove $$$$$
-	initialize: function(clientId, temValueKeepId, valueKeepId, tabberId, attributes, events, userStyles, commonStyles, barParams) {
-		//TODO: delete tabberId from parameters
+	initialize: function(clientId, options) {
 		this.inplaceInput = $(clientId);
 		this.inplaceInput.component = this;
 		
-		this.tempValueKeeper = $(temValueKeepId);
-		this.valueKeeper = $(valueKeepId);
-		this.attributes = attributes;
-		this.events = events;
+		this.tempValueKeeper = $(clientId + "tempValue");
+		this.valueKeeper = $(clientId + "value");
+		this.attributes = {
+				editEvent : "onclick",
+				verticalPosition : "center",
+				horizontalPosition : "right",
+				minInputWidth : "40px",
+				maxInputWidth : "500px"				
+		};
+		Object.extend(this.attributes, options.attributes);
+		this.events = options.events || {};
 		 
 		//TODO: static methods are preferred to be called within constructor
 		this.currentText = this.getCurrentText();
@@ -26,9 +32,7 @@
 		this.prevState = Richfaces.InplaceInput.STATES[0];
 		
 		if (this.attributes.showControls) {
-			//TODO: Consider passing attributes by name instead of by index
-			this.bar = new Richfaces.InplaceInputBar(barParams[0], barParams[1], barParams[2], barParams[3], barParams[4],  
-													 this.attributes.verticalPosition, this.attributes.horizontalPosition);
+			this.bar = new Richfaces.InplaceInputBar(clientId, this.attributes.verticalPosition, this.attributes.horizontalPosition);
 		}
 		//TODO: move converting 'on'-event to prototype style to utils
 		
@@ -38,7 +42,7 @@
 		
 		this.initHandlers();	
 		this.initEvents();
-		this.classes = Richfaces.mergeStyles(userStyles,commonStyles.getCommonStyles());
+		this.classes = Richfaces.mergeStyles(options.userStyles,new Richfaces.InplaceInputStyles().getCommonStyles());
 		this["rich:destructor"] = "destroy";
 		
 		this.skipSwitching = false;
@@ -391,12 +395,12 @@
 
 Richfaces.InplaceInputBar = Class.create();
 Richfaces.InplaceInputBar.prototype = {
-	initialize : function(barId, okId, cancelId, buttonsPanelId, buttonsShadowId, verticalPosition, horizontalPosition) {
-		this.bar = $(barId);
-		this.ok = $(okId);
-		this.cancel = $(cancelId);
-		this.bsPanel = $(buttonsPanelId);
-		this.buttonsShadow = $(buttonsShadowId);
+	initialize : function(id, verticalPosition, horizontalPosition) {
+		this.bar = $(id + "bar");
+		this.ok = $(id + "ok");
+		this.cancel = $(id + "cancel");
+		this.bsPanel = $(id + "buttons");
+		this.buttonsShadow = $(id + "btns_shadow");
 		
 		this.verticalPosition = verticalPosition;
 		this.horizontalPosition = horizontalPosition;

Modified: branches/community/3.3.X/ui/inplaceInput/src/main/templates/inplaceinput.jspx
===================================================================
--- branches/community/3.3.X/ui/inplaceInput/src/main/templates/inplaceinput.jspx	2009-06-18 12:02:43 UTC (rev 14659)
+++ branches/community/3.3.X/ui/inplaceInput/src/main/templates/inplaceinput.jspx	2009-06-18 17:50:41 UTC (rev 14660)
@@ -64,19 +64,19 @@
 	   	
 	   	String styleClass = (String)component.getAttributes().get("styleClass");
 	   	styleClass = styleClass != null ? styleClass.trim() : "";
-	   	variables.setVariable("styleClass", styleClass);
+	   	variables.setVariable("styleClass", styleClass.trim());
 	   	
 	   	String changedClass = (String)component.getAttributes().get("changedClass");
 	   	changedClass = (changedClass != null ? changedClass.trim() : "") + " " + styleClass;
-	   	variables.setVariable("changedClass", changedClass);
+	   	variables.setVariable("changedClass", changedClass.trim());
 	   	
 	   	String viewClass = (String)component.getAttributes().get("viewClass");
 	   	viewClass = (viewClass != null ? viewClass.trim() : "") + " " + styleClass;
-	   	variables.setVariable("viewClass", viewClass);
+	   	variables.setVariable("viewClass", viewClass.trim());
 	   	
 	   	String editClass = (String)component.getAttributes().get("editClass");
 	   	editClass = (editClass != null ? editClass.trim() : "") + " " + styleClass;
-	   	variables.setVariable("editClass", editClass);
+	   	variables.setVariable("editClass", editClass.trim());
 		
 	   	String layout = (String)component.getAttributes().get("layout");
 	   	if (layout != null && layout.length() != 0) {
@@ -176,29 +176,43 @@
 				 }
 				 ]]>
 			</jsp:scriptlet>
+			<c:scriptObject var="attributes">
+				<c:scriptOption name="defaultLabel" value="#{this:getDefaultLabel(context, component)}" />
+				<c:scriptOption attributes="showControls, selectOnEdit, inputWidth" />
+				<c:scriptOption attributes="editEvent" defaultValue="onclick"/>
+				<c:scriptOption name="verticalPosition" value="#{component.attributes['controlsVerticalPosition']}" defaultValue="center" />
+				<c:scriptOption name="horizontalPosition" value="#{component.attributes['controlsHorizontalPosition']}" defaultValue="right" />
+				<c:scriptOption attributes="minInputWidth" defaultValue="40px"/>
+				<c:scriptOption attributes="maxInputWidth" defaultValue="500px"/>
+			</c:scriptObject>
+			<c:scriptObject var="events">
+				<c:scriptOption attributes="oneditactivation, onviewactivation, oneditactivated, onviewactivated, onchange" wrapper="eventHandler" /> 
+			</c:scriptObject>
+			<c:scriptObject var="view">
+				<c:scriptOption name="normal" value="#{viewClass}" />
+				<c:scriptOption name="hovered" value="#{component.attributes['viewHoverClass']}" />
+			</c:scriptObject>
+			<c:scriptObject var="changed">
+				<c:scriptOption name="normal" value="#{changedClass}" />
+				<c:scriptOption name="hovered" value="#{component.attributes['changedHoverClass']}" />
+			</c:scriptObject>
+			<c:scriptObject var="componentStyles">
+				<c:scriptOption variables="view, changed" />
+				<c:scriptOption name="editable" value="#{editClass}" />
+			</c:scriptObject>
+			<c:scriptObject var="userStyles">
+				<c:scriptOption name="component" value="#{componentStyles}" />
+			</c:scriptObject>
+			<c:scriptObject var="options">
+				<c:scriptOption variables="attributes, events, userStyles" />
+			</c:scriptObject>
 			<script type="text/javascript">
 		
-			#{this:encodeScriptAttributes(context, component)};
-			#{this:encodeScriptEvents(context, component)};
-						
-			var inplaceInputUserStyles = {
-					component:{
-						view :{
-							normal:'#{viewClass}', 
-							hovered:'#{component.attributes["viewHoverClass"]}' 
-						},
-						changed:{
-							normal:'#{changedClass}',
-							hovered:'#{component.attributes["changedHoverClass"]}'
-						},
-						editable:'#{editClass}'
-						 
-					}
-			};
-		
-			var inplaceInput = new Richfaces.InplaceInput('#{clientId}', '#{clientId}tempValue', '#{clientId}value', '#{clientId}tabber', 
-													  attributes, events, inplaceInputUserStyles, new Richfaces.InplaceInputStyles(), ['#{clientId}bar', 
-													  '#{clientId}ok', '#{clientId}cancel', '#{clientId}buttons','#{clientId}btns_shadow']);
+			var inplaceInput = new Richfaces.InplaceInput('#{clientId}'
+				<c:if test="#{not empty options}">
+				, <f:writeAsScript value="#{options}" />
+				</c:if> 					
+			);
 		</script>			
 		</div>
 				




More information about the richfaces-svn-commits mailing list