[gatein-commits] gatein SVN: r4917 - in portal/branches/branch-GTNPORTAL-1592: webui/portal/src/main/java/org/exoplatform/portal/application and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Nov 3 07:05:26 EDT 2010


Author: hoang_to
Date: 2010-11-03 07:05:24 -0400 (Wed, 03 Nov 2010)
New Revision: 4917

Modified:
   portal/branches/branch-GTNPORTAL-1592/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalHttpRequest.js
   portal/branches/branch-GTNPORTAL-1592/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
   portal/branches/branch-GTNPORTAL-1592/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java
   portal/branches/branch-GTNPORTAL-1592/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
Log:
GTNPORTAL-1256: When adding a portlet to a page, HTML header is not refreshed

Modified: portal/branches/branch-GTNPORTAL-1592/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalHttpRequest.js
===================================================================
--- portal/branches/branch-GTNPORTAL-1592/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalHttpRequest.js	2010-11-03 10:48:58 UTC (rev 4916)
+++ portal/branches/branch-GTNPORTAL-1592/web/eXoResources/src/main/webapp/javascript/eXo/portal/PortalHttpRequest.js	2010-11-03 11:05:24 UTC (rev 4917)
@@ -133,6 +133,8 @@
         this.blocksToUpdate[j].scripts = eXo.core.DOMUtil.findDescendantsByTagName(dataBlocks[1], "script") ;
         
       }
+    } else if(div[i].className == "MarkupHeadElements") {
+      this.markupHeadElements = new MarkupHeadElements(div[i]);    
     } else if(div[i].className == "PortalResponseScript") {
       this.script = div[i].innerHTML ;
 			div[i].style.display = "none" ;
@@ -140,6 +142,16 @@
   }
 };
 
+function MarkupHeadElements(fragment) {
+	var  DOMUtil = eXo.core.DOMUtil ;
+	this.titles = DOMUtil.findDescendantsByTagName(fragment, "title");
+	this.bases = DOMUtil.findDescendantsByTagName(fragment, "base") ;
+	this.links = DOMUtil.findDescendantsByTagName(fragment, "link") ;
+	this.metas = DOMUtil.findDescendantsByTagName(fragment, "meta") ;
+	this.scripts = DOMUtil.findDescendantsByTagName(fragment, "script") ;		
+	this.styles = DOMUtil.findDescendantsByTagName(fragment, "style") ;
+}
+
 /*
 * This function is used to dynamically append a script to the head tag
 * of the page
@@ -158,7 +170,7 @@
   
   //check if contains source attribute
   if(scriptElement.src) {
-    script.src = scriptElement.src
+    script.src = scriptElement.src;
   } else {
   	script.text = scriptElement.innerHTML;
   }
@@ -409,6 +421,89 @@
 		  }
 	  } 
 	} ;
+	
+	instance.updateHtmlHead = function(response) {
+		cleanHtmlHead(response);
+		
+		var DOMUtil = eXo.core.DOMUtil;
+		var head = document.getElementsByTagName("head")[0]; 								
+		var markupHeadElements = response.markupHeadElements;		
+		
+		if (markupHeadElements.titles.length != 0) {
+			var oldTitle = DOMUtil.getChildrenByTagName(head, "title")[0];
+			var newTitle = markupHeadElements.titles[markupHeadElements.titles.length - 1];
+			if (oldTitle) {
+				head.replaceChild(newTitle, oldTitle);
+			} else {
+				head.appendChild(newTitle);
+			}
+		}			
+		
+		appendElementsToHead(markupHeadElements.metas);
+    		appendElementsToHead(markupHeadElements.bases);
+		appendElementsToHead(markupHeadElements.links);				
+		appendElementsToHead(markupHeadElements.styles);
+		appendElementsToHead(markupHeadElements.scripts);
+	};
+	
+	function cleanHtmlHead(response) {
+		var DOMUtil = eXo.core.DOMUtil;
+		var head = document.getElementsByTagName("head")[0];		
+		
+		var portletResponses = response.portletResponses;
+		if (portletResponses != null) {
+			for (var i = 0; i < portletResponses.length; i++) {
+				removeExtraHead(portletResponses[i].portletId);
+			}
+		}
+		
+		var portletFragments = DOMUtil.findDescendantsByClass(response.data, "div", "PORTLET-FRAGMENT");
+		for (var i = 0; i < portletFragments.length; i++) {
+			removeExtraHead(portletFragments[i].parentNode.id);
+		}
+		
+		var uiWorkingWorkspace = document.getElementById("UIWorkingWorkspace") ;
+		var portletFragsInWS = DOMUtil.findDescendantsByClass(uiWorkingWorkspace, "div", "PORTLET-FRAGMENT");		
+		var exHeads = DOMUtil.getElementsBy(function(elem) {
+			return elem.tagName != "TITLE" && elem.className.indexOf("ExHead-") == 0;
+		}, "*", head);
+		
+		for (var i = 0; i < exHeads.length; i++) {
+			var portletId = exHeads[i].className.substring(7);
+			var del = true;
+			for (var j = 0; j < portletFragsInWS.length; j++) {
+				if (portletId == portletFragsInWS[j].parentNode.id) {
+					del = false;
+					break;
+				}
+			}
+			if (del) {
+				head.removeChild(exHeads[i]);
+			}
+		}
+	}
+	
+	function removeExtraHead(portletId) {
+		var DOMUtil = eXo.core.DOMUtil;
+		var head = document.getElementsByTagName("head")[0];
+		
+		var elemsToRemove = DOMUtil.getElementsBy(function(elem) {
+			return elem.tagName != "TITLE" && elem.className == "ExHead-" + portletId;
+		}, "*", head);
+		
+		for (var i = 0; i < elemsToRemove.length; i++) {
+			head.removeChild(elemsToRemove[i]);
+		}
+	}
+	
+	function appendElementsToHead(elements) {
+		var head = document.getElementsByTagName("head")[0]; 
+		
+		for (var i = 0; i < elements.length; i++) {
+			head.appendChild(elements[i]);
+		}
+	}
+	
 	/*
 	* This methods will replace some block content by new one. 
 	* This is the important concept in any AJAX call where JS is used to dynamically
@@ -460,7 +555,7 @@
 	  eXo.portal.AjaxRequest.maskLayer = null ;
 	  eXo.portal.CurrentRequest = null ;
 	  window.location.reload() ;
-	}
+	};
 	
 	/*
 	* This method is called when the AJAX call is completed and that the request.responseText
@@ -520,6 +615,7 @@
 	  }
 	  //Handle the portal responses
 	  instance.updateBlocks(response.blocksToUpdate) ;
+	  instance.updateHtmlHead(response);
 	  instance.executeScript(response.script) ;
 	  /**
        * Clears the instance.to timeout if the request takes less time than expected to get response
@@ -556,7 +652,7 @@
 				eXo.core.UIMaskLayer.showAjaxLoading(eXo.portal.AjaxRequest.maskLayer);			   
 			}
 		}, 2000);
-	}
+	};
 	
 	return instance ;
 } ;

Modified: portal/branches/branch-GTNPORTAL-1592/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1592/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java	2010-11-03 10:48:58 UTC (rev 4916)
+++ portal/branches/branch-GTNPORTAL-1592/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java	2010-11-03 11:05:24 UTC (rev 4917)
@@ -450,9 +450,11 @@
    /**
     * Add an extra markup to the head of the html page.
     * @param element The element to add
+    * @param portletWindowId The ID of portlet window contributing markup header
     */
