fixing move up move down in repeats. needed to dispatch rebuild and refresh events after using the Instance itself to insert and delete nodes, rather than attempt to manipulate repeat indeces. less efficient, but does seem to at least be solid.

placing actions within xf:action wrappers within xf:triggers.  surprising that chiba didn't yell at me for this.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4788 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2007-01-11 00:42:05 +00:00
parent 90a54f63fc
commit 383d84e536
3 changed files with 71 additions and 86 deletions

View File

@@ -2821,7 +2821,7 @@ public class SchemaFormBuilder
final String id,
final String bindId,
final String label,
final Element action)
final Element... actions)
{
final Element trigger =
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
@@ -2845,10 +2845,13 @@ public class SchemaFormBuilder
final Element actionWrapper =
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":action");
actionWrapper.appendChild(action);
trigger.appendChild(action);
this.setXFormsId(action);
trigger.appendChild(actionWrapper);
for (final Element action : actions)
{
actionWrapper.appendChild(action);
this.setXFormsId(action);
}
return trigger;
}
@@ -2863,7 +2866,6 @@ public class SchemaFormBuilder
{
//xforms:at = xforms:index from the "id" attribute on the repeat element
//trigger insert
Element action =
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
NamespaceConstants.XFORMS_PREFIX + ":insert");

View File

@@ -62,8 +62,10 @@ import org.chiba.xml.xforms.XFormsElement;
import org.chiba.xml.xforms.connector.http.AbstractHTTPConnector;
import org.chiba.xml.xforms.core.Instance;
import org.chiba.xml.xforms.core.ModelItem;
import org.chiba.xml.xforms.core.Model;
import org.chiba.xml.xforms.core.UpdateHandler;
import org.chiba.xml.xforms.exception.XFormsException;
import org.chiba.xml.xforms.ui.BoundElement;
import org.chiba.xml.xforms.ui.RepeatItem;
import org.chiba.xml.xforms.ui.Upload;
import org.chiba.xml.ns.NamespaceConstants;
import org.springframework.util.FileCopyUtils;
@@ -211,8 +213,9 @@ public class XFormsBean
{
public void handleEvent(final Event e)
{
XFormsBean.LOGGER.debug("received event " + e);
XFormsBean.this.xformsSession.eventLog.add((XMLEvent)e);
final XMLEvent xmle = (XMLEvent)e;
XFormsBean.LOGGER.debug("received event " + xmle.getType() + ": " + xmle);
XFormsBean.this.xformsSession.eventLog.add(xmle);
}
};
// interaction events my occur during init so we have to register before
@@ -407,8 +410,8 @@ public class XFormsBean
final String toItemId = (String)requestParameters.get("toItemId");
LOGGER.debug(this + ".swapRepeatItems(" + fromItemId + ", " + toItemId + ")");
final ChibaBean chibaBean = this.xformsSession.chibaBean;
this.swapRepeatItems(chibaBean.getContainer().lookup(fromItemId),
chibaBean.getContainer().lookup(toItemId));
this.swapRepeatItems((RepeatItem)chibaBean.getContainer().lookup(fromItemId),
(RepeatItem)chibaBean.getContainer().lookup(toItemId));
final ResponseWriter out = context.getResponseWriter();
XMLUtil.print(this.getEventLog(), out);
@@ -578,39 +581,59 @@ public class XFormsBean
out.close();
}
private void swapRepeatItems(final XFormsElement from,
final XFormsElement to)
private void swapRepeatItems(final RepeatItem from,
final RepeatItem to)
throws XFormsException
{
LOGGER.debug("swapping repeat item " + from + " with " + to);
if (from instanceof BoundElement && to instanceof BoundElement)
LOGGER.debug("from instance id " + from.getInstanceId());
final Model model = from.getModel();
final Instance instance = model.getInstance(from.getInstanceId());
assert instance == to.getModel().getInstance(to.getInstanceId());
final String fromLocationPath = from.getLocationPath();
final String toLocationPath = to.getLocationPath();
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("from instance id " + ((BoundElement)from).getInstanceId());
final Instance instance = from.getModel().getInstance(((BoundElement)from).getInstanceId());
assert instance == to.getModel().getInstance(((BoundElement)to).getInstanceId());
LOGGER.debug("from {id: " + from.getId() + ",position: " + from.getPosition() +
"} " + fromLocationPath +
"=" + instance.getModelItem(fromLocationPath).getValue());
LOGGER.debug("to {id:" + to.getId() + ",position: " + to.getPosition() +
"} " + toLocationPath +
"=" + instance.getModelItem(toLocationPath).getValue());
}
final String fromLocationPath = ((BoundElement)from).getLocationPath();
final ModelItem fromModelItem = instance.getModelItem(fromLocationPath);
String beforeLocation = toLocationPath;
if (from.getPosition() < to.getPosition())
{
final RepeatItem beforeItem = to.getRepeat().getRepeatItem(to.getPosition() + 1);
beforeLocation = (beforeItem != null
? beforeItem.getLocationPath()
: to.getRepeat().getLocationPath().replaceAll("\\[position\\(\\)[\\s]*!=[\\s]*last\\(\\)]$",
"[position()=last()]"));
}
LOGGER.debug("inserting node before " + beforeLocation);
instance.insertNode(fromLocationPath, beforeLocation);
final String toLocationPath = ((BoundElement)to).getLocationPath();
final ModelItem toModelItem = instance.getModelItem(toLocationPath);
model.getContainer().dispatch(model.getTarget(), XFormsEventNames.REBUILD, null);
model.getContainer().dispatch(model.getTarget(), XFormsEventNames.RECALCULATE, null);
model.getContainer().dispatch(model.getTarget(), XFormsEventNames.REVALIDATE, null);
model.getContainer().dispatch(model.getTarget(), XFormsEventNames.REFRESH, null);
LOGGER.debug("from[" + from.getId() + "] " + fromLocationPath + "=" + fromModelItem.getValue());
LOGGER.debug("to[" + to.getId() + "] " + toLocationPath + "=" + toModelItem.getValue());
LOGGER.debug("deleting from " + from.getLocationPath());
// need to reload from location path since it has moved
instance.deleteNode(from.getLocationPath());
final Node fromNode = (Node)fromModelItem.getNode();
final Node toNode = (Node)toModelItem.getNode();
Node swapNode = fromNode;
fromModelItem.setNode(toNode);
toModelItem.setNode(swapNode);
model.getContainer().dispatch(model.getTarget(), XFormsEventNames.REBUILD, null);
model.getContainer().dispatch(model.getTarget(), XFormsEventNames.RECALCULATE, null);
model.getContainer().dispatch(model.getTarget(), XFormsEventNames.REVALIDATE, null);
model.getContainer().dispatch(model.getTarget(), XFormsEventNames.REFRESH, null);
final Node parentNode = fromNode.getParentNode();
assert parentNode.equals(toNode.getParentNode());
swapNode = parentNode.getOwnerDocument().createTextNode("swap");
parentNode.replaceChild(swapNode, fromNode);
parentNode.replaceChild(fromNode, toNode);
parentNode.replaceChild(toNode, swapNode);
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("swapped model data, instance data after manipulation:\n " +
XMLUtil.toString(instance.getInstanceDocument()));
}
}

