mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
- ported xforms javascript codebase to mootools. mostly complete - a few dangling effects and dom manipulation functions still use dojo. these should be removed at which point it will no longer be necessary to load dojo.js which should save a second or so on load time. a few of the date widgets and slider still use dojo widgets. this can probably stay as dojo can be loaded only if those widgets are used. - performance tuning of xforms js codebase. about %40 improvement in load time for large forms with lots of widgets. - switching wizards into almost standards compliance mode so that things will lay out properly in IE. - lots of layout cleanup and off by pixel issues, particularly for IE. - putting in an uncompressed version of mootools which includes some libraries needed by xforms - particularly all native objects, Element.Event, Window.DomReady, XHR and Ajax. at some point dojo effects should likely be replaced with those in mootools. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6903 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
163 lines
5.8 KiB
JavaScript
163 lines
5.8 KiB
JavaScript
/*
|
|
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*/
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Ajax helper library
|
|
//
|
|
// This script manages ajax requests and provides a wrapper around the dojo
|
|
// library.
|
|
//
|
|
// This script requires dojo.js to be loaded in advance.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// AJAX helper
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
alfresco = typeof alfresco == "undefined" ? {} : alfresco;
|
|
alfresco.constants = typeof alfresco.constants == "undefined" ? {} : alfresco.constants;
|
|
alfresco.constants.AJAX_LOADER_DIV_ID = "alfresco-ajax-loader";
|
|
|
|
alfresco.AjaxHelper = function()
|
|
{
|
|
}
|
|
|
|
/** All pending ajax requests. */
|
|
alfresco.AjaxHelper._requests = [];
|
|
|
|
/** A counter for numbering requests - for debugging */
|
|
alfresco.AjaxHelper._requestCounter = 0;
|
|
|
|
/** Creates an ajax request object. */
|
|
alfresco.AjaxHelper.sendRequest = function(serverMethod, methodArgs, asynchronous, success, failure)
|
|
{
|
|
var result = new XHR({ method: "post", encoding: "utf-8", async: asynchronous });
|
|
sucess = success || Class.empty;
|
|
failure = failure || Class.empty;
|
|
result._alfresco_AjaxHelper_request_counter = alfresco.AjaxHelper._requestCounter++;
|
|
result.addEvent("onRequest", alfresco.AjaxHelper._onRequestHandler.bindAsEventListener(result));
|
|
result.addEvent("onSuccess", alfresco.AjaxHelper._loadHandler.bindAsEventListener(result));
|
|
result.addEvent("onSuccess", function(text, xml) { success(xml); });
|
|
result.addEvent("onFailure", alfresco.AjaxHelper._loadHandler.bindAsEventListener(result));
|
|
result.addEvent("onFailure", alfresco.AjaxHelper._errorHandler.bindAsEventListener(result));
|
|
result.addEvent("onFailure", function(text, xml) { failure(xml); });
|
|
|
|
methodArgs = alfresco.AjaxHelper.toQueryString(methodArgs);
|
|
alfresco.log("sending request to " + serverMethod + "(" + methodArgs + ")");
|
|
result.send(alfresco.constants.WEBAPP_CONTEXT + "/ajax/invoke/" + serverMethod, methodArgs);
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Returns the ajax loader div element. If it hasn't yet been created, it is created.
|
|
*/
|
|
alfresco.AjaxHelper._getLoaderElement = function()
|
|
{
|
|
var result = $(alfresco.constants.AJAX_LOADER_DIV_ID);
|
|
if (!result)
|
|
{
|
|
result = new Element("div",
|
|
{
|
|
"id": alfresco.constants.AJAX_LOADER_DIV_ID,
|
|
"class": "xformsAjaxLoader"
|
|
});
|
|
result.setOpacity(0);
|
|
document.body.appendChild(result);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/** Updates the loader message or hides it if nothing is being loaded. */
|
|
alfresco.AjaxHelper._updateLoaderDisplay = function()
|
|
{
|
|
var ajaxLoader = alfresco.AjaxHelper._getLoaderElement();
|
|
ajaxLoader.setText(alfresco.AjaxHelper._requests.length == 0
|
|
? alfresco.resources["idle"]
|
|
: (alfresco.resources["loading"] +
|
|
(alfresco.AjaxHelper._requests.length > 1
|
|
? " (" + alfresco.AjaxHelper._requests.length + ")"
|
|
: "...")));
|
|
alfresco.log(ajaxLoader.getText());
|
|
ajaxLoader.setOpacity(alfresco.AjaxHelper._requests.length != 0 ? 1 : 0);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// ajax event handlers
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
alfresco.AjaxHelper._onRequestHandler = function()
|
|
{
|
|
alfresco.AjaxHelper._requests.push(this._alfresco_AjaxHelper_request_counter);
|
|
alfresco.AjaxHelper._updateLoaderDisplay();
|
|
}
|
|
|
|
alfresco.AjaxHelper._loadHandler = function()
|
|
{
|
|
var index = alfresco.AjaxHelper._requests.indexOf(this._alfresco_AjaxHelper_request_counter);
|
|
if (index != -1)
|
|
{
|
|
alfresco.AjaxHelper._requests.splice(index, 1);
|
|
}
|
|
else
|
|
{
|
|
var urls = [];
|
|
for (var i = 0; i < alfresco.AjaxHelper._requests.length; i++)
|
|
{
|
|
urls.push(alfresco.AjaxHelper._requests[i]);
|
|
}
|
|
throw new Error("unable to find " + req.url +
|
|
" in [" + urls.join(", ") + "]");
|
|
}
|
|
alfresco.AjaxHelper._updateLoaderDisplay();
|
|
}
|
|
|
|
alfresco.AjaxHelper._errorHandler = function(transport)
|
|
{
|
|
alfresco.log("error status = " + transport.status +
|
|
" response text = " + transport.responseText);
|
|
if (transport.status == 401)
|
|
{
|
|
document.getElementById("logout").onclick();
|
|
}
|
|
else if (transport.status != 0)
|
|
{
|
|
var d = document.createElement("div");
|
|
d.innerHTML = transport.responseText;
|
|
_show_error(d);
|
|
}
|
|
}
|
|
|
|
alfresco.AjaxHelper.toQueryString = function(source)
|
|
{
|
|
var queryString = [];
|
|
for (var property in source)
|
|
{
|
|
if (typeof source[property] == "object")
|
|
{
|
|
for (var i = 0; i < source[property].length; i++)
|
|
{
|
|
queryString.push(encodeURIComponent(property) + '=' + encodeURIComponent(source[property][i]));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
queryString.push(encodeURIComponent(property) + '=' + encodeURIComponent(source[property]));
|
|
}
|
|
}
|
|
return queryString.join('&');
|
|
};
|