svn commit: r831676 - in /ofbiz/trunk/framework: common/config/CommonUiLabels.xml widget/src/org/ofbiz/widget/form/MacroFormRenderer.java widget/src/org/ofbiz/widget/form/ModelForm.java widget/templates/htmlFormMacroLibrary.ftl

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r831676 - in /ofbiz/trunk/framework: common/config/CommonUiLabels.xml widget/src/org/ofbiz/widget/form/MacroFormRenderer.java widget/src/org/ofbiz/widget/form/ModelForm.java widget/templates/htmlFormMacroLibrary.ftl

bibryam
Author: bibryam
Date: Sun Nov  1 13:51:42 2009
New Revision: 831676

URL: http://svn.apache.org/viewvc?rev=831676&view=rev
Log:
A patch from Bruno Busco "Adding a page size selector in the pagination bar" - https://issues.apache.org/jira/browse/OFBIZ-3083

Modified:
    ofbiz/trunk/framework/common/config/CommonUiLabels.xml
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
    ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl

Modified: ofbiz/trunk/framework/common/config/CommonUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/config/CommonUiLabels.xml?rev=831676&r1=831675&r2=831676&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/config/CommonUiLabels.xml (original)
+++ ofbiz/trunk/framework/common/config/CommonUiLabels.xml Sun Nov  1 13:51:42 2009
@@ -3525,6 +3525,10 @@
         <value xml:lang="zh">明细</value>
         <value xml:lang="zh_CN">东西</value>
     </property>
+    <property key="CommonItemsPerPage">
+        <value xml:lang="en">Items per page</value>
+        <value xml:lang="it">Righe per pagina</value>
+    </property>
     <property key="CommonJanuary">
         <value xml:lang="ar">جانفي</value>
         <value xml:lang="de">Januar</value>

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=831676&r1=831675&r2=831676&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 Sun Nov  1 13:51:42 2009
@@ -1967,9 +1967,6 @@
         int highIndex = modelForm.getHighIndex(context);
         int actualPageSize = modelForm.getActualPageSize(context);
 
-        // if this is all there seems to be (if listSize < 0, then size is unknown)
-        if (actualPageSize >= listSize && listSize >= 0) return;
-
         // needed for the "Page" and "rows" labels
         Map<String, String> uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap"));
         String pageLabel = "";
@@ -2005,6 +2002,8 @@
         // add viewIndex/viewSize parameters to request parameter String
         String urlPath = UtilHttp.removeQueryStringFromTarget(targetService);
         String prepLinkText = UtilHttp.getQueryStringFromTarget(targetService);
+        String prepLinkSizeText;
+
         if (prepLinkText == null) {
             prepLinkText = "";
         }
@@ -2016,6 +2015,7 @@
         if (!UtilValidate.isEmpty(queryString) && !queryString.equals("null")) {
             prepLinkText += queryString + "&amp;";
         }
+        prepLinkSizeText = prepLinkText + viewSizeParam + "='+this.value+'" + "&amp;" + viewIndexParam + "=0";
         prepLinkText += viewSizeParam + "=" + viewSize + "&amp;" + viewIndexParam + "=";
         if (ajaxEnabled) {
             // Prepare params for prototype.js
@@ -2034,6 +2034,9 @@
         String ajaxPreviousUrl = "";
         String selectUrl = "";
         String ajaxSelectUrl = "";
+        String paginateViewSizeLabel = modelForm.getPaginateViewSizeLabel(context);
+        String selectSizeUrl = "";
+        String ajaxSelectSizeUrl = "";
         String paginateNextStyle = modelForm.getPaginateNextStyle();
         String paginateNextLabel = modelForm.getPaginateNextLabel(context);
         String nextUrl = "";
@@ -2092,6 +2095,19 @@
             }
         }
 
