Author: jonesde
Date: Sat Apr 5 08:13:09 2008 New Revision: 645115 URL: http://svn.apache.org/viewvc?rev=645115&view=rev Log: Added background-submit-refresh-target to form field submit, auto-update-target to screen container; also added example that uses thetainer; also updated example to use these new ajax features Removed: ofbiz/trunk/framework/example/webapp/example/ajax/ Modified: ofbiz/trunk/framework/example/webapp/example/WEB-INF/controller.xml ofbiz/trunk/framework/example/widget/example/ExampleAjaxScreens.xml ofbiz/trunk/framework/example/widget/example/ExampleForms.xml ofbiz/trunk/framework/images/webapp/images/selectall.js ofbiz/trunk/framework/widget/dtd/widget-form.xsd ofbiz/trunk/framework/widget/dtd/widget-screen.xsd ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java Modified: ofbiz/trunk/framework/example/webapp/example/WEB-INF/controller.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/webapp/example/WEB-INF/controller.xml?rev=645115&r1=645114&r2=645115&view=diff ============================================================================== --- ofbiz/trunk/framework/example/webapp/example/WEB-INF/controller.xml (original) +++ ofbiz/trunk/framework/example/webapp/example/WEB-INF/controller.xml Sat Apr 5 08:13:09 2008 @@ -146,6 +146,9 @@ <request-map uri="FormWidgetExamples"><security https="true" auth="true"/><response name="success" type="view" value="FormWidgetExamples"/></request-map> <request-map uri="LookupExampleFeature"><security https="true" auth="true"/><response name="success" type="view" value="LookupExampleFeature"/></request-map> + + <request-map uri="ListExampleFormOnly"><security https="true" auth="true"/><response name="success" type="view" value="ListExampleFormOnly"/></request-map> + <request-map uri="CreateExampleFormOnly"><security https="true" auth="true"/><response name="success" type="view" value="CreateExampleFormOnly"/></request-map> <!-- end of request mappings --> <!-- View Mappings --> @@ -166,8 +169,8 @@ <!-- ajax view mappings --> <view-map name="findExampleAjax" type="screen" page="component://example/widget/example/ExampleAjaxScreens.xml#AjaxExample"/> - <view-map name="listExamples" type="screen" page="component://example/widget/example/ExampleAjaxScreens.xml#listExamples"/> - <view-map name="createExampleForm" type="screen" page="component://example/widget/example/ExampleAjaxScreens.xml#createScreenForm"/> + <view-map name="ListExampleFormOnly" type="screen" page="component://example/widget/example/ExampleAjaxScreens.xml#ListExampleFormOnly"/> + <view-map name="CreateExampleFormOnly" type="screen" page="component://example/widget/example/ExampleAjaxScreens.xml#CreateExampleFormOnly"/> <!-- end of view mappings --> </site-conf> Modified: ofbiz/trunk/framework/example/widget/example/ExampleAjaxScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/widget/example/ExampleAjaxScreens.xml?rev=645115&r1=645114&r2=645115&view=diff ============================================================================== --- ofbiz/trunk/framework/example/widget/example/ExampleAjaxScreens.xml (original) +++ ofbiz/trunk/framework/example/widget/example/ExampleAjaxScreens.xml Sat Apr 5 08:13:09 2008 @@ -27,7 +27,6 @@ <set field="headerItem" value="AjaxExample"/> <set field="titleProperty" value="PageTitleFindExample"/> - <set field="layoutSettings.javaScripts[+0]" value="/images/prototypejs/validation.js" global="true"/> <set field="layoutSettings.javaScripts[+0]" value="/images/prototypejs/prototype.js" global="true"/> </actions> <widgets> @@ -39,13 +38,10 @@ </condition> <widgets> <container><label style="h1">${uiLabelMap.${titleProperty}}</label></container> - <container id="example-list"> - <include-screen name="listExamples"/> + <container id="ListExamplesAutoUpdate" auto-update-target="ListExampleFormOnly"> + <include-screen name="ListExampleFormOnly"/> </container> - <container/> - <container id="create-form"> - <include-screen name="createScreenForm"/> - </container> + <include-screen name="CreateExampleFormOnly"/> </widgets> <fail-widgets> <label style="h3">${uiLabelMap.ExampleViewPermissionError}</label> @@ -57,33 +53,28 @@ </section> </screen> - <screen name="listExamples"> + <screen name="ListExampleFormOnly"> <section> <actions> - <entity-condition entity-name="Example" list-name="examples"/> + <!-- NOTE: these are needed because this may be run as a top level screen and would have no decorator --> + <property-map resource="ExampleUiLabels" map-name="uiLabelMap" global="true"/> + <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/> </actions> <widgets> - <container id="list-example-table"> - <platform-specific><html><html-template location="component://example/webapp/example/ajax/listExamplesAjax.ftl"/></html></platform-specific> - </container> + <include-form name="ListExamples" location="component://example/widget/example/ExampleForms.xml"/> </widgets> </section> </screen> - - <screen name="createScreenForm"> + <screen name="CreateExampleFormOnly"> <section> <actions> - <entity-condition entity-name="ExampleType" list-name="types"/> - <entity-condition entity-name="StatusItem" list-name="statusItems"> - <condition-expr field-name="statusTypeId" operator="equals" value="EXAMPLE_STATUS"/> - <order-by field-name="sequenceId"/> - </entity-condition> + <!-- these are only needed so that when bsh evaluates use-when attributes these will exist and not cause an error --> + <set field="exampleId" from-field="parameters.exampleId"/> + <entity-one entity-name="Example" value-name="example"/> </actions> <widgets> - <container id="create-example-form"> - <platform-specific><html><html-template location="component://example/webapp/example/ajax/createExampleAjax.ftl"/></html></platform-specific> - </container> + <include-form name="EditExampleBackgroundSubmit" location="component://example/widget/example/ExampleForms.xml"/> </widgets> </section> </screen> -</screens> \ No newline at end of file +</screens> Modified: ofbiz/trunk/framework/example/widget/example/ExampleForms.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/widget/example/ExampleForms.xml?rev=645115&r1=645114&r2=645115&view=diff ============================================================================== --- ofbiz/trunk/framework/example/widget/example/ExampleForms.xml (original) +++ ofbiz/trunk/framework/example/widget/example/ExampleForms.xml Sat Apr 5 08:13:09 2008 @@ -20,10 +20,9 @@ <forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/widget-form.xsd"> - <form name="ListExamples" type="list" list-name="examples" - paginate-target="FindExample"> + <form name="ListExamples" type="list" list-name="examples" paginate-target="FindExample"> <actions> - <entity-condition entity-name="Example"><order-by field-name="description"/></entity-condition> + <entity-condition entity-name="Example"><order-by field-name="exampleName"/></entity-condition> </actions> <field name="exampleId" title="${uiLabelMap.ExampleExampleId}" widget-style="buttontext"> @@ -34,6 +33,7 @@ <field name="statusId" title="${uiLabelMap.CommonStatus}"><display-entity entity-name="StatusItem"/></field> <field name="description" title="${uiLabelMap.CommonDescription}"><display/></field> </form> + <form name="EditExample" type="single" target="updateExample" title="" default-map-name="example"> <actions> <entity-one entity-name="StatusItem" value-name="currentStatus" auto-field-map="false"> @@ -87,6 +87,10 @@ <field name="submitButton" use-when="example==null" title="${uiLabelMap.CommonCreate}"><submit button-type="button"/></field> <field name="submitButton" use-when="example!=null" title="${uiLabelMap.CommonUpdate}"><submit button-type="button"/></field> + </form> + <form name="EditExampleBackgroundSubmit" extends="EditExample"> + <field name="submitButton" use-when="example==null" title="${uiLabelMap.CommonCreate}"><submit button-type="button" background-submit-refresh-target="CreateExampleFormOnly"/></field> + <field name="submitButton" use-when="example!=null" title="${uiLabelMap.CommonUpdate}"><submit button-type="button" background-submit-refresh-target="CreateExampleFormOnly"/></field> </form> <!-- ExampleItem --> Modified: ofbiz/trunk/framework/images/webapp/images/selectall.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/selectall.js?rev=645115&r1=645114&r2=645115&view=diff ============================================================================== --- ofbiz/trunk/framework/images/webapp/images/selectall.js (original) +++ ofbiz/trunk/framework/images/webapp/images/selectall.js Sat Apr 5 08:13:09 2008 @@ -208,6 +208,17 @@ } } +// NOTE: REQUIRES prototype.js +// On the form element make sure you have something like: +// id="theFormId" +// On the submit button elements make sure you have something like: +// onclick="javascript:submitAjaxForm($('theFormId'), 'id-of-div-surrounding-or-on-form', '<@ofbizUrl>createExampleForm</@ofbizUrl>');" +function submitFormInBackground(form, areaName, submitUrl) { + submitFormDisableSubmits(form); + new Ajax.Request(form.action, { parameters: form.serialize(true) }); + new Ajax.Updater(areaName, submitUrl); +} + function submitFormDisableSubmits(form) { for (var i=0;i<form.length;i++) { var formel = form.elements[i]; Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?rev=645115&r1=645114&r2=645115&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original) +++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Sat Apr 5 08:13:09 2008 @@ -43,7 +43,8 @@ </xs:element> <xs:attributeGroup name="attlist.form"> <xs:attribute type="xs:string" name="name" use="required"/> - <xs:attribute name="type" use="required"> + <xs:attribute name="type"> + <xs:annotation><xs:documentation>The form type is always required unless you are extending another form.</xs:documentation></xs:annotation> <xs:simpleType> <xs:restriction base="xs:token"> <xs:enumeration value="single"> @@ -793,6 +794,9 @@ </xs:simpleType> </xs:attribute> <xs:attribute type="xs:string" name="image-location"/> + <xs:attribute type="xs:string" name="background-submit-refresh-target"> + <xs:annotation><xs:documentation>This will submit the form in the background and refresh just this form and not the rest of the page. Note that the button-type must be button.</xs:documentation></xs:annotation> + </xs:attribute> </xs:attributeGroup> <xs:element name="text" substitutionGroup="AllFields"> <xs:complexType> Modified: ofbiz/trunk/framework/widget/dtd/widget-screen.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-screen.xsd?rev=645115&r1=645114&r2=645115&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/dtd/widget-screen.xsd (original) +++ ofbiz/trunk/framework/widget/dtd/widget-screen.xsd Sat Apr 5 08:13:09 2008 @@ -754,6 +754,7 @@ <xs:attributeGroup name="attlist.container"> <xs:attribute type="xs:string" name="id"/> <xs:attribute type="xs:string" name="style"/> + <xs:attribute type="xs:string" name="auto-update-target"/> </xs:attributeGroup> <xs:element name="image" substitutionGroup="AllWidgets"> <xs:complexType mixed="true"> Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=645115&r1=645114&r2=645115&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Sat Apr 5 08:13:09 2008 @@ -1920,7 +1920,12 @@ * @return */ public String getContainerId() { - return this.containerId; + // use the name if there is no id + if (UtilValidate.isNotEmpty(this.containerId)) { + return this.containerId; + } else { + return this.getName(); + } } /** Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?rev=645115&r1=645114&r2=645115&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java Sat Apr 5 08:13:09 2008 @@ -2726,6 +2726,7 @@ public static class SubmitField extends FieldInfo { protected String buttonType; protected String imageLocation; + protected FlexibleStringExpander backgroundSubmitRefreshTargetExdr; protected SubmitField() { super(); @@ -2743,6 +2744,7 @@ super(element, modelFormField); this.buttonType = element.getAttribute("button-type"); this.imageLocation = element.getAttribute("image-location"); + this.backgroundSubmitRefreshTargetExdr = new FlexibleStringExpander(element.getAttribute("background-submit-refresh-target")); } public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { @@ -2775,6 +2777,10 @@ */ public void setImageLocation(String string) { imageLocation = string; + } + + public String getBackgroundSubmitRefreshTarget(Map context) { + return this.backgroundSubmitRefreshTargetExdr.expandString(context); } } Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java?rev=645115&r1=645114&r2=645115&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java Sat Apr 5 08:13:09 2008 @@ -823,7 +823,6 @@ public void renderSubmitField(StringBuffer buffer, Map context, SubmitField submitField) { ModelFormField modelFormField = submitField.getModelFormField(); ModelForm modelForm = modelFormField.getModelForm(); - String singleClickAction = " onClick=\"javascript:submitFormDisableButton(this)\" "; String event = null; String action = null; @@ -867,15 +866,18 @@ buffer.append("=\""); buffer.append(action); buffer.append('"'); - } else { - // disabling for now, using form onSubmit action instead: buffer.append(singleClickAction); } buffer.append("/>"); } else { // default to "button" - buffer.append("<input type=\"submit\""); + String backgroundSubmitRefreshTarget = submitField.getBackgroundSubmitRefreshTarget(context); + if (UtilValidate.isNotEmpty(backgroundSubmitRefreshTarget)) { + buffer.append("<input type=\"button\""); + } else { + buffer.append("<input type=\"submit\""); + } appendClassNames(buffer, context, modelFormField); @@ -902,6 +904,19 @@ } else { //add single click JS onclick // disabling for now, using form onSubmit action instead: buffer.append(singleClickAction); + } + + if (UtilValidate.isNotEmpty(backgroundSubmitRefreshTarget)) { + // onclick="javascript:submitFormInBackground($('EditExampleBackgroundSubmit'), 'EditExampleBackgroundSubmit', '<@ofbizUrl>/authview/CreateExampleFormOnly</@ofbizUrl>');" + String formId = submitField.getModelFormField().getModelForm().getContainerId(); + String formContainerId = submitField.getModelFormField().getModelForm().getContainerId(); + buffer.append(" onclick=\"javascript:submitFormInBackground($('"); + buffer.append(formId); + buffer.append("'), '"); + buffer.append(formContainerId); + buffer.append("', '"); + this.appendOfbizUrl(buffer, backgroundSubmitRefreshTarget); + buffer.append("');\""); } buffer.append("/>"); Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java?rev=645115&r1=645114&r2=645115&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java Sat Apr 5 08:13:09 2008 @@ -91,6 +91,21 @@ public void renderContainerEnd(Writer writer, Map context, ModelScreenWidget.Container container) throws IOException { writer.write("</div>"); appendWhitespace(writer); + String autoUpdateTarget = container.getAutoUpdateTargetExdr(context); + String containerId = container.getId(context); + if (UtilValidate.isNotEmpty(autoUpdateTarget) && UtilValidate.isNotEmpty(containerId)) { + HttpServletResponse response = (HttpServletResponse) context.get("response"); + HttpServletRequest request = (HttpServletRequest) context.get("request"); + ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); + RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); + + writer.write("<script type=\"text/javascript\">new Ajax.PeriodicalUpdater('"); + writer.write(containerId); + writer.write("', '"); + writer.write(rh.makeLink(request, response, autoUpdateTarget)); + writer.write("');</script>"); + appendWhitespace(writer); + } } public void renderScreenletBegin(Writer writer, Map context, boolean collapsed, ModelScreenWidget.Screenlet screenlet) throws IOException { Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java?rev=645115&r1=645114&r2=645115&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java Sat Apr 5 08:13:09 2008 @@ -262,12 +262,14 @@ public static class Container extends ModelScreenWidget { protected FlexibleStringExpander idExdr; protected FlexibleStringExpander styleExdr; + protected FlexibleStringExpander autoUpdateTargetExdr; protected List<ModelScreenWidget> subWidgets; public Container(ModelScreen modelScreen, Element containerElement) { super(modelScreen, containerElement); this.idExdr = new FlexibleStringExpander(containerElement.getAttribute("id")); this.styleExdr = new FlexibleStringExpander(containerElement.getAttribute("style")); + this.autoUpdateTargetExdr = new FlexibleStringExpander(containerElement.getAttribute("auto-update-target")); // read sub-widgets List subElementList = UtilXml.childElementList(containerElement); @@ -297,8 +299,12 @@ return this.styleExdr.expandString(context); } + public String getAutoUpdateTargetExdr(Map context) { + return this.autoUpdateTargetExdr.expandString(context); + } + public String rawString() { - return "<container id=\"" + this.idExdr.getOriginal() + "\" style=\"" + this.styleExdr.getOriginal() + "\">"; + return "<container id=\"" + this.idExdr.getOriginal() + "\" style=\"" + this.styleExdr.getOriginal() + "\" auto-update-target=\"" + this.autoUpdateTargetExdr.getOriginal() + "\">"; } } |
Free forum by Nabble | Edit this page |