- Made the client side context path dynamically driven

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4570 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2006-12-11 16:43:42 +00:00
parent bedaafd781
commit 84ca33ed6f
4 changed files with 47 additions and 33 deletions

View File

@@ -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<String, String> s_fileExtensionMap = new HashMap<String, String>(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\"> </script>\n");
// write out a global variable to hold the webapp context path
out.write("<script type=\"text/javascript\">var WEBAPP_CONTEXT = '");
out.write(context.getExternalContext().getRequestContextPath());
out.write("';</script>\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\"> </script>\n");
// write out a global variable to hold the webapp context path
out.write("<script type=\"text/javascript\">var WEBAPP_CONTEXT = '");
out.write(context.getExternalContext().getRequestContextPath());
out.write("';</script>\n");
// add marker to request
context.getExternalContext().getRequestMap().put(YAHOO_SCRIPTS_WRITTEN, Boolean.TRUE);
}

View File

@@ -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);
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;
}

View File

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

View File

@@ -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] = '><img src="' + WEBAPP_CONTEXT + '/images/icons/' + this.icon + '-16.gif"';
sb[sb.length] = '><img src="' + getContextPath() + '/images/icons/' + this.icon + '-16.gif"';
sb[sb.length] = ' class="treeNodeIcon"></td>';
// render the label (with node selected handler) (apply selected css class if approp.) (add contentElId)
@@ -318,15 +325,15 @@ YAHOO.extend(YAHOO.widget.AlfrescoNode, YAHOO.widget.Node,
{
if (this.isLoading)
{
el.src = WEBAPP_CONTEXT + '/scripts/ajax/yahoo/treeview/assets/loading.gif';
el.src = getContextPath() + '/scripts/ajax/yahoo/treeview/assets/loading.gif';
}
else if (this.expanded)
{
el.src = WEBAPP_CONTEXT + '/images/icons/arrow_open.gif';
el.src = getContextPath() + '/images/icons/arrow_open.gif';
}
else
{
el.src = WEBAPP_CONTEXT + '/images/icons/arrow_closed.gif';
el.src = getContextPath() + '/images/icons/arrow_closed.gif';
}
}
},