implementing chiba-item-delete.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3815 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-09-18 05:41:48 +00:00
parent 913aa6a830
commit 09141d5c52
2 changed files with 207 additions and 150 deletions

View File

@@ -813,6 +813,15 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
} }
protected String setXFormsId(final Element el) protected String setXFormsId(final Element el)
{
return this.setXFormsId(el, null);
}
protected String setXFormsId(final Element el, String id)
{
if (el.hasAttributeNS(SchemaFormBuilder.XFORMS_NS, "id"))
el.removeAttributeNS(SchemaFormBuilder.XFORMS_NS, "id");
if (id == null)
{ {
long count = 0; long count = 0;
final String name = el.getLocalName(); final String name = el.getLocalName();
@@ -823,14 +832,8 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
//increment the counter //increment the counter
counter.put(name, new Long(count + 1)); counter.put(name, new Long(count + 1));
return this.setXFormsId(el, name + "_" + count); id = name + "_" + count;
} }
protected String setXFormsId(final Element el, final String id)
{
if (el.hasAttributeNS(SchemaFormBuilder.XFORMS_NS, "id"))
el.removeAttributeNS(SchemaFormBuilder.XFORMS_NS, "id");
el.setAttributeNS(SchemaFormBuilder.XFORMS_NS, el.setAttributeNS(SchemaFormBuilder.XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "id", SchemaFormBuilder.XFORMS_NS_PREFIX + "id",
id); id);
@@ -2422,13 +2425,14 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
} }
private Element createTriggerForRepeat(final Document xForm, private Element createTriggerForRepeat(final Document xForm,
final String id,
final String label, final String label,
final Element action) final Element action)
{ {
final Element trigger = final Element trigger =
xForm.createElementNS(SchemaFormBuilder.XFORMS_NS, xForm.createElementNS(SchemaFormBuilder.XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "trigger"); SchemaFormBuilder.XFORMS_NS_PREFIX + "trigger");
this.setXFormsId(trigger); this.setXFormsId(trigger, id != null ? id : null);
//label insert //label insert
final Element triggerLabel = final Element triggerLabel =
@@ -2482,8 +2486,6 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
Element action = Element action =
xForm.createElementNS(SchemaFormBuilder.XFORMS_NS, xForm.createElementNS(SchemaFormBuilder.XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "insert"); SchemaFormBuilder.XFORMS_NS_PREFIX + "insert");
this.setXFormsId(action);
//insert: bind & other attributes //insert: bind & other attributes
if (bindId != null) if (bindId != null)
action.setAttributeNS(SchemaFormBuilder.XFORMS_NS, action.setAttributeNS(SchemaFormBuilder.XFORMS_NS,
@@ -2500,12 +2502,14 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
"1"); "1");
final Element trigger_insert_before = final Element trigger_insert_before =
this.createTriggerForRepeat(xForm, "insert at beginning", action); this.createTriggerForRepeat(xForm,
repeatId != null ? repeatId + "-insert_before" : null,
"insert at beginning",
action);
action = xForm.createElementNS(SchemaFormBuilder.XFORMS_NS, action = xForm.createElementNS(SchemaFormBuilder.XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "insert"); SchemaFormBuilder.XFORMS_NS_PREFIX + "insert");
this.setXFormsId(action);
//insert: bind & other attributes //insert: bind & other attributes
if (bindId != null) if (bindId != null)
@@ -2523,13 +2527,15 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
SchemaFormBuilder.XFORMS_NS_PREFIX + "index('" + repeatId + "')"); SchemaFormBuilder.XFORMS_NS_PREFIX + "index('" + repeatId + "')");
final Element trigger_insert_after = final Element trigger_insert_after =
this.createTriggerForRepeat(xForm, "insert after selected", action); this.createTriggerForRepeat(xForm,
repeatId != null ? repeatId + "-insert_after" : null,
"insert after selected",
action);
///////////// delete ////////////////// ///////////// delete //////////////////
//trigger delete //trigger delete
action = xForm.createElementNS(SchemaFormBuilder.XFORMS_NS, action = xForm.createElementNS(SchemaFormBuilder.XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "delete"); SchemaFormBuilder.XFORMS_NS_PREFIX + "delete");
this.setXFormsId(action);
//delete: bind & other attributes //delete: bind & other attributes
if (bindId != null) if (bindId != null)
@@ -2544,14 +2550,17 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
SchemaFormBuilder.XFORMS_NS_PREFIX + "index('" + repeatId + "')"); SchemaFormBuilder.XFORMS_NS_PREFIX + "index('" + repeatId + "')");
final Element trigger_delete = final Element trigger_delete =
this.createTriggerForRepeat(xForm, "delete selected", action); this.createTriggerForRepeat(xForm,
repeatId != null ? repeatId + "-delete" : null,
"delete selected",
action);
//add the triggers //add the triggers
final Element wrapper_triggers = final Element wrapper_triggers =
_wrapper.createControlsWrapper(trigger_insert_before); _wrapper.createControlsWrapper(trigger_insert_before);
if (wrapper_triggers == trigger_insert_after) if (wrapper_triggers == trigger_insert_before)
{ {
//no wrapper //no wrapper
formSection.appendChild(trigger_insert_before); formSection.appendChild(trigger_insert_before);
@@ -2565,7 +2574,7 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
if (insert_parent != null) if (insert_parent != null)
{ {
insert_parent.appendChild(trigger_insert_before); insert_parent.appendChild(trigger_insert_after);
insert_parent.appendChild(trigger_delete); insert_parent.appendChild(trigger_delete);
} }
} }
@@ -2597,9 +2606,9 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
XSTypeDefinition parentType = type.getBaseType(); XSTypeDefinition parentType = type.getBaseType();
if (parentType != null && if (parentType == null ||
type.getTypeCategory() == parentType.getTypeCategory()) type.getTypeCategory() != parentType.getTypeCategory())
{ return;
if (type != parentType && if (type != parentType &&
(parentType.getName() == null || !parentType.getName().equals("anyType"))) (parentType.getName() == null || !parentType.getName().equals("anyType")))
{ {
@@ -2612,22 +2621,15 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
//to have a type descendant to itself, but to consider it for the parent //to have a type descendant to itself, but to consider it for the parent
if (type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) if (type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE)
{ {
XSComplexTypeDefinition complexType = final XSComplexTypeDefinition complexType = (XSComplexTypeDefinition)type;
(XSComplexTypeDefinition) type; if (complexType.getDerivationMethod() == XSConstants.DERIVATION_EXTENSION &&
if (complexType.getDerivationMethod() == XSConstants.DERIVATION_EXTENSION !complexType.getAbstract() &&
&& !complexType.getAbstract() !descendents.contains(type))
&& !descendents.contains(type) //to be tested
//&& !descendents.contains(type.getName()) //to be tested
)
{
//newDescendents.add(type.getName());
newDescendents.add(type); newDescendents.add(type);
} }
}
//note: extensions are impossible on simpleTypes ! //note: extensions are impossible on simpleTypes !
buildTypeTree(parentType, newDescendents); this.buildTypeTree(parentType, newDescendents);
}
} }
} }
@@ -2740,20 +2742,20 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
// //
// e.g. Please provide a valid value for 'Address'. 'Address' is a mandatory decimal field. // e.g. Please provide a valid value for 'Address'. 'Address' is a mandatory decimal field.
// //
Element alertElement = (Element) // Element alertElement = (Element)
formControl.appendChild(xForm.createElementNS(XFORMS_NS, // formControl.appendChild(xForm.createElementNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "alert")); // SchemaFormBuilder.XFORMS_NS_PREFIX + "alert"));
this.setXFormsId(alertElement); // this.setXFormsId(alertElement);
//
StringBuffer alert = // StringBuffer alert =
new StringBuffer("Please provide a valid value for '" + caption + "'."); // new StringBuffer("Please provide a valid value for '" + caption + "'.");
//
Element enveloppe = xForm.getDocumentElement(); // Element enveloppe = xForm.getDocumentElement();
alert.append(" '" + caption + // alert.append(" '" + caption +
"' is " + (o.minimum == 0 ? "an optional" : "a required") + " '" + // "' is " + (o.minimum == 0 ? "an optional" : "a required") + " '" +
createCaption(this.getXFormsTypeName(enveloppe, controlType)) + // createCaption(this.getXFormsTypeName(enveloppe, controlType)) +
"' value."); // "' value.");
alertElement.appendChild(xForm.createTextNode(alert.toString())); // alertElement.appendChild(xForm.createTextNode(alert.toString()));
return formControl; return formControl;
} }
@@ -2898,11 +2900,13 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
if (namespace != null && namespace.length() != 0) if (namespace != null && namespace.length() != 0)
{ {
String prefix; String prefix;
if ((prefix = (String) namespacePrefixes.get(namespace)) == null) { if ((prefix = (String) namespacePrefixes.get(namespace)) == null)
{
String basePrefix = (namespace.substring(namespace.lastIndexOf('/', namespace.length()-2)+1)); String basePrefix = (namespace.substring(namespace.lastIndexOf('/', namespace.length()-2)+1));
int i=1; int i=1;
prefix = basePrefix; prefix = basePrefix;
while (namespacePrefixes.containsValue(prefix)) { while (namespacePrefixes.containsValue(prefix))
{
prefix = basePrefix + (i++); prefix = basePrefix + (i++);
} }
namespacePrefixes.put(namespace, prefix); namespacePrefixes.put(namespace, prefix);

View File

@@ -445,6 +445,15 @@ dojo.declare("alfresco.xforms.Group",
d.style.height = contentDiv.offsetHeight; d.style.height = contentDiv.offsetHeight;
return d; return d;
}, },
removeChildAt: function(position)
{
var child = this.getChildAt(position);
if (!child)
throw new Error("unabled to find child at " + position);
this.children.splice(position, 1);
dojo.dom.removeChildren(child.domContainer);
this.domNode.removeChild(child.domContainer);
},
isIndented: function() isIndented: function()
{ {
return false && this.parent != null; return false && this.parent != null;
@@ -491,8 +500,8 @@ dojo.declare("alfresco.xforms.Repeat",
var images = [ var images = [
{ src: "plus", action: this._insertRepeatItem_handler }, { src: "plus", action: this._insertRepeatItem_handler },
{ src: "arrow_up", action: this._moveRepeatItemUp_handler }, { src: "arrow_up", action: this._moveRepeatItemUp_handler },
{ src: "arrow_down", action: null }, { src: "arrow_down", action: this._moveRepeatItemDown_handler },
{ src: "minus", action: null } { src: "minus", action: this._removeRepeatItem_handler }
]; ];
for (var i in images) for (var i in images)
{ {
@@ -505,20 +514,37 @@ dojo.declare("alfresco.xforms.Repeat",
img.repeatItem = child; img.repeatItem = child;
img.repeat = this; img.repeat = this;
controls.appendChild(img); controls.appendChild(img);
dojo.event.browser.addListener(img, "onclick", images[i].action); dojo.event.connect(img, "onclick", this, images[i].action);
} }
return result; return result;
}, },
removeChildAt: function(position)
{
this.inherited("removeChildAt", [ position ]);
if (this.selectedIndex == position)
this.handleIndexChanged(position);
},
_insertRepeatItem_handler: function(event) _insertRepeatItem_handler: function(event)
{ {
alert("insert r=" + event.target.repeat.id + var trigger = _findElementById(this.node.parentNode,
" item " + event.target.repeatItem.id); this.id + "-insert_after");
this.xform.fireAction(trigger.getAttribute("id"));
},
_removeRepeatItem_handler: function(event)
{
var trigger = _findElementById(this.node.parentNode,
this.id + "-delete");
this.xform.fireAction(trigger.getAttribute("id"));
}, },
_moveRepeatItemUp_handler: function(event) _moveRepeatItemUp_handler: function(event)
{ {
alert("moveUp " + event); alert("moveUp " + event);
}, },
_moveRepeatItemDown_handler: function(event)
{
alert("moveDown " + event);
},
setFocusedChild: function(child) setFocusedChild: function(child)
{ {
if (!child) if (!child)
@@ -535,7 +561,6 @@ dojo.declare("alfresco.xforms.Repeat",
this.handleIndexChanged(0); this.handleIndexChanged(0);
// xforms repeat indexes are 1-based // xforms repeat indexes are 1-based
this.xform.setRepeatIndex(this.id, index + 1); this.xform.setRepeatIndex(this.id, index + 1);
} }
}, },
isIndented: function() isIndented: function()
@@ -552,7 +577,9 @@ dojo.declare("alfresco.xforms.Repeat",
d.repeat = this; d.repeat = this;
this.domNode.appendChild(d); this.domNode.appendChild(d);
d.setAttribute("style", "position: relative; line-height: 16px; background-color: #cddbe8; font-weight: bold;"); d.setAttribute("style", "position: relative; line-height: 16px; background-color: #cddbe8; font-weight: bold;");
dojo.event.browser.addListener(d, "onclick", function(event) dojo.event.browser.addListener(d,
"onclick",
function(event)
{ {
event.currentTarget.repeat.setFocusedChild(null); event.currentTarget.repeat.setFocusedChild(null);
}); });
@@ -571,10 +598,14 @@ dojo.declare("alfresco.xforms.Repeat",
addElement.style.top = "0px"; addElement.style.top = "0px";
addElement.style.left = "80%"; addElement.style.left = "80%";
dojo.event.browser.addListener(addElement, "onclick", function(event) dojo.event.browser.addListener(addElement,
"onclick",
function(event)
{ {
var repeat = event.currentTarget.parentNode.repeat; var repeat = event.currentTarget.parentNode.repeat;
repeat.xform.fireAction("trigger_0"); var trigger = _findElementById(repeat.node.parentNode,
repeat.id + "-insert_before");
repeat.xform.fireAction(trigger.getAttribute("id"));
}); });
return this.domNode; return this.domNode;
@@ -616,6 +647,11 @@ dojo.declare("alfresco.xforms.Repeat",
var w = create_widget(this.xform, clonedPrototype); var w = create_widget(this.xform, clonedPrototype);
this.insertChildAt(w, position); this.insertChildAt(w, position);
load_body(this.xform, w.node, w); load_body(this.xform, w.node, w);
},
handleItemDeleted: function(position)
{
dojo.debug(this.id + ".handleItemDeleted(" + position + ")");
this.removeChildAt(position);
} }
}); });
@@ -838,29 +874,15 @@ dojo.declare("alfresco.xforms.XForm",
originalId = dojo.dom.textContent(originalId); originalId = dojo.dom.textContent(originalId);
dojo.debug("handleIdGenerated(" + targetId + ", " + originalId + ")"); dojo.debug("handleIdGenerated(" + targetId + ", " + originalId + ")");
function applyId(node, oldId, newId)
{
dojo.debug("looking for " + oldId +
" in " + node.nodeName +
"(" + node.getAttribute("id") + ")");
if (node.getAttribute("id") == oldId)
{
dojo.debug("applying id " + newId +
" to " + node.nodeName + "(" + oldId + ")");
node.setAttribute("id", newId);
return true;
}
for (var i = 0; i < node.childNodes.length; i++)
{
if (dojo.dom.isNode(node.childNodes[i]) &&
applyId(node.childNodes[i], oldId, newId))
return true;
}
return false;
}
var clone = prototypeClones[prototypeClones.length - 1]; var clone = prototypeClones[prototypeClones.length - 1];
if (!applyId(clone, originalId, targetId)) var node = _findElementById(clone, originalId);
if (node)
{
dojo.debug("applying id " + targetId +
" to " + node.nodeName + "(" + originalId + ")");
node.setAttribute("id", targetId);
}
else
throw new Error("unable to find " + originalId + throw new Error("unable to find " + originalId +
" in clone " + dojo.dom.innerXML(clone)); " in clone " + dojo.dom.innerXML(clone));
break; break;
@@ -879,6 +901,18 @@ dojo.declare("alfresco.xforms.XForm",
target.handleItemInserted(clone, position); target.handleItemInserted(clone, position);
break; break;
} }
case "chiba-item-deleted":
{
var position = events.childNodes[i].getElementsByTagName("position")[0];
position = Number(dojo.dom.textContent(position)) - 1;
var targetDomNode = document.getElementById(targetId + "-domNode");
if (!targetDomNode)
throw new Error("unable to find node " + targetId + "-domNode");
var target = targetDomNode.widget;
target.handleItemDeleted(position);
break;
}
default: default:
{ {
dojo.debug("unhandled event " + events.childNodes[i].nodeName); dojo.debug("unhandled event " + events.childNodes[i].nodeName);
@@ -1002,3 +1036,22 @@ function addSubmitHandlerToButton(b)
} }
} }
} }
function _findElementById(node, id)
{
dojo.debug("looking for " + id +
" in " + node.nodeName +
"(" + node.getAttribute("id") + ")");
if (node.getAttribute("id") == id)
return node;
for (var i = 0; i < node.childNodes.length; i++)
{
if (dojo.dom.isNode(node.childNodes[i]))
{
var n = _findElementById(node.childNodes[i], id);
if (n)
return n;
}
}
return null;
}