2007-02-15 16:09:07 +00:00
|
|
|
@@----------------------------------------------------------------------------
|
2007-09-20 12:45:00 +00:00
|
|
|
@@-- Ada Web Server
|
|
|
|
|
@@--
|
2011-12-31 15:52:39 +01:00
|
|
|
@@-- Copyright (C) 2007-2012, AdaCore
|
2007-09-20 12:45:00 +00:00
|
|
|
@@--
|
2011-12-31 15:52:39 +01:00
|
|
|
@@-- This library is free software; you can redistribute it and/or modify
|
|
|
|
|
@@-- it under terms of the GNU General Public License as published by the
|
|
|
|
|
@@-- Free Software Foundation; either version 3, or (at your option) any
|
|
|
|
|
@@-- later version. This library 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.
|
2007-09-20 12:45:00 +00:00
|
|
|
@@--
|
2011-12-31 15:52:39 +01:00
|
|
|
@@-- As a special exception under Section 7 of GPL version 3, you are
|
|
|
|
|
@@-- granted additional permissions described in the GCC Runtime Library
|
|
|
|
|
@@-- Exception, version 3.1, as published by the Free Software Foundation.
|
2007-09-20 12:45:00 +00:00
|
|
|
@@--
|
2011-12-31 15:52:39 +01:00
|
|
|
@@-- You should have received a copy of the GNU General Public License and
|
|
|
|
|
@@-- a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
|
@@-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
|
@@-- <http://www.gnu.org/licenses/>.
|
2007-09-20 12:45:00 +00:00
|
|
|
@@--
|
2007-02-15 16:09:07 +00:00
|
|
|
@@----------------------------------------------------------------------------
|
|
|
|
|
|
2007-09-20 12:45:00 +00:00
|
|
|
@@SET@@ CTX_WB = "CTX_WB"
|
|
|
|
|
@@-- The context parameter name
|
|
|
|
|
|
2009-07-03 16:22:00 +00:00
|
|
|
@@SET@@ TIMEZONE_COOKIE = ""
|
|
|
|
|
@@-- Set to empty string for no timezone support
|
|
|
|
|
|
2007-02-15 16:09:07 +00:00
|
|
|
@@---------------------------------------------------------------- AWS
|
|
|
|
|
|
|
|
|
|
var AWS = {
|
2012-06-19 10:05:38 +02:00
|
|
|
Context : null,
|
|
|
|
|
Ajax : null,
|
|
|
|
|
WebSocket : null,
|
|
|
|
|
Tools : null
|
2007-02-15 16:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@---------------------------------------------------------------- TOOLS
|
|
|
|
|
|
|
|
|
|
AWS.Tools = new function() {
|
|
|
|
|
|
|
|
|
|
@@-----------
|
|
|
|
|
@@-- PUBLIC
|
|
|
|
|
@@-----------
|
|
|
|
|
|
|
|
|
|
@@-- --------------------------------
|
2007-09-20 12:45:00 +00:00
|
|
|
@@-- onload event to update CTX_WB
|
2007-02-15 16:09:07 +00:00
|
|
|
|
|
|
|
|
this.addLoadEvent = function (func)
|
|
|
|
|
{
|
|
|
|
|
var oldonload = window.onload;
|
|
|
|
|
|
|
|
|
|
if (typeof window.onload != 'function') {
|
|
|
|
|
window.onload = func;
|
|
|
|
|
} else {
|
|
|
|
|
window.onload = function() { oldonload(); func(); }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- --------------------------------
|
|
|
|
|
@@-- Used to report javascript errors
|
|
|
|
|
|
|
|
|
|
this.report_error = function (request)
|
|
|
|
|
{
|
|
|
|
|
alert ('There was! an error on this Ajax request.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Clear select content
|
|
|
|
|
|
|
|
|
|
this.clearSelect = function (select_id)
|
|
|
|
|
{
|
|
|
|
|
while ($(select_id).length > 0) {
|
|
|
|
|
$(select_id).remove(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Delete a given option from the select
|
|
|
|
|
|
|
|
|
|
this.delSelectOption = function (select_id, option)
|
|
|
|
|
{
|
|
|
|
|
var idx = 0;
|
|
|
|
|
while (idx < $(select_id).length) {
|
|
|
|
|
if ($(select_id).options[idx].value == option) {
|
|
|
|
|
$(select_id).remove(idx);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
idx = idx + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Add option_value/option_content into the given select
|
|
|
|
|
|
2007-09-20 12:45:00 +00:00
|
|
|
this.addToSelect =
|
2007-02-15 16:09:07 +00:00
|
|
|
function (select_id, option_value, option_content, option_class)
|
|
|
|
|
{
|
|
|
|
|
// Create a new option
|
|
|
|
|
var new_option = document.createElement("option");
|
|
|
|
|
new_option.value = option_value;
|
|
|
|
|
new_option.className = option_class;
|
|
|
|
|
var content = document.createTextNode(option_content);
|
|
|
|
|
new_option.appendChild(content);
|
|
|
|
|
|
|
|
|
|
// And add it to select
|
|
|
|
|
$(select_id).appendChild(new_option);
|
|
|
|
|
return new_option;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Select the given option from the select
|
|
|
|
|
|
|
|
|
|
this.selectChangeSelected =
|
|
|
|
|
function (select_id, option, hook_func, hook_param)
|
|
|
|
|
{
|
|
|
|
|
var idx = 0;
|
|
|
|
|
while (idx < $(select_id).length) {
|
|
|
|
|
if ($(select_id).options[idx].value == option) {
|
|
|
|
|
$(select_id).selectedIndex = idx;
|
|
|
|
|
if (hook_func != null && hook_func != "") {
|
|
|
|
|
hook_func($(select_id).options[idx], hook_param);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
idx = idx + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-03 16:22:00 +00:00
|
|
|
|
|
|
|
|
@@IF@@ @_TIMEZONE_COOKIE_@ /= ""
|
|
|
|
|
@@-- Use cookie to record that the timezone has been sent
|
|
|
|
|
@@INCLUDE@@ cookies.js
|
|
|
|
|
|
|
|
|
|
@@-- Handle Web Browser local timezone
|
|
|
|
|
|
|
|
|
|
this.TZ_offset = new Date().getTimezoneOffset();
|
|
|
|
|
|
|
|
|
|
this.setTimezone =
|
|
|
|
|
function ()
|
|
|
|
|
{
|
|
|
|
|
if (readCookie ("@_TIMEZONE_COOKIE_@") == null) {
|
|
|
|
|
createCookie ("@_TIMEZONE_COOKIE_@", this.TZ_offset, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@END_IF@@
|
2007-02-15 16:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@---------------------------------------------------------------- CONTEXT
|
|
|
|
|
|
|
|
|
|
AWS.Context = new function() {
|
|
|
|
|
|
|
|
|
|
@@-----------
|
|
|
|
|
@@-- PUBLIC
|
|
|
|
|
@@-----------
|
|
|
|
|
|
|
|
|
|
@@-- --------------------------------
|
|
|
|
|
@@-- Returns the context id
|
|
|
|
|
|
|
|
|
|
this.get = function ()
|
|
|
|
|
{
|
2007-09-20 12:45:00 +00:00
|
|
|
var context = document.getElementById('@_CTX_WB_@');
|
2007-02-15 16:09:07 +00:00
|
|
|
|
|
|
|
|
if (context == null)
|
|
|
|
|
return "";
|
|
|
|
|
else
|
|
|
|
|
return $(context).innerHTML;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-18 17:55:35 +00:00
|
|
|
this.set = function (value)
|
2008-11-03 11:30:36 +00:00
|
|
|
{
|
2009-11-18 17:55:35 +00:00
|
|
|
var context = document.getElementById('@_CTX_WB_@');
|
2008-11-03 11:30:36 +00:00
|
|
|
|
|
|
|
|
if (context == null)
|
2009-11-18 17:55:35 +00:00
|
|
|
return;
|
2008-11-03 11:30:36 +00:00
|
|
|
else
|
2009-11-18 17:55:35 +00:00
|
|
|
$(context).innerHTML = value;
|
|
|
|
|
|
|
|
|
|
this.update();
|
2008-11-03 11:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
2007-02-15 16:09:07 +00:00
|
|
|
@@-- --------------------------------
|
|
|
|
|
@@-- Update the context tag in anchors and forms
|
|
|
|
|
|
|
|
|
|
this.update = function ()
|
|
|
|
|
{
|
|
|
|
|
var k = 0;
|
|
|
|
|
|
|
|
|
|
@@-- anchors
|
|
|
|
|
|
|
|
|
|
var anchors = document.getElementsBySelector('a');
|
|
|
|
|
|
|
|
|
|
for (k=0; k<anchors.length; k++) {
|
|
|
|
|
var href = anchors[k].getAttribute('href');
|
2007-09-20 12:45:00 +00:00
|
|
|
if (href != null) {
|
2007-09-25 12:35:12 +00:00
|
|
|
@@-- IE insists on returning the derived absolute URL,
|
|
|
|
|
@@-- make sure that the ref is on the current page if the
|
|
|
|
|
@@-- prefix is HTTP.
|
|
|
|
|
if ((href.indexOf("http:",0) != 0
|
|
|
|
|
|| href.indexOf(window.location.hostname) == 7)
|
2007-02-15 16:09:07 +00:00
|
|
|
&& href.indexOf("mailto:",0) != 0
|
2007-09-20 12:45:00 +00:00
|
|
|
&& href.indexOf("#",0) != 0) {
|
|
|
|
|
|
|
|
|
|
anchors[k].setAttribute('href',
|
|
|
|
|
AWS.Context.href_add_anchor(href));
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-02-15 16:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- forms
|
|
|
|
|
|
|
|
|
|
var forms = document.getElementsBySelector('form');
|
|
|
|
|
|
|
|
|
|
for (k=0; k<forms.length; k++) {
|
|
|
|
|
var action = forms[k].getAttribute('action');
|
|
|
|
|
if (action != null) {
|
|
|
|
|
if (action != ""
|
2007-09-25 12:35:12 +00:00
|
|
|
&& action.indexOf("http:",0) != 0
|
2007-02-15 16:09:07 +00:00
|
|
|
&& action.indexOf("#", 0) != 0
|
|
|
|
|
&& forms[k].getAttribute('onsubmit') == null) {
|
2007-09-20 12:45:00 +00:00
|
|
|
add_context_to_form (forms[k]);
|
|
|
|
|
}
|
2007-02-15 16:09:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- --------------------------------
|
2007-09-20 12:45:00 +00:00
|
|
|
@@-- Add Context parameter CTX_WB for Ajax
|
2007-02-15 16:09:07 +00:00
|
|
|
|
|
|
|
|
this.add_ajax = function (pars)
|
|
|
|
|
{
|
|
|
|
|
if (pars == "")
|
|
|
|
|
pars = pars + "?";
|
|
|
|
|
else
|
|
|
|
|
pars = pars + "&";
|
|
|
|
|
|
2007-09-20 12:45:00 +00:00
|
|
|
pars = pars + "@_CTX_WB_@=" + this.get();
|
2007-02-15 16:09:07 +00:00
|
|
|
|
|
|
|
|
return pars;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- --------------------------------
|
2007-09-20 12:45:00 +00:00
|
|
|
@@-- Add context parameter CTX_WB for anchors
|
2007-02-15 16:09:07 +00:00
|
|
|
|
|
|
|
|
this.add_anchor = function (a)
|
|
|
|
|
{
|
2007-09-20 12:45:00 +00:00
|
|
|
a.href = this.href_add_anchor(a.href);
|
|
|
|
|
}
|
2007-02-15 16:09:07 +00:00
|
|
|
|
2007-09-20 12:45:00 +00:00
|
|
|
this.href_add_anchor = function (href)
|
|
|
|
|
{
|
|
|
|
|
var href_last = ""; // Contains fragment
|
|
|
|
|
|
|
|
|
|
if (href.indexOf('#', 0) != -1) {
|
|
|
|
|
var splitted_href = href.split('#');
|
|
|
|
|
href = splitted_href[0];
|
|
|
|
|
href_last = splitted_href[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove CTX_WB if exists
|
|
|
|
|
|
|
|
|
|
if (href.indexOf("@_CTX_WB_@", 0) != -1) {
|
|
|
|
|
href = href.split("@_CTX_WB_@")[0];
|
|
|
|
|
href = href.substr(0, href.length - 1); // Remove & or ?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (href.indexOf('?',0) == -1) {
|
|
|
|
|
href = href + '?';
|
|
|
|
|
} else {
|
|
|
|
|
href = href + '&';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
href = href + "@_CTX_WB_@=" + this.get();
|
|
|
|
|
|
|
|
|
|
if (href_last != "") {
|
|
|
|
|
href = href + "#" + href_last;
|
|
|
|
|
}
|
|
|
|
|
return (href);
|
2007-02-15 16:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@------------
|
|
|
|
|
@@-- PRIVATE
|
|
|
|
|
@@------------
|
|
|
|
|
|
|
|
|
|
@@-- --------------------------------
|
2007-09-20 12:45:00 +00:00
|
|
|
@@-- Append or update context into form
|
2007-02-15 16:09:07 +00:00
|
|
|
|
2007-09-20 12:45:00 +00:00
|
|
|
function add_context_to_form (form)
|
2007-02-15 16:09:07 +00:00
|
|
|
{
|
|
|
|
|
var k = 0;
|
2007-09-20 12:45:00 +00:00
|
|
|
var items = form.elements;
|
2008-11-03 11:30:36 +00:00
|
|
|
var found_context = false;
|
2007-09-20 12:45:00 +00:00
|
|
|
|
2007-02-15 16:09:07 +00:00
|
|
|
for (k=0; k<items.length; k++) {
|
|
|
|
|
if (items[k].tagName == "INPUT"
|
2007-09-20 12:45:00 +00:00
|
|
|
&& items[k].getAttribute('NAME') == '@_CTX_WB_@') {
|
|
|
|
|
|
|
|
|
|
// Update context if needed
|
|
|
|
|
|
|
|
|
|
if (items[k].getAttribute('VALUE') != AWS.Context.get()) {
|
|
|
|
|
items[k].setAttribute ('VALUE', AWS.Context.get());
|
|
|
|
|
}
|
2008-11-03 11:30:36 +00:00
|
|
|
found_context = true;
|
|
|
|
|
}
|
2007-02-15 16:09:07 +00:00
|
|
|
}
|
2007-09-20 12:45:00 +00:00
|
|
|
|
|
|
|
|
// Insert new context field
|
|
|
|
|
|
2008-11-20 09:17:23 +00:00
|
|
|
if (!found_context) {
|
2008-11-03 11:30:36 +00:00
|
|
|
hi = document.createElement('input');
|
|
|
|
|
hi.setAttribute('type', 'hidden');
|
|
|
|
|
hi.setAttribute('name', '@_CTX_WB_@');
|
|
|
|
|
hi.setAttribute('value', AWS.Context.get());
|
|
|
|
|
form.appendChild(hi);
|
|
|
|
|
}
|
2008-06-19 15:11:36 +00:00
|
|
|
}
|
2007-02-15 16:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@---------------------------------------------------------------- AJAX
|
|
|
|
|
|
|
|
|
|
AWS.Ajax = new function() {
|
|
|
|
|
|
|
|
|
|
@@-----------
|
|
|
|
|
@@-- PUBLIC
|
|
|
|
|
@@-----------
|
|
|
|
|
|
|
|
|
|
this.XML = null;
|
|
|
|
|
|
|
|
|
|
@@-- --------------------------------
|
|
|
|
|
@@-- Update the behavior rules, needed when loading new section
|
2007-09-20 12:45:00 +00:00
|
|
|
@@-- containing JavaScript code. Also update the CTX_WB.
|
2007-02-15 16:09:07 +00:00
|
|
|
|
|
|
|
|
this.update_framework = function()
|
|
|
|
|
{
|
|
|
|
|
Behaviour.apply ();
|
|
|
|
|
AWS.Context.update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- --------------------------------
|
|
|
|
|
@@-- Call url?pars and put result into placeholder
|
|
|
|
|
|
|
|
|
|
this.replace = function (url, pars, placeholder, oncomplete)
|
|
|
|
|
{
|
|
|
|
|
var rplaceholder = $(placeholder);
|
|
|
|
|
|
|
|
|
|
if (rplaceholder.tagName == "TEXTAREA" ||
|
|
|
|
|
rplaceholder.tagName == "INPUT")
|
|
|
|
|
var O_ajax = new Ajax.Request
|
|
|
|
|
(url,
|
|
|
|
|
{method: 'get',
|
|
|
|
|
parameters: AWS.Context.add_ajax(pars),
|
|
|
|
|
onFailure: AWS.Tools.report_error,
|
|
|
|
|
onComplete: function(req)
|
|
|
|
|
{rplaceholder.value = req.responseText;
|
|
|
|
|
if (oncomplete != "") oncomplete();}});
|
|
|
|
|
else
|
|
|
|
|
var O_ajax = new Ajax.Updater
|
|
|
|
|
({success: placeholder},
|
|
|
|
|
url,
|
2009-11-18 17:55:23 +00:00
|
|
|
{method: 'get',
|
2007-02-15 16:09:07 +00:00
|
|
|
parameters: AWS.Context.add_ajax(pars),
|
|
|
|
|
onFailure: AWS.Tools.report_error,
|
|
|
|
|
onComplete: function(req)
|
|
|
|
|
{AWS.Ajax.update_framework();
|
|
|
|
|
if (oncomplete != "") oncomplete();}});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- --------------------------------
|
|
|
|
|
@@-- Serialize a tag or all fields in a form
|
|
|
|
|
|
2007-11-14 16:00:22 +00:00
|
|
|
this.serialize = function(elm, name) {
|
2007-02-15 16:09:07 +00:00
|
|
|
var param = "";
|
|
|
|
|
|
2008-10-13 11:53:59 +00:00
|
|
|
if ($(elm) == null) return "";
|
2007-11-14 16:00:22 +00:00
|
|
|
|
2007-02-15 16:09:07 +00:00
|
|
|
if ($(elm).tagName == "FORM") {
|
|
|
|
|
param = Form.serialize (elm);
|
|
|
|
|
} else if ($(elm).tagName == "UL") {
|
|
|
|
|
param = Sortable.serialize(elm);
|
2008-06-19 15:11:36 +00:00
|
|
|
} else if (name == "" || name == null) {
|
2007-02-15 16:09:07 +00:00
|
|
|
param = elm + "=" + $F(elm);
|
2007-11-14 16:00:22 +00:00
|
|
|
} else {
|
|
|
|
|
param = name + "=" + $F(elm);
|
2007-02-15 16:09:07 +00:00
|
|
|
}
|
|
|
|
|
return (param);
|
|
|
|
|
}
|
2007-11-14 16:00:22 +00:00
|
|
|
|
2007-02-15 16:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AWS.Ajax.XML = new function() {
|
|
|
|
|
|
|
|
|
|
@@-- --------------------------------
|
|
|
|
|
@@-- Call url?pars and execute aws_xml_handler methods then the
|
|
|
|
|
@@-- oncomplete method (to chain commands) if defined
|
|
|
|
|
|
|
|
|
|
this.request = function (url, pars, oncomplete)
|
|
|
|
|
{
|
|
|
|
|
var myAjax = new Ajax.Request
|
|
|
|
|
(url,
|
|
|
|
|
{method: 'get',
|
|
|
|
|
parameters: AWS.Context.add_ajax(pars),
|
|
|
|
|
onFailure : AWS.Tools.report_error,
|
|
|
|
|
onComplete : function(req)
|
2012-06-19 10:05:38 +02:00
|
|
|
{AWS.Ajax.XML.handler(req.responseXML);
|
2007-02-15 16:09:07 +00:00
|
|
|
AWS.Ajax.update_framework();
|
|
|
|
|
if (oncomplete != "") oncomplete();}});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Handle XML responses
|
|
|
|
|
|
2012-06-19 10:05:38 +02:00
|
|
|
this.fromString = function (str)
|
2007-02-15 16:09:07 +00:00
|
|
|
{
|
2012-06-19 10:05:38 +02:00
|
|
|
var parser = new DOMParser();
|
|
|
|
|
var doc = parser.parseFromString(str, "application/xml");
|
|
|
|
|
AWS.Ajax.XML.handler(doc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Handle XML responses
|
|
|
|
|
|
|
|
|
|
this.handler = function (xml_actions)
|
|
|
|
|
{
|
|
|
|
|
var response = xml_actions.getElementsByTagName('response');
|
|
|
|
|
|
2007-02-15 16:09:07 +00:00
|
|
|
var i = 0;
|
|
|
|
|
for (i = 0; i < response[0].childNodes.length; i++) {
|
|
|
|
|
var node = response[0].childNodes[i];
|
|
|
|
|
if (node.nodeName == 'replace') {
|
|
|
|
|
handler_replace (node);
|
|
|
|
|
} else if (node.nodeName == 'clear') {
|
|
|
|
|
handler_clear (node);
|
|
|
|
|
} else if (node.nodeName == 'select') {
|
|
|
|
|
handler_select (node);
|
|
|
|
|
} else if (node.nodeName == 'radio') {
|
|
|
|
|
handler_radio (node);
|
|
|
|
|
} else if (node.nodeName == 'check') {
|
|
|
|
|
handler_check (node);
|
|
|
|
|
} else if (node.nodeName == 'get') {
|
|
|
|
|
handler_get (node);
|
|
|
|
|
} else if (node.nodeName == 'location') {
|
|
|
|
|
handler_location (node);
|
2007-09-24 19:30:16 +00:00
|
|
|
} else if (node.nodeName == 'refresh') {
|
|
|
|
|
window.location.reload (true);
|
2007-02-15 16:09:07 +00:00
|
|
|
} else if (node.nodeName == 'create_sortable') {
|
|
|
|
|
handler_create_sortable (node);
|
|
|
|
|
} else if (node.nodeName == 'destroy_sortable') {
|
|
|
|
|
handler_destroy_sortable (node);
|
|
|
|
|
} else if (node.nodeName == 'apply_style') {
|
|
|
|
|
handler_apply_style (node);
|
|
|
|
|
} else if (node.nodeName == 'insert_after') {
|
|
|
|
|
handler_insert_after (node);
|
2009-11-18 17:55:35 +00:00
|
|
|
} else if (node.nodeName == 'ctx') {
|
|
|
|
|
handler_ctx (node);
|
2010-10-01 08:30:14 +00:00
|
|
|
} else if (node.nodeName == 'read_only') {
|
|
|
|
|
handler_read_only (node);
|
|
|
|
|
} else if (node.nodeName == 'disabled') {
|
|
|
|
|
handler_disabled (node);
|
|
|
|
|
} else if (node.nodeName == 'reset') {
|
|
|
|
|
handler_reset (node);
|
2007-02-15 16:09:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-18 17:55:35 +00:00
|
|
|
@@-- Internal handler, replace current context in Web page
|
|
|
|
|
|
|
|
|
|
function handler_ctx (node)
|
|
|
|
|
{
|
|
|
|
|
var cid = node.getAttribute("id");
|
|
|
|
|
AWS.Context.set (cid);
|
|
|
|
|
|
|
|
|
|
AWS.Ajax.update_framework();
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-15 16:09:07 +00:00
|
|
|
@@-- Replace a node content by an HTML String
|
|
|
|
|
|
|
|
|
|
function handler_replace (node)
|
|
|
|
|
{
|
|
|
|
|
var placeholder_id = node.getAttribute("id");
|
|
|
|
|
var placeholder_content;
|
|
|
|
|
|
2007-09-25 12:35:12 +00:00
|
|
|
if ($(placeholder_id) == null) return;
|
|
|
|
|
|
2007-02-15 16:09:07 +00:00
|
|
|
if (node.childNodes.length > 1) {
|
|
|
|
|
placeholder_content = node.childNodes[1].nodeValue;
|
|
|
|
|
} else {
|
|
|
|
|
placeholder_content = node.firstChild.nodeValue;
|
|
|
|
|
}
|
|
|
|
|
if ($(placeholder_id).tagName == "TEXTAREA" ||
|
|
|
|
|
$(placeholder_id).tagName == "INPUT") {
|
|
|
|
|
$(placeholder_id).value = placeholder_content;
|
|
|
|
|
} else {
|
|
|
|
|
$(placeholder_id).innerHTML = placeholder_content;
|
|
|
|
|
}
|
2007-09-20 12:45:00 +00:00
|
|
|
|
2007-02-15 16:09:07 +00:00
|
|
|
AWS.Ajax.update_framework();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Clear a node
|
|
|
|
|
|
|
|
|
|
function handler_clear (node)
|
|
|
|
|
{
|
|
|
|
|
var placeholder_id = node.getAttribute("id");
|
|
|
|
|
if ($(placeholder_id).tagName == "TEXTAREA" ||
|
|
|
|
|
$(placeholder_id).tagName == "INPUT") {
|
|
|
|
|
$(placeholder_id).value = "";
|
2008-01-15 14:01:18 +00:00
|
|
|
} else if ( $(placeholder_id).tagName == "IFRAME") {
|
|
|
|
|
window.frames[placeholder_id].document.body.innerHTML="";
|
2007-02-15 16:09:07 +00:00
|
|
|
} else {
|
|
|
|
|
$(placeholder_id).innerHTML = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Action on select : add, delete or select an option, or clear a select
|
|
|
|
|
|
|
|
|
|
function handler_select (node)
|
|
|
|
|
{
|
|
|
|
|
var select_action = node.getAttribute("action");
|
|
|
|
|
var select_id = node.getAttribute("id");
|
|
|
|
|
if (select_action == "add") {
|
|
|
|
|
var option_value = node.getAttribute("option_value");
|
|
|
|
|
var option_content = node.getAttribute("option_content");
|
|
|
|
|
AWS.Tools.addToSelect (select_id, option_value, option_content);
|
|
|
|
|
} else if (select_action == "clear") {
|
|
|
|
|
AWS.Tools.clearSelect (select_id);
|
|
|
|
|
} else if (select_action == "delete") {
|
|
|
|
|
var option_value = node.getAttribute("option_value");
|
|
|
|
|
AWS.Tools.delSelectOption (select_id, option_value);
|
|
|
|
|
} else if (select_action == "select") {
|
|
|
|
|
var option_value = node.getAttribute("option_value");
|
|
|
|
|
AWS.Tools.selectChangeSelected (select_id, option_value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Action on list : add an element
|
|
|
|
|
|
|
|
|
|
function handler_insert_after (node)
|
|
|
|
|
{
|
|
|
|
|
var id = node.getAttribute('id');
|
|
|
|
|
var placeholder_content;
|
|
|
|
|
|
|
|
|
|
if (node.childNodes.length > 1) {
|
|
|
|
|
placeholder_content = node.childNodes[1].nodeValue;
|
|
|
|
|
} else {
|
|
|
|
|
placeholder_content = node.firstChild.nodeValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new Insertion.After (id, placeholder_content);
|
|
|
|
|
AWS.Ajax.update_framework();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Action on radio
|
|
|
|
|
|
|
|
|
|
function handler_radio (node)
|
|
|
|
|
{
|
|
|
|
|
var action = node.getAttribute('action');
|
|
|
|
|
var id = node.getAttribute('id');
|
|
|
|
|
if (action == 'select') {
|
|
|
|
|
$(id).checked = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Action on check
|
|
|
|
|
|
|
|
|
|
function handler_check (node)
|
|
|
|
|
{
|
|
|
|
|
var action = node.getAttribute('action');
|
|
|
|
|
var id = node.getAttribute('id');
|
|
|
|
|
if (action == 'select') {
|
|
|
|
|
$(id).checked = 1;
|
|
|
|
|
} else if (action == 'clear') {
|
|
|
|
|
$(id).checked = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Action on get
|
|
|
|
|
|
|
|
|
|
function handler_get (node)
|
|
|
|
|
{
|
|
|
|
|
var url = node.getAttribute('url');
|
|
|
|
|
var pars = '';
|
|
|
|
|
var i = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < node.childNodes.length; i++) {
|
|
|
|
|
var current_node = node.childNodes[i];
|
|
|
|
|
if (current_node.nodeName == 'parameters') {
|
|
|
|
|
if (pars != '') {
|
|
|
|
|
pars = pars + '&';
|
|
|
|
|
}
|
|
|
|
|
pars = pars + current_node.getAttribute('value');
|
|
|
|
|
} else if (current_node.nodeName == 'field') {
|
|
|
|
|
if (pars != '') {
|
|
|
|
|
pars = pars + '&';
|
|
|
|
|
}
|
|
|
|
|
var id = current_node.getAttribute('id');
|
|
|
|
|
pars = pars + AWS.Ajax.serialize (id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
AWS.Ajax.update_framework(); /* Update behaviour before request url */
|
|
|
|
|
AWS.Ajax.XML.request (url, pars, '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Action on location
|
|
|
|
|
|
|
|
|
|
function handler_location (node)
|
|
|
|
|
{
|
|
|
|
|
var url = node.getAttribute('url');
|
|
|
|
|
|
2009-07-03 16:22:05 +00:00
|
|
|
if (url.indexOf('http',0) == -1
|
|
|
|
|
&& url.indexOf('@_CTX_WB_@') == -1
|
|
|
|
|
&& url[0] != '#')
|
|
|
|
|
{
|
2007-09-20 12:45:00 +00:00
|
|
|
@@-- pointing inside server and no context
|
|
|
|
|
if (url.indexOf("?",0) == -1)
|
|
|
|
|
url = url + '?';
|
|
|
|
|
else
|
|
|
|
|
url = url + '&';
|
|
|
|
|
|
|
|
|
|
url = url + "@_CTX_WB_@=" + AWS.Context.get();
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-15 16:09:07 +00:00
|
|
|
/* Redirect to url */
|
|
|
|
|
document.location.href = url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Action on create_sortable
|
|
|
|
|
|
|
|
|
|
function handler_create_sortable (node)
|
|
|
|
|
{
|
|
|
|
|
var lists = []; /* Get all list for containment */
|
|
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < node.childNodes.length; i++) {
|
|
|
|
|
var current_node = node.childNodes[i];
|
|
|
|
|
if (current_node.nodeName == 'list') {
|
|
|
|
|
lists.push (current_node.getAttribute('id'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Call Sortable.create for each element */
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < node.childNodes.length; i++) {
|
|
|
|
|
var current_node = node.childNodes[i];
|
|
|
|
|
if (current_node.nodeName == 'list') {
|
|
|
|
|
var id = current_node.getAttribute('id');
|
|
|
|
|
|
|
|
|
|
/* Add cursor style */
|
|
|
|
|
|
|
|
|
|
var elm = document.getElementById (id);
|
|
|
|
|
elm.style.cursor = 'move';
|
|
|
|
|
|
|
|
|
|
/* Create sortable */
|
|
|
|
|
|
|
|
|
|
Sortable.create
|
|
|
|
|
(id, { containment:lists, constraint:false, dropOnEmpty:true });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Action on destroy_sortable
|
|
|
|
|
|
|
|
|
|
function handler_destroy_sortable (node)
|
|
|
|
|
{
|
|
|
|
|
var i = 0;
|
|
|
|
|
|
|
|
|
|
/* Call Sortable.destroy for each element */
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < node.childNodes.length; i++) {
|
|
|
|
|
var current_node = node.childNodes[i];
|
|
|
|
|
if (current_node.nodeName == 'list') {
|
|
|
|
|
var list_id = current_node.getAttribute('id');
|
|
|
|
|
|
|
|
|
|
/* Revert cursor style */
|
|
|
|
|
|
|
|
|
|
var elm = document.getElementById (list_id);
|
|
|
|
|
elm.style.cursor = 'default';
|
|
|
|
|
|
|
|
|
|
/* Destroy sortable */
|
|
|
|
|
Sortable.destroy (list_id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Action on apply_style
|
|
|
|
|
|
|
|
|
|
function handler_apply_style (node)
|
|
|
|
|
{
|
|
|
|
|
var elm_id = node.getAttribute('id');
|
|
|
|
|
|
|
|
|
|
if ($(elm_id) == null) return;
|
|
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
|
for (i = 0; i < node.childNodes.length; i++) {
|
|
|
|
|
var current_node = node.childNodes[i];
|
|
|
|
|
if (current_node.nodeName == 'attribute') {
|
|
|
|
|
var id = current_node.getAttribute('id');
|
|
|
|
|
var value = current_node.getAttribute('value');
|
|
|
|
|
$(elm_id).style[id] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-10-01 08:30:14 +00:00
|
|
|
|
|
|
|
|
@@-- Action on read_only
|
|
|
|
|
|
|
|
|
|
function handler_read_only (node)
|
|
|
|
|
{
|
|
|
|
|
var id = node.getAttribute('id');
|
|
|
|
|
var value = node.getAttribute('value');
|
|
|
|
|
|
|
|
|
|
if (value == 'true') {
|
|
|
|
|
$(id).readOnly = true;
|
|
|
|
|
} else if (value == 'false') {
|
|
|
|
|
$(id).readOnly = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Action on disabled
|
|
|
|
|
|
|
|
|
|
function handler_disabled (node)
|
|
|
|
|
{
|
|
|
|
|
var id = node.getAttribute('id');
|
|
|
|
|
var value = node.getAttribute('value');
|
|
|
|
|
|
|
|
|
|
if (value == 'true') {
|
|
|
|
|
$(id).disabled = true;
|
|
|
|
|
} else if (value == 'false') {
|
|
|
|
|
$(id).disabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@-- Action on reset
|
|
|
|
|
|
|
|
|
|
function handler_reset (node)
|
|
|
|
|
{
|
|
|
|
|
var id = node.getAttribute('id');
|
|
|
|
|
$(id).reset();
|
|
|
|
|
}
|
2007-02-15 16:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-19 10:05:38 +02:00
|
|
|
@@---------------------------------------------------------------- TOOLS
|
|
|
|
|
|
|
|
|
|
AWS.WebSocket = new function() {
|
|
|
|
|
|
|
|
|
|
@@-----------
|
|
|
|
|
@@-- PUBLIC
|
|
|
|
|
@@-----------
|
|
|
|
|
|
|
|
|
|
@@-- --------------------------------
|
|
|
|
|
@@-- getTransport
|
|
|
|
|
|
|
|
|
|
this.getTransport = function (url)
|
|
|
|
|
{
|
|
|
|
|
return Try.these(
|
|
|
|
|
function() {return new WebSocket(url)},
|
|
|
|
|
function() {return new MozWebSocket(url)}
|
|
|
|
|
) || false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.open = function(url, message_id, status_id)
|
|
|
|
|
{
|
|
|
|
|
ws = AWS.WebSocket.getTransport(url);
|
|
|
|
|
|
|
|
|
|
if (ws == false) {
|
2012-07-27 16:55:13 +02:00
|
|
|
if (status_id != null) {
|
|
|
|
|
var a = document.getElementById(status_id);
|
|
|
|
|
a.innerHTML = a.innerHTML + '<br>Your browser does NOT support webSocket.';
|
|
|
|
|
}
|
2012-06-19 10:05:38 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ws.onmessage = default_onmessage;
|
|
|
|
|
ws.onerror = default_onerror;
|
|
|
|
|
ws.onclose = default_onclose;
|
2012-07-27 16:55:13 +02:00
|
|
|
ws.onopen = default_onopen;
|
2012-06-19 10:05:38 +02:00
|
|
|
|
|
|
|
|
if (message_id != null)
|
|
|
|
|
ws.aws_message_id=message_id;
|
|
|
|
|
if (status_id != null)
|
|
|
|
|
ws.aws_status_id=status_id;
|
|
|
|
|
|
|
|
|
|
return ws;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function default_onmessage(e)
|
|
|
|
|
{
|
|
|
|
|
var data=e.data;
|
|
|
|
|
|
|
|
|
|
// if the first characters are an <response, let's pretends this is
|
|
|
|
|
// an AWS XML response. Parse using the AWS XML Ajax framework.
|
|
|
|
|
|
|
|
|
|
if (data.substring(0,5) == '<?xml')
|
|
|
|
|
AWS.Ajax.XML.fromString(data);
|
2012-07-27 16:55:13 +02:00
|
|
|
else if (this.aws_message_id != null) {
|
|
|
|
|
var a = document.getElementById(this.aws_message_id);
|
|
|
|
|
a.innerHTML = a.innerHTML + "<br>" + data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function default_onopen(e)
|
|
|
|
|
{
|
|
|
|
|
if (this.aws_status_id != null) {
|
|
|
|
|
var a = document.getElementById(this.aws_status_id);
|
|
|
|
|
a.innerHTML = a.innerHTML + '<br>WebSocket now opened';
|
|
|
|
|
}
|
2012-06-19 10:05:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function default_onclose(e)
|
|
|
|
|
{
|
2012-07-27 16:55:13 +02:00
|
|
|
if (this.aws_status_id != null) {
|
|
|
|
|
var a = document.getElementById(this.aws_status_id);
|
|
|
|
|
a.innerHTML = a.innerHTML + '<br>WebSocket now closed';
|
|
|
|
|
}
|
2012-06-19 10:05:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function default_onerror(e)
|
|
|
|
|
{
|
2012-07-27 16:55:13 +02:00
|
|
|
if (this.aws_status_id != null) {
|
|
|
|
|
var a = document.getElementById(this.aws_status_id);
|
|
|
|
|
a.innerHTML = a.innerHTML + "<br>Error: " + e.data;
|
|
|
|
|
}
|
2012-06-19 10:05:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-15 16:09:07 +00:00
|
|
|
@@-- INIT
|
|
|
|
|
|
|
|
|
|
AWS.Tools.addLoadEvent (AWS.Context.update);
|
2009-07-03 16:22:00 +00:00
|
|
|
|
|
|
|
|
@@IF@@ @_TIMEZONE_COOKIE_@ /= ""
|
|
|
|
|
AWS.Tools.setTimezone();
|
|
|
|
|
@@END_IF@@
|