Author: abelevich
Date: 2009-12-10 09:27:38 -0500 (Thu, 10 Dec 2009)
New Revision: 16105
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ToggleControlRendererBase.java
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/toggler.js
Log:
change toggle control client script
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ToggleControlRendererBase.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ToggleControlRendererBase.java 2009-12-10
11:23:56 UTC (rev 16104)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ToggleControlRendererBase.java 2009-12-10
14:27:38 UTC (rev 16105)
@@ -24,16 +24,17 @@
* @author Anton Belevich
*
*/
-@ResourceDependencies( { @ResourceDependency(name = "toggler.js") })
+@ResourceDependencies( {@ResourceDependency(library = "javax.faces", name =
"jsf-uncompressed.js"),
+ @ResourceDependency(name = "richfaces.js"), @ResourceDependency(name =
"toggler.js")})
public abstract class ToggleControlRendererBase extends RendererBase {
- private static final String MANAGER_SCRIPT = "ToggleManager.add(new
Toggle(''{0}'', {1}));";
+ private static final String MANAGER_SCRIPT =
"RichFaces.ui.ToggleManager.addToggler(new
RichFaces.ui.Toggle(''{0}'', {1}));";
- private static final String CLIENT_TOGGLE_SCRIPT =
"ToggleManager.clientToggle(''{0}'', {1});";
+ private static final String CLIENT_TOGGLE_SCRIPT =
"RichFaces.ui.ToggleManager.clientToggle(''{0}'', {1});";
- private static final String SERVER_TOGGLE_SCRIPT =
"ToggleManager.serverToggle(''{0}'', {1});";
+ private static final String SERVER_TOGGLE_SCRIPT =
"RichFaces.ui.ToggleManager.serverToggle(''{0}'', {1});";
- private static final String AJAX_TOGGLE_SCRIPT =
"ToggleManager.ajaxToggle(''{0}'', {1});";
+ private static final String AJAX_TOGGLE_SCRIPT =
"RichFaces.ui.ToggleManager.ajaxToggle(''{0}'', {1});";
private static final String DISPLAY_NONE = "display: none;";
@@ -82,11 +83,6 @@
String toggleId = toggleControl.getClientId(context);
String options = encodeOptions(context, toggleControl, subTable);
- writer.startElement(HTML.SCRIPT_ELEM, subTable);
- String registerScript = MessageFormat.format(MANAGER_SCRIPT, toggleId,
options);
- writer.writeText(registerScript, null);
- writer.endElement(HTML.SCRIPT_ELEM);
-
String switchType = subTable.getSwichType();
boolean expanded = subTable.isExpanded();
@@ -95,6 +91,10 @@
encodeHiddenInput(context, writer, toggleControl);
+ writer.startElement(HTML.SCRIPT_ELEM, subTable);
+ String registerScript = MessageFormat.format(MANAGER_SCRIPT, toggleId,
options);
+ writer.writeText(registerScript, null);
+ writer.endElement(HTML.SCRIPT_ELEM);
}
}
}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/toggler.js
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/toggler.js 2009-12-10
11:23:56 UTC (rev 16104)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/toggler.js 2009-12-10
14:27:38 UTC (rev 16105)
@@ -1,104 +1,128 @@
-function Toggle(id, options){
- this.id = id;
- this.forId = options.forId;
- this.state = options.initialState;
- this.formId = options.formId;
- this.hidden = id + ":hidden";
- this.expandControl = this.id + ":expand";
- this.collapseControl = this.id + ":collapse";
-}
-
-Toggle.prototype.convertId = function(id) {
- return id.replace(/:/g, "\\:");
-}
-
-Toggle.prototype.toggle = function(toState) {
- var elements = this.getElement(this.forId);
-
- if(this.state != toState) {
-
- this.toggleControls(toState);
-
- if(toState) {
- this.command("show", elements);
- } else {
- this.command("hide", elements);
- }
-
- this.state = toState;
- this.saveState(this.state);
- }
-}
-
-Toggle.prototype.toggleControls = function(toState) {
-
- var hideControlId = toState ? this.expandControl : this.collapseControl;
- var showControlId = this.state ? this.expandControl : this.collapseControl;
+(function(jQuery, richfaces) {
- var hideElement = this.getElement(hideControlId);
- var showElement = this.getElement(showControlId);
+ richfaces.ui = richfaces.ui || {};
+
+ richfaces.ui.ToggleManager = {};
- this.command("show", showElement);
- this.command("hide", hideElement);
-}
+ (function(manager){
+ var togglers = {};
+
+ manager['addToggler'] = function(toggler) {
+ if(toggler) {
+ togglers[toggler.id] = toggler;
+ }
+ };
+
+ manager['clientToggle'] = function(id, toState) {
+ if(id) {
+ togglers[id].clientToggle(toState);
+ }
+ };
+
+ manager['serverToggle'] = function(id, toState) {
+ if(id) {
+ togglers[id].serverToggle(toState);
+ }
+ };
+
+ manager['ajaxToggle'] = function(id, toState) {
+ if(id) {
+ togglers[id].ajaxToggle(toState);
+ }
+ };
+
+ manager['clearTogglers'] = function() {
+ togglers = {};
+ };
+
+ manager['getTogglers'] = function () {
+ return togglers;
+ };
+
+ })(richfaces.ui.ToggleManager);
+
+})(jQuery, window.RichFaces);
-Toggle.prototype.saveState= function(state) {
- var id = this.hidden;
- var element = this.getElement(id);
- if(element) {
- element.attr('value', state);
- }
-}
-Toggle.prototype.clientToggle= function(expand){
- this.toggle(expand);
-}
-
-Toggle.prototype.serverToggle = function(expand) {
- this.saveState(expand);
- var form = this.getElement(this.formId);
- form.submit();
-}
-
-Toggle.prototype.ajaxToggle = function(expand) {
-}
-
-Toggle.prototype.command = function(name, element){
- if(name) {
- if(element && typeof element[name] == 'function') {
- element[name]();
- }
- }
-}
-
-Toggle.prototype.getElement = function(id) {
- return $("#" + this.convertId(id));
-}
-
-ToggleManager = new Object();
-
-ToggleManager.process = {};
-
-ToggleManager.add = function (toggler){
- if(toggler) {
- this.process[toggler.id] = toggler;
- }
-}
-
-ToggleManager.clientToggle = function(id, expand) {
- if(id) {
- this.process[id].clientToggle(expand);
- }
-}
-
-ToggleManager.serverToggle = function(id, expand) {
- if(id) {
- this.process[id].serverToggle(expand);
- }
-}
-
-ToggleManager.ajaxToggle = function(id, expand) {
- if(id) {
- this.process[id].ajaxToggle(expand);
- }
-}
+(function (jQuery, richfaces) {
+
+ richfaces.ui = richfaces.ui || {};
+
+ richfaces.ui.Toggle = function(id, options) {
+ this.getElement(id).rich= {component: this};
+ this.id = id;
+ this.hiddenInput = this.getElement(id + ":hidden");
+ this.expandControl = this.getElement(id + ":expand");
+ this.collapseControl = this.getElement(id + ":collapse");
+ this.form = this.getElement(options.formId);
+ this.forId = options.forId;
+
+ this.state = options.initialState;
+ };
+
+ jQuery.extend(richfaces.ui.Toggle.prototype, ( function () {
+
+ var convertId = function (id){
+ return id.replace(/:/g, "\\:");
+ };
+
+ return {
+ getElement : function (id) {
+ return $("#" + convertId(id));
+ },
+
+ saveState : function(state) {
+ if(this.hiddenInput) {
+ this.hiddenInput.attr('value', state);
+ }
+ },
+
+ toggle: function (toState) {
+ var element = this.getElement(this.forId);
+ if(this.state != toState) {
+ this.toggleControls(toState);
+
+ if(toState) {
+ this.command("show", element);
+ } else {
+ this.command("hide", element);
+ }
+
+ this.state = toState;
+ this.saveState(this.state);
+ }
+ },
+
+ toggleControls: function (toState){
+ var hideControl = toState ? this.expandControl : this.collapseControl;
+ var showControl = this.state ? this.expandControl : this.collapseControl;
+ this.command("show", showControl);
+ this.command("hide", hideControl);
+ },
+
+ clientToggle: function(expand){
+ this.toggle(expand);
+ },
+
+ serverToggle: function(expand){
+ this.saveState(expand);
+ if(this.form) {
+ this.form.submit();
+ }
+ },
+
+ ajaxToggle: function(expand){
+ },
+
+ command: function(name, element){
+ if(name) {
+ if(element && typeof element[name] == 'function') {
+ element[name]();
+ }
+ }
+ }
+
+ };
+
+ })());
+})(jQuery, window.RichFaces);
\ No newline at end of file