From f5e16dfcd0c0152c476926775ec3064f765cdc93 Mon Sep 17 00:00:00 2001 From: Ariel Backenroth Date: Wed, 10 Jan 2007 06:21:20 +0000 Subject: [PATCH] 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 --- .../alfresco/web/forms/xforms/XFormsBean.java | 18 +++-- source/web/scripts/ajax/xforms.js | 80 ++++++++++++++----- 2 files changed, 72 insertions(+), 26 deletions(-) diff --git a/source/java/org/alfresco/web/forms/xforms/XFormsBean.java b/source/java/org/alfresco/web/forms/xforms/XFormsBean.java index b212fc5eaa..3fb254e935 100644 --- a/source/java/org/alfresco/web/forms/xforms/XFormsBean.java +++ b/source/java/org/alfresco/web/forms/xforms/XFormsBean.java @@ -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(); diff --git a/source/web/scripts/ajax/xforms.js b/source/web/scripts/ajax/xforms.js index f529adc00b..203b221917 100644 --- a/source/web/scripts/ajax/xforms.js +++ b/source/web/scripts/ajax/xforms.js @@ -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);