View File

@@ -235,8 +235,6 @@ dojo.declare("alfresco.xforms.Widget",
{
dojo.debug("destroying " + this.id);
},
_handlePrepareForMove: function() {},
_handleMoveComplete: function() {},
getRepeatIndices: function()
{
var result = [];
@@ -501,14 +499,6 @@ dojo.declare("alfresco.xforms.TextArea",
tinyMCE.removeMCEControl(this.id);
}
},
_handlePrepareForMove: function()
{
this._removeTinyMCE();
},
_handleMoveComplete: function()
{
this._createTinyMCE();
},
_removeTinyMCE: function()
{
var value = tinyMCE.getContent(this.id);
@@ -964,22 +954,6 @@ dojo.declare("alfresco.xforms.Group",
this.children[i]._destroy();
}
},
_handlePrepareForMove: function()
{
this.inherited("_handlePrepareForMove", [ ]);
for (var i = 0; i < this.children.length; i++)
{
this.children[i]._handlePrepareForMove();
}
},
_handleMoveComplete: function()
{
this.inherited("_handleMoveComplete", [ ]);
for (var i = 0; i < this.children.length; i++)
{
this.children[i]._handleMoveComplete();
}
},
setReadonly: function(readonly)
{
this.inherited("setReadonly", [ readonly ]);
@@ -1322,19 +1296,6 @@ dojo.declare("alfresco.xforms.Repeat",
", " + toIndex + ")");
var fromChild = this.getChildAt(fromIndex);
var toChild = this.getChildAt(toIndex);
fromChild._handlePrepareForMove();
toChild._handlePrepareForMove();
var swapNode = document.createElement("div");
this.domNode.childContainerNode.replaceChild(swapNode, fromChild.domContainer);
this.domNode.childContainerNode.replaceChild(fromChild.domContainer, toChild.domContainer);
this.domNode.childContainerNode.replaceChild(toChild.domContainer, swapNode);
fromChild._handleMoveComplete();
toChild._handleMoveComplete();
this.children[fromIndex] = toChild;
this.children[toIndex] = fromChild;
this._selectedIndex = toIndex;
this._updateDisplay();
var req = create_ajax_request(this.xform,
"swapRepeatItems",
{
@@ -1347,6 +1308,13 @@ dojo.declare("alfresco.xforms.Repeat",
this.target._handleEventLog(data.documentElement)
});
send_ajax_request(req);
var anim = dojo.lfx.html.fadeOut(fromChild.domContainer, 500);
anim.onEnd = function()
{
fromChild.domContainer.style.display = "none";
};
anim.play();
},
setFocusedChild: function(child)
{
@@ -1481,7 +1449,6 @@ dojo.declare("alfresco.xforms.Trigger",
{
initializer: function(xform, xformsNode)
{
// this.inherited("initializer", [ xform, xformsNode ]);
},
isValidForSubmit: function()
{
@@ -1502,17 +1469,11 @@ dojo.declare("alfresco.xforms.Trigger",
},
getAction: function()
{
for (var i = 0; i < this.xformsNode.childNodes.length; i++)
{
var c = this.xformsNode.childNodes[i];
if (c.nodeType != dojo.dom.ELEMENT_NODE)
continue;
if (c.nodeName == alfresco_xforms_constants.XFORMS_PREFIX + ":label" ||
c.nodeName == alfresco_xforms_constants.XFORMS_PREFIX + ":alert")
continue;
return new alfresco.xforms.XFormsAction(this.xform, c);
}
throw new Error("unable to find action node for " + this.id);
var action = _getElementsByTagNameNS(this.xformsNode,
alfresco_xforms_constants.XFORMS_NS,
alfresco_xforms_constants.XFORMS_PREFIX,
"action")[0];
return new alfresco.xforms.XFormsAction(this.xform, dojo.dom.firstElement(action));
},
_clickHandler: function(event)
{
@@ -1525,7 +1486,6 @@ dojo.declare("alfresco.xforms.Submit",
{
initializer: function(xform, xformsNode)
{
// this.inherited("initializer", [ xform, xformsNode ]);
var submit_buttons = _xforms_getSubmitButtons();
for (var i = 0; i < submit_buttons.length; i++)
{