portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r882397 - in /portals/jetspeed-2: applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/ applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/toolbox/ portal/trunk/applications/jetspeed/src/main/webapp/jetui/eng...
Date Fri, 20 Nov 2009 03:19:45 GMT
Author: taylor
Date: Fri Nov 20 03:19:45 2009
New Revision: 882397

URL: http://svn.apache.org/viewvc?rev=882397&view=rev
Log:
https://issues.apache.org/jira/browse/JS2-1057
- contribution from Gonzalo Aguilar Delgado
- toolbox retrieve portlets over ajax api

Reviewed. I've modified and fixed a few things...
- fixed the display names to display
- rewrote the row population script to use YUI Node api replacing direct DOM manipulation
- dont' use a onclick handler, simply call the first load of portlets directly inline
  im actually not sure what should be populated first, perhaps a "Whats New" category
- added some TODOs for you, see source code for details

Im also thinking that it might be better to create the nodes directly from javascript, and
not pass in the hidden table (I added a display:none attribute on it) although the hidden
table is definitely easier. Optionally you may want to consider loading from a string, something
like:

var clone = Y.Node.create("<table><tr>....etc....");


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
    portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/ajax-xml/getportlets.vm
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java

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=882397&r1=882396&r2=882397&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
Fri Nov 20 03:19:45 2009
@@ -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));

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=882397&r1=882396&r2=882397&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
Fri Nov 20 03:19:45 2009
@@ -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="display: none; 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

Modified: portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js?rev=882397&r1=882396&r2=882397&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js
(original)
+++ portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js
Fri Nov 20 03:19:45 2009
@@ -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
@@ -234,14 +234,11 @@
     var cleanseForSelector = function(s) {
     	return s.replace(/(\.|\#)/g, "\\$1");
     }
-
-    Y.log(" *** replacing " + cleanseForSelector("widget.name#address.cool#3"));
     
     var onRemoveComplete = function(id, o, args) { 
     	var id = id; // Transaction ID. 
     	var data = o.responseText; // Response data. 
     	var widgetId = args[0];
-    	// widgetId = widgetId.replace("\.", "\\.");
     	widgetId = cleanseForSelector(widgetId);
     	var widget = Y.one("#" + widgetId);
     	if (widget)
@@ -439,6 +436,9 @@
         persistMove(drag.get('node'));
     });
     
+
+	 
+
     var persistMove = function(drag) {
         if (drag.data.get("toolbar") == false) {
         	var uri = document.location.href;
@@ -459,6 +459,77 @@
             var request = Y.io(uri);         	    	
         }    	
     };
+
+    var onLoadPortletComplete = function(id, o, args) { 
+    	var id = id; // Transaction ID. 
+    	var data = o.responseText; // Response 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;
+		}     
+		if(dataOut!=null)
+		{
+			// TODO: error handling
+			if(dataOut.error)
+			{
+				alert("Error: " + dataOut.error);
+			}
+			else
+			{						
+				var templatePanel = Y.Node.one("#portlet-body-html"); 				
+				for(var i=0; i<dataOut.results.length; i++)
+				{
+					var clone = templatePanel.cloneNode(true);
+					clone.setStyle('display', '');
+					var imgNode = clone.one('img');
+					if(imgNode!=null)
+					{
+						var url = imgNode.getAttribute('src');
+						var imgURL = url + "/" + dataOut.results[i].image;
+						imgNode.setAttribute('src', imgURL);
+						var nameNode = clone.one('#name');
+						nameNode.setContent(dataOut.results[i].displayName);
+						// TODO: add handlers for add and preview
+						// TODO: limit # of portlets to n...
+						// TODO: support paging...
+						node.appendChild(clone);
+					}
+				}
+			}
+		}
+
+		
+    };   
+	///////////////////////////////////////////////////
+	//
+    var loadPortlets = function(panel) {
+    	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, [panel]); 
+        var request = Y.io(uri);         	    	
+       	    	
+    };
+
+    var portletPanel = Y.Node.all('.portlet-panel-portlets');    
+    portletPanel.each(function(v, k) {
+        //v.on('click', loadPortlets(v));
+		loadPortlets(v);
+    });
+
 	var reallocateColumn = function(column) {
 	    var columns = Y.Node.all('.portal-layout-column');
 	    columns.each(function(v, k) {
@@ -612,4 +683,4 @@
 //    });    
     
     
-});
+});
\ No newline at end of file

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/ajax-xml/getportlets.vm
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/ajax-xml/getportlets.vm?rev=882397&r1=882396&r2=882397&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/ajax-xml/getportlets.vm
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/ajax-xml/getportlets.vm
Fri Nov 20 03:19:45 2009
@@ -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

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java?rev=882397&r1=882396&r2=882397&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java
Fri Nov 20 03:19:45 2009
@@ -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: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message