Author: taylor
Date: Thu Jan 25 17:57:48 2007
New Revision: 500088

URL: http://svn.apache.org/viewvc?view=rev&rev=500088
Log:
https://issues.apache.org/jira/browse/JS2-635
In the portlet selector.count against the portlet doesn't match with number of 
that portlet on the same page
Paging functionality implemented as well.

contribution from Vivek Kumar

Modified:
    
portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/PortletInfo.java
    
portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/selector/CategoryPortletSelector.java
    
portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/view/selectors/category-portlet-selector.vm

Modified: 
portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/PortletInfo.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/PortletInfo.java?view=diff&rev=500088&r1=500087&r2=500088
==============================================================================
--- 
portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/PortletInfo.java
 (original)
+++ 
portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/PortletInfo.java
 Thu Jan 25 17:57:48 2007
@@ -31,8 +31,9 @@
     String displayName;
     String description;
     String image;
+    int count;
     
-    public PortletInfo(String name, String displayName, String description)
+       public PortletInfo(String name, String displayName, String description)
     {
         this.name = name;
         this.displayName = displayName;
@@ -47,6 +48,16 @@
         this.image = image;
     }
     
+    public PortletInfo(String name, String displayName, String description, 
String image,int count)
+    {
+        this.name = name;
+        this.displayName = displayName;
+        this.description = description;
+        this.image = image;
+        this.count = count;
+    }
+    
+    
     /**
      * @return Returns the description.
      */
@@ -86,4 +97,23 @@
     {
         this.image = image;
     }
+    /**
+        * @return the count
+        */
+       public int getCount() {
+               return count;
+       }
+
+       /**
+        * @param count the count to set
+        */
+       public void setCount(int count) {
+               this.count = count;
+       }
+
+       public Object clone() throws CloneNotSupportedException {
+               return new 
PortletInfo(this.name,this.displayName,this.description,this.image,this.count);
+       }
+       
+       
 }

Modified: 
portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/selector/CategoryPortletSelector.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/selector/CategoryPortletSelector.java?view=diff&rev=500088&r1=500087&r2=500088
==============================================================================
--- 
portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/selector/CategoryPortletSelector.java
 (original)
+++ 
portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/selector/CategoryPortletSelector.java
 Thu Jan 25 17:57:48 2007
@@ -22,6 +22,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
@@ -49,6 +50,11 @@
 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 import org.apache.jetspeed.om.common.preference.PreferenceComposite;
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.om.page.Fragment;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.page.document.Node;
 import org.apache.jetspeed.portlets.CategoryInfo;
 import org.apache.jetspeed.portlets.PortletInfo;
 import org.apache.jetspeed.search.ParsedObject;
@@ -78,10 +84,14 @@
     protected final static String PORTLETS = "category.selector.portlets";
     protected final static String CATEGORIES = "category.selector.categories";
     protected final static String PAGE = "category.selector.page";
-    public final static String JSPAGE = "jspage";
+    private final  String JSPAGE = "jspage";
+       private final String CATEGORY = "category";
+       private final String PAGENUMNER = "pageNumber";
+       private final String FILTER = "filter";
     
     protected PortletRegistry registry;
     protected SearchEngine searchEngine;
+    protected PageManager pageManager;
     protected Random rand;
     
     public void init(PortletConfig config)