+        // Page size select dropdown
+        if (listSize > 0 && this.javaScriptEnabled) {
+            if (ajaxEnabled) {
+                ajaxSelectSizeUrl = createAjaxParamsFromUpdateAreas(updateAreas, prepLinkSizeText + anchor, context);
+            } else {
+                linkText = prepLinkSizeText;
+                if (linkText.startsWith("/")) {
+                    linkText = linkText.substring(1);
+                }
+                selectSizeUrl = rh.makeLink(this.request, this.response, urlPath + linkText);
+            }
+        }
+        
         StringWriter sr = new StringWriter();
         sr.append("<@renderNextPrev ");
         sr.append(" paginateStyle=\"");
@@ -2134,6 +2150,10 @@
         sr.append(ajaxSelectUrl);
         sr.append("\" selectUrl=\"");
         sr.append(selectUrl);
+        sr.append("\" ajaxSelectSizeUrl=\"");
+        sr.append(ajaxSelectSizeUrl);
+        sr.append("\" selectSizeUrl=\"");
+        sr.append(selectSizeUrl);
         sr.append("\" commonDisplaying=\"");
         sr.append(commonDisplaying);
         sr.append("\" paginateNextStyle=\"");
@@ -2152,6 +2172,8 @@
         sr.append(lastUrl);
         sr.append("\" paginateLastLabel=\"");
         sr.append(paginateLastLabel);
+        sr.append("\" paginateViewSizeLabel=\"");
+        sr.append(paginateViewSizeLabel);
         sr.append("\" />");
         executeMacro(sr.toString());
     }

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=831676&r1=831675&r2=831676&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 Sun Nov  1 13:51:42 2009
@@ -108,6 +108,7 @@
     protected FlexibleStringExpander paginatePreviousLabel;
     protected FlexibleStringExpander paginateNextLabel;
     protected FlexibleStringExpander paginateLastLabel;
+    protected FlexibleStringExpander paginateViewSizeLabel;
     protected String paginateTargetAnchor;
     protected String paginateStyle;
     protected boolean separateColumns = false;
@@ -435,6 +436,9 @@
         if (this.paginateLastLabel == null || formElement.hasAttribute("paginate-last-label")) {
             this.paginateLastLabel = FlexibleStringExpander.getInstance(formElement.getAttribute("paginate-last-label"));
         }
+        if (this.paginateViewSizeLabel == null || formElement.hasAttribute("paginate-viewsize-label")) {
+            this.paginateViewSizeLabel = FlexibleStringExpander.getInstance(formElement.getAttribute("paginate-viewsize-label"));
+        }
         if (this.paginateStyle == null || formElement.hasAttribute("paginate-style")) {
             setPaginateStyle(formElement.getAttribute("paginate-style"));
         }
@@ -2278,6 +2282,15 @@
         return field;
     }
 
+    public String getPaginateViewSizeLabel(Map<String, Object> context) {
+        Locale locale = (Locale)context.get("locale");
+        String field = this.paginateViewSizeLabel.expandString(context);
+        if (UtilValidate.isEmpty(field)) {
+            field = UtilProperties.getMessage("CommonUiLabels", "CommonItemsPerPage", locale);
+        }
+        return field;
+    }
+
     public String getPaginateStyle() {
         return this.paginateStyle;
     }

Modified: ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl?rev=831676&r1=831675&r2=831676&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl (original)
+++ ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Sun Nov  1 13:51:42 2009
@@ -422,7 +422,8 @@
 );"><#rt>
 <img src="${imgSrc}"width="15" height="14" border="0" alt="Lookup"/></a><#rt>
 </#macro>
