portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r921888 - /portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/page-navigator.jsp
Date Thu, 11 Mar 2010 15:13:16 GMT
Author: woonsan
Date: Thu Mar 11 15:13:16 2010
New Revision: 921888

URL: http://svn.apache.org/viewvc?rev=921888&view=rev
Log:
JS2-1057: Detaching/Re-attaching event handlers because folder structure can change dynamically.
Also, set "active" style class on a menu list item on selected menu or menu item.

Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/page-navigator.jsp

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/page-navigator.jsp
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/page-navigator.jsp?rev=921888&r1=921887&r2=921888&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/page-navigator.jsp
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/page-navigator.jsp
Thu Mar 11 15:13:16 2010
@@ -46,6 +46,7 @@ private void printMenuItem(MenuElement e
                            RenderRequest renderRequest, 
                            RenderResponse renderResponse,
                            RequestContext rc,
+                           PortalSiteRequestContext psrc,
                            PageNavigator pageNavigator) throws java.io.IOException
 {
     String type = element.getElementType();
@@ -56,7 +57,12 @@ private void printMenuItem(MenuElement e
     
     if (MenuElement.MENU_ELEMENT_TYPE.equals(type))
     { 
-        out.write("<li type='" + type + "' nodeType='" + nodeType + "' editable='" + editable
+ "' path='" + path + "' class='closed'>\n");
+        String styleClass = "closed"; 
+        if (((Menu) element).isSelected(psrc))
+        {
+            styleClass = "active expanded";
+        }
+        out.write("<li type='" + type + "' nodeType='" + nodeType + "' editable='" + editable
+ "' path='" + path + "' class='" + styleClass + "'>\n");
         out.write("<a href='#'>" + title + "</a>\n");
         
         if (depth < maxDepth)
@@ -65,11 +71,11 @@ private void printMenuItem(MenuElement e
 	        
 	        if (childElements != null && !childElements.isEmpty())
 	        {
-	            out.write("<ul style='display: none'>\n");
+	            out.write("<ul>\n");
 	            
 	            for (MenuElement child : childElements)
 	            {
-	                printMenuItem(child, depth + 1, maxDepth, out, renderRequest, renderResponse,
rc, pageNavigator);
+	                printMenuItem(child, depth + 1, maxDepth, out, renderRequest, renderResponse,
rc, psrc, pageNavigator);
 	            }
 	            
 	            out.write("</ul>\n");
@@ -81,48 +87,13 @@ private void printMenuItem(MenuElement e
     else if (MenuElement.OPTION_ELEMENT_TYPE.equals(type))
     {
         String url = ((MenuOption) element).getUrl();
-        out.write("<li type='" + type + "' nodeType='" + nodeType + "' editable='" + editable
+ "' path='" + path +"' class='leaf'>");
-        out.write("<div>");
-        out.write("<a href='" + pageNavigator.getAbsoluteUrl(url, renderResponse, rc)
+ "'>" + title + "</a>");
-        out.write("</div>");
-        out.write("</li>\n");
-    }
-}
-
-private void printFolderMenuItem(MenuElement element,
-                                 int depth,
-                                 int maxDepth,
-                                 javax.servlet.jsp.JspWriter out,
-                                 RenderRequest renderRequest) throws java.io.IOException
-{
-    String type = element.getElementType();
-    String nodeType = element.getManagedNode().getType();
-    boolean editable = element.isEditable();
-    String path = element.getManagedNode().getPath();
-    String title = element.getTitle(renderRequest.getLocale());
-    if (MenuElement.MENU_ELEMENT_TYPE.equals(type))
-    { 
-        out.write("<li path='" + path + "' class='closed'>\n");
-        out.write("<input type='radio' name='targetFolder' value='" + path + "' />\n");
-        out.write("<a href='#'>" + title + "</a>\n");
-        
-        if (depth < maxDepth)
+        String styleClass = "leaf"; 
+        if (((MenuOption) element).isSelected(psrc))
         {
-            List<MenuElement> childElements = (List<MenuElement>) ((Menu) element).getElements();
-            
-            if (childElements != null && !childElements.isEmpty())
-            {
-                out.write("<ul style='display: none'>\n");
-                
-                for (MenuElement child : childElements)
-                {
-                    printFolderMenuItem(child, depth + 1, maxDepth, out, renderRequest);
-                }
-                
-                out.write("</ul>\n");
-            }
+            styleClass = "active leaf";
         }
-        
+        out.write("<li type='" + type + "' nodeType='" + nodeType + "' editable='" + editable
+ "' path='" + path +"' class='" + styleClass + "'>");
+        out.write("<a href='" + pageNavigator.getAbsoluteUrl(url, renderResponse, rc)
+ "'>" + title + "</a>");
         out.write("</li>\n");
     }
 }
@@ -133,6 +104,7 @@ private void printFolderMenuItem(MenuEle
 
 <%
 RequestContext rc = (RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV);
+PortalSiteRequestContext psrc = (PortalSiteRequestContext) rc.getAttribute("org.apache.jetspeed.portalsite.PortalSiteRequestContext");
 String contextPath = rc.getRequest().getContextPath();
 String basePath = rc.getPortalURL().getBasePath();
 String portalPagePath = rc.getPortalURL().getPath();
@@ -155,7 +127,7 @@ Theme theme = (Theme) rc.getRequest().ge
 <%
 for (MenuElement element : menuElements)
 {
-    printMenuItem(element, 0, 6, out, renderRequest, renderResponse, rc, pageNavigator);
+    printMenuItem(element, 0, 6, out, renderRequest, renderResponse, rc, psrc, pageNavigator);
 }
 %>
       </ul>
@@ -171,7 +143,7 @@ if (!linkElements.isEmpty())
 <%
 for (MenuElement element : linkElements)
 {
-    printMenuItem(element, 0, 6, out, renderRequest, renderResponse, rc, pageNavigator);
+    printMenuItem(element, 0, 6, out, renderRequest, renderResponse, rc, psrc, pageNavigator);
 }
 %>
       </ul>
@@ -246,13 +218,7 @@ for (MenuElement element : linkElements)
           <li path='<%=space.getPath()%>' class='expanded'>
             <input type='radio' name='targetFolder' value='<%=space.getPath()%>'/>
             <a href='#'><%=space.getTitle()%></a>
-            <ul class="navmenu">
-<%
-for (MenuElement element : menuElements)
-{
-    printFolderMenuItem(element, 0, 6, out, renderRequest);
-}
-%>
+            <ul id="<portlet:namespace/>targetSubFolders" class="navmenu">
             </ul>
           </li>
         </ul>
@@ -295,6 +261,8 @@ YUI().use('jetui-portal', 'io', 'json', 
     var onMenuItemMouseEnter = function(e) {
         if (nodePopupMenu == null) {
             nodePopupMenu = Y.Node.one("#<portlet:namespace/>nodePopupMenu");
+            nodePopupMenu.plug(Y.Plugin.NodeMenuNav, { autoSubmenuDisplay: false, mouseOutHideDelay:
0 });
+            resetNodePopupMenuEventHandlers();
         }
         var li = e.target;
         if ("true" == li.getAttribute("editable")) {
@@ -392,6 +360,7 @@ YUI().use('jetui-portal', 'io', 'json', 
         if (listItem) {
             onCopyComplete(id, o, args);
             listItem.remove();
+            resetMenuItemEventHandlers();
         }
     };
     
@@ -408,6 +377,7 @@ YUI().use('jetui-portal', 'io', 'json', 
                     v.one("UL").append(clonedListItem);
                 }
             });
+            resetMenuItemEventHandlers();
         }
     };
     
@@ -464,11 +434,12 @@ YUI().use('jetui-portal', 'io', 'json', 
         }
         e.halt();
     };
-    
+
     var onMoveClick = function(e) {
         if (!curNodeListItem) {
             return;
         }
+        resetModalPanelEventHandlers();
         var modalFeatures = {
             "width": 400,
             "height": 300,
@@ -486,6 +457,7 @@ YUI().use('jetui-portal', 'io', 'json', 
         if (!curNodeListItem) {
             return;
         }
+        resetModalPanelEventHandlers();
         var modalFeatures = {
             "width": 400,
             "height": 300,
@@ -499,46 +471,83 @@ YUI().use('jetui-portal', 'io', 'json', 
         e.halt();
     };
 
-    var pageNavMenu = Y.Node.one("#<portlet:namespace/>pageNavMenu");
-    pageNavMenu.all("A").each(function(v, k) {
-        v.on("click", onMenuItemClick);
-    });
-
-    var targetFolders = Y.Node.one("#<portlet:namespace/>modalBody").one("UL");
-    targetFolders.all("A").each(function(v, k) {
-        v.on("click", onMenuItemClick);
-    });
-    
-    <c:if test="${pageEditable}">
-    pageNavMenu.all("LI").each(function(v, k) {
-        v.on("mouseenter", onMenuItemMouseEnter);
-    });
-
-    var pageNavLinks = Y.Node.one("#<portlet:namespace/>pageNavLinks");
-    if (pageNavLinks) {
-        pageNavLinks.all("LI").each(function(v, k) {
-            v.on("mouseenter", onMenuItemMouseEnter);
+    var menuItemEventHandles = [];
+    var resetMenuItemEventHandlers = function() {
+        for (var i = 0; i < menuItemEventHandles.length; i++) {
+            menuItemEventHandles[i].detach();
+        }
+        menuItemEventHandles = [];
+        var pageNavMenu = Y.Node.one("#<portlet:namespace/>pageNavMenu");
+        pageNavMenu.all("A").each(function(v, k) {
+            menuItemEventHandles.push(v.on("click", onMenuItemClick));
         });
-    }
-    </c:if>
+
+        <c:if test="${pageEditable}">
+        pageNavMenu.all("LI").each(function(v, k) {
+            menuItemEventHandles.push(v.on("mouseenter", onMenuItemMouseEnter));
+        });
+
+        var pageNavLinks = Y.Node.one("#<portlet:namespace/>pageNavLinks");
+        if (pageNavLinks) {
+            pageNavLinks.all("LI").each(function(v, k) {
+                menuItemEventHandles.push(v.on("mouseenter", onMenuItemMouseEnter));
+            });
+        }
+        </c:if>
+    };
+    
+    var resetNodePopupMenuEventHandlers = function() {
+        Y.detach("click", onRenameClick, "#<portlet:namespace/>nodePopupMenu_rename");
+        Y.Node.one("#<portlet:namespace/>nodePopupMenu_rename").on("click", onRenameClick);
+        Y.detach("click", onDeleteClick, "#<portlet:namespace/>nodePopupMenu_delete");
+        Y.Node.one("#<portlet:namespace/>nodePopupMenu_delete").on("click", onDeleteClick);
+        Y.detach("click", onMoveClick, "#<portlet:namespace/>nodePopupMenu_move");
+        Y.Node.one("#<portlet:namespace/>nodePopupMenu_move").on("click", onMoveClick);
+        Y.detach("click", onCopyClick, "#<portlet:namespace/>nodePopupMenu_copy");
+        Y.Node.one("#<portlet:namespace/>nodePopupMenu_copy").on("click", onCopyClick);
+    };
+    
+    var modalPanelEventHandles = [];
+    var resetModalPanelEventHandlers = function() {
+        for (var i = 0; i < modalPanelEventHandles.length; i++) {
+            modalPanelEventHandles[i].detach();
+        }
+        modalPanelEventHandles = [];
+        
+        var targetSubFolders = Y.Node.one("#<portlet:namespace/>targetSubFolders");
+        targetSubFolders.all("LI").each(function(v, k) {
+            v.remove();
+        });
+        var pageNavMenu = Y.Node.one("#<portlet:namespace/>pageNavMenu");
+        pageNavMenu.all("LI").each(function(v, k) {
+            if (v.getAttribute("nodeType") == "folder") {
+                var cloned = v.cloneNode(true);
+                cloned.all("LI").each(function(v2, k2) {
+                    if (v2.getAttribute("nodeType") != "folder") {
+                        v2.remove();
+                    } else {
+                        var path = v2.getAttribute("path");
+                        var option = Y.Node.create("<input type='radio' name='targetFolder'
value='" + path + "' />");
+                        v2.prepend(option);
+                    }
+                });
+                var path = cloned.getAttribute("path");
+                var option = Y.Node.create("<input type='radio' name='targetFolder' value='"
+ path + "' />");
+                cloned.prepend(option);
+                targetSubFolders.append(cloned);
+            }
+        });
+        
+        var targetFolders = Y.Node.one("#<portlet:namespace/>modalBody").one("UL");
+        targetFolders.all("A").each(function(v, k) {
+            v.on("click", onMenuItemClick);
+        });
+        Y.detach("click", onModalOKClick, "#<portlet:namespace/>modalOK");
+        Y.Node.one("#<portlet:namespace/>modalOK").on("click", onModalOKClick);
+        Y.detach("click", onModalCancelClick, "#<portlet:namespace/>modalCancel");
+        Y.Node.one("#<portlet:namespace/>modalCancel").on("click", onModalCancelClick);
+    };
     
-    var portalPagePath = "<%=portalPagePath%>";
-    var curMenuItem = null;
-    pageNavMenu.all("LI").each(function(v, k) {
-        var path = v.getAttribute("path");
-        if (path && portalPagePath.indexOf(path) == 0) {
-            v.addClass("active");
-        }
-    });
-    
-    var nodePopupMenu = Y.one("#<portlet:namespace/>nodePopupMenu");
-    nodePopupMenu.plug(Y.Plugin.NodeMenuNav, { autoSubmenuDisplay: false, mouseOutHideDelay:
0 });
-    
-    Y.Node.one("#<portlet:namespace/>nodePopupMenu_rename").on("click", onRenameClick);
-    Y.Node.one("#<portlet:namespace/>nodePopupMenu_delete").on("click", onDeleteClick);
-    Y.Node.one("#<portlet:namespace/>nodePopupMenu_move").on("click", onMoveClick);
-    Y.Node.one("#<portlet:namespace/>nodePopupMenu_copy").on("click", onCopyClick);
-    Y.Node.one("#<portlet:namespace/>modalOK").on("click", onModalOKClick);
-    Y.Node.one("#<portlet:namespace/>modalCancel").on("click", onModalCancelClick);
+    resetMenuItemEventHandlers();
 });
 </script>



---------------------------------------------------------------------
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