@@ -99,16 +109,39 @@
         {
             throw new PortletException("Failed to find the Search Engine on 
portlet initialization");
         }
+        pageManager = 
(PageManager)context.getAttribute(CommonPortletServices.CPS_PAGE_MANAGER_COMPONENT);
+        if (null == pageManager)
+        {
+            throw new PortletException("Failed to find the Page Manager on 
portlet initialization");
+        }        
         rand = new Random( 19580427 );
     }
     
     public void doView(RenderRequest request, RenderResponse response)
             throws PortletException, IOException
     {
-        PortletPreferences prefs = request.getPreferences();
-        this.getContext(request).put("Columns", prefs.getValue("Columns", 
"4"));
-        this.getContext(request).put("Rows", prefs.getValue("Rows", "6"));
-        this.getContext(request).put("portlets", retrievePortlets(request, 
null));
+       String category = "All";
+       String pageNumber = ""; 
+               String row = "";                
+               String columns = "";
+               int portletPerPages=0;
+       PortletPreferences prefs = request.getPreferences();
+               category = request.getParameter(CATEGORY);
+               pageNumber = request.getParameter(PAGENUMNER);
+               String filter = request.getParameter(FILTER);
+               columns = prefs.getValue("Columns", "4");
+               row = prefs.getValue("Rows", "6");
+               portletPerPages = Integer.parseInt(columns) * 
Integer.parseInt(row);
+               if (category == null || category.equals("")) category = "All";
+               if (pageNumber == null || pageNumber.equals("")) pageNumber = 
"1";
+               if (filter == null ||  filter.equals("")) filter = null;
+               CategoryResult result = getPortlets(request, category, 
pageNumber, portletPerPages, filter);
+        this.getContext(request).put("Columns", columns);
+        this.getContext(request).put("Rows", row);
+        this.getContext(request).put("pageNumber", pageNumber);
+        this.getContext(request).put("category", category);
+        this.getContext(request).put("portlets", 
mergePortletCount(result.getList(),request));
+        this.getContext(request).put("Count", new 
Integer(result.getResultSize()));
         this.getContext(request).put("categories", 
retrieveCategories(request));
         processPage(request);
         super.doView(request, response);
@@ -125,8 +158,7 @@
         {
             request.getPortletSession().setAttribute(PAGE, page);
         }
-        this.getContext(request).put(JSPAGE, page);
-        
+        this.getContext(request).put(JSPAGE, page);        
     }
     
     public List retrieveCategories(RenderRequest request)
@@ -191,7 +223,7 @@
     public List retrievePortlets(RenderRequest request, String filter)
     {
         List portletsList = 
(List)request.getPortletSession().getAttribute(PORTLETS);
-        if (portletsList != null)
+        if (filter == null && portletsList != null)
         {
             return portletsList;
         }        
@@ -218,11 +250,41 @@
             }
         }            
         Collections.sort(list, this);
-        request.getPortletSession().setAttribute(PORTLETS, list);
+        if(filter == null ) request.getPortletSession().setAttribute(PORTLETS, 
list);
         return list;
     }
-
     
