Author: abelevich
Date: 2010-03-10 13:06:44 -0500 (Wed, 10 Mar 2010)
New Revision: 16551
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
root/ui-sandbox/trunk/components/datascroller/ui/src/main/templates/datascroller.template.xml
Log:
add client js script encoding
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-03-10
15:28:56 UTC (rev 16550)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-03-10
18:06:44 UTC (rev 16551)
@@ -34,16 +34,21 @@
import javax.faces.context.ResponseWriter;
import javax.faces.render.Renderer;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.renderkit.RendererUtils;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.UIDataScroller;
import org.richfaces.event.DataScrollerEvent;
@ResourceDependencies( {@ResourceDependency(library = "javax.faces", name =
"jsf-uncompressed.js"),
- @ResourceDependency(name = "richfaces.js"),
- @ResourceDependency(name="richfaces-queue.js"),
+ @ResourceDependency(name = "richfaces.js"),
+ @ResourceDependency(name = "richfaces-queue.js"),
+ @ResourceDependency(name = "richfaces-base-component.js"),
@ResourceDependency(name = "script/datascroller.js"),
- @ResourceDependency(name = "css/datascroller.css")})
+ @ResourceDependency(name = "css/datascroller.css")
+
+})
public class DataScrollerBaseRenderer extends Renderer {
public void doDecode(FacesContext context, UIComponent component) {
@@ -158,14 +163,16 @@
return controlsState;
}
- public void renderPager(FacesContext context,ResponseWriter out, UIComponent
component) throws IOException {
+ public Map<String,String> renderPager(ResponseWriter out, FacesContext context,
UIComponent component) throws IOException {
int currentPage = (Integer)component.getAttributes().get("page");
int maxPages = (Integer)component.getAttributes().get("maxPages");
int pageCount = (Integer)component.getAttributes().get("pageCount");
-
+
+ Map<String,String> digital = new HashMap<String, String>();
+
if (pageCount <= 1) {
- return;
+ return digital;
}
if (maxPages <= 1) {
@@ -176,6 +183,7 @@
int pages;
int start;
+
if (pageCount > maxPages && currentPage > delta) {
pages = maxPages;
start = currentPage - pages / 2 - 1;
@@ -192,13 +200,15 @@
boolean isCurrentPage = (i + 1 == currentPage);
String styleClass;
String style;
- if (isCurrentPage) {
+
+ if (isCurrentPage) {
styleClass =
(String)component.getAttributes().get("selectedStyleClass");
style = (String)component.getAttributes().get("selectedStyle");
} else {
styleClass = (String)component.getAttributes().get("inactiveStyleClass");
style = (String)component.getAttributes().get("inactiveStyle");
}
+
if (styleClass==null){
styleClass="";
}
@@ -215,19 +225,59 @@
out.writeAttribute(HTML.ONMOUSEUP_ATTRIBUTE,
"this.className='ds_digital ds_over'", null);
out.writeAttribute(HTML.ONMOUSEDOWN_ATTRIBUTE,
"this.className='ds_digital ds_press'", null);
- out.writeAttribute(HTML.ONCLICK_ATTRIBUTE, getOnClick(context, component,
Integer.toString(i + 1)), null);
+ out.writeAttribute(HTML.ONCLICK_ATTRIBUTE, getOnClick(context, component,
Integer.toString(i + 1)), null);
}
if (null != style) {
out.writeAttribute(HTML.STYLE_ATTRIBUTE, style, null);
}
- out.writeText(Integer.toString(i + 1), null);
+
+ String page = Integer.toString(i + 1);
+ out.writeText(page, null);
+ digital.put("ds_" + page, page);
out.endElement(HTML.SPAN_ELEM);
}
+
+ return digital;
}
+ public Map<String, String> getControls(FacesContext context, UIComponent
component, ControlsState controlsState) {
+ //will be refactored
+ Map<String, String> controls = new HashMap<String, String>();
+
+ if(controlsState.getFirstRendered() && controlsState.getFirstEnabled())
{
+ controls.put("ds_f", "first");
+ }
+
+ if(controlsState.getFastRewindRendered()&&
controlsState.getFastRewindEnabled()) {
+ controls.put("ds_fr", "fastRewind");
+ }
+
+ if(controlsState.getFastForwardRendered()&&
controlsState.getFastForwardEnabled()) {
+ controls.put("ds_ff", "fastForward");
+ }
+
+ if(controlsState.getLastRendered()&& controlsState.getLastEnabled()) {
+ controls.put("ds_l", "last");
+ }
+
+ return controls;
+ }
-
+ public void buildScript(ResponseWriter writer, FacesContext context, UIComponent
component, Map buttons, Map controls) throws IOException {
+
+ JSFunction function = new JSFunction("new RichFaces.ui.DataScroller");
+ function.addParameter(component.getClientId(context));
+
+ Map<String, Object> options = new HashMap<String, Object>();
+ options.put("buttons", buttons);
+ options.put("controls", controls);
+
+ function.addParameter(options);
+
+ writer.writeText(function.toScript(),null);
+ }
+
public Object getOnClick(FacesContext facesContext, UIComponent component, String
string) {
String id = component.getClientId(facesContext);
return "RichFaces.Event.callHandlerById('" + id + "',
'rich:datascroller:onscroll', {'page': '" + string +
"'});";
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/templates/datascroller.template.xml
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/templates/datascroller.template.xml 2010-03-10
15:28:56 UTC (rev 16550)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/templates/datascroller.template.xml 2010-03-10
18:06:44 UTC (rev 16551)
@@ -47,9 +47,9 @@
</c:otherwise>
</c:choose>
</c:if>
+
+ <cdk:object type="java.util.Map" name="buttons"
value="#{renderPager(responseWriter, facesContext, component)}" />
- <cdk:call expression="renderPager(facesContext, responseWriter,
component);"/>
-
<c:if test="#{controlsState.fastForwardRendered}">
<c:choose>
<c:when test="#{controlsState.fastForwardEnabled}">
@@ -80,5 +80,11 @@
</c:choose>
</c:if>
</span>
+
+ <cdk:object type="java.util.Map" name="controls"
value="#{getControls(facesContext, component, controlsState)}" />
+
+ <script type="text/javascript">
+ <cdk:call expression="buildScript(responseWriter, facesContext, component,
buttons, controls);"/>
+ </script>
</cc:implementation>
</cdk:root>
\ No newline at end of file