Author: abelevich
Date: 2010-03-15 14:03:04 -0400 (Mon, 15 Mar 2010)
New Revision: 16580
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/resources/META-INF/resources/script/datascroller.js
Log:
add submit function
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-15
14:18:52 UTC (rev 16579)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-03-15
18:03:04 UTC (rev 16580)
@@ -35,7 +35,11 @@
import javax.faces.render.Renderer;
import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.renderkit.RendererUtils;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.JSLiteral;
+import org.ajax4jsf.javascript.JSReference;
+import org.ajax4jsf.renderkit.AjaxEventOptions;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.UIDataScroller;
import org.richfaces.event.DataScrollerEvent;
@@ -68,7 +72,12 @@
}
}
}
+ @Override
+ public void decode(FacesContext context, UIComponent component) {
+ Map <String, String> paramMap =
context.getExternalContext().getRequestParameterMap();
+
+ }
public ControlsState getControlsState(FacesContext context, UIComponent component) {
@@ -290,17 +299,30 @@
Map<String, Object> options = new HashMap<String, Object>();
options.put("buttons", buttons);
options.put("digitals", digitals);
-
+ function.addParameter(getSubmitFunction(context, component));
function.addParameter(options);
- writer.writeText(function.toScript(),null);
+ writer.write(function.toString());
}
- public Object getOnClick(FacesContext facesContext, UIComponent component, String
string) {
- String id = component.getClientId(facesContext);
- return "RichFaces.Event.callHandlerById('" + id + "',
'rich:datascroller:onscroll', {'page': '" + string +
"'});";
+ public JSFunctionDefinition getSubmitFunction(FacesContext facesContext, UIComponent
component) {
+ JSFunctionDefinition definition = new JSFunctionDefinition(JSReference.EVENT, new
JSReference("element"), new JSReference("data"));
+
+ JSFunction function = AjaxRendererUtils.buildAjaxFunction(facesContext, component,
AjaxRendererUtils.AJAX_FUNCTION_NAME);
+ AjaxEventOptions options = AjaxRendererUtils.buildEventOptions(facesContext,
component);
+
+ Map<String, Object> parameters = options.getParameters();
+ parameters.put(component.getClientId(facesContext) + ":page", new
JSLiteral("data.page"));
+
+ function.addParameter(options);
+
+ StringBuffer buffer = new StringBuffer();
+ function.appendScript(buffer);
+
+ definition.addToBody(buffer);
+ return definition;
}
-
+
public void renderPages(FacesContext context, UIComponent component, int pageIndex,
int count) throws IOException {
int currentPage = pageIndex;
@@ -341,12 +363,6 @@
}
return parameters;
}
-
-
- public String getSubmitFunction(FacesContext context, UIComponent component) {
-// TODO: anton - add
- return null;
- }
public boolean getRendersChildren() {
return true;
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/resources/META-INF/resources/script/datascroller.js
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/resources/META-INF/resources/script/datascroller.js 2010-03-15
14:18:52 UTC (rev 16579)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/resources/META-INF/resources/script/datascroller.js 2010-03-15
18:03:04 UTC (rev 16580)
@@ -2,7 +2,7 @@
richfaces.ui = richfaces.ui || {};
- richfaces.ui.DataScroller = function(id, options) {
+ richfaces.ui.DataScroller = function(id, submit, options) {
$super.constructor.call(this,id);
@@ -11,11 +11,14 @@
var buttons = options.buttons;
var digitals = options.digitals;
+ if (submit && typeof submit == 'function') {
+ RichFaces.Event.bindById(id, this.getScrollEventName(), submit);
+ }
+
var css = {};
if(buttons) {
var leftButtons = buttons.left;
-
css.mouseover = "ds_button ds_left ds_over";
css.mouseup = "ds_button ds_left";
css.mouseout = "ds_button ds_left";
@@ -40,8 +43,6 @@
this.initButtons(digitals,css);
}
-
-
};
var $super = richfaces.BaseComponent.extend(richfaces.BaseComponent,
richfaces.ui.DataScroller);
@@ -59,24 +60,32 @@
return eventData;
};
- var processEvents = function(event) {
+ var processStyles = function(event) {
var data = event.data;
if(data) {
-
var element = data.element;
var css = data.css;
- var page = data.page;
-
+
if(element && css) {
element.attr('class', css);
}
-
- if(event.type == 'click') {
+ }
+
+ };
+
+ var processClick = function(event) {
+ var data = event.data;
+
+ if(data) {
+ var page = data.page;
+ if(page) {
this.switchToPage(page);
- }
+ }
}
- };
+ }
+
+ var scrollEventName = "rich:datascroller:onscroll";
return {
@@ -92,7 +101,6 @@
var data = {};
data.component = this;
- data.fn = processEvents;
for(id in buttons) {
@@ -101,10 +109,13 @@
data.id = id;
data.page = buttons[id];
data.element = element;
-
+ data.fn = processClick;
+
element.bind('click', copy(data), fn);
if(css) {
+ data.fn = processStyles;
+
data.css = css.mousedown;
element.bind('mousedown', copy(data), fn);
@@ -118,11 +129,12 @@
element.bind('mouseover', copy(data), fn);
}
}
-
},
switchToPage: function(page) {
- alert(page);
+ if (typeof page != 'undefined' && page != null) {
+ RichFaces.Event.fireById(this.id, this.getScrollEventName(), {'page' :
page});
+ }
},
next: function() {
@@ -147,6 +159,10 @@
fastRewind: function() {
this.switchToPage("fastrewind");
+ },
+
+ getScrollEventName: function() {
+ return scrollEventName;
}
}