mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
a bunch of refactoring of back end templating wizards. removing the chiba-web stuff as it is no longer used. more updates to dojo generator. adding in an XFormsBean to handle ajax requests from the form.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3500 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
195
source/web/scripts/ajax/LICENSE
Normal file
195
source/web/scripts/ajax/LICENSE
Normal file
@@ -0,0 +1,195 @@
|
||||
Dojo is availble under *either* the terms of the modified BSD license *or* the
|
||||
Academic Free License version 2.1. As a recipient of Dojo, you may choose which
|
||||
license to receive this code under (except as noted in per-module LICENSE
|
||||
files). Some modules may not be the copyright of the Dojo Foundation. These
|
||||
modules contain explicit declarations of copyright in both the LICENSE files in
|
||||
the directories in which they reside and in the code itself. No external
|
||||
contributions are allowed under licenses which are fundamentally incompatible
|
||||
with the AFL or BSD licenses that Dojo is distributed under.
|
||||
|
||||
The text of the AFL and BSD licenses is reproduced below.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
The "New" BSD License:
|
||||
**********************
|
||||
|
||||
Copyright (c) 2005, The Dojo Foundation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the Dojo Foundation nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
The Academic Free License, v. 2.1:
|
||||
**********************************
|
||||
|
||||
This Academic Free License (the "License") applies to any original work of
|
||||
authorship (the "Original Work") whose owner (the "Licensor") has placed the
|
||||
following notice immediately following the copyright notice for the Original
|
||||
Work:
|
||||
|
||||
Licensed under the Academic Free License version 2.1
|
||||
|
||||
1) Grant of Copyright License. Licensor hereby grants You a world-wide,
|
||||
royalty-free, non-exclusive, perpetual, sublicenseable license to do the
|
||||
following:
|
||||
|
||||
a) to reproduce the Original Work in copies;
|
||||
|
||||
b) to prepare derivative works ("Derivative Works") based upon the Original
|
||||
Work;
|
||||
|
||||
c) to distribute copies of the Original Work and Derivative Works to the
|
||||
public;
|
||||
|
||||
d) to perform the Original Work publicly; and
|
||||
|
||||
e) to display the Original Work publicly.
|
||||
|
||||
2) Grant of Patent License. Licensor hereby grants You a world-wide,
|
||||
royalty-free, non-exclusive, perpetual, sublicenseable license, under patent
|
||||
claims owned or controlled by the Licensor that are embodied in the Original
|
||||
Work as furnished by the Licensor, to make, use, sell and offer for sale the
|
||||
Original Work and Derivative Works.
|
||||
|
||||
3) Grant of Source Code License. The term "Source Code" means the preferred
|
||||
form of the Original Work for making modifications to it and all available
|
||||
documentation describing how to modify the Original Work. Licensor hereby
|
||||
agrees to provide a machine-readable copy of the Source Code of the Original
|
||||
Work along with each copy of the Original Work that Licensor distributes.
|
||||
Licensor reserves the right to satisfy this obligation by placing a
|
||||
machine-readable copy of the Source Code in an information repository
|
||||
reasonably calculated to permit inexpensive and convenient access by You for as
|
||||
long as Licensor continues to distribute the Original Work, and by publishing
|
||||
the address of that information repository in a notice immediately following
|
||||
the copyright notice that applies to the Original Work.
|
||||
|
||||
4) Exclusions From License Grant. Neither the names of Licensor, nor the names
|
||||
of any contributors to the Original Work, nor any of their trademarks or
|
||||
service marks, may be used to endorse or promote products derived from this
|
||||
Original Work without express prior written permission of the Licensor. Nothing
|
||||
in this License shall be deemed to grant any rights to trademarks, copyrights,
|
||||
patents, trade secrets or any other intellectual property of Licensor except as
|
||||
expressly stated herein. No patent license is granted to make, use, sell or
|
||||
offer to sell embodiments of any patent claims other than the licensed claims
|
||||
defined in Section 2. No right is granted to the trademarks of Licensor even if
|
||||
such marks are included in the Original Work. Nothing in this License shall be
|
||||
interpreted to prohibit Licensor from licensing under different terms from this
|
||||
License any Original Work that Licensor otherwise would have a right to
|
||||
license.
|
||||
|
||||
5) This section intentionally omitted.
|
||||
|
||||
6) Attribution Rights. You must retain, in the Source Code of any Derivative
|
||||
Works that You create, all copyright, patent or trademark notices from the
|
||||
Source Code of the Original Work, as well as any notices of licensing and any
|
||||
descriptive text identified therein as an "Attribution Notice." You must cause
|
||||
the Source Code for any Derivative Works that You create to carry a prominent
|
||||
Attribution Notice reasonably calculated to inform recipients that You have
|
||||
modified the Original Work.
|
||||
|
||||
7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that
|
||||
the copyright in and to the Original Work and the patent rights granted herein
|
||||
by Licensor are owned by the Licensor or are sublicensed to You under the terms
|
||||
of this License with the permission of the contributor(s) of those copyrights
|
||||
and patent rights. Except as expressly stated in the immediately proceeding
|
||||
sentence, the Original Work is provided under this License on an "AS IS" BASIS
|
||||
and WITHOUT WARRANTY, either express or implied, including, without limitation,
|
||||
the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU.
|
||||
This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No
|
||||
license to Original Work is granted hereunder except under this disclaimer.
|
||||
|
||||
8) Limitation of Liability. Under no circumstances and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise, shall the
|
||||
Licensor be liable to any person for any direct, indirect, special, incidental,
|
||||
or consequential damages of any character arising as a result of this License
|
||||
or the use of the Original Work including, without limitation, damages for loss
|
||||
of goodwill, work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses. This limitation of liability shall not
|
||||
apply to liability for death or personal injury resulting from Licensor's
|
||||
negligence to the extent applicable law prohibits such limitation. Some
|
||||
jurisdictions do not allow the exclusion or limitation of incidental or
|
||||
consequential damages, so this exclusion and limitation may not apply to You.
|
||||
|
||||
9) Acceptance and Termination. If You distribute copies of the Original Work or
|
||||
a Derivative Work, You must make a reasonable effort under the circumstances to
|
||||
obtain the express assent of recipients to the terms of this License. Nothing
|
||||
else but this License (or another written agreement between Licensor and You)
|
||||
grants You permission to create Derivative Works based upon the Original Work
|
||||
or to exercise any of the rights granted in Section 1 herein, and any attempt
|
||||
to do so except under the terms of this License (or another written agreement
|
||||
between Licensor and You) is expressly prohibited by U.S. copyright law, the
|
||||
equivalent laws of other countries, and by international treaty. Therefore, by
|
||||
exercising any of the rights granted to You in Section 1 herein, You indicate
|
||||
Your acceptance of this License and all of its terms and conditions.
|
||||
|
||||
10) Termination for Patent Action. This License shall terminate automatically
|
||||
and You may no longer exercise any of the rights granted to You by this License
|
||||
as of the date You commence an action, including a cross-claim or counterclaim,
|
||||
against Licensor or any licensee alleging that the Original Work infringes a
|
||||
patent. This termination provision shall not apply for an action alleging
|
||||
patent infringement by combinations of the Original Work with other software or
|
||||
hardware.
|
||||
|
||||
11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this
|
||||
License may be brought only in the courts of a jurisdiction wherein the
|
||||
Licensor resides or in which Licensor conducts its primary business, and under
|
||||
the laws of that jurisdiction excluding its conflict-of-law provisions. The
|
||||
application of the United Nations Convention on Contracts for the International
|
||||
Sale of Goods is expressly excluded. Any use of the Original Work outside the
|
||||
scope of this License or after its termination shall be subject to the
|
||||
requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101 et
|
||||
seq., the equivalent laws of other countries, and international treaty. This
|
||||
section shall survive the termination of this License.
|
||||
|
||||
12) Attorneys Fees. In any action to enforce the terms of this License or
|
||||
seeking damages relating thereto, the prevailing party shall be entitled to
|
||||
recover its costs and expenses, including, without limitation, reasonable
|
||||
attorneys' fees and costs incurred in connection with such action, including
|
||||
any appeal of such action. This section shall survive the termination of this
|
||||
License.
|
||||
|
||||
13) Miscellaneous. This License represents the complete agreement concerning
|
||||
the subject matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent necessary to
|
||||
make it enforceable.
|
||||
|
||||
14) Definition of "You" in This License. "You" throughout this License, whether
|
||||
in upper or lower case, means an individual or a legal entity exercising rights
|
||||
under, and complying with all of the terms of, this License. For legal
|
||||
entities, "You" includes any entity that controls, is controlled by, or is
|
||||
under common control with you. For purposes of this definition, "control" means
|
||||
(i) the power, direct or indirect, to cause the direction or management of such
|
||||
entity, whether by contract or otherwise, or (ii) ownership of fifty percent
|
||||
(50%) or more of the outstanding shares, or (iii) beneficial ownership of such
|
||||
entity.
|
||||
|
||||
15) Right to Use. You may use the Original Work in all ways not otherwise
|
||||
restricted or conditioned by this License or by law, and Licensor promises not
|
||||
to interfere with or be responsible for such uses by You.
|
||||
|
||||
This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights reserved.
|
||||
Permission is hereby granted to copy and distribute this license without
|
||||
modification. This license may not be modified without the express written
|
||||
permission of its copyright owner.
|
54
source/web/scripts/ajax/iframe_history.html
Normal file
54
source/web/scripts/ajax/iframe_history.html
Normal file
@@ -0,0 +1,54 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title></title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
|
||||
<script type="text/javascript">
|
||||
// <!--
|
||||
var noInit = false;
|
||||
var domain = "";
|
||||
// document.domain = "localhost";
|
||||
function init(){
|
||||
// parse the query string if there is one to try to get args that
|
||||
// we can act on
|
||||
var sparams = document.location.search;
|
||||
if(sparams.length >= 0){
|
||||
if(sparams.charAt(0) == "?"){
|
||||
sparams = sparams.substring(1);
|
||||
}
|
||||
var ss = (sparams.indexOf("&") >= 0) ? "&" : "&";
|
||||
sparams = sparams.split(ss);
|
||||
for(var x=0; x<sparams.length; x++){
|
||||
var tp = sparams[x].split("=");
|
||||
if(typeof window[tp[0]] != "undefined"){
|
||||
window[tp[0]] = ((tp[1]=="true")||(tp[1]=="false")) ? eval(tp[1]) : tp[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(noInit){ return; }
|
||||
if(domain.length > 0){
|
||||
document.domain = domain;
|
||||
}
|
||||
if((window.parent != window)&&(window.parent["dojo"])){
|
||||
//Set the page title so IE history shows up with a somewhat correct name.
|
||||
document.title = window.parent.document.title;
|
||||
|
||||
//Notify parent that we are loaded.
|
||||
var pdj = window.parent.dojo;
|
||||
if(pdj["undo"] && pdj["undo"]["browser"]){
|
||||
pdj.undo.browser.iframeLoaded(null, window.location);
|
||||
}
|
||||
}
|
||||
}
|
||||
// -->
|
||||
</script>
|
||||
</head>
|
||||
<body onload="try{ init(); }catch(e){ alert(e); }">
|
||||
<h4>The Dojo Toolkit -- iframe_history.html</h4>
|
||||
|
||||
<p>This file is used in Dojo's back/fwd button management.</p>
|
||||
</body>
|
||||
</html>
|
442
source/web/scripts/ajax/xforms.js
Normal file
442
source/web/scripts/ajax/xforms.js
Normal file
@@ -0,0 +1,442 @@
|
||||
dojo.require("dojo.widget.DebugConsole");
|
||||
dojo.require("dojo.widget.Button");
|
||||
dojo.require("dojo.widget.validate");
|
||||
dojo.require("dojo.widget.ComboBox");
|
||||
dojo.require("dojo.widget.Checkbox");
|
||||
dojo.require("dojo.widget.Editor");
|
||||
dojo.require("dojo.widget.Spinner");
|
||||
dojo.require("dojo.html.style");
|
||||
dojo.hostenv.writeIncludes();
|
||||
dojo.addOnLoad(xforms_init);
|
||||
|
||||
var bindings = {};
|
||||
var xform = null;
|
||||
function xforms_init()
|
||||
{
|
||||
var req = {
|
||||
url: WEBAPP_CONTEXT + "/ajax/invoke/XFormsBean.getXForm",
|
||||
content: { },
|
||||
mimetype: "text/xml",
|
||||
load: function(type, data, evt)
|
||||
{
|
||||
xform = data.documentElement;
|
||||
var model = xform.getElementsByTagName("model");
|
||||
load_bindings(model[0]);
|
||||
for (var i in bindings)
|
||||
{
|
||||
dojo.debug("bindings[" + i + "]=" + bindings[i].id +
|
||||
", parent = " + (bindings[i].parent ? bindings[i].parent.id : 'null'));
|
||||
}
|
||||
|
||||
var body = xform.getElementsByTagName("body");
|
||||
load_body(body[body.length - 1], [ document.getElementById("alf-ui") ]);
|
||||
},
|
||||
error: function(type, e)
|
||||
{
|
||||
alert("error!! " + type + " e = " + e.message);
|
||||
}
|
||||
};
|
||||
dojo.io.bind(req);
|
||||
}
|
||||
|
||||
function get_instance()
|
||||
{
|
||||
var model = xform.getElementsByTagName("model")[0];
|
||||
return model.getElementsByTagName("instance")[0];
|
||||
}
|
||||
|
||||
function load_bindings(bind, parent)
|
||||
{
|
||||
dojo.debug("loading bindings for " + bind.nodeName);
|
||||
dojo.lang.forEach(bind.childNodes, function(b)
|
||||
{
|
||||
if (b.nodeName.toLowerCase() == "xforms:bind")
|
||||
{
|
||||
var id = b.getAttribute("id");
|
||||
dojo.debug("loading binding " + id);
|
||||
bindings[id] = {
|
||||
id: b.getAttribute("id"),
|
||||
required: b.getAttribute("xforms:required"),
|
||||
nodeset: b.getAttribute("xforms:nodeset"),
|
||||
type: b.getAttribute("xforms:type"),
|
||||
parent: parent
|
||||
}
|
||||
load_bindings(b, bindings[id]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function load_body(body, ui_element_stack)
|
||||
{
|
||||
dojo.lang.forEach(body.childNodes, function(o)
|
||||
{
|
||||
dojo.debug("loading " + o + " NN " + o.nodeName);
|
||||
switch (o.nodeName.toLowerCase())
|
||||
{
|
||||
case "xforms:group":
|
||||
if (ui_element_stack[ui_element_stack.length - 1].nodeName.toLowerCase() == "table")
|
||||
{
|
||||
var tr = document.createElement("tr");
|
||||
var td = document.createElement("td");
|
||||
td.setAttribute("colspan", "3");
|
||||
tr.appendChild(td);
|
||||
ui_element_stack[ui_element_stack.length - 1].appendChild(tr);
|
||||
ui_element_stack.push(td);
|
||||
}
|
||||
var table = document.createElement("table");
|
||||
table.setAttribute("style", "width:100%; border: 0px solid blue;");
|
||||
ui_element_stack[ui_element_stack.length - 1].appendChild(table);
|
||||
ui_element_stack.push(table);
|
||||
load_body(o, ui_element_stack);
|
||||
ui_element_stack.pop();
|
||||
if (ui_element_stack[ui_element_stack.length - 1].nodeName.toLowerCase() == "td")
|
||||
ui_element_stack.pop();
|
||||
break;
|
||||
case "xforms:textarea":
|
||||
var row = document.createElement("tr");
|
||||
ui_element_stack[ui_element_stack.length - 1].appendChild(row);
|
||||
|
||||
var cell = document.createElement("td");
|
||||
row.appendChild(cell);
|
||||
add_required_cell(cell, o);
|
||||
|
||||
var cell = document.createElement("td");
|
||||
row.appendChild(cell);
|
||||
var label = get_label_node(o);
|
||||
if (label)
|
||||
cell.appendChild(document.createTextNode(dojo.dom.textContent(label)));
|
||||
cell = document.createElement("td");
|
||||
row.appendChild(cell);
|
||||
var nodeRef = document.createElement("div");
|
||||
nodeRef.setAttribute("style", "height: 200px; border: solid 1px black;");
|
||||
cell.appendChild(nodeRef);
|
||||
var w = dojo.widget.createWidget("Editor", { items: ["|", "bold", "italic", "underline", "strikethrough", "|", "colorGroup", "|", "createLink", "insertImage" ] }, nodeRef);
|
||||
break;
|
||||
case "xforms:input":
|
||||
var id = o.getAttribute("id");
|
||||
var row = document.createElement("tr");
|
||||
ui_element_stack[ui_element_stack.length - 1].appendChild(row);
|
||||
|
||||
var cell = document.createElement("td");
|
||||
row.appendChild(cell);
|
||||
add_required_cell(cell, o);
|
||||
|
||||
cell = document.createElement("td");
|
||||
row.appendChild(cell);
|
||||
var label = get_label_node(o);
|
||||
if (label)
|
||||
{
|
||||
cell.appendChild(document.createTextNode(dojo.dom.textContent(label)));
|
||||
}
|
||||
|
||||
cell = document.createElement("td");
|
||||
row.appendChild(cell);
|
||||
var nodeRef = document.createElement("div");
|
||||
cell.appendChild(nodeRef);
|
||||
var value = get_initial_value(o);
|
||||
switch (get_type(o))
|
||||
{
|
||||
case "date":
|
||||
var dateTextBoxDiv = document.createElement("div");
|
||||
nodeRef.appendChild(dateTextBoxDiv);
|
||||
var dateTextBox = dojo.widget.createWidget("DateTextBox",
|
||||
{
|
||||
widgetId: id,
|
||||
required: is_required(o),
|
||||
format: "YYYY-MM-DD",
|
||||
value: value
|
||||
},
|
||||
dateTextBoxDiv);
|
||||
dateTextBox.onfocus = function(o) {
|
||||
dateTextBox.hide(); dojo.debug("hiding " + o);
|
||||
dateTextBox.picker.show();
|
||||
|
||||
};
|
||||
var datePickerDiv = document.createElement("div");
|
||||
nodeRef.appendChild(datePickerDiv);
|
||||
dateTextBox.picker = dojo.widget.createWidget("DatePicker",
|
||||
{
|
||||
isHidden: true,
|
||||
value : value
|
||||
},
|
||||
datePickerDiv);
|
||||
dateTextBox.picker.hide();
|
||||
dojo.event.connect(dateTextBox.picker,
|
||||
"onSetDate",
|
||||
function(event)
|
||||
{
|
||||
dateTextBox.picker.hide();
|
||||
dateTextBox.show();
|
||||
dateTextBox.setValue(dojo.widget.DatePicker.util.toRfcDate(dateTextBox.picker.date));
|
||||
setXFormsValue(dateTextBox.widgetId,
|
||||
dateTextBox.getValue());
|
||||
});
|
||||
break;
|
||||
case "integer":
|
||||
case "positiveInteger":
|
||||
case "negativeInteger":
|
||||
var w = dojo.widget.createWidget("SpinnerIntegerTextBox",
|
||||
{
|
||||
widgetId: id,
|
||||
required: is_required(o),
|
||||
value: value
|
||||
},
|
||||
nodeRef);
|
||||
var handler = function(event)
|
||||
{
|
||||
dojo.debug("value changed " + w.widgetId +
|
||||
" value " + w.getValue() +
|
||||
" t " + event.target +
|
||||
" w " + w + " this " + this);
|
||||
setXFormsValue(w.widgetId, w.getValue());
|
||||
}
|
||||
dojo.event.connect(w, "adjustValue", handler);
|
||||
dojo.event.connect(w, "onkeyup", handler);
|
||||
break;
|
||||
case "double":
|
||||
var w = dojo.widget.createWidget("SpinnerRealNumberTextBox",
|
||||
{
|
||||
widgetId: id,
|
||||
required: is_required(o),
|
||||
value: value
|
||||
},
|
||||
nodeRef);
|
||||
var handler = function(event)
|
||||
{
|
||||
dojo.debug("value changed " + w.widgetId +
|
||||
" value " + w.getValue() +
|
||||
" t " + event.target +
|
||||
" w " + w + " this " + this);
|
||||
setXFormsValue(w.widgetId, w.getValue());
|
||||
}
|
||||
dojo.event.connect(w, "adjustValue", handler);
|
||||
dojo.event.connect(w, "onkeyup", handler);
|
||||
break;
|
||||
case "string":
|
||||
default:
|
||||
var w = dojo.widget.createWidget("ValidationTextBox",
|
||||
{
|
||||
widgetId: id,
|
||||
required: is_required(o),
|
||||
value: value
|
||||
},
|
||||
nodeRef);
|
||||
dojo.event.connect(w,
|
||||
"onkeyup",
|
||||
function(event)
|
||||
{
|
||||
dojo.debug("value changed " + w.widgetId + " value " + w.getValue() + " t " + event.target + " w " + w + " this " + this);
|
||||
setXFormsValue(w.widgetId, w.getValue());
|
||||
});
|
||||
|
||||
}
|
||||
break;
|
||||
case "xforms:select1":
|
||||
var row = document.createElement("tr");
|
||||
ui_element_stack[ui_element_stack.length - 1].appendChild(row);
|
||||
var cell = document.createElement("td");
|
||||
row.appendChild(cell);
|
||||
add_required_cell(cell, o);
|
||||
|
||||
var cell = document.createElement("td");
|
||||
row.appendChild(cell);
|
||||
var label = get_label_node(o);
|
||||
if (label)
|
||||
cell.appendChild(document.createTextNode(dojo.dom.textContent(label)));
|
||||
cell = document.createElement("td");
|
||||
row.appendChild(cell);
|
||||
var nodeRef = document.createElement("div");
|
||||
cell.appendChild(nodeRef);
|
||||
var values = get_select_values(o);
|
||||
for (var i in values)
|
||||
{
|
||||
dojo.debug("values["+ i + "] = " + values[i].id + ", " + values[i].label + ", " + values[i].value);
|
||||
}
|
||||
var initial_value = get_initial_value(o);
|
||||
if (get_type(o) == "boolean")
|
||||
{
|
||||
var w = dojo.widget.createWidget("CheckBox",
|
||||
{
|
||||
checked: initial_value
|
||||
},
|
||||
nodeRef);
|
||||
}
|
||||
else if (values.length <= 5)
|
||||
{
|
||||
for (var i in values)
|
||||
{
|
||||
var radio = document.createElement("input");
|
||||
radio.setAttribute("name", o.getAttribute("id"));
|
||||
radio.setAttribute("type", "radio");
|
||||
radio.setAttribute("value", values[i].value);
|
||||
if (values[i].value == initial_value)
|
||||
radio.setAttribute("checked", "true");
|
||||
nodeRef.appendChild(radio);
|
||||
nodeRef.appendChild(document.createTextNode(values[i].label));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var combobox = document.createElement("select");
|
||||
nodeRef.appendChild(combobox);
|
||||
for (var i in values)
|
||||
{
|
||||
var option = document.createElement("option");
|
||||
option.appendChild(document.createTextNode(values[i].label));
|
||||
option.setAttribute("value", values[i].value);
|
||||
if (values[i].value == initial_value)
|
||||
option.setAttribute("selected", "true");
|
||||
combobox.appendChild(option);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "xforms:submit":
|
||||
var id = o.getAttribute("id");
|
||||
var row = document.createElement("tr");
|
||||
ui_element_stack[ui_element_stack.length - 1].appendChild(row);
|
||||
var cell = document.createElement("td");
|
||||
cell.setAttribute("colspan", "3");
|
||||
row.appendChild(cell);
|
||||
var nodeRef = document.createElement("div");
|
||||
cell.appendChild(nodeRef);
|
||||
var w = dojo.widget.createWidget("Button",
|
||||
{
|
||||
widgetId: id,
|
||||
caption: "submit"
|
||||
},
|
||||
nodeRef);
|
||||
w.onClick = function()
|
||||
{
|
||||
fireAction(w.widgetId);
|
||||
};
|
||||
break;
|
||||
case "xforms:repeat":
|
||||
dojo.debug("repeat unimplemented");
|
||||
break;
|
||||
default:
|
||||
load_body(o, ui_element_stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function get_type(o)
|
||||
{
|
||||
var binding = bindings[o.getAttribute("xforms:bind")];
|
||||
return binding.type;
|
||||
}
|
||||
|
||||
function is_required(o)
|
||||
{
|
||||
var binding = bindings[o.getAttribute("xforms:bind")];
|
||||
var required = binding.required == "true()";
|
||||
return required;
|
||||
}
|
||||
|
||||
function add_required_cell(cell, element)
|
||||
{
|
||||
if (is_required(element))
|
||||
{
|
||||
var req = document.createElement("img");
|
||||
req.setAttribute("src", WEBAPP_CONTEXT + "/images/icons/required_field.gif");
|
||||
req.setAttribute("style", "margin:5px");
|
||||
cell.appendChild(req);
|
||||
}
|
||||
// else
|
||||
// cell.appendChild(document.createTextNode(" "));
|
||||
}
|
||||
|
||||
function get_label_node(o)
|
||||
{
|
||||
var labels = o.getElementsByTagName("label");
|
||||
for (var i = 0; i < labels.length; i++)
|
||||
{
|
||||
dojo.debug("parent " + labels[i].parentNode.nodeName +
|
||||
" o " + o.nodeName);
|
||||
if (labels[i].parentNode == o)
|
||||
return labels[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function get_initial_value(o)
|
||||
{
|
||||
var b = bindings[o.getAttribute("xforms:bind")];
|
||||
var a = [];
|
||||
do
|
||||
{
|
||||
a.push(b);
|
||||
b = b.parent
|
||||
}
|
||||
while (b);
|
||||
var node = get_instance();
|
||||
for (var i = a.length - 1; i >= 0; i--)
|
||||
{
|
||||
var element_name = (a[i].nodeset.match(/^\//)
|
||||
? a[i].nodeset.replace(/^\/(.+)/, "$1")
|
||||
: a[i].nodeset);
|
||||
dojo.debug("locating " + a[i].nodeset + "(" + element_name + ")" +
|
||||
" in " + node.nodeName);
|
||||
if (element_name.match(/^@/))
|
||||
return node.getAttribute(a[i].nodeset.replace(/^@(.+)/, "$1"));
|
||||
else if (element_name == '.')
|
||||
break;
|
||||
node = node.getElementsByTagName(element_name)[0];
|
||||
dojo.debug("got node " + node.nodeName);
|
||||
}
|
||||
return dojo.dom.textContent(node);
|
||||
}
|
||||
|
||||
function get_select_values(o)
|
||||
{
|
||||
var values = o.getElementsByTagName("item");
|
||||
var result = [];
|
||||
for (var v in values)
|
||||
{
|
||||
if (values[v].getElementsByTagName)
|
||||
{
|
||||
var label = values[v].getElementsByTagName("label")[0];
|
||||
var value = values[v].getElementsByTagName("value")[0];
|
||||
result.push({
|
||||
id: value.getAttribute("id"),
|
||||
label: dojo.dom.textContent(label),
|
||||
value: dojo.dom.textContent(value)
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function fireAction(id)
|
||||
{
|
||||
var req = {
|
||||
url: WEBAPP_CONTEXT + "/ajax/invoke/XFormsBean.fireAction",
|
||||
content: { id: id },
|
||||
mimetype: "text/xml",
|
||||
load: function(type, data, evt)
|
||||
{
|
||||
alert("fired action " + id);
|
||||
},
|
||||
error: function(type, e)
|
||||
{
|
||||
alert("error!! " + type + " e = " + e.message);
|
||||
}
|
||||
};
|
||||
dojo.io.bind(req);
|
||||
}
|
||||
|
||||
function setXFormsValue(id, value)
|
||||
{
|
||||
var req = {
|
||||
url: WEBAPP_CONTEXT + "/ajax/invoke/XFormsBean.setXFormsValue",
|
||||
content: { id: id, value: value },
|
||||
mimetype: "text/xml",
|
||||
load: function(type, data, evt)
|
||||
{
|
||||
},
|
||||
error: function(type, e)
|
||||
{
|
||||
alert("error!! " + type + " e = " + e.message);
|
||||
}
|
||||
};
|
||||
dojo.io.bind(req);
|
||||
}
|
Reference in New Issue
Block a user