-   public void addExtraMarkupHeader(Element element)
+   public void addExtraMarkupHeader(Element element, String portletWindowId)
    {
+      element.setAttribute("class", "ExHead-" + portletWindowId);
 	  if (this.extraMarkupHeaders == null)
 	  {
 		  this.extraMarkupHeaders = new ArrayList<Element>();

Modified: portal/branches/branch-GTNPORTAL-1592/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1592/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java	2010-11-03 10:48:58 UTC (rev 4916)
+++ portal/branches/branch-GTNPORTAL-1592/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java	2010-11-03 11:05:24 UTC (rev 4917)
@@ -256,7 +256,7 @@
                         {
                            for (Element element : markupElements)
                            {
-                              if ("title".equals(element.getNodeName().toLowerCase())
+                              if (!context.useAjax() && "title".equals(element.getNodeName().toLowerCase())
                                     && element.getFirstChild() != null)
                               {
                                  String title = element.getFirstChild().getTextContent();
@@ -264,7 +264,7 @@
                               }
                               else
                               {
-                                 prcontext.addExtraMarkupHeader(element);
+                                 prcontext.addExtraMarkupHeader(element, uicomponent.getId());
                               }
                            }
                         }

Modified: portal/branches/branch-GTNPORTAL-1592/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
===================================================================
--- portal/branches/branch-GTNPORTAL-1592/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java	2010-11-03 10:48:58 UTC (rev 4916)
+++ portal/branches/branch-GTNPORTAL-1592/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java	2010-11-03 11:05:24 UTC (rev 4917)
@@ -596,7 +596,13 @@
                w.write("</div>");
             }
          }
-
+         w.write("<div class=\"MarkupHeadElements\">");
+         List<String> headElems = ((PortalRequestContext)context).getExtraMarkupHeadersAsStrings();
+         for (String elem : headElems) 
+         {
+            w.write(elem);
+         }
+         w.write("</div>");
          w.write("<div class=\"PortalResponseScript\">");
          pcontext.getJavascriptManager().writeJavascript(w);
          w.write("eXo.core.Browser.onLoad();\n");



More information about the gatein-commits mailing list