+
+    private List mergePortletCount(List sysPortlets,
+                       RenderRequest request) {
+               List list = new ArrayList();
+               int sPortletCnt = 0;
+               Iterator iterator;
+               String usrPortletName = null;
+               PortletInfo tmpPortletInfo = null;
+               String portletName;
+               try {
+                       Map usrPortlet = getUserPortlet(getPage(request));
+                       sPortletCnt = sysPortlets.size();
+                       for (int si = 0; si < sPortletCnt; si++) {
+                               tmpPortletInfo = 
(PortletInfo)((PortletInfo)sysPortlets.get(si)).clone(); 
+                               portletName = tmpPortletInfo.getName();
+                               iterator = usrPortlet.keySet().iterator();
+                               while (iterator.hasNext()) {
+                                       usrPortletName = (String) 
iterator.next();
+                                       if 
(usrPortletName.equalsIgnoreCase(portletName)) {
+                                               
tmpPortletInfo.setCount(((Integer)usrPortlet.get(usrPortletName)).intValue());
+                                       }
+                               }
+                               list.add(tmpPortletInfo);
+                               tmpPortletInfo = null;
+                       }
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+               return list;
+       }
+
     
     /**
      * Filters portlets being added to the based on security checks and layout 
criteria
@@ -437,8 +499,8 @@
             actionResponse.setRenderParameter(JSPAGE, page);
         }
         else
-        {
-            String reset = request.getParameter("reset");        
+        {            
+               String reset = request.getParameter("reset");        
             if (reset != null && reset.equals("true"))
             {
                 PortletSession session = request.getPortletSession();
@@ -572,4 +634,130 @@
         processPage(request);
         super.doEdit(request, response);
     }
+    
+    private CategoryResult getPortlets(RenderRequest request,
+                       String category, String pageNumber, int 
portletPerPages,String filter) {
+               List list = new ArrayList();
+               List tmpList = null;
+               List catList = null;
+               Iterator iterator = null;
+               int portletCount = 0;
+               CategoryInfo catInfo = null;
+               int strtCnt = getStartRow(pageNumber, portletPerPages);
+               int endCnt = getEndRow(pageNumber, portletPerPages);
+               try {                   
+                       if (category.equalsIgnoreCase("all")) {                 
        
+                               tmpList = retrievePortlets(request, filter);
+                               portletCount = tmpList.size();
+                               if (endCnt > portletCount)
+                                       endCnt = portletCount;
+                               for (int index = strtCnt; index < endCnt; 
index++) {
+                                       list.add(tmpList.get(index));
+                               }
+                       } else if (category.equalsIgnoreCase("search")) {
+                               tmpList = retrievePortlets(request, filter);
+                               portletCount = tmpList.size();
+                               if (endCnt > portletCount)
+                                       endCnt = portletCount;
+                               for (int index = strtCnt; index < endCnt; 
index++) {
+                                       list.add(tmpList.get(index));
+                               }
+                       } else {
+                               tmpList =  retrieveCategories(request);
+                               iterator = tmpList.iterator();
+                               while (iterator.hasNext()) {
+                                       catInfo = (CategoryInfo) 
iterator.next();
+                                       if 
(catInfo.getName().equalsIgnoreCase(category)) {
+                                               catList = catInfo.getPortlets();
+                                               break;
+                                       }
+                               }
+                               portletCount = catList.size();
+                               if (endCnt > portletCount)
+                                       endCnt = portletCount;
+                               for (int index = strtCnt; index < endCnt; 
index++) {
+                                       list.add(catList.get(index));
+                               }
+                       }
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+               return new CategoryResult(list, portletCount);
+       }
+    
+    
+       private int getStartRow(String sPageNumber, int portletPerPages) {
+               int iPageNumber = Integer.parseInt(sPageNumber);
+               return (iPageNumber - 1) * portletPerPages;
+       }
+
+       private int getEndRow(String sPageNumber,int portletPerPages) {
+               int iPageNumber = Integer.parseInt(sPageNumber);
+               return iPageNumber * portletPerPages;
+       }
+       private Map getUserPortlet(Page page) {
+               int portletCount = 0;
+               Map map = new HashMap();
+               try {
+                       Fragment fragment;
+                       Iterator it = 
page.getRootFragment().getFragments().iterator();
+                       while (it.hasNext()) {
+                               fragment = (Fragment) it.next();
+                               if (map.containsKey(fragment.getName())) {
+                                       portletCount =((Integer) 
map.get(fragment.getName())).intValue();                               
+                                       map.put(fragment.getName(), new 
Integer(portletCount + 1));                                     
+                               } else {
+                                       map.put(fragment.getName(), new 
Integer(1));
+                               }
+                       }
+               } catch (Exception e) {
+                       System.out.println(e.getMessage());
+                       e.printStackTrace();
+               }
+               return map;
+       }
+       private Page getPage(RenderRequest request) throws Exception
+       {
+               String user = request.getUserPrincipal().getName();
+               String page = request.getParameter("jspage");
+               String path;
+               if (page.equals("/")) page= Node.PATH_SEPARATOR + 
Folder.FALLBACK_DEFAULT_PAGE;
+               if (user.equals("admin"))
+               {
+                       path  = page;
+               }else
+               {
+                       path  = Folder.USER_FOLDER  + user + page;
+               }
+               return pageManager.getPage(path);                 
+
+       }
+       class CategoryResult {
+               List list;
+
+               int resultSize;
+
+               /**
+                * @param list
+                * @param resultSize
+                */
+               public CategoryResult(List list, int resultSize) {
+                       this.list = list;
+                       this.resultSize = resultSize;
+               }
+
+               /**
+                * @return the list
+                */
+               public List getList() {
+                       return list;
+               }
+
+               /**
+                * @return the resultSize
+                */
+               public int getResultSize() {
+                       return resultSize;
+               }
+       }
 }

