Merged from BRANCHES/DEV/KEVINR:

. NodeInfo panel and Ajax client library
 - Rewrite of Node Info panel
 - Alfresco common DOM methods refactored into namespaced object (YUI/Dojo style) Alfresco.Dom
 - Addition of useful DOM and 'smart' alignment method to common.js
 - OpenSearch now uses additional namespace for it's global method handlers: Alfresco.OpenSearchEngine
 - Temporary icons added for pop-up node info panel
. Additional FreeMarker model API method "cropContent(contentprop, length)" to return the first N bytes of a content stream - auto converted to plain/text from all supported transformation mimetypes
. DownloadContentServlet now handles ContentIOException more gracefully
. AbstractContentReader fixed to handle empty file data when requesting N characters from a content stream

. Yahoo scripts move to PageTag rendering as appropriate
. Refactoring of existing ajax components that output Yahoo scripts

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5253 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2007-03-01 17:24:08 +00:00
parent 2c1fe352a3
commit a4aa830af2
13 changed files with 509 additions and 413 deletions

View File

@@ -51,10 +51,10 @@ function handleErrorDojo(type, errObj)
/**
* Default handler for errors when using the yahoo toolkit
*/
function handleErrorYahoo(msg)
function handleErrorYahoo(e)
{
// TODO: Show a nicer error page, an alert will do for now!
alert(msg);
alert(e.status + " : " + e.statusText);
}
/**
@@ -89,117 +89,173 @@ function getContextPath()
}
/**
* Returns a single child element with the given tag
* name from the given parent. If more than one tag
* exists the first one is returned, if none exist null
* is returned.
* Alfresco Utility libraries
*/
function getElementByTagName(elParent, tagName)
(function()
{
var el = null;
if (elParent != null && tagName != null)
{
var elems = elParent.getElementsByTagName(tagName);
if (elems != null && elems.length > 0)
{
el = elems[0];
}
}
return el;
}
/**
* Returns a single child element with the given tag
* name and namespace from the given parent.
* If more than one tag exists the first one is returned,
* if none exist null is returned.
*/
function getElementByTagNameNS(elParent, nsUri, nsPrefix, tagName)
{
var el = null;
if (elParent != null && tagName != null)
{
var elems = null;
/**
* DOM library
*/
Alfresco.Dom = {
if (elParent.getElementsByTagNameNS)
/**
* Returns a single child element with the given tag
* name from the given parent. If more than one tag
* exists the first one is returned, if none exist null
* is returned.
*/
getElementByTagName: function(elParent, tagName)
{
elems = elParent.getElementsByTagNameNS(nsUri, tagName);
}
else
{
elems = elParent.getElementsByTagName(nsPrefix + ":" + tagName);
}
var el = null;
if (elParent != null && tagName != null)
{
var elems = elParent.getElementsByTagName(tagName);
if (elems != null && elems.length > 0)
{
el = elems[0];
}
}
return el;
},
if (elems != null && elems.length > 0)
/**
* Returns a single child element with the given tag
* name and namespace from the given parent.
* If more than one tag exists the first one is returned,
* if none exist null is returned.
*/
getElementByTagNameNS: function(elParent, nsUri, nsPrefix, tagName)
{
el = elems[0];
var el = null;
if (elParent != null && tagName != null)
{
var elems = null;
if (elParent.getElementsByTagNameNS)
{
elems = elParent.getElementsByTagNameNS(nsUri, tagName);
}
else
{
elems = elParent.getElementsByTagName(nsPrefix + ":" + tagName);
}
if (elems != null && elems.length > 0)
{
el = elems[0];
}
}
return el;
},
/**
* Returns the text of the given DOM element object
*/
getElementText: function(el)
{
var txt = null;
if (el.text != undefined)
{
// get text using IE specific property
txt = el.text;
}
else
{
// use the W3C textContent property
txt = el.textContent;
}
return txt;
},
/**
* Returns the text content of a single child element
* with the given tag name from the given parent.
* If more than one tag exists the text of the first one
* is returned, if none exist null is returned.
*/
getElementTextByTagName: function(elParent, tagName)
{
var txt = null;
var el = this.getElementByTagName(elParent, tagName);
if (el != null)
{
txt = this.getElementText(el);
}
return txt;
},
/**
* Returns the text a single child element with the given tag
* name and namespace from the given parent.
* If more than one tag exists the text of the first one is returned,
* if none exist null is returned.
*/
getElementTextByTagNameNS: function(elParent, nsUri, nsPrefix, tagName)
{
var txt = null;
var el = this.getElementByTagNameNS(elParent, nsUri, nsPrefix, tagName);
if (el != null)
{
txt = this.getElementText(el);
}
return txt;
},
/**
* Aligns an element against the specified element. Automatically adjusts the element above or to
* the left of the destination if the element would cause a scrollbar to appear.
*
* @param el Element to align
* @param destEl Destination element to align against
* @param maxwidth Maximum width of the element (assumed max-width CSS applied)
*/
smartAlignElement: function (el, destEl, maxwidth)
{
// get the position of the element we are aligning against
var pos = YAHOO.util.Dom.getXY(destEl);
// calculate display position for the element
var region = YAHOO.util.Dom.getRegion(el);
//log("DIV popup size: Width:" + (region.right-region.left) + ", Height:" + (region.bottom-region.top));
var elHeight = region.bottom - region.top;
var elWidth = region.right - region.left;
//log("elWidth:" + elWidth + " maxwidth:" + maxwidth);
if (maxwidth != undefined && maxwidth != null)
{
if (elWidth > maxwidth) elWidth = maxwidth;
}
var docWidth = YAHOO.util.Dom.getDocumentWidth();
if (pos[0] + elWidth < docWidth)
{
el.style.left = pos[0];
}
else
{
el.style.left = pos[0] - ((pos[0] + elWidth) - docWidth);
}
//log(" Element Y:" + pos[1] + " doc height:" + YAHOO.util.Dom.getDocumentHeight());
if (pos[1] + 16 + elHeight < YAHOO.util.Dom.getDocumentHeight())
{
el.style.top = pos[1] + 12;
}
else
{
//log(" ***Changing position - will overflow");
el.style.top = pos[1] - elHeight - 4;
}
}
}
return el;
}
/**
* Returns the text of the given DOM element object
*/
function getElementText(el)
{
var txt = null;
if (el.text != undefined)
{
// get text using IE specific property
txt = el.text;
}
else
{
// use the W3C textContent property
txt = el.textContent;
}
return txt;
}
/**
* Returns the text content of a single child element
* with the given tag name from the given parent.
* If more than one tag exists the text of the first one
* is returned, if none exist null is returned.
*/
function getElementTextByTagName(elParent, tagName)
{
var txt = null;
var el = getElementByTagName(elParent, tagName);
if (el != null)
{
txt = getElementText(el);
}
return txt;
}
/**
* Returns the text a single child element with the given tag
* name and namespace from the given parent.
* If more than one tag exists the text of the first one is returned,
* if none exist null is returned.
*/
function getElementTextByTagNameNS(elParent, nsUri, nsPrefix, tagName)
{
var txt = null;
var el = getElementByTagNameNS(elParent, nsUri, nsPrefix, tagName);
if (el != null)
{
txt = getElementText(el);
}
return txt;
}
};
})();
/**
* Logs a message to a debug log window.
@@ -210,7 +266,7 @@ function log(message)
{
if (!log.window_ || log.window_.closed)
{
var win = window.open("", null, "width=400,height=200," +
var win = window.open("", null, "width=600,height=400," +
"scrollbars=yes,resizable=yes,status=no," +
"location=no,menubar=no,toolbar=no");
if (!win) return;
@@ -224,9 +280,4 @@ function log(message)
var logLine = log.window_.document.createElement("div");
logLine.appendChild(log.window_.document.createTextNode(message));
log.window_.document.body.appendChild(logLine);
}
}

View File

@@ -1,75 +1,189 @@
//
// Supporting JavaScript for the NodeInfo component
// Gavin Cornwell 17-07-2006
// Kevin Roast 21-02-2007 (rewrite to use individual panel objects and convert to YUI)
//
// NOTE: This script relies on common.js so therefore needs to be loaded
// NOTE: This script requires common.js - which needs to be loaded
// prior to this one on the containing HTML page.
var _launchElement = null;
var _popupElement = null;
/**
* Makes the AJAX request back to the server to get the node info.
*
* @param nodeRef The node reference to get information for
* @param launchElement The element that requested the summary panel
* Node Info Manager constructor
*/
function showNodeInfo(nodeRef, launchElement)
Alfresco.NodeInfoManager = function()
{
_launchElement = launchElement;
dojo.io.bind({
method: 'post',
url: getContextPath() + '/ajax/invoke/NodeInfoBean.sendNodeInfo',
content: { noderef: nodeRef },
load: showNodeInfoHandler,
error: handleErrorDojo,
mimetype: 'text/html'
});
//YAHOO.util.Event.addListener(window, "resize", this.resize);
}
/**
* Fades in the summary panel containing the node information.
* This function is called back via the dojo bind call above.
* Definition of the Node Info Manager class.
* Responsible for open/closing NodeInfoPanel dynamic summary panel objects.
*/
function showNodeInfoHandler(type, data, evt)
Alfresco.NodeInfoManager.prototype =
{
// create a 'div' to hold the summary table
var div = document.createElement("div");
panels: [],
displayed: [],
// get the position of the element we are showing info for
var pos = dojo.html.getAbsolutePosition(_launchElement, false);
// setup the div with the correct appearance
div.innerHTML = data;
div.setAttribute("class", "summaryPopupPanel");
// NOTE: use className for IE
div.setAttribute("className", "summaryPopupPanel");
div.style.position = "absolute";
div.style.left = pos[0];
div.style.top = pos[1] + 16;
div.style.zIndex = 99;
// is there a better way of doing this, dojo.dom.insertBefore??
var body = document.getElementsByTagName("body")[0];
dojo.html.setOpacity(div, 0);
_popupElement = div;
body.appendChild(div);
dojo.lfx.html.fadeIn(div, 300).play();
}
/**
* Fades out the summary panel with the node info
* and then removes it from the DOM
*/
function hideNodeInfo()
{
// remove the node from the DOM and reset variables
dojo.lfx.html.fadeOut(_popupElement, 300, dojo.lfx.easeOut, function(nodes)
/**
* Request toggle of the open/close state of a node info panel
*/
toggle: function(nodeRef, launchElement)
{
dojo.lang.forEach(nodes, dojo.dom.removeNode);
_popupElement = null;
_launchElement = null;
}).play();
if (this.displayed[nodeRef] == undefined || this.displayed[nodeRef] == null)
{
var panel = this.panels[nodeRef];
if (panel == undefined || panel == null)
{
panel = new Alfresco.NodeInfoPanel(nodeRef, launchElement);
this.panels[nodeRef] = panel;
}
this.displayed[nodeRef] = true;
panel.showNodeInfo();
}
else
{
this.close(nodeRef);
}
},
/**
* Request a Close of the node info panel
*/
close: function(nodeRef)
{
var panel = this.panels[nodeRef];
if (panel != undefined && panel != null)
{
this.displayed[nodeRef] = null;
panel.hideNodeInfo();
}
},
/**
* Return if a given node info panel is currently displayable
*/
displayable: function(nodeRef)
{
return (this.displayed[nodeRef] != undefined && this.displayed[nodeRef] != null);
}
}
/**
* Construct the single Node Info Manager instance
*/
var AlfNodeInfoMgr = new Alfresco.NodeInfoManager();
/**
* Constructor for the Node Info Panel object
*/
Alfresco.NodeInfoPanel = function(nodeRef, launchElement)
{
this.nodeRef = nodeRef;
this.launchElement = launchElement;
}
/**
* Definition of the Node Info Panel object
*/
Alfresco.NodeInfoPanel.prototype =
{
nodeRef: null,
launchElement: null,
popupElement: null,
visible: false,
/**
* Makes the AJAX request back to the server to get the node info.
*/
showNodeInfo: function()
{
if (this.popupElement == null)
{
YAHOO.util.Connect.asyncRequest(
"POST",
getContextPath() + '/ajax/invoke/NodeInfoBean.sendNodeInfo',
{
success: this.loadNodeInfoHandler,
failure: handleErrorYahoo, // global error handler
argument: [this.nodeRef, this]
},
"noderef=" + this.nodeRef);
}
else
{
this.displayNodeInfo();
}
},
/**
* Callback function for showNodeInfo() above
*/
loadNodeInfoHandler: function(response)
{
var panel = response.argument[1];
// create a 'div' to hold the summary table
var div = document.createElement("div");
// setup the div with the correct appearance
div.innerHTML = response.responseText;
div.setAttribute("class", "summaryPopupPanel");
// NOTE: use className for IE
div.setAttribute("className", "summaryPopupPanel");
div.style.position = "absolute";
div.style.zIndex = 99;
div.style.display = "none";
div.style.left = 0;
div.style.top = 0;
var body = document.getElementsByTagName("body")[0];
body.appendChild(div);
// keep track of the div element we created
panel.popupElement = div;
// display the div for the first time
panel.displayNodeInfo();
},
/**
* Display the summary info panel for the node
*/
displayNodeInfo: function()
{
if (AlfNodeInfoMgr.displayable(this.nodeRef) == true)
{
if (this.popupElement != null && this.visible == false)
{
// set opacity in browser independant way
YAHOO.util.Dom.setStyle(this.popupElement, "opacity", 0.0);
this.popupElement.style.display = "block";
Alfresco.Dom.smartAlignElement(this.popupElement, this.launchElement, 700);
var anim = new YAHOO.util.Anim(
this.popupElement, { opacity: { to: 1.0 } }, 0.333, YAHOO.util.Easing.easeOut);
anim.animate();
// drag-drop object
new YAHOO.util.DD(this.popupElement);
this.visible = true;
}
}
},
/**
* Hide the summary info panel for the node
*/
hideNodeInfo: function()
{
if (this.popupElement != null && this.visible == true)
{
this.visible = false;
YAHOO.util.Dom.setStyle(this.popupElement, "opacity", 0.0);
this.popupElement.style.display = "none";
}
}
}

