portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r891409 - in /portals/jetspeed-2/applications/j2-admin/trunk/src/main: java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java webapp/WEB-INF/view/toolbox/toolbox.jsp
Date Wed, 16 Dec 2009 19:58:45 GMT
Author: woonsan
Date: Wed Dec 16 19:58:44 2009
New Revision: 891409

URL: http://svn.apache.org/viewvc?rev=891409&view=rev
Log:
JS2-1057: Adding pagination

Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/toolbox/toolbox.jsp

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java?rev=891409&r1=891408&r2=891409&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java
Wed Dec 16 19:58:44 2009
@@ -18,7 +18,9 @@
 
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
@@ -26,6 +28,7 @@
 import javax.portlet.PortletConfig;
 import javax.portlet.PortletContext;
 import javax.portlet.PortletException;
+import javax.portlet.PortletPreferences;
 import javax.portlet.PortletRequest;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
@@ -102,9 +105,15 @@
     public void doView(RenderRequest request, RenderResponse response)
             throws PortletException, IOException
     {
-        request.setAttribute("categories", retrieveCategories(request));
+        List<String> categories = retrieveCategories(request);
+        request.setAttribute("categories", categories);
+        Map<String, String> categoryKeywordsMap = retrieveCategoryKeywordsMap(categories,
request);
+        request.setAttribute("categoryKeywords", categoryKeywordsMap);
+        
         request.setAttribute("layouts", LayoutBean.retrieveLayouts(request, decorationFactory));
         request.setAttribute("themes", ThemeBean.retrieveThemes(request, decorationFactory));
+        PortletPreferences prefs = request.getPreferences();
+        request.setAttribute("prefs", prefs.getMap());
         
         boolean hasEditAccess = false;
         
@@ -186,4 +195,18 @@
         return categories;
     }
     
+    public Map<String, String> retrieveCategoryKeywordsMap(List<String> categories,
PortletRequest request) throws PortletException
+    {
+        Map<String, String> keywordsMap = new HashMap<String, String>();
+        PortletPreferences prefs = request.getPreferences();
+        
+        for (String category : categories)
+        {
+            String keywords = prefs.getValue("Keywords:" + category, "");
+            keywordsMap.put(category, keywords);
+        }
+        
+        return keywordsMap;
+    }
+    
 }

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/toolbox/toolbox.jsp
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/toolbox/toolbox.jsp?rev=891409&r1=891408&r2=891409&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/toolbox/toolbox.jsp
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/toolbox/toolbox.jsp
Wed Dec 16 19:58:44 2009
@@ -31,16 +31,17 @@
 
 <portlet:defineObjects/>
 <c_rt:set var="requestContext" value="<%=request.getAttribute(RequestContext.REQUEST_PORTALENV)%>"/>
-<c:set var="portalContextPrefix" value="${requestContext.request.contextPath}"/>
 <c:set var="portalContextPath" value="${requestContext.request.contextPath}"/>
 <c:set var="portalPagePath" value="${requestContext.portalURL.path}"/>
 <c:if test="${empty portalPagePath}">
   <c:set var="portalPagePath" value="/"/>
 </c:if>
 
+<c:set var="portletPageSize" value="${prefs['Rows'][0]}"/>
+
 <table style="border-collapse: collapse;  width: 100%; margin-top: 0px; margin-bottom:
0px; float: left;">
     <tr>
-    <td class="portlet-section-subheader" colspan='10'>
+    <td class="portlet-section-subheader">
         <a href="#" id="<portlet:namespace/>portletsTabAction">Portlets</a>
         |
         <a href="#" id="<portlet:namespace/>layoutTabAction">Layout</a>
@@ -55,21 +56,21 @@
 <form id="<portlet:namespace/>form">
 <table id="<portlet:namespace/>portletsTab" style="display: none; border-collapse:
collapse;  width: 100%; margin-top: 0px; margin-bottom: 0px; float: left;">
     <tr>
-        <th class="portlet-section-header" colspan="10">Portlets</th>
+        <th class="portlet-section-header">Portlets</th>
     </tr>
     <tr>
-        <td class="portlet-section-subheader" colspan='10'>
+        <td class="portlet-section-subheader">
             <input type="text" name="query" size="15" value="" >
             <input type="submit" value="Search" />
         </td>
     </tr>
     
     <tr>
-        <td class="portlet-section-subheader" colspan='10'>
+        <td class="portlet-section-subheader">
             <select id="<portlet:namespace/>categories">
                 <option value="">Choose a category</option>
                 <c:forEach var="category" items="${categories}">
-                    <option value="${category}">${category}</option>
+                    <option value="${category}" keywords="${categoryKeywords[category]}">${category}</option>
                 </c:forEach>
             </select>
         </td>
@@ -82,7 +83,22 @@
     </tr>
 
     <tr>