Modified: 
portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/view/selectors/category-portlet-selector.vm
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/view/selectors/category-portlet-selector.vm?view=diff&rev=500088&r1=500087&r2=500088
==============================================================================
--- 
portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/view/selectors/category-portlet-selector.vm
 (original)
+++ 
portals/jetspeed-2/trunk/applications/j2-admin/src/webapp/WEB-INF/view/selectors/category-portlet-selector.vm
 Thu Jan 25 17:57:48 2007
@@ -15,15 +15,20 @@
 *#
 #set ($refreshLink = $renderResponse.createActionURL())
 $refreshLink.setParameter("reset","true")
+#set ($renderLink = $renderResponse.createRenderURL())
+#set ($pagePath = $renderRequest.getParameter("jspage"))
 <!-- Search Form -->
 <form id='jsSelectorForm' onSubmit='return false;' style="height:21px; 
padding: 2px; margin:10px">
 <table>
 <tr>
 <td nowrap class="portlet-section-alternate" align="right">Search for 
portlets:&nbsp;</td>
 <td nowrap class="portlet-section-alternate">
-<input type="text" name="searchString" id="searchString" size="40" 
value="$!searchString" class="portlet-form-field-label">    
+<input type="text" name="filter" id="searchString" size="40" 
value="$!searchString" class="portlet-form-field-label">    
 <input type="submit" value="Search" onClick='javascript:performSearch();'>
 <input type="submit" value="Refresh" onClick="javascript:performRefresh()">
+<input type="hidden" value="$category" id="category" name="category">
+<input type="hidden" value="$pageNumber" id="pageNumber" name="pageNumber">
+<input type="hidden" value="$pagePath" id="pageNumber" name="jspage">
 </td>
 <td nowrap>
 <a href='' id='previousButton'><img style="border:none" 
src="images/portlets/go-previous.png"></a>
@@ -34,21 +39,35 @@
 
 <table id='ctable' cellspacing="5" cellpadding="5" style="margin:10px">
 </table>
+<table id='pagtable' border="1" cellspacing="10" cellpadding="1" 
align="center">
+    <tr>
+        <td>
+            <table id='pagtable1' border="1" cellspacing="10" cellpadding="1">
+            </table>
+        </td>
+        <td>
+            <table id='pagtable2' border="1" cellspacing="10" cellpadding="1">
+            </table>
+        </td>
+        <td>
+            <table id='pagtable3' border="1" cellspacing="10" cellpadding="1">
+            </table>
+        </td>    
+</table>
 <table id='ptable' border="1" cellspacing="10" cellpadding="1">
 </table>
 <script language="JavaScript" type="text/javascript">
-function PortletInfo(name, display, desc, image)
+function PortletInfo(name, display, desc, image, count)
 {
   this.name = name;
   this.display = display;
   this.desc = desc;
   this.image = image;
-  this.count = 0;
+  this.count = count;
 }
 function CategoryInfo(name)
 {
    this.name = name;
-   this.portlets = new Array();
 }
 function performRefresh()
 {
@@ -56,100 +75,26 @@
    searchForm.action = "$refreshLink";
    searchForm.submit();
 }
