fixing some bugs with setting repeat indices. tinymce was blocking capture of click events so it was never setting repeat indexes so that was causing issues. secondly, for nested repeats, now setting the full hierarchy of repeats in order to avoid any blocking issues when events aren't being properly propogated. a bit brute force, but does seem to make things more stable.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4778 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2007-01-10 06:21:20 +00:00
parent b57f548014
commit f5e16dfcd0
2 changed files with 72 additions and 26 deletions

View File

@@ -320,18 +320,20 @@ public class XFormsBean
* @param value the new value
* @return the list of events that may result through this action
*/
public void setRepeatIndex()
public void setRepeatIndeces()
throws XFormsException, IOException
{
final FacesContext context = FacesContext.getCurrentInstance();
final Map requestParameters = context.getExternalContext().getRequestParameterMap();
final String id = (String)requestParameters.get("id");
final int index = Integer.parseInt((String)requestParameters.get("index"));
LOGGER.debug(this + ".setRepeatIndex(" + id + ", " + index + ")");
final ChibaBean chibaBean = this.xformsSession.chibaBean;
chibaBean.updateRepeatIndex(id, index);
final String repeatIds = (String)requestParameters.get("repeatIds");
LOGGER.debug(this + ".setRepeatIndeces(" + repeatIds + ")");
for (String id : repeatIds.split(","))
{
final int index = Integer.parseInt((String)requestParameters.get(id));
LOGGER.debug(this + ".setRepeatIndex(" + id + ", " + index + ")");
final ChibaBean chibaBean = this.xformsSession.chibaBean;
chibaBean.updateRepeatIndex(id, index);
}
final ResponseWriter out = context.getResponseWriter();
XMLUtil.print(this.getEventLog(), out);
out.close();

View File

@@ -239,23 +239,14 @@ dojo.declare("alfresco.xforms.Widget",
_handleMoveComplete: function() {},
getRepeatIndices: function()
{
function RepeatIndexData(repeat, index)
{
this.repeat = repeat;
this.index = index;
this.toString = function()
{
return "{" + this.repeat.id + " = " + this.index + "}";
};
}
var result = [];
var w = this;
while (w.parent)
{
if (w.parent instanceof alfresco.xforms.Repeat)
{
result.push(new RepeatIndexData(w.parent,
w.parent.getChildIndex(w)));
result.push(new alfresco.xforms.RepeatIndexData(w.parent,
w.parent.getChildIndex(w)));
}
w = w.parent;
}
@@ -426,6 +417,7 @@ dojo.declare("alfresco.xforms.TextArea",
{
initializer: function(xform, xformsNode)
{
this.focused = false;
},
render: function(attach_point)
{
@@ -473,6 +465,32 @@ dojo.declare("alfresco.xforms.TextArea",
{
var widget = event.target.widget;
widget.xform.setXFormsValue(widget.id, widget.getValue());
this.focused = false;
},
_tinyMCE_focusHandler: function(event)
{
var widget = event.target.widget;
var repeatIndices = widget.getRepeatIndices();
if (repeatIndices.length != 0 && !this.focused)
{
var r = repeatIndices[repeatIndices.length - 1].repeat;
var p = widget;
while (p && p.parent != r)
{
if (p.parent instanceof alfresco.xforms.Repeat)
{
throw new Error("unexpected parent repeat " + p.parent.id);
}
p = p.parent;
}
if (!p)
{
throw new Error("unable to find parent repeat " + r.id +
" of " + widget.id);
}
repeatIndices[repeatIndices.length - 1].repeat.setFocusedChild(p);
}
this.focused = true;
},
_destroy: function()
{
@@ -503,6 +521,7 @@ dojo.declare("alfresco.xforms.TextArea",
var editorDocument = tinyMCE.getInstanceById(this.id).getDoc();
editorDocument.widget = this;
tinyMCE.addEvent(editorDocument, "blur", this._tinyMCE_blurHandler);
tinyMCE.addEvent(editorDocument, "focus", this._tinyMCE_focusHandler);
}
});
@@ -1069,6 +1088,16 @@ dojo.declare("alfresco.xforms.Group",
}
});
alfresco.xforms.RepeatIndexData = function(repeat, index)
{
this.repeat = repeat;
this.index = index;
this.toString = function()
{
return "{" + this.repeat.id + " = " + this.index + "}";
};
}
dojo.declare("alfresco.xforms.Repeat",
alfresco.xforms.Group,
{
@@ -1321,9 +1350,13 @@ dojo.declare("alfresco.xforms.Repeat",
},
setFocusedChild: function(child)
{
var repeatIndices = this.getRepeatIndices();
if (!child)
this.xform.setRepeatIndex(this.id, 0);
else
{
repeatIndices.push(new alfresco.xforms.RepeatIndexData(this, 0));
this.xform.setRepeatIndeces(repeatIndices);
}
else
{
var index = this.getChildIndex(child);
if (index < 0)
@@ -1334,8 +1367,11 @@ dojo.declare("alfresco.xforms.Repeat",
if (this.getSelectedIndex() == -1 && index == 0)
this.handleIndexChanged(0);
else
{
repeatIndices.push(new alfresco.xforms.RepeatIndexData(this, index));
// xforms repeat indexes are 1-based
this.xform.setRepeatIndex(this.id, index + 1);
this.xform.setRepeatIndeces(repeatIndices);
}
}
},
render: function(attach_point)
@@ -1782,12 +1818,20 @@ dojo.declare("alfresco.xforms.XForm",
}
return result;
},
setRepeatIndex: function(id, index)
setRepeatIndeces: function(repeatIndeces)
{
dojo.debug("setting repeat index " + index + " on " + id);
dojo.debug("setting repeat indeces [" + repeatIndeces.join(", ") + "]");
var params = { };
params["repeatIds"] = [];
for (var i = 0; i < repeatIndeces.length; i++)
{
params.repeatIds.push(repeatIndeces[i].repeat.id);
params[repeatIndeces[i].repeat.id] = repeatIndeces[i].index + 1;
}
params.repeatIds = params.repeatIds.join(",");
var req = create_ajax_request(this,
"setRepeatIndex",
{ id: id, index: index },
"setRepeatIndeces",
params,
function(type, data, evt)
{
this.target._handleEventLog(data.documentElement);