I've done several changes to the code. I'm near form the whole change.

But, I have a problem with the panel. I don't know what's the best way
to put
portlet information on web. 

It's supposed that I have to use the table already created but I don't
know how
te set information via YUI3:

+<table id="portlet-body-html" style="border-collapse: collapse; width:
100%; margin-top: 0px; margin-bottom: 0px; float: left;">
+    <tr>
+       <td rowspan="2" width="20%" class="portlet-section-body">
+           <img src='${portalContextPath}' />
+       </td>
+       <td id="name" width="80%" class="portlet-section-body">#</td>
+    </tr>       
+    <tr>
+       <td class="portlet-section-body">
+           <a href="#">Preview</a>  
+           <a href="#">Add</a>
+       </td>
+    </tr>
+</table>
+

I only managed to set the images. Normally a custom widget should be
created but I have
not enough knowledge about YUI. 

The rest works well... The only change needed is to do the filter to be
able to load on category click
but this will be trivial. 

If you help me to put information in each field I will finish this.


The rest of the changes:



        Prepatch-j2-admin-JS2-1057: 
        
                * Removed server retrieve of portlets (famous two lines)
                * Modified a bit the jsp code.
                
        
        Prepatch-jetspeed-2-JS2-1057:
        
                * portal.js - added ajax request and load using JSON
                * modified getportlets to handle json output.
                * GetPortletsAction - added support for JSON
                * Fixed a bug that caused xml and json fail when bad
                escaped texts found in description or name of the
                portlet.
                
                

It's not much but it took me a lot of time figure out how everything
glue, and setting dev environment caused some trouble :D

Your ideas will be welcome...

Tnx

<<attachment: face-smile-big.png>>

Index: src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java
===================================================================
--- src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java     
(revision 882123)
+++ src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java     
(working copy)
@@ -157,8 +157,8 @@
         
         //TODO: The following two lines need to be move somewhere like 
'serveResource()'
         //      because portlets info should be retrieved from ajax calls.
-        List<PortletInfo> portlets = retrievePortlets(request, null);
-        request.setAttribute("portlets", portlets);
+        //List<PortletInfo> portlets = retrievePortlets(request, null);
+        //request.setAttribute("portlets", portlets);
         
         request.setAttribute("categories", retrieveCategories(request));
         request.setAttribute("layouts", LayoutBean.retrieveLayouts(request, 
decorationFactory));
Index: src/main/webapp/META-INF/MANIFEST.MF
===================================================================
--- src/main/webapp/META-INF/MANIFEST.MF        (revision 0)
+++ src/main/webapp/META-INF/MANIFEST.MF        (revision 0)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path: 
+
Index: src/main/webapp/WEB-INF/view/toolbox/toolbox.jsp
===================================================================
--- src/main/webapp/WEB-INF/view/toolbox/toolbox.jsp    (revision 882123)
+++ src/main/webapp/WEB-INF/view/toolbox/toolbox.jsp    (working copy)
@@ -64,6 +64,7 @@
         div.style.display = (div.style.display == "none" ? "" : "none");
     }
 }
+
 </script>
 
 <form id='jsPortletSearch' method="POST" action='<portlet:actionURL/>'>
@@ -88,7 +89,7 @@
     <tr>
         <td class="portlet-section-subheader" colspan='10'>
             <input type="text" name="filter" size="15" value="" >
-            <input type="submit" value="search" />
+            <input type="submit" value="search" onClick="loadPortlets(null); 
alert('test');"/>
         </td>
     </tr>
     
@@ -106,29 +107,16 @@
     <tr>
         <td>
             <div style="height: 400px; overflow: auto;">
-                <table style="border-collapse: collapse; width: 100%; 
margin-top: 0px; margin-bottom: 0px; float: left;">
+                <table class="portlet-panel-portlets" style="border-collapse: 
collapse; width: 100%; margin-top: 0px; margin-bottom: 0px; float: left;">
+                                       <!--
                     <c:forEach var="portletInfo" items="${portlets}">
                         <tr>
                             <td class="portlet-section-body" 
