xlawrence 2005/08/05 15:56:50 CEST
Modified files:
core/src/webapp/jsp/test actions.js
Log:
AJAX javascript code
Revision Changes Path
1.2 +227 -33 jahia/core/src/webapp/jsp/test/actions.js
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/webapp/jsp/test/actions.js.diff?r1=1.1&r2=1.2&f=h
Index: actions.js
===================================================================
RCS file: /home/cvs/repository/jahia/core/src/webapp/jsp/test/actions.js,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- actions.js 23 Jun 2004 15:11:16 -0000 1.1
+++ actions.js 5 Aug 2005 13:56:49 -0000 1.2
@@ -4,6 +4,8 @@
//
// Copyright 2000 by Mike Hall.
// See http://www.brainjar.com for terms of use.
+
+// Modified by Xavier Lawrence, 2005 Copyright Jahia Solutions
//*****************************************************************************
//----------------------------------------------------------------------------
@@ -52,6 +54,9 @@
var activeButton = null;
+// AJAX variables
+var req;
+
// Capture mouse clicks on the page so any active button can be
// deactivated.
@@ -90,66 +95,56 @@
}
}
-function buttonClick(event, menuId) {
-
- var button;
-
- // Get the target button element.
-
- if (browser.isIE)
- button = window.event.srcElement;
- else
- button = event.currentTarget;
+// Opens up the menu of the given id
+function buttonClick (menuId) {
+ var button = getObjectById ("button_" + menuId);
// Blur focus from the link to remove that annoying outline.
-
button.blur();
// Associate the named menu to this button if not already done.
// Additionally, initialize menu display.
-
if (button.menu == null) {
- button.menu = document.getElementById(menuId);
- if (button.menu.isInitialized == null)
+ button.menu = getObjectById (menuId);
+ if (button.menu.isInitialized == null) {
menuInit(button.menu);
+ }
}
// Reset the currently active button, if any.
- if (activeButton != null)
+ if (activeButton != null) {
resetButton(activeButton);
+ }
// Activate this button, unless it was the currently active one.
if (button != activeButton) {
depressButton(button);
activeButton = button;
- }
- else
+ } else {
activeButton = null;
-
- return false;
+ }
}
+// Switches menu if the user's mouse goes on another menu
function buttonMouseover(event, menuId) {
+ var button;
- var button;
-
- // Find the target button element.
-
- if (browser.isIE)
- button = window.event.srcElement;
- else
- button = event.currentTarget;
-
- // If any other button menu is active, make this one active instead.
-
- if (activeButton != null && activeButton != button)
- buttonClick(event, menuId);
+ // Find the target button element.
+ if (browser.isIE) {
+ button = window.event.srcElement;
+ } else {
+ button = event.currentTarget;
+ }
+
+ // If any other button menu is active, make this one active instead.
+ if (activeButton != null && activeButton != button) {
+ buttonClick (menuId);
+ }
}
function depressButton(button) {
-
var x, y;
// Update the button's style class to make it look like it's
@@ -444,3 +439,202 @@
return y;
}
+
+// Check the browser for DOM manipulation
+function checkBrowser(){
+ this.ver=navigator.appVersion;
+ this.dom=document.getElementById?1:0;
+ this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
+ this.ie55=((this.ver.indexOf("MSIE 5.5")>-1 || this.ie6) &&
this.dom)?1:0;
+ this.ie5=((this.ver.indexOf("MSIE 5")>-1 || this.ie5 || this.ie6) &&
this.dom)?1:0;
+ this.ie4=(document.all && !this.dom)?1:0;
+ this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
+ this.ns4=(document.layers && !this.dom)?1:0;
+ this.ie4plus=(this.ie6 || this.ie5 || this.ie4);
+ this.ie5plus=(this.ie6 || this.ie5)
+ this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns5);
+ return this;
+}
+
+bw = new checkBrowser();
+
+// Get an Object contained in a DOM document by its ID attribute
+function getObjectById (ID) {
+ var obj;
+ if (bw.dom)
+ return document.getElementById (ID);
+ else if (bw.ie4)
+ return document.all (ID);
+ else
+ alert ("Error: Your browser version is not supported. Please
upgrade...");
+}
+
+// Returns an array of values. The delimiter is the ',' character
+function getNodeValues (content, nodeName) {
+ var tag = "<" + nodeName + ">";
+ var start = content.indexOf (tag);
+ var end = content.indexOf ("</" + nodeName + ">");
+
+ if (start < end) {
+ var values = content.substring (start + tag.length, end);
+ return values.split (";;");
+ } else {
+ return new Array (0);
+ }
+}
+
+// Returns the value of an XML tag
+function getNodeValue (content, nodeName) {
+ var tag = "<" + nodeName + ">";
+ var start = content.indexOf (tag);
+ var end = content.indexOf ("</" + nodeName + ">");
+
+ if (start < end) {
+ return content.substring (start + tag.length, end);
+ } else {
+ return null;
+ }
+}
+
+// AJAX based function to get all Actions to fill up the Action menu
+function getActionMenu (context, objectType, objectKey, definitionID,
parentID, pageID) {
+ try {
+ // correct values are "POST" or "GET" (HTTP methods).
+ var method = "POST" ;
+ var data = "key=" + objectKey + "&type=" + objectType +
+ "&def=" + definitionID + "&parent=" + parentID
+
+ "&page=" + pageID;
+ var url = context + "/menu/";
+
+ if (method == "GET") {
+ url += "?" + data;
+ data = null;
+ }
+
+ // Create new XMLHttpRequest request
+ if (window.XMLHttpRequest) {
+ req = new XMLHttpRequest ();
+
+ } else if (window.ActiveXObject) {
+ req = new ActiveXObject ("Microsoft.XMLHTTP");
+
+ } else {
+ alert ("Error: Your Browser does not support
XMLHTTPRequests, please upgrade...");
+ return;
+ }
+
+ req.open (method, url, true);
+
+ req.onreadystatechange = function () {
+ buildActionMenu();
+ }
+
+ if (method == "POST") {
+ req.setRequestHeader ("Content-type",
"application/x-www-form-urlencoded");
+ }
+ req.send (data);
+
+ } catch (e) {
+ alert ("Exception sending the Request: " + e);
+ }
+}
+
+// Build the Action Menu
+function buildActionMenu () {
+ var readyState = req.readyState;
+ if (req.readyState == 4) {
+ // alert ("resp: " + req.responseText);
+ if (req.status == 200) {
+ try {
+ var response = req.responseText;
+ var objectType = getNodeValue (response,
"type");
+ var objectKey = getNodeValue (response, "key");
+ var definitionID = getNodeValue (response,
"def");
+ var parentID = getNodeValue (response,
"parent");
+ var pageID = getNodeValue (response, "page");
+
+ var uniqueID = objectType + "_" + objectKey +
"_" +
+ definitionID + "_" +
parentID + "_" + pageID;
+
+ var methods = getNodeValues (response,
"method");
+ var launchers = getNodeValues (response,
"launcher");
+ var images = getNodeValues (response, "image");
+
+ var fieldset = getNodeValue (response,
"fieldset");
+ updateFieldSet (uniqueID, fieldset);
+
+ addActions (uniqueID, methods, launchers,
images);
+
+ changeURL (uniqueID);
+
+ buttonClick (uniqueID);
+
+ } catch (e) {
+ alert ("Exception building Action Menu: " + e);
+ }
+
+ } else {
+ alert ("There was a problem processing the request.
Status: " +
+ req.status + ", msg: " +
req.statusText);
+ }
+ }
+}
+
+// Changes the default grey border. Use in case the object is locked for
example
+function updateFieldSet (id, param) {
+ // alert ("Updating fieldSet for " + id + ", param = " + param);
+ if (param == null) { return; }
+
+ var setID = "fieldset_" + id;
+ var setElem = getObjectById (setID);
+
+ var content;
+ if (param == "complete") {
+ content = "completeLocked";
+
+ } else if (param == "partial") {
+ content = "partialLocked";
+
+ } else {
+ return;
+ }
+
+ setElem.className = content;
+}
+
+// Changes the href value of the given element
+function changeURL (id) {
+ var button = getObjectById ("button_" + id);
+ button.href = "javascript:buttonClick('" + id + "');";
+}
+
+// Adds the Actions to the action menu
+function addActions (id, methods, launchers, images) {
+ var menuDiv = getObjectById (id);
+ var content = "\n";
+
+ var i;
+ for (i=0; i<methods.length; i++) {
+ if (methods[i].length > 0) {
+ // alert ("Adding action: '" + methods[i] + "' in div "
+ id);
+ content += printLauncher(launchers[i]) +
printImage(images[i]) +
+ printMethod(methods[i]);
+ }
+ }
+ menuDiv.innerHTML = content;
+}
+
+// Returns a String for the Action Launcher URI
+function printLauncher (launcher) {
+ return " <a class=\"menuItem\" href=\"javascript:" + launcher +
"\">\n";
+}
+
+// Returns a String for the Action Image
+function printImage (imageName) {
+ return " <img src=\"" + imageName + "\" alt=\"\" border=\"0\"
/> ";
+}
+
+// Returns a String for the Action method name
+function printMethod (methodName) {
+ return methodName + "\n </a>\n";
+}