-        <th class="portlet-section-header" colspan="2"></th>
+        <td class="portlet-section-subheader">
+            <div id="<portlet:namespace/>pageNavBar" class="jstbPageNavBar">
+	            <a href="#" class="jstbPageNav" pageIndex="first">&lt;&lt;</a>
+	            <a href="#" class="jstbPageNav" pageIndex="prev">&lt;</a>
+	            <select id="<portlet:namespace/>pageNavIndex">
+	              <option value="">Page</option>
+	            </select>
+	            </select>
+	            <a href="#" class="jstbPageNav" pageIndex="next">&gt;</a>
+	            <a href="#" class="jstbPageNav" pageIndex="last">&gt;&gt;</a>
+	        </div>
+        </td>
+    </tr>
+
+    <tr>
+        <th class="portlet-section-header"></th>
     </tr>
 </table>
 </form>
@@ -170,7 +186,57 @@
 </table>
 
 <script language="javascript">
-YUI().use('io', 'json', 'node-base', 'cookie', 'jetui-portal', function(Y) {
+YUI().use('jetui-portal', 'io', 'json', 'node-base', 'cookie', function(Y) {
+
+    var pagination = {
+            portlet : { uri : null, totalSize : 0, pageSize : ${portletPageSize}, beginIndex
: 0 },
+
+            getPageBeginIndex : function(info, scrollTo) {
+                if (isNaN(scrollTo)) {
+	                if ("first" == scrollTo) {
+	                    return 0;
+	                } else if ("prev" == scrollTo) {
+	                    return Math.max(info.beginIndex - info.pageSize, 0);
+	                } else if ("next" == scrollTo) {
+                        var lastPageBeginIndex = 0;
+                        if (info.totalSize > 0) {
+                            lastPageBeginIndex = parseInt((info.totalSize - 1) / info.pageSize)
* info.pageSize;
+                        }
+	                    return Math.min(info.beginIndex + info.pageSize, lastPageBeginIndex);
+	                } else if ("last" == scrollTo) {
+	                    var lastPageBeginIndex = 0;
+	                    if (info.totalSize > 0) {
+	                        lastPageBeginIndex = parseInt((info.totalSize - 1) / info.pageSize)
* info.pageSize;
+	                    }
+	                    return lastPageBeginIndex;
+	                } else {
+	                    return -1;
+	                }
+                } else {
+                    var lastPageBeginIndex = 0;
+                    if (info.totalSize > 0) {
+                        lastPageBeginIndex = parseInt((info.totalSize - 1) / info.pageSize)
* info.pageSize;
+                    }
+                    return Math.min((parseInt(scrollTo) - 1) * info.pageSize, lastPageBeginIndex);
+                }
+            },
+
+            getPageCount : function(info) {
+                var count = parseInt(info.totalSize / info.pageSize);
+                if (info.totalSize % info.pageSize != 0) {
+                    ++count;
+                }
+                return count;
+            },
+            
+            getCurrentPageIndex : function(info) {
+                if (info.totalSize > 0) {
+                    return parseInt(info.beginIndex / info.pageSize) + 1;
+                } else {
+                    return 0;
+                }
+            }
+    };
     
     function switchTab(e) {
         var tabId = null;
@@ -222,6 +288,9 @@
             return;
         }
         
+        pagination.portlet.totalSize = dataOut.totalSize;
+        pagination.portlet.beginIndex = Math.max(dataOut.beginIndex, 0);
+        
         var portletsPanel = Y.Node.one("#<portlet:namespace/>portletItemsPanel");
         var clonedPortletsPanel = portletsPanel.cloneNode(false);
         portletsPanel.get("parentNode").replaceChild(clonedPortletsPanel, portletsPanel);
@@ -236,9 +305,9 @@
             clone.setStyle('display', '');
             var imgNode = clone.one('img');
             if (def.portletIcon) {
-                imgNode.set("src", "${portalContextPrefix}/images/portlets/" + def.portletIcon);
+                imgNode.set("src", "${portalContextPath}/images/portlets/" + def.portletIcon);
             } else {
-                imgNode.set("src", "${portalContextPefix}/images/portlets/applications-other.png");
+                imgNode.set("src", "${portalContextPath}/images/portlets/applications-other.png");
             }
             
             var nameNode = clone.one('div');
@@ -260,6 +329,20 @@
             
             portletsPanel.appendChild(clone);
         }
+
+        var navSel = Y.one("#<portlet:namespace/>pageNavIndex");
+        var options = navSel.getElementsByTagName("OPTION");
+        for (var i = options.size() - 1; i > 0; i--) {
+            navSel.removeChild(options.item(i));
+        }
+        var pageCount = pagination.getPageCount(pagination.portlet);
+        for (var i = 1; i <= pageCount; i++) {
+            var option = Y.Node.create("<option value='" + i + "'>" + (i < 10 ?
" " + i : i) + "</option>");
+            navSel.appendChild(option);
+        }
+        var curPageIndex = pagination.getCurrentPageIndex(pagination.portlet);
+        var pageIndices = Y.Node.getDOMNode(navSel);
+        pageIndices.options[curPageIndex].selected = true;
     };
     
     var loadPortletsInCategory = function(e) {
@@ -272,8 +355,10 @@
             return;
         }
         Y.Cookie.set("toolboxcat", category);
-        var uri = "${portalContextPrefix}/services/portletregistry/definition/?_type=json";
+        var uri = "${portalContextPath}/services/portletregistry/definition/?_type=json";
+        uri += "&max=" + pagination.portlet.pageSize + "&begin=0";
         uri += "&query=" + category;
+        pagination.portlet.uri = uri;
         var request = Y.io(uri, { on: { complete: onLoadPortletComplete } });
         Y.Node.getDOMNode(Y.Node.one("#<portlet:namespace/>form")).query.value = "";
     }
@@ -281,14 +366,43 @@
     var loadPortletsByQuery = function(e) {
         var form = Y.Node.getDOMNode(e.target);
         var query = form.query.value;
-        var uri = "${portalContextPrefix}/services/portletregistry/definition/?_type=json";
+        var uri = "${portalContextPath}/services/portletregistry/definition/?_type=json";
+        uri += "&max=" + pagination.portlet.pageSize + "&begin=0";
         if (query) {
             uri += "&query=" + query;
         }
+        pagination.portlet.uri = uri;
         var request = Y.io(uri, { on: { complete: onLoadPortletComplete } });
-        
         Y.Node.getDOMNode(Y.Node.one("#<portlet:namespace/>categories")).selectedIndex
= 0;
+        e.halt();
+    };
 
+    var onPortletPaginationLinkClick = function(e) {
+        var navElem = e.target;
+        var beginIndex = pagination.getPageBeginIndex(pagination.portlet, navElem.getAttribute("pageIndex"));
+        
+        if (beginIndex != -1 && beginIndex != pagination.portlet.beginIndex) {
+            var uri = pagination.portlet.uri.replace(/&begin=\d+/, "&begin=" + beginIndex);
+            var request = Y.io(uri, { on: { complete: onLoadPortletComplete } });
+        }
+        
+        e.halt();
+    };
+
+    var onPortletPaginationSelectChange = function(e) {
+        var pageIndices = Y.Node.getDOMNode(e.target);
+        var pageIndex = pageIndices.options[pageIndices.selectedIndex].value;
+        if (pageIndex) {
+	        var beginIndex = pagination.getPageBeginIndex(pagination.portlet, pageIndex);
+	        
+	        if (beginIndex != -1 && beginIndex != pagination.portlet.beginIndex) {
+	            var uri = pagination.portlet.uri.replace(/&begin=\d+/, "&begin=" + beginIndex);
+	            var request = Y.io(uri, { on: { complete: onLoadPortletComplete } });
+	        }
+        } else {
+            var curPageIndex = pagination.getCurrentPageIndex(pagination.portlet);
+            pageIndices.options[curPageIndex].selected = true;
+        }
         e.halt();
     };
 
@@ -308,7 +422,7 @@
             return;
         }
 
