Author: andrei_exadel
Date: 2008-01-09 13:01:47 -0500 (Wed, 09 Jan 2008)
New Revision: 5236
Modified:
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java
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:
Refactoring according to changes done in component spec.
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-09
18:01:00 UTC (rev 5235)
+++
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java 2008-01-09
18:01:47 UTC (rev 5236)
@@ -133,7 +133,7 @@
writer.startElement(HTML.DIV_ELEM, component);
writer.writeAttribute(HTML.id_ATTRIBUTE, (isAjax ? clientId : clientId
+ ":initialState"), null);
-
+
UIComponent initial = component.getFacet("initial");
if (initial != null) {
renderChild(context, initial);
@@ -157,41 +157,49 @@
String style = (String) component.getAttributes().get("style");
String permanent = (String) component.getAttributes().get("permanent");
- String completeClass = (component.getAttributes().get("completeClass") !=
null) ? (String) component
- .getAttributes().get("completeClass")
- : ((permanent != null && "true".equals(permanent)) ?
"rich-progress-bar-permanent"
- : "rich-progress-bar-completed");
+ if (!(permanent != null && "true".equals(permanent))) {
- String remainClass = (component.getAttributes().get("remainClass") != null) ?
(String) component
- .getAttributes().get("remainClass")
- : "rich-progress-bar-remained";
+ String completeClass = (component.getAttributes().get(
+ "completeClass") != null) ? (String) component
+ .getAttributes().get("completeClass")
+ : "rich-progress-bar-completed";
- writer.startElement("div", component);
- getUtils().writeAttribute(writer, "class",
- remainClass + " rich-progress-bar-base");
- getUtils().writeAttribute(writer, "id", clientId + ":remain");
- getUtils().writeAttribute(writer, "style", style);
+ String remainClass = (component.getAttributes().get("remainClass") !=
null) ? (String) component
+ .getAttributes().get("remainClass")
+ : "rich-progress-bar-remained";
- writer.write(percent);
+ 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 + "; width: " + width + "%;");
+ writer.write(percent);
- 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.startElement("div", component);
+ getUtils().writeAttribute(writer, "class",
+ "rich-progress-bar-uploaded");
+ getUtils().writeAttribute(writer, "id", clientId + ":upload");
+ getUtils().writeAttribute(writer, "style",
+ style + "; width: " + width + "%;");
- writer.write(percent);
+ 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.write(percent);
+
+ writer.endElement("div");
+ writer.endElement("div");
+ } else {
+ writer.startElement("div", component);
+ getUtils().writeAttribute(writer,
"class","rich-progress-bar-permanent");
+ getUtils().writeAttribute(writer, "style", style + " width:
100%");
+ writer.endElement("div");
+ }
}
/**
@@ -227,7 +235,7 @@
ResponseWriter writer = context.getResponseWriter();
writer.startElement(HTML.DIV_ELEM, component);
writer.writeAttribute(HTML.id_ATTRIBUTE, clientId, null);
-
+
UIComponent completed = component.getFacet("completed");
if (completed != null) {
renderChild(context, completed);
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-09
18:01:00 UTC (rev 5235)
+++
trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js 2008-01-09
18:01:47 UTC (rev 5236)
@@ -7,7 +7,7 @@
this.id = id;
this.mode = "initial";
},
- getPercent: function () {
+ getProgress: function () {
var d = $(this.id + ":remain");
if (d != null) {
var v = d.innerHTML;
@@ -17,24 +17,33 @@
}
else return null;
},
- setPercent: function (val) {
+ setProgress: function (val) {
var p = val;
if (val != null) {
if (val.indexOf("%") < 0)
val = val + "%";
}
if ($(this.id + ":progressState") != null)
- if (p <= 0) this.switchMode("initial");
- else if (p > 0 && p < 100) this.switchMode("progress");
- else if (p >= 100) this.switchMode("completed");
-
- var d = $(this.id + ":remain");
- if (d != null) d.innerHTML = val;
- d = $(this.id + ":complete");
- if (d != null) d.innerHTML = val;
- d = $(this.id + ":upload");
- if (d != null) d.style.width = val;
+ {
+ if (this.mode == "progress")
+ {
+ var d = $(this.id + ":remain");
+ if (d != null) d.innerHTML = val;
+ d = $(this.id + ":complete");
+ if (d != null) d.innerHTML = val;
+ d = $(this.id + ":upload");
+ if (d != null) d.style.width = val;
+ }
+ }
},
+ enable: function () {
+ this.switchMode("progress");
+ this.setProgress("0");
+ },
+ finish: function () {
+ A4J.AJAX.StopPoll(this.id);
+ this.switchMode("completed");
+ },
switchMode : function (mode) {
switch (mode) {
case "initial" :
@@ -59,10 +68,7 @@
}
},
init : function () {
- var p = this.getPercent();
- if (p <= 0) this.switchMode("initial");
- else if (p > 0 && p < 100) this.switchMode("progress");
- else if (p >= 100) this.switchMode("completed");
+ this.switchMode("initial");
},
hide : function (o) {
if (o != null)
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-09
18:01:00 UTC (rev 5235)
+++
trunk/sandbox/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx 2008-01-09
18:01:47 UTC (rev 5236)
@@ -19,6 +19,7 @@
<![CDATA[
String mode = (String) component.getAttributes().get("mode");
boolean isAjax = !(mode != null &&
"client".equalsIgnoreCase(mode));
+ Boolean enabled = (Boolean) component.getAttributes().get("enabled");
Number value = (Number)component.getAttributes().get("value");
Integer percent = value.intValue();
variables.setVariable("percent",value);
@@ -32,9 +33,9 @@
<jsp:scriptlet>
<![CDATA[
if (isAjax) {
-if (percent <= 0) {
+if (!enabled && percent == 0) {
encodeInitialState(context, component, "true");
-} else if (percent >= 100) {
+} else if (!enabled && percent >= 100 ) {
encodeCompletedState(context, component, "true");
} else {
]]>
@@ -49,8 +50,8 @@
}else {
]]>
</jsp:scriptlet>
-<div class="rich-progress-bar #{styleClass}" style="#{style}"
id="#{clientId}">
- <div id="#{clientId}:progressState">
+<div id="#{clientId}">
+ <div id="#{clientId}:progressState" class="rich-progress-bar
#{styleClass}" style="#{style}">
<f:call name="encodeProgressState" />
</div>
<f:call name="encodeInitialState">