-function displayPortlets(cat)
-{                                             
-   if (cat == null)
-   {
-      cat = "All"; // TODO: localize
-   }
-   var currentPortlets = selectorPortlets;
-
-   for (i=0; i < this.categories.length; i++)
-   {
-       if (this.categories[i].name == cat)
-       {
-          catPortlets = this.categories[i].portlets;
-          break;
-       }
-   }
-    var ptable = document.getElementById('ptable');
-    while (ptable.hasChildNodes())
-    {
-      ptable.removeChild(ptable.lastChild);
-    }
-    var portletCount = 0;
-    var rowCount = 0;
-    var columns = $Columns;
-    var outerRow = null;
-    // TODO: rows
-    for (iz = 0; iz <  catPortlets.length; iz++)
-    {         
-         var cellIndex = portletCount % columns;
-         if (cellIndex == 0)
-         {
-             outerRow = ptable.insertRow(rowCount);
-             rowCount = rowCount + 1;
-         }
-         var cell = outerRow.insertCell(cellIndex);            
-         var pt1 = document.createElement("table");
-         var row0 = pt1.insertRow(0);
-         var c0 = row0.insertCell(0);
-         var c1 = row0.insertCell(1);
-         c1.setAttribute("style","font-size: 9pt; color: blue;");
-         //c1.setAttribute("class","portlet-selector-title");
-         var image = new Image();
-
-         image.src = currentPortlets[catPortlets[iz]].image;
-
-         c0.appendChild(image);
-         c1.innerHTML = currentPortlets[catPortlets[iz]].display;
-        
-         var pt2 = document.createElement("table");
-         var row1 = pt2.insertRow(0);
-         c0 = row1.insertCell(0);
-         c0.setAttribute("style","font-size: 8pt; color: green;");
-         //c0.setAttribute("class","portlet-selector-text");
-         c0.innerHTML = currentPortlets[catPortlets[iz]].desc;
-         
-         var pt3 = document.createElement("table");
-         var row3 = pt3.insertRow(0);
-         c0 = row3.insertCell(0);
-         c0.setAttribute("style","font-size: 8pt; color: blue;");
-         var a = document.createElement("a");
-         a.innerHTML = "Add"; // TODO: localize
-         a.href = "javascript:addPortletToPage(" + "\"" + 
currentPortlets[catPortlets[iz]].name + "\"" + ")";
-         c0.appendChild(a);
-         c1 = row3.insertCell(1);
-         c1.innerHTML = "Count: " + currentPortlets[catPortlets[iz]].count; // 
TODO: localize
-         c1.setAttribute("style","font-size: 8pt; color: blue;");
-         c1.setAttribute("id", currentPortlets[catPortlets[iz]].name);
-
-         cell.appendChild(pt1);
-         cell.appendChild(pt2);
-         cell.appendChild(pt3);
-         portletCount = portletCount + 1;
-    }
-    highlightSelectedCategory(cat);
-}
-function addPortletToPage(theNewPortlet)
+function addPortletToPage(theNewPortlet,pID)
 {                                                      
    //dojo.widget.byId("AddPortletDialog").hide();   
    var portletDef = new jetspeed.om.PortletDef( theNewPortlet );   
    var pagePath = jetspeed.url.basePortalUrl() + jetspeed.url.path.AJAX_API + 
getReturnPagePath();
    jetspeed.addNewPortletDefinition( portletDef, null, pagePath, 
getAddToLayoutId() );
-   selectorPortlets[theNewPortlet].count = 
selectorPortlets[theNewPortlet].count + 1;
+   selectorPortlets[pID].count = parseInt(selectorPortlets[pID].count) + 1;
    var cell = document.getElementById(theNewPortlet);
    if (cell != null)
    {
-      cell.innerHTML = "Count: " + selectorPortlets[theNewPortlet].count; // 
TODO: localize
+      cell.innerHTML = "Count: " + selectorPortlets[pID].count; // TODO: 
localize
    }   
 }
 function performSearch()
 {
-   var ix = this.categories.length-1;
-   this.categories[ix].portlets = new Array();    
-   var searchString = document.getElementById("searchString").value;
-   jetspeed.searchForPortletDefinitions(searchString, searchFinishedFunction);
+    var searchForm = document.getElementById('jsSelectorForm');        
+       document.getElementById("category").value = 'Search';
+    document.getElementById("pageNumber").value='1';
+    searchForm.action = "$renderLink";
+    searchForm.submit();
 }
 function searchFinishedFunction(domainObjects, portletList)
 {
@@ -175,51 +120,216 @@
              a.setAttribute("style", "font-weight:normal");
     }
 }
