Browse files

Use form 's serialize() method in JQuery Core

  • Loading branch information...
1 parent ff0c000 commit 42d6dd21b3db2fdbef53006b3bb8af467c648205 @mto mto committed with trongtt May 8, 2012
View
64 web/eXoResources/src/main/webapp/javascript/eXo/webui/UIForm.js
@@ -30,7 +30,7 @@ eXo.webui.UIForm = {
ajaxPost : function(formElement, callback) {
if (!callback)
callback = null;
- var queryString = eXo.webui.UIForm.serializeForm(formElement);
+ var queryString = xj(formElement).serialize();
var url = formElement.action + "&ajaxRequest=true";
doRequest("POST", url, queryString, callback);
},
@@ -136,67 +136,5 @@ eXo.webui.UIForm = {
form = xj("#UIMaskWorkspace").find("#" + formId)[0];
}
form.elements[typeId].value = hiddenValue;
- },
- /**
- * Returns a string that contains all the values of the elements of a form
- * (formElement) in this format . fieldName=value The result is a string like
- * this : abc=def&ghi=jkl... The values are encoded to be used in an URL Only
- * serializes the elements of type : . text, hidden, password, textarea .
- * checkbox and radio if they are checked . select-one if one option is
- * selected
- */
- /*
- * This method goes through the form element passed as an argument and
- * generates a string output in a GET request way. It also encodes the the
- * form parameter values
- */
- serializeForm : function(formElement) {
- var queryString = "";
- var element;
- var elements = formElement.elements;
-
- this.addField = function(name, value) {
- if (queryString.length > 0)
- queryString += "&";
- queryString += name + "=" + encodeURIComponent(value);
- };
-
- for ( var i = 0; i < elements.length; i++) {
- element = elements[i];
- // if(element.disabled) continue;
- switch (element.type) {
- case "text":
- case "hidden":
- case "password":
- case "textarea":
- this.addField(element.name, element.value.replace(/\r/gi, ""));
- break;
-
- case "checkbox":
- if (element.checked)
- this.addField(element.name, "true");
- else
- this.addField(element.name, "false");
- break;
- case "radio":
- if (element.checked)
- this.addField(element.name, element.value);
- break;
-
- case "select-one":
- if (element.selectedIndex > -1) {
- this.addField(element.name,
- element.options[element.selectedIndex].value);
- }
- break;
- case "select-multiple":
- for ( var j = 0; j < element.options.length; j++) {
- if (element.options[j].selected)
- this.addField(element.name, element.options[j].value);
- }
- break;
- } // switch
- } // for
- return queryString;
}
}
View
4 ...portal/src/main/webapp/groovy/organization/webui/component/UIListPermissionSelector.gtmpl
@@ -1,7 +1,7 @@
<%
import org.exoplatform.webui.form.UIFormPopupWindow;
import org.exoplatform.webui.form.UIFormGrid;
- import org.exoplatform.webui.form.UIFormCheckBoxInput;
+ import org.exoplatform.webui.form.input.UICheckBoxInput;
def rcontext = _ctx.getRequestContext();
def uiPublicMode = uicomponent.getChildById("publicMode");
@@ -12,7 +12,7 @@
<table class="UIFormGrid">
<tr>
<td class="FieldLabel"><%=uicomponent.getLabel(uiPublicMode.getId())%></td>
- <td class="FieldComponent"><%uicomponent.renderChild(UIFormCheckBoxInput.class)%></td>
+ <td class="FieldComponent"><%uicomponent.renderChild(UICheckBoxInput.class)%></td>
</tr>
</table>
</div>
View
13 webui/core/src/main/java/org/exoplatform/webui/form/UIFormCheckBoxInput.java
@@ -120,15 +120,10 @@ public void decode(Object input, WebuiRequestContext context) throws Exception
{
if (isDisabled())
return;
- if (input != null) {
- if(input.equals("true"))
- checked = true;
- else
- checked = false;
- if (typeValue_ == Boolean.class || typeValue_ == boolean.class)
- {
- value_ = typeValue_.cast(checked);
- }
+ checked = "true".equals(input);
+ if (typeValue_ == Boolean.class || typeValue_ == boolean.class)
+ {
+ value_ = typeValue_.cast(checked);
}
}
View
4 webui/core/src/main/java/org/exoplatform/webui/form/input/UICheckBoxInput.java
@@ -114,12 +114,12 @@ public void decode(Object input, WebuiRequestContext context) throws Exception
{
if (isDisabled())
return;
-
+
if (input == null || "false".equals(input.toString()))
{
setValue(false);
}
- else
+ else
{
setValue(true);
}
View
21 webui/eXo/src/main/java/org/exoplatform/webui/organization/UIListPermissionSelector.java
@@ -19,15 +19,12 @@
package org.exoplatform.webui.organization;
-import java.io.Serializable;
-import java.util.*;
-
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.commons.utils.SerializablePageList;
import org.exoplatform.portal.config.UserACL;
import org.exoplatform.portal.config.UserACL.Permission;
import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.webui.application.WebuiRequestContext;
-import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.webui.config.annotation.ComponentConfig;
import org.exoplatform.webui.config.annotation.EventConfig;
import org.exoplatform.webui.core.UIBreadcumbs;
@@ -40,12 +37,18 @@
import org.exoplatform.webui.event.EventListener;
import org.exoplatform.webui.exception.MessageException;
import org.exoplatform.webui.form.UIForm;
-import org.exoplatform.webui.form.UIFormCheckBoxInput;
import org.exoplatform.webui.form.UIFormGrid;
import org.exoplatform.webui.form.UIFormInput;
import org.exoplatform.webui.form.UIFormPageIterator;
import org.exoplatform.webui.form.UIFormPopupWindow;
+import org.exoplatform.webui.form.input.UICheckBoxInput;
import org.exoplatform.webui.form.validator.Validator;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
/** Created by The eXo Platform SARL Author : Pham Dung Ha ha.pham@exoplatform.com May 7, 2007o */
@ComponentConfig(template = "system:/groovy/organization/webui/component/UIListPermissionSelector.gtmpl", events = {
@@ -59,7 +62,7 @@
public UIListPermissionSelector() throws Exception
{
- UIFormCheckBoxInput<Boolean> uiPublicMode = new UIFormCheckBoxInput<Boolean>("publicMode", null, false);
+ UICheckBoxInput uiPublicMode = new UICheckBoxInput("publicMode", null, false);
addChild(uiPublicMode);
UIFormGrid uiGrid = addChild(UIFormGrid.class, null, "PermissionGrid");
uiGrid.setLabel("UIListPermissionSelector");
@@ -84,7 +87,7 @@ public void configure(String iname, String bfield)
setName(iname);
setId(iname);
setBindingField(bfield);
- UIFormCheckBoxInput uiPublicMode = getChild(UIFormCheckBoxInput.class);
+ UICheckBoxInput uiPublicMode = getChild(UICheckBoxInput.class);
uiPublicMode.setOnChange("ChangePublicMode", iname);
UIFormPopupWindow uiPopup = getChild(UIFormPopupWindow.class);
uiPopup.setId(iname + "Popup");
@@ -228,7 +231,7 @@ public boolean isPublicMode()
public void setPublicMode(boolean mode) throws Exception
{
publicMode_ = mode;
- UIFormCheckBoxInput<Boolean> uiPublicMode = getChildById("publicMode");
+ UICheckBoxInput uiPublicMode = getChildById("publicMode");
uiPublicMode.setChecked(publicMode_);
UIFormGrid uiGrid = getChild(UIFormGrid.class);
uiGrid.setRendered(!publicMode_);
@@ -272,7 +275,7 @@ public void execute(Event<UIListPermissionSelector> event) throws Exception
public void execute(Event<UIListPermissionSelector> event) throws Exception
{
UIListPermissionSelector uicom = event.getSource();
- UIFormCheckBoxInput<Boolean> uiPublicModeInput = uicom.getChildById("publicMode");
+ UICheckBoxInput uiPublicModeInput = uicom.getChildById("publicMode");
uicom.setPublicMode(uiPublicModeInput.isChecked());
uicom.setRendered(true);
UIForm uiForm = uicom.getAncestorOfType(UIForm.class);
View
8 webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageForm.java
@@ -46,13 +46,13 @@
import org.exoplatform.webui.event.Event;
import org.exoplatform.webui.event.Event.Phase;
import org.exoplatform.webui.event.EventListener;
-import org.exoplatform.webui.form.UIFormCheckBoxInput;
import org.exoplatform.webui.form.UIFormInputItemSelector;
import org.exoplatform.webui.form.UIFormInputSet;
import org.exoplatform.webui.form.UIFormPopupWindow;
import org.exoplatform.webui.form.UIFormSelectBox;
import org.exoplatform.webui.form.UIFormStringInput;
import org.exoplatform.webui.form.UIFormTabPane;
+import org.exoplatform.webui.form.input.UICheckBoxInput;
import org.exoplatform.webui.form.validator.IdentifierValidator;
import org.exoplatform.webui.form.validator.MandatoryValidator;
import org.exoplatform.webui.form.validator.StringLengthValidator;
@@ -136,7 +136,7 @@ public void invokeSetBindingBean(Object bean) throws Exception
if (!page.isShowMaxWindow())
{
- page.setShowMaxWindow((Boolean)getUIFormCheckBoxInput("showMaxWindow").getValue());
+ page.setShowMaxWindow(getUICheckBoxInput("showMaxWindow").getValue());
}
if (!SiteType.USER.getName().equals(page.getOwnerType()))
{
@@ -221,7 +221,7 @@ public void buildForm(UIPage uiPage) throws Exception
.addValidator(IdentifierValidator.class).addValidator(MandatoryValidator.class))
.addUIFormInput(
new UIFormStringInput("title", "title", null).addValidator(StringLengthValidator.class, 3, 120))
- .addUIFormInput(new UIFormCheckBoxInput("showMaxWindow", "showMaxWindow", false));
+ .addUIFormInput(new UICheckBoxInput("showMaxWindow", "showMaxWindow", false));
addUIFormInput(uiSettingSet);
setSelectedTab(uiSettingSet.getId());
@@ -261,7 +261,7 @@ public void buildForm(UIPage uiPage) throws Exception
getUIStringInput("name").setReadOnly(true);
getUIStringInput("pageId").setValue(uiPage.getPageId());
getUIStringInput("title").setValue(uiPage.getTitle());
- getUIFormCheckBoxInput("showMaxWindow").setValue(uiPage.isShowMaxWindow());
+ getUICheckBoxInput("showMaxWindow").setValue(uiPage.isShowMaxWindow());
getUIFormSelectBox(OWNER_TYPE).setDisabled(true).setValue(uiPage.getSiteKey().getTypeName());
}

0 comments on commit 42d6dd2

Please sign in to comment.