Author: jacopoc
Date: Thu Apr 30 14:32:45 2009 New Revision: 770243 URL: http://svn.apache.org/viewvc?rev=770243&view=rev Log: Migrated code, and adjusted to work with the new macro renderers, that implements the in-place editor for display fields. Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl ofbiz/trunk/framework/widget/templates/textFormMacroLibrary.ftl ofbiz/trunk/framework/widget/templates/xmlFormMacroLibrary.ftl Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java?rev=770243&r1=770242&r2=770243&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java Thu Apr 30 14:32:45 2009 @@ -32,6 +32,8 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -174,6 +176,10 @@ // FIXME: this is only valid for html and should be moved outside of this class // Replace new lines with <br/> description = description.replaceAll("\n", "<br/>"); + + ModelFormField.InPlaceEditor inPlaceEditor = displayField.getInPlaceEditor(); + boolean ajaxEnabled = inPlaceEditor != null && this.javaScriptEnabled; + StringWriter sr = new StringWriter(); sr.append("<@renderDisplayField "); sr.append("idName=\""); @@ -184,6 +190,128 @@ sr.append(modelFormField.getWidgetStyle()); sr.append("\" alert=\""); sr.append(modelFormField.shouldBeRed(context)? "true": "false"); + + if (ajaxEnabled) { + String url = inPlaceEditor.getUrl(context); + Map<String, Object> fieldMap = inPlaceEditor.getFieldMap(context); + if (fieldMap != null) { + url += '?'; + Set<Entry<String, Object>> fieldSet = fieldMap.entrySet(); + Iterator<Entry<String, Object>> fieldIterator = fieldSet.iterator(); + int count = 0; + while (fieldIterator.hasNext()) { + count++; + Entry<String, Object> field = fieldIterator.next(); + url += (String) field.getKey() + '=' + (String) field.getValue(); + if (count < fieldSet.size()) { + url += '&'; + } + } + } + sr.append("\" inPlaceEditorId=\""); + sr.append(idName); + sr.append("\" inPlaceEditorUrl=\""); + sr.append(url); + sr.append("\" inPlaceEditorParams=\""); + StringWriter inPlaceEditorParams = new StringWriter(); + inPlaceEditorParams.append("{paramName: '"); + if (UtilValidate.isNotEmpty(inPlaceEditor.getParamName())) { + inPlaceEditorParams.append(inPlaceEditor.getParamName()); + } else { + inPlaceEditorParams.append(modelFormField.getFieldName()); + } + inPlaceEditorParams.append("'"); + if (UtilValidate.isNotEmpty(inPlaceEditor.getCancelControl())) { + inPlaceEditorParams.append(", cancelControl: "); + if (!"false".equals(inPlaceEditor.getCancelControl())) { + inPlaceEditorParams.append("'"); + } + inPlaceEditorParams.append(inPlaceEditor.getCancelControl()); + if (!"false".equals(inPlaceEditor.getCancelControl())) { + inPlaceEditorParams.append("'"); + } + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getCancelText())) { + inPlaceEditorParams.append(", cancelText: '" +inPlaceEditor.getCancelText()+ "'"); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getClickToEditText())) { + inPlaceEditorParams.append(", clickToEditText: '" +inPlaceEditor.getClickToEditText()+ "'"); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getFieldPostCreation())) { + inPlaceEditorParams.append(", fieldPostCreation: "); + if (!"false".equals(inPlaceEditor.getFieldPostCreation())) { + inPlaceEditorParams.append("'"); + } + inPlaceEditorParams.append(inPlaceEditor.getFieldPostCreation()); + if (!"false".equals(inPlaceEditor.getFieldPostCreation())) { + inPlaceEditorParams.append("'"); + } + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getFormClassName())) { + inPlaceEditorParams.append(", formClassName: '" +inPlaceEditor.getFormClassName()+ "'"); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getHighlightColor())) { + inPlaceEditorParams.append(", highlightColor: '" +inPlaceEditor.getHighlightColor()+ "'"); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getHighlightEndColor())) { + inPlaceEditorParams.append(", highlightEndColor: '" +inPlaceEditor.getHighlightEndColor()+ "'"); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getHoverClassName())) { + inPlaceEditorParams.append(", hoverClassName: '" +inPlaceEditor.getHoverClassName()+ "'"); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getHtmlResponse())) { + inPlaceEditorParams.append(", htmlResponse: " +inPlaceEditor.getHtmlResponse()); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getLoadingClassName())) { + inPlaceEditorParams.append(", loadingClassName: '" +inPlaceEditor.getLoadingClassName()+ "'"); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getLoadingText())) { + inPlaceEditorParams.append(", loadingText: '" +inPlaceEditor.getLoadingText()+ "'"); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getOkControl())) { + inPlaceEditorParams.append(", okControl: "); + if (!"false".equals(inPlaceEditor.getOkControl())) { + inPlaceEditorParams.append("'"); + } + inPlaceEditorParams.append(inPlaceEditor.getOkControl()); + if (!"false".equals(inPlaceEditor.getOkControl())) { + inPlaceEditorParams.append("'"); + } + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getOkText())) { + inPlaceEditorParams.append(", okText: '" +inPlaceEditor.getOkText()+ "'"); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getSavingClassName())) { + inPlaceEditorParams.append(", savingClassName: '" +inPlaceEditor.getSavingClassName()+ "', "); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getSavingText())) { + inPlaceEditorParams.append(", savingText: '" +inPlaceEditor.getSavingText()+ "'"); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getSubmitOnBlur())) { + inPlaceEditorParams.append(", submitOnBlur: " +inPlaceEditor.getSubmitOnBlur()); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getTextBeforeControls())) { + inPlaceEditorParams.append(", textBeforeControls: '" +inPlaceEditor.getTextBeforeControls()+ "'"); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getTextAfterControls())) { + inPlaceEditorParams.append(", textAfterControls: '" +inPlaceEditor.getTextAfterControls()+ "'"); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getTextBetweenControls())) { + inPlaceEditorParams.append(", textBetweenControls: '" +inPlaceEditor.getTextBetweenControls()+ "'"); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getUpdateAfterRequestCall())) { + inPlaceEditorParams.append(", updateAfterRequestCall: " +inPlaceEditor.getUpdateAfterRequestCall()); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getRows())) { + inPlaceEditorParams.append(", rows: '" +inPlaceEditor.getRows()+ "'"); + } + if (UtilValidate.isNotEmpty(inPlaceEditor.getCols())) { + inPlaceEditorParams.append(", cols: '" +inPlaceEditor.getCols()+ "'"); + } + inPlaceEditorParams.append("}"); + sr.append(inPlaceEditorParams.toString()); + } + sr.append("\" />"); executeMacro(sr.toString()); if (displayField instanceof DisplayEntityField) { Modified: ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl?rev=770243&r1=770242&r2=770243&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl (original) +++ ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl Thu Apr 30 14:32:45 2009 @@ -37,7 +37,9 @@ <#macro renderField text><#if text?exists>${text}</#if></#macro> -<#macro renderDisplayField idName description class alert><@makeBlock class description /></#macro> +<#macro renderDisplayField idName description class alert inPlaceEditorId="" inPlaceEditorUrl="" inPlaceEditorParams=""> +<@makeBlock class description /> +</#macro> <#macro renderHyperlinkField></#macro> <#macro renderTextField name className alert value textSize maxlength id event action clientAutocomplete ajaxUrl ajaxEnabled><@makeBlock className value /></#macro> Modified: ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl?rev=770243&r1=770242&r2=770243&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl (original) +++ ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Thu Apr 30 14:32:45 2009 @@ -23,9 +23,9 @@ </#if> </#macro> -<#macro renderDisplayField idName description class alert> +<#macro renderDisplayField idName description class alert inPlaceEditorId="" inPlaceEditorUrl="" inPlaceEditorParams=""> <#if class?has_content || alert=="true"> - <span <@renderClass className alert />><#t/> + <span <#if idName?has_content>id="${idName}"</#if> <@renderClass class alert />><#t/> </#if> <#if description?has_content> ${description}<#t/> @@ -35,6 +35,11 @@ <#if class?has_content || alert=="true"> </span><#lt/> </#if> + <#if inPlaceEditorId?has_content> + <script language="JavaScript" type="text/javascript"><#lt/> + ajaxInPlaceEditDisplayField('${inPlaceEditorId}', '${inPlaceEditorUrl}', ${inPlaceEditorParams});<#lt/> + </script><#lt/> + </#if> </#macro> <#macro renderHyperlinkField></#macro> @@ -169,6 +174,7 @@ <#else> <input type="<#if containerId?has_content>button<#else>submit</#if>" <@renderClass className alert /><#if name?exists> name="${name}"</#if><#if title?has_content> value="${title}"</#if><#if event?has_content> ${event}="${action}"</#if><#if containerId?has_content> onclick="ajaxSubmitFormUpdateAreas('${containerId}', '${ajaxUrl}')"</#if>/></#if> </#macro> + <#macro renderResetField className alert name title> <input type="reset" <@renderClass className alert /> name="${name}"<#if title?has_content> value="${title}"</#if>/> </#macro> Modified: ofbiz/trunk/framework/widget/templates/textFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/textFormMacroLibrary.ftl?rev=770243&r1=770242&r2=770243&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/templates/textFormMacroLibrary.ftl (original) +++ ofbiz/trunk/framework/widget/templates/textFormMacroLibrary.ftl Thu Apr 30 14:32:45 2009 @@ -19,7 +19,9 @@ <#macro renderField text><#if text?exists>${text}</#if></#macro> -<#macro renderDisplayField idName description class alert><@renderField description /></#macro> +<#macro renderDisplayField idName description class alert inPlaceEditorId="" inPlaceEditorUrl="" inPlaceEditorParams=""> +<@renderField description /> +</#macro> <#macro renderHyperlinkField></#macro> <#macro renderTextField name className alert value textSize maxlength id event action clientAutocomplete ajaxUrl ajaxEnabled><@renderField value /></#macro> Modified: ofbiz/trunk/framework/widget/templates/xmlFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/xmlFormMacroLibrary.ftl?rev=770243&r1=770242&r2=770243&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/templates/xmlFormMacroLibrary.ftl (original) +++ ofbiz/trunk/framework/widget/templates/xmlFormMacroLibrary.ftl Thu Apr 30 14:32:45 2009 @@ -40,7 +40,9 @@ -<#macro renderDisplayField idName description class alert><@renderField description/></#macro> +<#macro renderDisplayField idName description class alert inPlaceEditorId="" inPlaceEditorUrl="" inPlaceEditorParams=""> +<@renderField description/> +</#macro> <#macro renderHyperlinkField></#macro> <#macro renderTextField name className alert value textSize maxlength id event action clientAutocomplete ajaxUrl ajaxEnabled><@renderField value/></#macro> |
Free forum by Nabble | Edit this page |