-function initializePortletSelector()
+function createPagination(Pagenumber,PageCount)
 {
-    categories[0] = new CategoryInfo("All");
-    #foreach ( $portlet in $portlets )
-    selectorPortlets["$portlet.Name"] = new PortletInfo("$portlet.Name", 
"$!portlet.DisplayName", "$!portlet.Description", "$!portlet.Image");
-    #set ($count = $velocityCount - 1)
-    categories[0].portlets[$count] = "$portlet.Name";
-    #end
-    #foreach ( $cat in $categories)
-    categories[$velocityCount] = new CategoryInfo("$cat.Name");
-    #set ($icount = $velocityCount)
-    #foreach ( $portlet in $cat.Portlets )
-    #set ($jcount = $velocityCount - 1)
-    categories[$icount].portlets[$jcount] = "$portlet.Name";
-    #end
-    #end
-    var ctable = document.getElementById('ctable');
-    var row = ctable.insertRow(0);
-    for(i=0; i<categories.length; i++)
-    {    
-         var c1 = row.insertCell(i);
-         var a = document.createElement("a");
-         a.innerHTML = categories[i].name;
-         a.href = "javascript:displayPortlets(" + "\"" + categories[i].name + 
"\"" + ")";
-         a.setAttribute("style", "font-weight:normal");
-         c1.appendChild(a);
+    var pagtable1 = document.getElementById('pagtable1');   
+    while (pagtable1.hasChildNodes())
+    {
+      pagtable1.removeChild(pagtable1.lastChild);
     }
-     categories[categories.length] = new CategoryInfo("Search"); // TODO: 
localize
-     var c1 = row.insertCell(i);
-     var a = document.createElement("a");
-     a.innerHTML = categories[i].name;
-     a.href = "javascript:displayPortlets(" + "\"" + categories[i].name + "\"" 
+ ")";
-     a.setAttribute("style", "font-weight:normal");
-     c1.appendChild(a);
-     var c2 = row.insertCell(i+1);
-     var a2 = document.createElement("a");
-     a2.innerHTML = "[Go Back]";  // TODO: localize
-     // TODO: determine if JETSPEED or DESKTOP 
-     a2.href = getReturnURL();
-     a2.setAttribute("style", "font-weight:normal");
-     c2.appendChild(a2);
-     var prevButton = document.getElementById("previousButton");
-     prevButton.setAttribute('href', getReturnURL());
-     displayPortlets("All");
+    var pagtable3 = document.getElementById('pagtable3');   
+    while (pagtable3.hasChildNodes())
+    {
+      pagtable3.removeChild(pagtable3.lastChild);
+    }
+    
+    var pagtable = document.getElementById('pagtable2');   
+    while (pagtable.hasChildNodes())
+    {
+      pagtable.removeChild(pagtable.lastChild);
+    }    
+    var pgRoww = null;
+    var pgCol=null;
+    var a = null;    
+    pgRoww = pagtable1.insertRow(0);
+    pgCol = pgRoww.insertCell(0);
+    if (Pagenumber != 1)
+    {
+        a = document.createElement("a");
+        a.innerHTML = 'Previous';
+        a.href = "javascript:displayPortlets(" + "\"" + (Pagenumber-1)+ "\"" + 
")";
+        pgCol.appendChild(a);              
+        pgCol = pgRoww.insertCell(1);    
+        a = document.createElement("a");
+        a.innerHTML = 'First';
+        a.href = "javascript:displayPortlets(" + "\"" + 1+ "\"" + ")";
+        pgCol.appendChild(a);              
+    }
+    
+    if (PageCount > 1)
+    {
+        var pgRoww = pagtable.insertRow(0);
+        var pgCol=null;
+        var a = null;  
+        for(iz=0;iz<PageCount;iz++)
+        {
+            pgCol = pgRoww.insertCell(iz);
+            if (Pagenumber != iz+1){
+                a = document.createElement("a");
+                a.innerHTML = iz+1;
+                a.href = "javascript:displayPortlets(" + "\"" + (iz+1) + "\"" 
+ ")";
+                pgCol.appendChild(a);       
+            }else{
+                pgCol.innerHTML = (iz+1);
+            }       
+         }
+     }
+    pgRoww = pagtable3.insertRow(0);
+    pgCol = pgRoww.insertCell(0);
+    if (Pagenumber != PageCount)
+    {
+        if (PageCount > 1)     
+        {
+                                 a = document.createElement("a");
+                               a.innerHTML = 'Last';
+                               a.href = "javascript:displayPortlets(" + "\"" + 
PageCount+ "\"" + ")";
+                               pgCol.appendChild(a);              
+                               pgCol = pgRoww.insertCell(1);   
+                               a = document.createElement("a");    
+                               a.innerHTML = 'Next';
+                               a.href = "javascript:displayPortlets(" + "\"" + 
(parseInt(Pagenumber)+1)+ "\"" + ")";
+                               pgCol.appendChild(a);              
+                       }
+    }
+}
+
+function categoriesBar()
+{
+         categories[0] = new CategoryInfo("All");    
+  #foreach ( $cat in $categories)
+                 categories[$velocityCount] = new CategoryInfo("$cat.Name");
+               #set ($icount = $velocityCount)
+  #end
+  var ctable = document.getElementById('ctable');
+  var row = ctable.insertRow(0);
+  for(i=0; i<categories.length; i++)
+  {    
+    var c1 = row.insertCell(i);
+    var a = document.createElement("a");
+    a.innerHTML = categories[i].name;
+    a.href = "javascript:displayCategorties(" + "\"" + categories[i].name + 
"\"" + ")";
+    a.setAttribute("style", "font-weight:normal");
+    c1.appendChild(a);
+  }
+  categories[categories.length] = new CategoryInfo("Search"); // TODO: localize
+  var c1 = row.insertCell(i);
+  var a = document.createElement("a");
+  a.innerHTML = categories[i].name;
+  a.href = "javascript:displayCategorties(" + "\"" + categories[i].name + "\"" 
+ ")";
+  a.setAttribute("style", "font-weight:normal");
+  c1.appendChild(a);
+  var c2 = row.insertCell(i+1);
+  var a2 = document.createElement("a");
+  a2.innerHTML = "[Go Back]";  // TODO: localize
+  // TODO: determine if JETSPEED or DESKTOP 
+  a2.href = getReturnURL();
+  a2.setAttribute("style", "font-weight:normal");
+  c2.appendChild(a2);
+  var prevButton = document.getElementById("previousButton");
+  prevButton.setAttribute('href', getReturnURL());
 }
+function displayGridPortlet()
+{
+  //var currentPortlets = selectorPortlets;
+       //getting portlet table and deleting all items
+       //befor adding the new
+       var ptable = document.getElementById('ptable');
+  while (ptable.hasChildNodes())
+  {
+      ptable.removeChild(ptable.lastChild);
+  }
+       var outerRow = null;
+       var iz = 0;
+       var ri = 0;
+       var ci = 0;
+  //for(ri=0;ri<$Rows;ri++)
+                 //alert(' s ' +  selectorPortlets.length);
+               while(iz<selectorPortlets.length)
+                 {
+                       //alert('cret  iz ' + iz);      
+                       //alert('cret  row ' + ci);     
+                       if (iz > 0)
+                       {
+                               //alert('cret  row ' + iz % $Columns);  
+                               if (iz % $Columns ==0)
+                               {
+        ri =  ri+1;
+                                               ci = 0;
+                                               outerRow = 
ptable.insertRow(ri);                                                           
     
+                               }
+                       }
+                       else
+                       {
+                                       outerRow = ptable.insertRow(ri);        
                                                        
+                       }               
+                                var cell = outerRow.insertCell(ci);            
+                                // Creating the image and Name table           
+                                var pt1 = document.createElement("table");
+                                   var row0 = pt1.insertRow(0);
+                                   var c0 = row0.insertCell(0);
+                                var c1 = row0.insertCell(1);
+                                   c1.setAttribute("style","font-size: 9pt; 
color: blue;");
+                                   var image = new Image();
+                                   image.src = selectorPortlets[iz].image;
+                                c0.appendChild(image);
+                                c1.innerHTML = selectorPortlets[iz].display;
+                                
+                                // Creating description table
+                                var pt2 = document.createElement("table");
+                                var row1 = pt2.insertRow(0);
+                                c0 = row1.insertCell(0);
+                                   c0.setAttribute("style","font-size: 8pt; 
color: green;");
+                                c0.innerHTML = selectorPortlets[iz].desc;
+                                
+                                // Creating the Add link and count table
+                                var pt3 = document.createElement("table");
+                                var row3 = pt3.insertRow(0);
+                                c0 = row3.insertCell(0);
+                                c0.setAttribute("style","font-size: 8pt; 
color: blue;");
+                                var a = document.createElement("a");
+                                a.innerHTML = "Add"; // TODO: localize
+                                a.href = 
"javascript:addPortletToPage("+"\""+selectorPortlets[iz].name+"\""+",\"" + iz + 
"\")";
+                                c0.appendChild(a);
+                                c1 = row3.insertCell(1);
+                                // TODO: localize
+                                c1.innerHTML = "Count: " + 
selectorPortlets[iz].count;
+                                c1.setAttribute("style","font-size: 8pt; 
color: blue;");
+                                c1.setAttribute("id", 
selectorPortlets[iz].name);
+
+                                //Adding the final tables in Cell
+                                cell.appendChild(pt1);
+                                cell.appendChild(pt2);
+                                cell.appendChild(pt3);
+                               iz=iz+1;
+                               ci =  ci + 1;
+                       //}
+                 }
+}
+function initializePortletSelector()
+{
+  categoriesBar();
+       var pageCount = getPageCount($Count,$Columns*$Rows);    
+       displayGridPortlet();
+       createPagination($pageNumber,pageCount);
+       highlightSelectedCategory('$category');
+}
+function displayCategorties(category)
+{
+       renderPage(category,1);
+}
+function displayPortlets(pageNumber)
+{
+       renderPage(document.getElementById("category").value,pageNumber);
+}
+function renderPage(category,pageNumber)
+{
+       document.getElementById("category").value = category;
+    document.getElementById("pageNumber").value=pageNumber;
+    var searchForm = document.getElementById('jsSelectorForm');
+    searchForm.action = "$renderLink";
+    searchForm.submit();
+}
+
 function getReturnPagePath()
 {
    var jsPagePath = jetspeed.url.getQueryParameter( document.location.href, 
"jspage" );
@@ -227,6 +337,15 @@
       jsPagePath = "";
    return jsPagePath;
 }
+function getPageCount(portletCount,portletPerPage)
+{
+                 var tmp = Math.floor(portletCount / portletPerPage);
+                 if (portletCount % portletPerPage > 0) {
+                           return (tmp + 1);
+               } else {
+                       return (tmp);
+               }
+}
 function getAddToLayoutId()
 {
    var jsLayoutId = jetspeed.url.getQueryParameter( document.location.href, 
"jslayoutid" );
@@ -236,8 +355,12 @@
 {
    return jetspeed.url.basePortalUrl() + jetspeed.url.path.JETSPEED + 
jetspeed.url.servletPath() + getReturnPagePath();
 }
-
 window.selectorPortlets = new Array();
 window.categories = new Array();
+#set ($count = 0)
+#foreach ( $portlet in $portlets )
+   selectorPortlets[$count] = new PortletInfo("$portlet.Name", 
"$!portlet.DisplayName", "$!portlet.Description", "$!portlet.Image", 
"$!portlet.Count");
+   #set ($count = $count + 1)
+#end
 dojo.addOnLoad( window.initializePortletSelector );
 </script>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to