-<#macro renderNextPrev paginateStyle paginateFirstStyle viewIndex highIndex listSize viewSize ajaxEnabled javaScriptEnabled ajaxFirstUrl firstUrl paginateFirstLabel paginatePreviousStyle ajaxPreviousUrl previousUrl paginatePreviousLabel pageLabel ajaxSelectUrl selectUrl commonDisplaying paginateNextStyle ajaxNextUrl nextUrl paginateNextLabel paginateLastStyle ajaxLastUrl lastUrl paginateLastLabel>
+<#macro renderNextPrev paginateStyle paginateFirstStyle viewIndex highIndex listSize viewSize ajaxEnabled javaScriptEnabled ajaxFirstUrl firstUrl paginateFirstLabel paginatePreviousStyle ajaxPreviousUrl previousUrl paginatePreviousLabel pageLabel ajaxSelectUrl selectUrl ajaxSelectSizeUrl selectSizeUrl commonDisplaying paginateNextStyle ajaxNextUrl nextUrl paginateNextLabel paginateLastStyle ajaxLastUrl lastUrl paginateLastLabel paginateViewSizeLabel>
+<#if listSize gt 20>
 <div class="${paginateStyle}">&nbsp; <ul>
 <li class="${paginateFirstStyle}<#if viewIndex gt 0>"><a href="<#if ajaxEnabled>javascript:ajaxUpdateAreas('${ajaxFirstUrl}')<#else>${firstUrl}</#if>">${paginateFirstLabel}</a><#else>-disabled">${paginateFirstLabel}</#if></li>
 <li class="${paginatePreviousStyle}<#if viewIndex gt 0>"><a href="<#if ajaxEnabled>javascript:ajaxUpdateAreas('${ajaxPreviousUrl}')<#else>${previousUrl}</#if>">${paginatePreviousLabel}</a><#else>-disabled">${paginatePreviousLabel}</#if></li>
@@ -432,11 +433,18 @@
 <#list 1..x as i>
 <#if i == (viewIndex+1)><option selected="selected" value="<#else><option value="</#if>${i-1}">${i}</option>
 </#list>
-</select></li><li>${commonDisplaying}</li>
-</#if>
+</select></li></#if>
+<li>${commonDisplaying}</li>
 <li class="${paginateNextStyle}<#if highIndex lt listSize>"><a href="<#if ajaxEnabled>javascript:ajaxUpdateAreas('${ajaxNextUrl}')<#else>${nextUrl}</#if>">${paginateNextLabel}</a><#else>-disabled">${paginateNextLabel}</#if></li>
 <li class="${paginateLastStyle}<#if highIndex lt listSize>"><a href="<#if ajaxEnabled>javascript:ajaxUpdateAreas('${ajaxLastUrl}')<#else>${lastUrl}</#if>">${paginateLastLabel}</a><#else>-disabled">${paginateLastLabel}</#if></li>
+<#if javaScriptEnabled><li class="nav-pagesize"><select name="pageSize" size="1" onchange="<#if ajaxEnabled>javascript:ajaxUpdateAreas('${ajaxSelectSizeUrl}')<#else>location.href='${selectSizeUrl}';</#if>"><#rt/>
+<#assign availPageSizes = [20, 30, 50, 100, 200]>
+<#list availPageSizes as ps>
+  <option <#if viewSize == ps>selected="selected" </#if> value="${ps}">${ps}</option>
+</#list>
+</select> ${paginateViewSizeLabel}</li></#if>
 </ul></div><br/>
+</#if>
 </#macro>
 <#macro renderFileField className alert name value size maxlength autocomplete><input type="file" <@renderClass className alert /><#if name?has_content> name="${name}"</#if><#if value?has_content> value="${value}"</#if><#if size?has_content> size="${size}"</#if><#if maxlength?has_content> maxlength="${maxlength}"</#if><#if autocomplete?has_content> autocomplete="off"</#if>/><#rt/></#macro>
 <#macro renderPasswordField className alert name value size maxlength id autocomplete><input type="password" <@renderClass className alert /><#if name?has_content> name="${name}"</#if><#if value?has_content> value="${value}"</#if><#if size?has_content> size="${size}"</#if><#if maxlength?has_content> maxlength="${maxlength}"</#if><#if id?has_content> id="${id}"</#if><#if autocomplete?has_content> autocomplete="off"</#if>/></#macro>