View File

@@ -169,8 +169,8 @@ Alfresco.OpenSearchClient.prototype =
{
YAHOO.util.Connect.asyncRequest("GET", searchUrl,
{
success: Alfresco.processSearchResults,
failure: Alfresco.handleSearchError,
success: Alfresco.OpenSearchEngine.processSearchResults,
failure: Alfresco.OpenSearchEngine.handleSearchError,
argument: [ose.id, this]
},
null);
@@ -191,8 +191,8 @@ Alfresco.OpenSearchClient.prototype =
// execute the query and process the results
YAHOO.util.Connect.asyncRequest("GET", url,
{
success: Alfresco.processShowPageResults,
failure: Alfresco.handleSearchError,
success: Alfresco.OpenSearchEngine.processShowPageResults,
failure: Alfresco.OpenSearchEngine.handleSearchError,
argument: [engineId, this]
},
null);
@@ -340,21 +340,21 @@ Alfresco.OpenSearchClient.prototype =
var elResult = results[x];
// get the title, icon and summary
var title = getElementTextByTagName(elResult, "title");
var icon = getElementTextByTagName(elResult, "icon");
var title = Alfresco.Dom.getElementTextByTagName(elResult, "title");
var icon = Alfresco.Dom.getElementTextByTagName(elResult, "icon");
var summary = null;
if (isAtom)
{
summary = getElementTextByTagName(elResult, "summary");
summary = Alfresco.Dom.getElementTextByTagName(elResult, "summary");
}
else
{
summary = getElementTextByTagName(elResult, "description");
summary = Alfresco.Dom.getElementTextByTagName(elResult, "description");
}
// get the link href
var link = null;
var elLink = getElementByTagName(elResult, "link");
var elLink = Alfresco.Dom.getElementByTagName(elResult, "link");
if (elLink != null)
{
if (isAtom)
@@ -363,7 +363,7 @@ Alfresco.OpenSearchClient.prototype =
}
else
{
link = getElementText(elLink);
link = Alfresco.Dom.getElementText(elLink);
}
}
@@ -416,10 +416,10 @@ Alfresco.OpenSearchClient.prototype =
var startIndex = 0;
// check there are results
var elTotalResults = getElementByTagNameNS(feed, _OS_NS_URI, _OS_NS_PREFIX, "totalResults");
var elTotalResults = Alfresco.Dom.getElementByTagNameNS(feed, _OS_NS_URI, _OS_NS_PREFIX, "totalResults");
if (elTotalResults != null)
{
totalResults = getElementText(elTotalResults);
totalResults = Alfresco.Dom.getElementText(elTotalResults);
}
// if there are no results return an empty string
@@ -428,16 +428,16 @@ Alfresco.OpenSearchClient.prototype =
return "";
}
var elStartIndex = getElementByTagNameNS(feed, _OS_NS_URI, _OS_NS_PREFIX, "startIndex");
var elStartIndex = Alfresco.Dom.getElementByTagNameNS(feed, _OS_NS_URI, _OS_NS_PREFIX, "startIndex");
if (elStartIndex != null)
{
startIndex = getElementText(elStartIndex);
startIndex = Alfresco.Dom.getElementText(elStartIndex);
}
var elItemsPerPage = getElementByTagNameNS(feed, _OS_NS_URI, _OS_NS_PREFIX, "itemsPerPage");
var elItemsPerPage = Alfresco.Dom.getElementByTagNameNS(feed, _OS_NS_URI, _OS_NS_PREFIX, "itemsPerPage");
if (elItemsPerPage != null)
{
pageSize = getElementText(elItemsPerPage);
pageSize = Alfresco.Dom.getElementText(elItemsPerPage);
}
// calculate the number of pages the results span
@@ -587,7 +587,7 @@ Alfresco.OpenSearchClient.prototype =
/**
* Processes the XML search results
*/
Alfresco.processSearchResults = function(ajaxResponse)
Alfresco.OpenSearchEngine.processSearchResults = function(ajaxResponse)
{
try
{
@@ -599,7 +599,7 @@ Alfresco.processSearchResults = function(ajaxResponse)
// if the name of the feed element is "rss", get the channel child element
if (feed.tagName == "rss")
{
feed = getElementByTagName(feed, "channel");
feed = Alfresco.Dom.getElementByTagName(feed, "channel");
}
var resultsDiv = clientInstance.renderSearchResults(engineId, feed);
@@ -628,7 +628,7 @@ Alfresco.processSearchResults = function(ajaxResponse)
* Processes the search results and updates the postion, result list
* and paging controls.
*/
Alfresco.processShowPageResults = function(ajaxResponse)
Alfresco.OpenSearchEngine.processShowPageResults = function(ajaxResponse)
{
try
{
@@ -640,7 +640,7 @@ Alfresco.processShowPageResults = function(ajaxResponse)
// if the name of the feed element is "rss", get the channel child element
if (feed.tagName == "rss")
{
feed = getElementByTagName(feed, "channel");
feed = Alfresco.Dom.getElementByTagName(feed, "channel");
}
// append the results list to the results list div
@@ -668,7 +668,7 @@ Alfresco.processShowPageResults = function(ajaxResponse)
/**
* Error handler for Ajax call to search engine
*/
Alfresco.handleSearchError = function(ajaxResponse)
Alfresco.OpenSearchEngine.handleSearchError = function(ajaxResponse)
{
var engineId = ajaxResponse.argument[0];
var clientInstance = ajaxResponse.argument[1];