mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -2821,7 +2821,7 @@ public class SchemaFormBuilder
|
|||||||
final String id,
|
final String id,
|
||||||
final String bindId,
|
final String bindId,
|
||||||
final String label,
|
final String label,
|
||||||
final Element action)
|
final Element... actions)
|
||||||
{
|
{
|
||||||
final Element trigger =
|
final Element trigger =
|
||||||
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
||||||
@@ -2845,10 +2845,13 @@ public class SchemaFormBuilder
|
|||||||
final Element actionWrapper =
|
final Element actionWrapper =
|
||||||
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
||||||
NamespaceConstants.XFORMS_PREFIX + ":action");
|
NamespaceConstants.XFORMS_PREFIX + ":action");
|
||||||
actionWrapper.appendChild(action);
|
trigger.appendChild(actionWrapper);
|
||||||
trigger.appendChild(action);
|
|
||||||
this.setXFormsId(action);
|
|
||||||
|
|
||||||
|
for (final Element action : actions)
|
||||||
|
{
|
||||||
|
actionWrapper.appendChild(action);
|
||||||
|
this.setXFormsId(action);
|
||||||
|
}
|
||||||
return trigger;
|
return trigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2863,7 +2866,6 @@ public class SchemaFormBuilder
|
|||||||
{
|
{
|
||||||
//xforms:at = xforms:index from the "id" attribute on the repeat element
|
//xforms:at = xforms:index from the "id" attribute on the repeat element
|
||||||
//trigger insert
|
//trigger insert
|
||||||
|
|
||||||
Element action =
|
Element action =
|
||||||
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,
|
||||||
NamespaceConstants.XFORMS_PREFIX + ":insert");
|
NamespaceConstants.XFORMS_PREFIX + ":insert");
|
||||||
|
@@ -62,8 +62,10 @@ import org.chiba.xml.xforms.XFormsElement;
|
|||||||
import org.chiba.xml.xforms.connector.http.AbstractHTTPConnector;
|
import org.chiba.xml.xforms.connector.http.AbstractHTTPConnector;
|
||||||
import org.chiba.xml.xforms.core.Instance;
|
import org.chiba.xml.xforms.core.Instance;
|
||||||
import org.chiba.xml.xforms.core.ModelItem;
|
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.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.xforms.ui.Upload;
|
||||||
import org.chiba.xml.ns.NamespaceConstants;
|
import org.chiba.xml.ns.NamespaceConstants;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
@@ -211,8 +213,9 @@ public class XFormsBean
|
|||||||
{
|
{
|
||||||
public void handleEvent(final Event e)
|
public void handleEvent(final Event e)
|
||||||
{
|
{
|
||||||
XFormsBean.LOGGER.debug("received event " + e);
|
final XMLEvent xmle = (XMLEvent)e;
|
||||||
XFormsBean.this.xformsSession.eventLog.add((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
|
// 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");
|
final String toItemId = (String)requestParameters.get("toItemId");
|
||||||
LOGGER.debug(this + ".swapRepeatItems(" + fromItemId + ", " + toItemId + ")");
|
LOGGER.debug(this + ".swapRepeatItems(" + fromItemId + ", " + toItemId + ")");
|
||||||
final ChibaBean chibaBean = this.xformsSession.chibaBean;
|
final ChibaBean chibaBean = this.xformsSession.chibaBean;
|
||||||
this.swapRepeatItems(chibaBean.getContainer().lookup(fromItemId),
|
this.swapRepeatItems((RepeatItem)chibaBean.getContainer().lookup(fromItemId),
|
||||||
chibaBean.getContainer().lookup(toItemId));
|
(RepeatItem)chibaBean.getContainer().lookup(toItemId));
|
||||||
|
|
||||||
final ResponseWriter out = context.getResponseWriter();
|
final ResponseWriter out = context.getResponseWriter();
|
||||||
XMLUtil.print(this.getEventLog(), out);
|
XMLUtil.print(this.getEventLog(), out);
|
||||||
@@ -578,39 +581,59 @@ public class XFormsBean
|
|||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void swapRepeatItems(final XFormsElement from,
|
private void swapRepeatItems(final RepeatItem from,
|
||||||
final XFormsElement to)
|
final RepeatItem to)
|
||||||
|
throws XFormsException
|
||||||
{
|
{
|
||||||
LOGGER.debug("swapping repeat item " + from + " with " + to);
|
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());
|
LOGGER.debug("from {id: " + from.getId() + ",position: " + from.getPosition() +
|
||||||
final Instance instance = from.getModel().getInstance(((BoundElement)from).getInstanceId());
|
"} " + fromLocationPath +
|
||||||
assert instance == to.getModel().getInstance(((BoundElement)to).getInstanceId());
|
"=" + instance.getModelItem(fromLocationPath).getValue());
|
||||||
|
LOGGER.debug("to {id:" + to.getId() + ",position: " + to.getPosition() +
|
||||||
|
"} " + toLocationPath +
|
||||||
|
"=" + instance.getModelItem(toLocationPath).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
final String fromLocationPath = ((BoundElement)from).getLocationPath();
|
String beforeLocation = toLocationPath;
|
||||||
final ModelItem fromModelItem = instance.getModelItem(fromLocationPath);
|
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();
|
model.getContainer().dispatch(model.getTarget(), XFormsEventNames.REBUILD, null);
|
||||||
final ModelItem toModelItem = instance.getModelItem(toLocationPath);
|
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("deleting from " + from.getLocationPath());
|
||||||
LOGGER.debug("to[" + to.getId() + "] " + toLocationPath + "=" + toModelItem.getValue());
|
// need to reload from location path since it has moved
|
||||||
|
instance.deleteNode(from.getLocationPath());
|
||||||
|
|
||||||
final Node fromNode = (Node)fromModelItem.getNode();
|
model.getContainer().dispatch(model.getTarget(), XFormsEventNames.REBUILD, null);
|
||||||
final Node toNode = (Node)toModelItem.getNode();
|
model.getContainer().dispatch(model.getTarget(), XFormsEventNames.RECALCULATE, null);
|
||||||
Node swapNode = fromNode;
|
model.getContainer().dispatch(model.getTarget(), XFormsEventNames.REVALIDATE, null);
|
||||||
fromModelItem.setNode(toNode);
|
model.getContainer().dispatch(model.getTarget(), XFormsEventNames.REFRESH, null);
|
||||||
toModelItem.setNode(swapNode);
|
|
||||||
|
|
||||||
final Node parentNode = fromNode.getParentNode();
|
if (LOGGER.isDebugEnabled())
|
||||||
assert parentNode.equals(toNode.getParentNode());
|
{
|
||||||
|
LOGGER.debug("swapped model data, instance data after manipulation:\n " +
|
||||||
swapNode = parentNode.getOwnerDocument().createTextNode("swap");
|
XMLUtil.toString(instance.getInstanceDocument()));
|
||||||
parentNode.replaceChild(swapNode, fromNode);
|
|
||||||
parentNode.replaceChild(fromNode, toNode);
|
|
||||||
parentNode.replaceChild(toNode, swapNode);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -235,8 +235,6 @@ dojo.declare("alfresco.xforms.Widget",
|
|||||||
{
|
{
|
||||||
dojo.debug("destroying " + this.id);
|
dojo.debug("destroying " + this.id);
|
||||||
},
|
},
|
||||||
_handlePrepareForMove: function() {},
|
|
||||||
_handleMoveComplete: function() {},
|
|
||||||
getRepeatIndices: function()
|
getRepeatIndices: function()
|
||||||
{
|
{
|
||||||
var result = [];
|
var result = [];
|
||||||
@@ -501,14 +499,6 @@ dojo.declare("alfresco.xforms.TextArea",
|
|||||||
tinyMCE.removeMCEControl(this.id);
|
tinyMCE.removeMCEControl(this.id);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_handlePrepareForMove: function()
|
|
||||||
{
|
|
||||||
this._removeTinyMCE();
|
|
||||||
},
|
|
||||||
_handleMoveComplete: function()
|
|
||||||
{
|
|
||||||
this._createTinyMCE();
|
|
||||||
},
|
|
||||||
_removeTinyMCE: function()
|
_removeTinyMCE: function()
|
||||||
{
|
{
|
||||||
var value = tinyMCE.getContent(this.id);
|
var value = tinyMCE.getContent(this.id);
|
||||||
@@ -964,22 +954,6 @@ dojo.declare("alfresco.xforms.Group",
|
|||||||
this.children[i]._destroy();
|
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)
|
setReadonly: function(readonly)
|
||||||
{
|
{
|
||||||
this.inherited("setReadonly", [ readonly ]);
|
this.inherited("setReadonly", [ readonly ]);
|
||||||
@@ -1322,19 +1296,6 @@ dojo.declare("alfresco.xforms.Repeat",
|
|||||||
", " + toIndex + ")");
|
", " + toIndex + ")");
|
||||||
var fromChild = this.getChildAt(fromIndex);
|
var fromChild = this.getChildAt(fromIndex);
|
||||||
var toChild = this.getChildAt(toIndex);
|
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,
|
var req = create_ajax_request(this.xform,
|
||||||
"swapRepeatItems",
|
"swapRepeatItems",
|
||||||
{
|
{
|
||||||
@@ -1347,6 +1308,13 @@ dojo.declare("alfresco.xforms.Repeat",
|
|||||||
this.target._handleEventLog(data.documentElement)
|
this.target._handleEventLog(data.documentElement)
|
||||||
});
|
});
|
||||||
send_ajax_request(req);
|
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)
|
setFocusedChild: function(child)
|
||||||
{
|
{
|
||||||
@@ -1481,7 +1449,6 @@ dojo.declare("alfresco.xforms.Trigger",
|
|||||||
{
|
{
|
||||||
initializer: function(xform, xformsNode)
|
initializer: function(xform, xformsNode)
|
||||||
{
|
{
|
||||||
// this.inherited("initializer", [ xform, xformsNode ]);
|
|
||||||
},
|
},
|
||||||
isValidForSubmit: function()
|
isValidForSubmit: function()
|
||||||
{
|
{
|
||||||
@@ -1502,17 +1469,11 @@ dojo.declare("alfresco.xforms.Trigger",
|
|||||||
},
|
},
|
||||||
getAction: function()
|
getAction: function()
|
||||||
{
|
{
|
||||||
for (var i = 0; i < this.xformsNode.childNodes.length; i++)
|
var action = _getElementsByTagNameNS(this.xformsNode,
|
||||||
{
|
alfresco_xforms_constants.XFORMS_NS,
|
||||||
var c = this.xformsNode.childNodes[i];
|
alfresco_xforms_constants.XFORMS_PREFIX,
|
||||||
if (c.nodeType != dojo.dom.ELEMENT_NODE)
|
"action")[0];
|
||||||
continue;
|
return new alfresco.xforms.XFormsAction(this.xform, dojo.dom.firstElement(action));
|
||||||
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);
|
|
||||||
},
|
},
|
||||||
_clickHandler: function(event)
|
_clickHandler: function(event)
|
||||||
{
|
{
|
||||||
@@ -1525,7 +1486,6 @@ dojo.declare("alfresco.xforms.Submit",
|
|||||||
{
|
{
|
||||||
initializer: function(xform, xformsNode)
|
initializer: function(xform, xformsNode)
|
||||||
{
|
{
|
||||||
// this.inherited("initializer", [ xform, xformsNode ]);
|
|
||||||
var submit_buttons = _xforms_getSubmitButtons();
|
var submit_buttons = _xforms_getSubmitButtons();
|
||||||
for (var i = 0; i < submit_buttons.length; i++)
|
for (var i = 0; i < submit_buttons.length; i++)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user