[richfaces-svn-commits] JBoss Rich Faces SVN: r5645 - in trunk/sandbox/ui/progressBAR/src/main: java/org/richfaces/renderkit and 3 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Jan 25 13:22:06 EST 2008


Author: andrei_exadel
Date: 2008-01-25 13:22:06 -0500 (Fri, 25 Jan 2008)
New Revision: 5645

Modified:
   trunk/sandbox/ui/progressBAR/src/main/config/component/progressBar.xml
   trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java
   trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/css/progressBar.xcss
   trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js
   trunk/sandbox/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx
Log:
Progress bar component refactoring

Modified: trunk/sandbox/ui/progressBAR/src/main/config/component/progressBar.xml
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/config/component/progressBar.xml	2008-01-25 17:15:29 UTC (rev 5644)
+++ trunk/sandbox/ui/progressBAR/src/main/config/component/progressBar.xml	2008-01-25 18:22:06 UTC (rev 5645)
@@ -84,18 +84,6 @@
 			<description>CSS class that defines style for complete state of the component</description>
 		</property>
 		<property>
-			<name>determined</name>
-			<classname>boolean</classname>
-			<description>Attribute defines if component should render percent value</description>
-			<defaultvalue>true</defaultvalue>
-		</property>
-		<property>
-			<name>permanent</name>
-			<classname>boolean</classname>
-			<description>Attribute defines background should be permanent</description>
-			<defaultvalue>false</defaultvalue>
-		</property>
-		<property>
 			<name>reRenderAfterComplete</name>
 			<classname>java.lang.String</classname>
 			<description>Set of componets to rerender after completion</description>

Modified: trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java	2008-01-25 17:15:29 UTC (rev 5644)
+++ trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java	2008-01-25 18:22:06 UTC (rev 5645)
@@ -24,6 +24,7 @@
 import org.ajax4jsf.context.AjaxContextImpl;
 import org.ajax4jsf.javascript.JSFunction;
 import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.JSReference;
 import org.ajax4jsf.javascript.ScriptUtils;
 import org.ajax4jsf.renderkit.AjaxRendererUtils;
 import org.ajax4jsf.renderkit.ComponentVariables;
@@ -46,8 +47,10 @@
     /** Expression for params string split */
     private static final String SPLIT_EXPRS = "[;,]";
 
+    /** Request parameter name containing component state to render */
     private static final String FORCE_STATE_PARAM = "forceState";
 
+    /** Ajax function performing polling */
     private static final String AJAX_POLL_FUNCTION = "A4J.AJAX.Poll";
 
     /*
@@ -73,11 +76,10 @@
 	Map params = request.getParameterMap();
 	if (params.containsKey(FORCE_STATE_PARAM)) {
 	    ajaxContext.addComponentToAjaxRender(uiComponent);
-	    String [] str = (String [])params.get(FORCE_STATE_PARAM);
+	    String[] str = (String[]) params.get(FORCE_STATE_PARAM);
 	    for (String s : str) {
-		uiComponent.getAttributes().put(FORCE_STATE_PARAM,s);
+		uiComponent.getAttributes().put(FORCE_STATE_PARAM, s);
 	    }
-
 	} else if (percent.doubleValue() < maxValue.doubleValue()
 		&& params.containsKey("percent")) {
 	    ajaxContext.removeRenderedArea(uiComponent
@@ -99,7 +101,7 @@
     }
 
     /**
-     * TODO Description goes here.
+     * Render progress state forced from javascript
      * @param state
      * @param context
      * @param component
@@ -118,7 +120,7 @@
     }
 
     /**
-     * TODO Description goes here.
+     * Gets state forced from javascript
      * @param component
      * @return
      */
