using browser based xpath (for now just mozilla). fixes a combobox bug where i wasn't evaluating an xpath:constraint, and allows reading back model data with more complicated xpaths (such as repeater data).

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3819 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-09-18 11:01:53 +00:00
parent e1a92d2983
commit 97ea14c605
2 changed files with 58 additions and 57 deletions

View File

@@ -83,26 +83,23 @@ public class XFormsInputMethod
" };\n" + " };\n" +
"var WEBAPP_CONTEXT = \"" + cp + "\";\n")); "var WEBAPP_CONTEXT = \"" + cp + "\";\n"));
div.appendChild(e); div.appendChild(e);
final String[] scripts =
{
"/scripts/tiny_mce/tiny_mce_src.js",
"/scripts/ajax/dojo.js",
"/scripts/ajax/xforms.js"
};
// include all our scripts, order is significant // include all our scripts, order is significant
e = result.createElement("script"); for (int i = 0; i < scripts.length; i++)
e.setAttribute("type", "text/javascript"); {
e.setAttribute("src", cp + "/scripts/tiny_mce/tiny_mce_src.js"); e = result.createElement("script");
e.appendChild(result.createTextNode("\n")); e.setAttribute("type", "text/javascript");
div.appendChild(e); e.setAttribute("src", cp + scripts[i]);
e.appendChild(result.createTextNode("\n"));
div.appendChild(e);
}
e = result.createElement("script");
e.setAttribute("type", "text/javascript");
e.setAttribute("src", cp + "/scripts/ajax/dojo.js");
e.appendChild(result.createTextNode("\n"));
div.appendChild(e);
e = result.createElement("script");
e.setAttribute("type", "text/javascript");
e.setAttribute("src", cp + "/scripts/ajax/xforms.js");
e.appendChild(result.createTextNode("\n"));
div.appendChild(e);
ts.writeXML(result, out); ts.writeXML(result, out);
} }

View File

@@ -64,41 +64,26 @@ dojo.declare("alfresco.xforms.Widget",
var required = binding && binding.required == "true()"; var required = binding && binding.required == "true()";
return required; return required;
}, },
getModelNode: function()
{
///XXXarielb todo
},
getInitialValue: function() getInitialValue: function()
{ {
var b = this._getBinding(); var chibaData = this.node.getElementsByTagName("data");
var a = []; if (chibaData.length == 0)
do return null;
{
a.push(b.nodeset); chibaData = chibaData[chibaData.length - 1];
b = b.parent; var xpath = "/" + chibaData.getAttribute("chiba:xpath");
} var d = this.node.ownerDocument;
while (b); var nsResolver = d.createNSResolver(d);
var node = this.xform.getInstance(); var contextNode = this.xform.getInstance();
for (var i = a.length - 1; i >= 0; i--) dojo.debug("locating " + xpath +
{ " from " + chibaData.nodeName +
var element_name = (a[i].match(/^\//) " in " + contextNode.nodeName);
? a[i].replace(/^\/(.+)/, "$1") var result = d.evaluate(xpath,
: a[i]); this.xform.getInstance(),
dojo.debug("locating " + a[i] + "(" + element_name + ")" + nsResolver,
" in " + node.nodeName); XPathResult.STRING_TYPE,
if (element_name.match(/^@/)) null);
return node.getAttribute(a[i].replace(/^@(.+)/, "$1")); return result.stringValue;
else if (element_name == '.')
break;
node = node.getElementsByTagName(element_name)[0];
if (node)
dojo.debug("got node " + node.nodeName);
else
return null;
}
var result = dojo.dom.textContent(node);
dojo.debug("got '" + result + "' for " + a.reverse().join("/"));
return result;
}, },
_getLabelNode: function() _getLabelNode: function()
{ {
@@ -278,6 +263,7 @@ dojo.declare("alfresco.xforms.Select1",
}, },
getValues: function() getValues: function()
{ {
var binding = this._getBinding();
var values = this.node.getElementsByTagName("item"); var values = this.node.getElementsByTagName("item");
var result = []; var result = [];
for (var v in values) for (var v in values)
@@ -286,11 +272,28 @@ dojo.declare("alfresco.xforms.Select1",
{ {
var label = values[v].getElementsByTagName("label")[0]; var label = values[v].getElementsByTagName("label")[0];
var value = values[v].getElementsByTagName("value")[0]; var value = values[v].getElementsByTagName("value")[0];
result.push({ var valid = true;
id: value.getAttribute("id"), if (binding.constraint)
label: dojo.dom.textContent(label), {
value: dojo.dom.textContent(value) dojo.debug("testing " + binding.constraint +
}); " on " + dojo.dom.textContent(value));
var d = this.node.ownerDocument;
valid = d.evaluate(binding.constraint,
value,
d.createNSResolver(d),
XPathResult.ANY_TYPE,
null);
dojo.debug("valid " + dojo.dom.textContent(value) + "? " + valid);
valid = valid.booleanValue;
}
if (valid)
{
result.push({
id: value.getAttribute("id"),
label: dojo.dom.textContent(label),
value: dojo.dom.textContent(value)
});
}
} }
} }
return result; return result;
@@ -571,7 +574,7 @@ dojo.declare("alfresco.xforms.Repeat",
{ {
var index = this.getChildIndex(child); var index = this.getChildIndex(child);
if (index < 0) if (index < 0)
alert("unable to find child " + child.id + " in " + this.id); throw new Error("unable to find child " + child.id + " in " + this.id);
// chiba thinks indexes are initialized to 1 so just // chiba thinks indexes are initialized to 1 so just
// highlight the thing // highlight the thing
@@ -803,6 +806,7 @@ dojo.declare("alfresco.xforms.XForm",
required: bind.childNodes[i].getAttribute("xforms:required"), required: bind.childNodes[i].getAttribute("xforms:required"),
nodeset: bind.childNodes[i].getAttribute("xforms:nodeset"), nodeset: bind.childNodes[i].getAttribute("xforms:nodeset"),
type: bind.childNodes[i].getAttribute("xforms:type"), type: bind.childNodes[i].getAttribute("xforms:type"),
constraint: bind.childNodes[i].getAttribute("xforms:constraint"),
parent: parent parent: parent
}; };
this._loadBindings(bind.childNodes[i], result[id], result); this._loadBindings(bind.childNodes[i], result[id], result);