style='background: #fff'>
-                                <table style="border-collapse: collapse; 
width: 100%; margin-top: 0px; margin-bottom: 0px; float: left;">
-                                    <tr>
-                                       <td rowspan="2" width="20%" 
class="portlet-section-body">
-                                           <img src='<c:url 
context="${portalContextPath}" value="${portletInfo.image}"/>'/>
-                                       </td>
-                                       <td width="80%" 
class="portlet-section-body">${portletInfo.displayName}</td>
-                                    </tr>       
-                                    <tr>
-                                       <td class="portlet-section-body">
-                                           <a 
href="<portlet:actionURL><portlet:param name='portletPreview' 
value='${portletInfo.name}'/></portlet:actionURL>">Preview</a>
-                                            <c:if test="${editAccess}">
-                                               <a 
href="<portlet:actionURL><portlet:param name='portletAdd' 
value='${portletInfo.name}'/></portlet:actionURL>">Add</a>
-                                           </c:if>
-                                       </td>
-                                    </tr>
-                                </table>
+                                
                             </td>
                         </tr>
                     </c:forEach>
+                                       -->
                 </table>
             </div>
         </td>
@@ -139,6 +127,21 @@
     </tr>
 </table>
 
+<table id="portlet-body-html" style="border-collapse: collapse; width: 100%; 
margin-top: 0px; margin-bottom: 0px; float: left;">
+    <tr>
+       <td rowspan="2" width="20%" class="portlet-section-body">
+           <img src='${portalContextPath}' />
+       </td>
+       <td id="name" width="80%" class="portlet-section-body">#</td>
+    </tr>       
+    <tr>
+       <td class="portlet-section-body">
+           <a href="#">Preview</a>  
+           <a href="#">Add</a>
+       </td>
+    </tr>
+</table>
+
 <table id="<portlet:namespace/>layoutsTab" style="display: none; 
border-collapse: collapse;  width: 100%; margin-top: 0px; margin-bottom: 0px; 
float: left;">
     <tr>
         <th class="portlet-section-header" colspan="2">Layouts</th>
@@ -191,4 +194,4 @@
     </tr>
 </table>
 
-</form>
+</form>
\ No newline at end of file
Index: applications/jetspeed/src/main/webapp/jetui/engine/portal.js
===================================================================
--- applications/jetspeed/src/main/webapp/jetui/engine/portal.js        
(revision 882086)
+++ applications/jetspeed/src/main/webapp/jetui/engine/portal.js        
(working copy)
@@ -1,5 +1,5 @@
 //Use loader to grab the modules needed