@@ -131,7 +133,6 @@
 
     /**
      * Returns ajax response data
-     * 
      * @param uiComponent
      * @param percent
      * @return
@@ -143,9 +144,15 @@
 	buffer.append(percent);
 	buffer.append(",");
 
-	buffer.append("data:");
-	buffer.append(percent);
+	buffer.append("interval:");
+	buffer.append(progressBar.getInterval());
 	buffer.append(",");
+	
+	if (progressBar.getAttributes().get("style") != null) {
+	    buffer.append("style:");
+	    buffer.append(progressBar.getAttributes().get("style"));
+	    buffer.append(",");
+	}
 
 	boolean enabled = (Boolean) uiComponent.getAttributes().get("enabled");
 	buffer.append("enabled:");
@@ -158,11 +165,6 @@
 		.getAttributes().get("remainClass"));
 	addStyles2Responce(buffer, "styleClass", (String) uiComponent
 		.getAttributes().get("styleClass"));
-	addStyles2Responce(buffer, "initialClass", (String) uiComponent
-		.getAttributes().get("initialClass"));
-	addStyles2Responce(buffer, "finishClass", (String) uiComponent
-		.getAttributes().get("finishClass"));
-
 	return buffer.toString();
 
     }
@@ -220,26 +222,8 @@
 	    JSFunction function = AjaxRendererUtils.buildAjaxFunction(
 		    component, context, AJAX_POLL_FUNCTION);
 
-	    Map options = AjaxRendererUtils.buildEventOptions(context,
-		    component);
-	    Integer interval = new Integer(progressBar.getInterval());
-	    options.put("pollId", clientId);
-	    options.put("pollinterval", interval);
-	    Map parameters = (Map) options.get("parameters");
-	    parameters.put("percent", "percent");
-	    options.put("oncomplete", getOnComplete(clientId, progressBar,
-		    context, writer, options));
-	    pollScript.append("ProgressBar.Pollers['" + clientId
-		    + "']['options'] = " + ScriptUtils.toScript(options)
-		    + ";\n");
-	    Object onsubmit = component.getAttributes().get("onsubmit");
-	    if (null != onsubmit) {
-		JSFunctionDefinition onsubmitFunction = new JSFunctionDefinition();
-		onsubmitFunction.addToBody(onsubmit);
-		options.put("onsubmit", onsubmitFunction);
-	    }
-
-	    function.addParameter(options);
+	    function.addParameter(new JSReference("ProgressBar.Pollers['"
+		    + clientId + "']['options']"));
 	    function.appendScript(script);
 
 	    pollScript.append(script);
@@ -253,7 +237,8 @@
     }
 
     /**
-     * TODO Description goes here.
+     * Encodes script for label rendering in client
+     * 
      * @param context
      * @param component
      * @throws IOException
@@ -273,7 +258,8 @@
     }
 
     /**
-     * TODO Description goes here.
+     * Encode initial javascript
+     * 
      * @param context
      * @param component
      * @throws IOException
@@ -281,44 +267,72 @@
     public void encodeInitialScript(FacesContext context, UIComponent component)
 	    throws IOException {
 	ResponseWriter writer = context.getResponseWriter();
-	
+	UIProgressBar progressBar = (UIProgressBar) component;
+	AjaxContext ajaxContext = AjaxContextImpl.getCurrentInstance(context);
 	writer.startElement(HTML.SPAN_ELEM, component);
 	writer.startElement(HTML.SCRIPT_ELEM, component);
 
 	StringBuffer script = new StringBuffer();
 	String clientId = component.getClientId(context);
-	String containerId = ((UIComponent)AjaxRendererUtils.findAjaxContainer(context, component)).getClientId(context);
-	String formId = ((UIComponent)AjaxRendererUtils.getNestingForm(component)).getClientId(context);
-	String mode = (String)component.getAttributes().get("mode");
-	Integer minValue = (Integer)component.getAttributes().get("minValue");
-	Integer maxValue = (Integer)component.getAttributes().get("maxValue");
-	
-	script.append("new ProgressBar().init('")
-	.append(clientId)
-	.append("','")
-	.append(containerId)
-	.append("','")
-	.append(formId)
-	.append("','")
-	.append(mode)	
-	.append("',")
-	.append(minValue)
-	.append(",")
-	.append(maxValue)
-	.append(",");
+	String containerId = ((UIComponent) AjaxRendererUtils
+		.findAjaxContainer(context, component)).getClientId(context);
+	String formId = ((UIComponent) AjaxRendererUtils
+		.getNestingForm(component)).getClientId(context);
+	String mode = (String) component.getAttributes().get("mode");
+	Integer minValue = (Integer) component.getAttributes().get("minValue");
+	Integer maxValue = (Integer) component.getAttributes().get("maxValue");
+
+	script.append("new ProgressBar().init('").append(clientId)
+		.append("','").append(containerId).append("','").append(formId)
+		.append("','").append(mode).append("',").append(minValue)
+		.append(",").append(maxValue).append(",");
 	writer.write(script.toString());
 	writeScriptBody(context, component, true);
 	script = new StringBuffer();
 	script.append(",");
 	script.append(ScriptUtils.toScript(getParametersMap(component)));
+	script.append(",");
+	script.append(ScriptUtils.toScript(buildAjaxOptions(clientId,
+		progressBar, context)));
+	String progressVar = (String)component.getAttributes().get("progressVar");
+	if (progressVar != null) {
+	    script.append(",'");
+	    script.append(progressVar);
+	    script.append("'");
+	}else {
+	    script.append(",null");
+	}
+	
 	script.append(");\n");
 	writer.write(script.toString());
-	
+
 	writer.endElement(HTML.SCRIPT_ELEM);
 	writer.endElement(HTML.SPAN_ELEM);
     }
 
     /**
+     * Creates options map for AJAX requests
+     * 
+     * @param clientId
+     * @param progressBar
+     * @param context
+     * @return
+     */
+    private Map buildAjaxOptions(String clientId, UIProgressBar progressBar,
+	    FacesContext context) {
+	Map options = AjaxRendererUtils.buildEventOptions(context, progressBar);
+	Integer interval = new Integer(progressBar.getInterval());
+	options.put("pollId", clientId);
+	options.put("pollinterval", interval);
+	Map parameters = (Map) options.get("parameters");
+	parameters.put("percent", "percent");
+	options
+		.put("oncomplete",
+			getOnComplete(clientId, progressBar, context));
+	return options;
+    }
+
+    /**
      * Check if component mode is AJAX
      * 
      * @param component
@@ -340,8 +354,7 @@
      * @return
      */
     public JSFunctionDefinition getOnComplete(String clientId,
-	    UIProgressBar component, FacesContext context,
-	    ResponseWriter writer, Map options) {
+	    UIProgressBar component, FacesContext context) {
 	JSFunctionDefinition functionDefinition = new JSFunctionDefinition();
 	functionDefinition.addParameter("request");
 	functionDefinition.addParameter("event");
@@ -385,6 +398,7 @@
 	if (initial != null) {
 	    renderChild(context, initial);
 	}
+	encodeInitialScript(context, component);
 	if (isAjaxMode(component)) {
 	    encodePollScript(context, component);
 	}
@@ -393,27 +407,8 @@
     }
 
     /**
-     * Sets up the progressVar page attribute
+     * Encodes progress state of the component
      * 
-     * @param context -
-     *                facesContext
-     * @param component -
-     *                component instance
-     * @param value -
-     *                percent value
-     */
-    public void setProgressVar(FacesContext context, UIComponent component,
-	    Number persent) {
-	String progresssVar = (String) component.getAttributes().get(
-		"progressVar");
-	if (progresssVar != null) {
-	    Map attrs = context.getExternalContext().getRequestMap();
-	    attrs.put(progresssVar, persent);
-	}
-    }
-
-    /**
-     * TODO Description goes here.
      * @param context
      * @param component
      * @throws IOException
@@ -440,7 +435,7 @@
     }
 
     /**
-     * Encodes progress state of component
+     * Encodes html of component
      * 
      * @param context -
      *                faces context
@@ -458,56 +453,41 @@
 
 	String width = String.valueOf(value.intValue());
 	String style = (String) component.getAttributes().get("style");
-	Boolean permanent = (Boolean) component.getAttributes()
-		.get("permanent");
-	if (!(permanent != null && permanent.booleanValue())) {
 
-	    String completeClass = (String) component.getAttributes().get(
-		    "completeClass");
+	String completeClass = (String) component.getAttributes().get(
+		"completeClass");
 
-	    String remainClass = (String) component.getAttributes().get(
-		    "remainClass");
+	String remainClass = (String) component.getAttributes().get(
+		"remainClass");
 
-	    writer.startElement("div", component);
-	    getUtils().writeAttribute(writer, "class",
-		    remainClass + " rich-progress-bar-base");
-	    getUtils().writeAttribute(writer, "id", clientId + ":remain");
-	    getUtils().writeAttribute(writer, "style", style);
+	writer.startElement("div", component);
+	getUtils().writeAttribute(writer, "class",
+		remainClass + " rich-progress-bar-base");
+	getUtils().writeAttribute(writer, "id", clientId + ":remain");
+	getUtils().writeAttribute(writer, "style", style);
 
-	    writer.endElement("div");
-	    writer.startElement("div", component);
-	    getUtils().writeAttribute(writer, "class",
-		    "rich-progress-bar-uploaded");
-	    getUtils().writeAttribute(writer, "id", clientId + ":upload");
-	    getUtils().writeAttribute(
-		    writer,
-		    "style",
-		    (style != null ? style + ";" : "") + " width: " + width
-			    + "%;");
+	writer.endElement("div");
+	writer.startElement("div", component);
+	getUtils()
+		.writeAttribute(writer, "class", "rich-progress-bar-uploaded");
+	getUtils().writeAttribute(writer, "id", clientId + ":upload");
+	getUtils().writeAttribute(writer, "style",
+		(style != null ? style + ";" : "") + " width: " + width + "%;");
 
-	    writer.startElement("div", component);
-	    getUtils().writeAttribute(writer, "class",
-		    completeClass + " rich-progress-bar-base");
-	    getUtils().writeAttribute(writer, "id", clientId + ":complete");
-	    getUtils().writeAttribute(writer, "style", style);
+	writer.startElement("div", component);
+	getUtils().writeAttribute(writer, "class",
+		completeClass + " rich-progress-bar-base");
+	getUtils().writeAttribute(writer, "id", clientId + ":complete");
+	getUtils().writeAttribute(writer, "style", style);
 
-	    writer.endElement("div");
+	writer.endElement("div");
 
-	    writer.endElement("div");
+	writer.endElement("div");
 
-	    if (isAjaxMode(component)) {
-		encodePollScript(context, component);
-	    }
-	} else {
-	    writer.startElement("div", component);
-	    getUtils().writeAttribute(writer, "class",
-		    "rich-progress-bar-permanent");
-	    getUtils().writeAttribute(writer, "style", style + " width: 100%");
-	    writer.endElement("div");
-	    if (isAjaxMode(component)) {
-		encodePollScript(context, component);
-	    }
+	if (isAjaxMode(component)) {
+	    encodePollScript(context, component);
 	}
+
     }
 
     /**
@@ -532,7 +512,6 @@
 	    }
 	    return map;
 	}
-
 	return null;
     }
 
@@ -549,20 +528,19 @@
     public void encodeCompletedState(FacesContext context, UIComponent component)
 	    throws IOException {
 	boolean isAjax = isAjaxMode(component);
-	if (isAjax) {
-	    Object rerenderAfterComplete = component.getAttributes().get(
-		    "reRenderAfterComplete");
-	    Set ajaxRegions = AjaxRendererUtils.asSet(rerenderAfterComplete);
+	Object rerenderAfterComplete = component.getAttributes().get(
+		"reRenderAfterComplete");
+	Set ajaxRegions = AjaxRendererUtils.asSet(rerenderAfterComplete);
 
-	    if (ajaxRegions != null) {
-		for (Iterator iter = ajaxRegions.iterator(); iter.hasNext();) {
-		    String id = iter.next().toString();
-		    AjaxContext ajaxContext = AjaxContext
-			    .getCurrentInstance(context);
-		    ajaxContext.addComponentToAjaxRender(component, id);
-		}
+	if (ajaxRegions != null) {
+	    for (Iterator iter = ajaxRegions.iterator(); iter.hasNext();) {
+		String id = iter.next().toString();
+		AjaxContext ajaxContext = AjaxContext
+			.getCurrentInstance(context);
+		ajaxContext.addComponentToAjaxRender(component, id);
 	    }
 	}
+
 	String clientId = component.getClientId(context);
 	String finishClass = (String) component.getAttributes().get(
 		"finishClass");
@@ -577,6 +555,7 @@
 	if (completed != null) {
 	    renderChild(context, completed);
 	}
+	encodeInitialScript(context, component);
 	if (isAjax) {
 	    writer.startElement(HTML.SPAN_ELEM, component);
 	    writer.startElement(HTML.SCRIPT_ELEM, component);
@@ -648,7 +627,7 @@
     @Override
     public void encodeChildren(FacesContext context, UIComponent component)
 	    throws IOException {
-	;
+	; // We should not render children
     }
 
     /*
@@ -660,7 +639,7 @@
     @Override
     public void doEncodeChildren(ResponseWriter writer, FacesContext context,
 	    UIComponent component) throws IOException {
-	;
+	; // We should not render children
     }
 
 }

Modified: trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/css/progressBar.xcss
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/css/progressBar.xcss	2008-01-25 17:15:29 UTC (rev 5644)
+++ trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/css/progressBar.xcss	2008-01-25 18:22:06 UTC (rev 5645)
@@ -8,25 +8,30 @@
 	<f:verbatim>
 		
 		
-.rich-progress-bar-uploaded{overflow : hidden; position : absolute; border : 0px solid #cccccc; height : 16px;}
+.rich-progress-bar-uploaded{overflow : hidden; position : absolute; border : 0px solid ; height : 16px;}
 .rich-progress-bar{position : relative; margin-bottom : 2px; height : 16px; width : 200px}
 .rich-progress-bar-base{text-align : center; position : absolute; height : 16px; width : 200px; font-weight : bold;}
-.rich-progress-bar-remained{background : #F1F1F1; border : 1px solid #cccccc; color : #000000;}
-.rich-progress-bar-completed{background : #FF9409; color : #FFFFFF;;  background-repeat : repeat-x; repeat-y;}
-.rich-progress-bar-permanent{background : #FF9409; color : #FFFFFF;;  background-repeat : repeat-x; repeat-y; height : 16px; width : 200px;}
+.rich-progress-bar-remained{border : 1px solid; color : #000000;}
+.rich-progress-bar-completed{background-repeat : repeat-x; repeat-y;}
 		
 	</f:verbatim>
 	
-	<u:selector name=".rich-progress-bar-completed">
-    <u:style name="background-image">
-        <f:resource f:key="org.richfaces.renderkit.html.images.ProgressBarBg" />
-    </u:style>
+	<u:selector name=".rich-progress-bar-remained">
+    <u:style name="background-color" skin="controlBackgroundColor" />
+    <u:style name="border-color" skin="panelBorderColor" />
+    <u:style name="text-color" skin="controlTextColor" />
 	</u:selector>
+	
+	<u:selector name=".rich-progress-bar-uploaded">
+     <u:style name="border-color" skin="panelBorderColor" />
+ 	</u:selector>
+ 	
+ 	<u:selector name=".rich-progress-bar-completed">
+ 	<u:style name="background-image">
+  		<f:resource f:key="org.richfaces.renderkit.html.images.ProgressBarBg" />
+	</u:style>
+ 	<u:style name="background-color" skin="selectControlColor" />
+ 	<u:style name="text-color" skin="controlBackgroundColor" />
+ 	</u:selector>
 
-	<u:selector name=".rich-progress-bar-permanent">
-    <u:style name="background-image">
-       	<f:resource f:key="org.richfaces.renderkit.html.images.ProgressBarAnimatedBg" />
-    </u:style>
-	</u:selector>
-
 </f:template>
\ No newline at end of file

Modified: trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js	2008-01-25 17:15:29 UTC (rev 5644)
+++ trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js	2008-01-25 18:22:06 UTC (rev 5645)
@@ -6,11 +6,9 @@
     	if (arguments.length > 0) {
     		var id = arguments[0];
     		this.id = id;
-    		this.maxValue = ProgressBar.Pollers[id]['maxValue'];
-    		this.minValue = ProgressBar.Pollers[id]['minValue'];
     	}
     },
-    init: function (id, containerId, formId, mode, minValue, maxValue, label , context) {
+    init: function (id, containerId, formId, mode, minValue, maxValue, label , context, options, progressVar) {
     	ProgressBar.Pollers[id] = {};
     	ProgressBar.Pollers[id]['containerId'] = containerId;
     	ProgressBar.Pollers[id]['formId'] = formId;
@@ -19,6 +17,8 @@
     	ProgressBar.Pollers[id]['maxValue'] = maxValue;
     	ProgressBar.Pollers[id]['label'] = label;
     	ProgressBar.Pollers[id]['context'] = context;
+    	ProgressBar.Pollers[id]['options'] = options;
+    	ProgressBar.Pollers[id]['progressVar'] = progressVar;
     },
 	getValue: function () {
 		var d = $(this.id + ":upload");
@@ -67,15 +67,27 @@
 	},
 	updateComponent: function (k,v) {
 		switch (k) {
+			case "style" : this.updateStyle(v); break;
 			case "percent" : this.value = v; break;
 			case "enabled" : if (v == "false") { this.disable(); }; break;  
 			case "completeClass" : this.updateClassName($(this.id + ":complete"), v, "rich-progress-bar-base"); break;
 			case "remainClass" : this.updateClassName($(this.id + ":remain"), v, "rich-progress-bar-base");  break;
 			case "styleClass" : this.updateClassName($(this.id), v, "rich-progress-bar"); break;
-			case "initialClass" : break;
-			case "finishClass" : break;
+			case "interval" : if (ProgressBar.Pollers[this.id]['options']['pollinterval'] != v) ProgressBar.Pollers[this.id]['options']['pollinterval'] = v; break;
 		}
 	},
+	updateStyle: function (style) {
+		var d = $(this.id);
+		if (d.style != style) {
+			d.style = style;
+			d = $(this.id + ":remain");
+			if (d) d.style = style;
+			d = $(this.id + ":complete");
+			if (d) d.style = style; 
+			d = $(this.id + ":upload");
+			if (d) d.style = style;
+		}
+	},
 	updateClassName: function (o, newName, defaultClass) {
 		if (o.className) {
 			if (o.className.indexOf(newName) < 0){
@@ -83,16 +95,32 @@
 			}
 		}
 	},
-	renderLabel: function () {
+	getContext: function () {
 		var context = ProgressBar.Pollers[this.id]['context'];
 			context['minValue'] = ProgressBar.Pollers[this.id]['minValue'];
 			context['maxValue'] = ProgressBar.Pollers[this.id]['maxValue'];
 			context['value'] = (this.value ? this.value : this.getValue());
+			context[ProgressBar.Pollers[this.id]['progressVar']] = context['value'];
+		return context;
+	},
+	renderLabel: function () {
+		var context = this.getContext();
 		var markup = ProgressBar.Pollers[this.id]['label'];
 		var html = markup.invoke('getContent', context).join('');
 		$(this.id + ":remain").innerHTML = $(this.id + ":complete").innerHTML = html;
 	},
+	interpolate: function (placeholders, context) {
+		for(var k in context) {
+			var v = context[k];
+			var regexp = new RegExp("\\{" + k + "\\}", "g");
+			placeholders = placeholders.replace(regexp, v);
+		}
+		return placeholders;
+	},
 	setLabel: function (str) {
+		var lbl = this.interpolate(str, this.getContext());
+		if (lbl)
+			$(this.id + ":remain").innerHTML = $(this.id + ":complete").innerHTML = lbl;
 	},
 	getMode: function () {
 		return ProgressBar.Pollers[this.id]['mode'];
@@ -100,6 +128,9 @@
 	getMaxValue: function () {
 		return ProgressBar.Pollers[this.id]['maxValue'];	
 	},
+	getMinValue: function () {
+		return ProgressBar.Pollers[this.id]['minValue'];
+	},
 	isAjaxMode: function () {
 		return (this.getMode() == "ajax");
 	}, 
@@ -110,9 +141,15 @@
 				val = val + "%";
 		}
 		
-		if ( parseFloat(p) >=  parseFloat(this.getMaxValue()))  {
+		if ( parseFloat(p) <  parseFloat(this.getMinValue())) {
 			if (!this.isAjaxMode()) { 
-				//this.switchMode("completed"); return;
+				this.forceState("initial",null);
+				return;
+			}
+		} else if ( parseFloat(p) >=  parseFloat(this.getMaxValue()))  {
+			if (!this.isAjaxMode()) { 
+				this.forceState("complete",null);
+				return;
 			} 
 		}
 		
@@ -122,7 +159,7 @@
 	},
 	enable: function (ev) {
 		if (!this.isAjaxMode()) {
-			this.forceProgressState();
+			this.forceState("progress",new Function ("new ProgressBar('"+this.id+"').setValue('0');"));
 		}else {
 			this.disable();
 			this.poll();			
@@ -134,13 +171,15 @@
 	finish: function () {
 		//this.switchMode("completed");
 	},
-	forceProgressState : function () {
+	forceState: function (state, oncomplete) {
 		var options = {};
 		options['parameters'] = {};
 		options['parameters'][this.id] = this.id;
-		options['parameters']['forceState'] = "progress";
+		options['parameters']['forceState'] = state;
 		options['actionUrl'] = ProgressBar.Pollers[this.id]['options']['actionUrl'];
-		options['oncomplete'] = function () { new ProgressBar(this.id).setValue("0") };
+		if (oncomplete) {
+			options['oncomplete'] = oncomplete;
+		}
 		A4J.AJAX.SubmitRequest(ProgressBar.Pollers[this.id]['containerId'],ProgressBar.Pollers[this.id]['formId'],null,options);
 	}
 	});

Modified: trunk/sandbox/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx	2008-01-25 17:15:29 UTC (rev 5644)
+++ trunk/sandbox/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx	2008-01-25 18:22:06 UTC (rev 5645)
@@ -38,7 +38,6 @@
 
 	<jsp:scriptlet>
 <![CDATA[
-setProgressVar(context, component, value);
 if (forcedState != null) {
     renderForcedState(forcedState,context,component);
 }else if (value.doubleValue() < minValue.doubleValue()) { 




More information about the richfaces-svn-commits mailing list