-        var portal = JETUI_YUI.getPortalInstance();
+        var portal = (JETUI_YUI ? JETUI_YUI.getPortalInstance() : null);
         if (portal) {
 	        portal.addPortlet(dataOut);
         } else {
@@ -321,7 +435,7 @@
         var portletUniqueName = a.getAttribute("portletUniqueName");
 
         if (portletUniqueName) {
-            var uri = "${portalContextPrefix}/services/pagelayout/fragment/portlet/" + portletUniqueName
+ "/?_type=json";
+            var uri = "${portalContextPath}/services/pagelayout/fragment/portlet/" + portletUniqueName
+ "/?_type=json";
             var config = {
                     on: { complete: onAddPortletComplete },
                     method: "POST",
@@ -341,6 +455,13 @@
     Y.on("change", loadPortletsInCategory, "#<portlet:namespace/>categories");
     Y.on("submit", loadPortletsByQuery, "#<portlet:namespace/>form");
     
+    var pageNavBar = Y.one("#<portlet:namespace/>pageNavBar");
+    var navLinks = pageNavBar.all(".jstbPageNav");
+    navLinks.each(function(v, k) {
+        v.on("click", onPortletPaginationLinkClick);
+    });
+    Y.one("#<portlet:namespace/>pageNavIndex").on("change", onPortletPaginationSelectChange);
+    
     var tabId = Y.Cookie.get("toolboxtab");
     if (!tabId) {
         tabId = "portlets";



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message