diff --git a/source/java/org/alfresco/web/ui/common/Utils.java b/source/java/org/alfresco/web/ui/common/Utils.java index adbbf039fe..34d4c58580 100644 --- a/source/java/org/alfresco/web/ui/common/Utils.java +++ b/source/java/org/alfresco/web/ui/common/Utils.java @@ -89,7 +89,7 @@ public final class Utils private static final String DEFAULT_FILE_IMAGE16 = IMAGE_PREFIX16 + "_default" + IMAGE_POSTFIX; private static final String DEFAULT_FILE_IMAGE32 = IMAGE_PREFIX32 + "_default" + IMAGE_POSTFIX; - private static final String AJAX_SCRIPTS_WRITTEN = "_alfAjaxScriptsWritten"; + private static final String DOJO_SCRIPTS_WRITTEN = "_alfDojoScriptsWritten"; private static final String YAHOO_SCRIPTS_WRITTEN = "_alfYahooScriptsWritten"; private static final Map s_fileExtensionMap = new HashMap(89, 1.0f); @@ -1290,7 +1290,7 @@ public final class Utils public static void writeDojoScripts(FacesContext context, ResponseWriter out) throws IOException { - Object present = context.getExternalContext().getRequestMap().get(AJAX_SCRIPTS_WRITTEN); + Object present = context.getExternalContext().getRequestMap().get(DOJO_SCRIPTS_WRITTEN); if (present == null) { @@ -1306,13 +1306,8 @@ public final class Utils out.write(context.getExternalContext().getRequestContextPath()); out.write("/scripts/ajax/common.js\"> \n"); - // write out a global variable to hold the webapp context path - out.write("\n"); - // add marker to request - context.getExternalContext().getRequestMap().put(AJAX_SCRIPTS_WRITTEN, Boolean.TRUE); + context.getExternalContext().getRequestMap().put(DOJO_SCRIPTS_WRITTEN, Boolean.TRUE); } } @@ -1359,11 +1354,6 @@ public final class Utils out.write(context.getExternalContext().getRequestContextPath()); out.write("/scripts/ajax/common.js\"> \n"); - // write out a global variable to hold the webapp context path - out.write("\n"); - // add marker to request context.getExternalContext().getRequestMap().put(YAHOO_SCRIPTS_WRITTEN, Boolean.TRUE); } diff --git a/source/web/scripts/ajax/common.js b/source/web/scripts/ajax/common.js index 8c56c4136d..71d314b7dc 100644 --- a/source/web/scripts/ajax/common.js +++ b/source/web/scripts/ajax/common.js @@ -3,6 +3,8 @@ // Gavin Cornwell 14-07-2006 // +var _alfContextPath = null; + /** * Default handler for errors when using the dojo toolkit */ @@ -35,6 +37,19 @@ function handleErrorYahoo(msg) */ function getContextPath() { - var w = window.location; - alert(w.pathname); -} \ No newline at end of file + if (_alfContextPath == null) + { + var path = window.location.pathname; + var idx = path.indexOf("/", 1); + if (idx != -1) + { + _alfContextPath = path.substring(0, idx); + } + else + { + _alfContextPath = ""; + } + } + + return _alfContextPath; +} diff --git a/source/web/scripts/ajax/node-info.js b/source/web/scripts/ajax/node-info.js index cf32ccd503..a20f251718 100644 --- a/source/web/scripts/ajax/node-info.js +++ b/source/web/scripts/ajax/node-info.js @@ -2,6 +2,8 @@ // Supporting JavaScript for the NodeInfo component // Gavin Cornwell 17-07-2006 // +// NOTE: This script relies on common.js so therefore needs to be loaded +// prior to this one on the containing HTML page. var _launchElement = null; var _popupElement = null; @@ -18,7 +20,7 @@ function showNodeInfo(nodeRef, launchElement) dojo.io.bind({ method: 'post', - url: WEBAPP_CONTEXT + '/ajax/invoke/NodeInfoBean.sendNodeInfo', + url: getContextPath() + '/ajax/invoke/NodeInfoBean.sendNodeInfo', content: { noderef: nodeRef }, load: showNodeInfoHandler, error: handleErrorDojo, diff --git a/source/web/scripts/ajax/yahoo-tree.js b/source/web/scripts/ajax/yahoo-tree.js index f1054b9d3d..f78b58efa7 100644 --- a/source/web/scripts/ajax/yahoo-tree.js +++ b/source/web/scripts/ajax/yahoo-tree.js @@ -1,13 +1,20 @@ -var loadDataUrl = null; -var collapseUrl = null; -var nodeSelectedHandler = null; +// +// Alfresco Yahoo Tree support library +// Gavin Cornwell 01-12-2006 +// +// NOTE: This script relies on common.js so therefore needs to be loaded +// prior to this one on the containing HTML page. + +var _loadDataUrl = null; +var _collapseUrl = null; +var _nodeSelectedHandler = null; /** * Sets the URL to use to retrive child nodes */ function setLoadDataUrl(url) { - loadDataUrl = url; + _loadDataUrl = url; } /** @@ -15,7 +22,7 @@ function setLoadDataUrl(url) */ function setCollapseUrl(url) { - collapseUrl = url; + _collapseUrl = url; } /** @@ -23,7 +30,7 @@ function setCollapseUrl(url) */ function setNodeSelectedHandler(handler) { - nodeSelectedHandler = handler; + _nodeSelectedHandler = handler; } /** @@ -31,7 +38,7 @@ function setNodeSelectedHandler(handler) */ function loadDataForNode(node, onCompleteCallback) { - if (loadDataUrl == null) + if (_loadDataUrl == null) { alert("AJAX URL has not been set for retrieving child nodes, call setLoadDataUrl()!"); return; @@ -40,7 +47,7 @@ function loadDataForNode(node, onCompleteCallback) var nodeRef = node.data.nodeRef; // TODO: add method to add param to url - var transaction = YAHOO.util.Connect.asyncRequest('GET', WEBAPP_CONTEXT + loadDataUrl + "&nodeRef=" + nodeRef, + var transaction = YAHOO.util.Connect.asyncRequest('GET', getContextPath() + _loadDataUrl + "&nodeRef=" + nodeRef, { success: function(o) { @@ -96,7 +103,7 @@ function parseChildData(parentNode, data) */ function createYahooTreeNode(parentNode, nodeRef, name, icon, expanded, selected) { - var nodeData = { label: name, nodeRef: nodeRef, icon: icon, selectedHandler: nodeSelectedHandler}; + var nodeData = { label: name, nodeRef: nodeRef, icon: icon, selectedHandler: _nodeSelectedHandler}; return new YAHOO.widget.AlfrescoNode(nodeData, parentNode, expanded, selected); } @@ -105,7 +112,7 @@ function createYahooTreeNode(parentNode, nodeRef, name, icon, expanded, selected */ function informOfCollapse(node) { - if (collapseUrl == null) + if (_collapseUrl == null) { alert("AJAX URL has not been set for collapsing nodes, call setCollapseUrl()!"); return; @@ -122,7 +129,7 @@ function informOfCollapse(node) } // TODO: add method to add param to url - var transaction = YAHOO.util.Connect.asyncRequest('GET', WEBAPP_CONTEXT + collapseUrl + "&nodeRef=" + nodeRef, + var transaction = YAHOO.util.Connect.asyncRequest('GET', getContextPath() + _collapseUrl + "&nodeRef=" + nodeRef, { success: function(o) { @@ -272,7 +279,7 @@ YAHOO.extend(YAHOO.widget.AlfrescoNode, YAHOO.widget.Node, sb[sb.length] = ' id="' + this.getToggleElId() + '"'; sb[sb.length] = ' class="' + this.getStyle() + '"'; sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '"'; - sb[sb.length] = ' src="' + WEBAPP_CONTEXT + "/images/icons/arrow_"; + sb[sb.length] = ' src="' + getContextPath() + "/images/icons/arrow_"; if (this.expanded) { sb[sb.length] = 'open'; @@ -289,7 +296,7 @@ YAHOO.extend(YAHOO.widget.AlfrescoNode, YAHOO.widget.Node, { sb[sb.length] = ' onclick=' + this.selectedHandler + '("' + this.nodeRef + '");'; } - sb[sb.length] = '>