-YUI(yuiConfig).use('console', 'dd', 'anim', 'io', 'datatype-xml', 
'dataschema-xml', 'node-base', 'node-menunav', function(Y) {
+YUI(yuiConfig).use('console', 'dd', 'anim', 'io', 'datatype-xml', 
'dataschema-xml', 'dataschema-json', 'node-base', 'node-menunav', function(Y) {
        
        //      Retrieve the Node instance representing the root menu
        //      (<div id="environments-menu">) and call the "plug" method
@@ -439,6 +439,9 @@
         persistMove(drag.get('node'));
     });
     
+
+        
+
     var persistMove = function(drag) {
         if (drag.data.get("toolbar") == false) {
                var uri = document.location.href;
@@ -459,6 +462,85 @@
             var request = Y.io(uri);                   
         }      
     };
+
+
+
+    var onLoadPortletComplete = function(id, o, args) { 
+       var id = id; // Transaction ID. 
+       var data = o.responseText; // Response data.
+       Y.log("move result = " + data);
+               var node = args[0];
+               
+               var schemaPortletList = {
+                       metaFields: {status:"status", action:"action"},
+                       resultListLocator: "portlets", 
+                       resultFields: [{key:"name"}, {key:"displayName"}, 
{key:"description"}, {key:"image"}]
+               };
+               
+               try {
+               var dataOut = Y.DataSchema.JSON.apply(schemaPortletList, data);
+               } catch (err)
+               {
+               Y.log("Error: " + err.message);
+                       return;
+               }
+
+               Y.log("data = " + dataOut)   
+     
+
+               if(dataOut!=null)
+               {
+                       if(dataOut.error)
+                       {
+                               alert("Error: " + dataOut.error);
+                       }
+                       else
+                       {
+                                               
+                               var new_panel = 
document.getElementById('portlet-body-html');
+       
+       
+                               for(var i=0; i<dataOut.results.length; i++)
+                               {
+                                       
+                                       var cloned_node = 
new_panel.cloneNode(true);
+                                       var name_node = 
cloned_node.getElementsByTagName('img')[0];
+                                       if(name_node!=null)
+                                       {
+                                               var url = 
name_node.getAttribute('src');
+                                               var imgURL = url + "/" + 
dataOut.results[i].image;
+                                               var textNameNode = 
document.createTextNode(imgURL);
+                                               name_node.setAttribute('src', 
imgURL);
+                                               
name_node.appendChild(textNameNode); 
+                                               node.appendChild(cloned_node);
+                                       }
+                               }
+                       }
+               }
+
+               
+    };   
+       ///////////////////////////////////////////////////
+       //
+    var loadPortlets = function(e) {
+       var uri = document.location.href;
+               uri = uri.replace("/ui", "/ajaxapi");
+       
+               var uri = uri + "?action=getportlets&format=json"; //"id=" + 
windowId + "&col=" + drag.data.get('column') + "&row=" + drag.data.get('row');
+       
+               //var uri = "http://localhost:8080/jetspeed/test.json";;
+
+        Y.on('io:complete', onLoadPortletComplete, this, [e]); 
+        var request = Y.io(uri);                       
+                       
+    };
+
+    var portletPanel = Y.Node.all('.portlet-panel-portlets');    
+    portletPanel.each(function(v, k) {
+        v.on('click', loadPortlets(v));
+               
+    });
+
        var reallocateColumn = function(column) {
            var columns = Y.Node.all('.portal-layout-column');
            columns.each(function(v, k) {
@@ -612,4 +694,4 @@
 //    });    
     
     
-});
+});
\ No newline at end of file
Index: 
components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/ajax-xml/getportlets.vm
===================================================================
--- 
components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/ajax-xml/getportlets.vm
 (revision 882086)
+++ 
components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/ajax-xml/getportlets.vm
 (working copy)
@@ -13,7 +13,27 @@
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
+
+---------------------------------------------------------------------------------
+
+  Be carefull about white spaces and carriage returns because JSON YUI3 library
+  will complain about json parse error. The library is very picky and don't 
catch
+  comments at all...
+
+---------------------------------------------------------------------------------
 *#
+#if ($format == "json"){
+       "status": "$status",
+       "action": "$action",
+       "portlets": [#foreach($portlet in $portlets)    
+       #if($velocityCount > 1),#end{
+                       "name": "$!portlet.Name", 
+                       "displayName": "$!portlet.DisplayName",
+                       "description": "$!portlet.Description",
+                       "image": "$portlet.Image"
+               }#end]
+}
+#else   
 <js>
     <status>$status</status>
     <action>$action</action>
@@ -25,3 +45,4 @@
     </portlets>
     
 </js>
+#end
\ No newline at end of file
Index: 
components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java
===================================================================
--- 
components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java
     (revision 882086)
+++ 
components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java
     (working copy)
@@ -27,6 +27,7 @@
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.jetspeed.JetspeedActions;
 import org.apache.jetspeed.ajax.AjaxAction;
 import org.apache.jetspeed.ajax.AjaxBuilder;
@@ -98,8 +99,14 @@
 //                }
 //                status = "refresh";
             }            
+            String type = getActionParameter(requestContext, TYPE );
+            String format = getActionParameter(requestContext, FORMAT );
+            
             String filter = getActionParameter(requestContext, FILTER);        
                            
-            List portlets = retrievePortlets(requestContext, filter);          
  
+            List<PortletInfo> portlets = retrievePortlets(requestContext, 
filter); 
+            
+            resultMap.put(TYPE, type );
+            resultMap.put(FORMAT, format );
             resultMap.put(STATUS, status);
             resultMap.put(PORTLETS, portlets);
         } 
@@ -158,8 +165,14 @@
                 else
                 {                                        
                     image = "images/portlets/applications-internet.png";
-                }                
-                list.add(new PortletInfo(uniqueName, 
portlet.getDisplayNameText(locale), portlet.getDescriptionText(locale), image));
+                }
+                
+
+                PortletInfo portInfo=new PortletInfo(uniqueName, 
+                               
StringEscapeUtils.escapeXml(portlet.getDisplayNameText(locale)), 
+                        
StringEscapeUtils.escapeXml(portlet.getDescriptionText(locale)), image);
+                
+                list.add(portInfo);
             }
         }            
         Collections.sort(list, this);

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to