mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -813,6 +813,15 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
}
|
||||
|
||||
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;
|
||||
final String name = el.getLocalName();
|
||||
@@ -823,14 +832,8 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
//increment the counter
|
||||
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,
|
||||
SchemaFormBuilder.XFORMS_NS_PREFIX + "id",
|
||||
id);
|
||||
@@ -2422,13 +2425,14 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
}
|
||||
|
||||
private Element createTriggerForRepeat(final Document xForm,
|
||||
final String id,
|
||||
final String label,
|
||||
final Element action)
|
||||
{
|
||||
final Element trigger =
|
||||
xForm.createElementNS(SchemaFormBuilder.XFORMS_NS,
|
||||
SchemaFormBuilder.XFORMS_NS_PREFIX + "trigger");
|
||||
this.setXFormsId(trigger);
|
||||
this.setXFormsId(trigger, id != null ? id : null);
|
||||
|
||||
//label insert
|
||||
final Element triggerLabel =
|
||||
@@ -2482,8 +2486,6 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
Element action =
|
||||
xForm.createElementNS(SchemaFormBuilder.XFORMS_NS,
|
||||
SchemaFormBuilder.XFORMS_NS_PREFIX + "insert");
|
||||
this.setXFormsId(action);
|
||||
|
||||
//insert: bind & other attributes
|
||||
if (bindId != null)
|
||||
action.setAttributeNS(SchemaFormBuilder.XFORMS_NS,
|
||||
@@ -2500,12 +2502,14 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
"1");
|
||||
|
||||
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,
|
||||
SchemaFormBuilder.XFORMS_NS_PREFIX + "insert");
|
||||
this.setXFormsId(action);
|
||||
|
||||
//insert: bind & other attributes
|
||||
if (bindId != null)
|
||||
@@ -2523,13 +2527,15 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
SchemaFormBuilder.XFORMS_NS_PREFIX + "index('" + repeatId + "')");
|
||||
|
||||
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 //////////////////
|
||||
//trigger delete
|
||||
action = xForm.createElementNS(SchemaFormBuilder.XFORMS_NS,
|
||||
SchemaFormBuilder.XFORMS_NS_PREFIX + "delete");
|
||||
this.setXFormsId(action);
|
||||
|
||||
//delete: bind & other attributes
|
||||
if (bindId != null)
|
||||
@@ -2544,14 +2550,17 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
SchemaFormBuilder.XFORMS_NS_PREFIX + "index('" + repeatId + "')");
|
||||
|
||||
final Element trigger_delete =
|
||||
this.createTriggerForRepeat(xForm, "delete selected", action);
|
||||
this.createTriggerForRepeat(xForm,
|
||||
repeatId != null ? repeatId + "-delete" : null,
|
||||
"delete selected",
|
||||
action);
|
||||
|
||||
|
||||
//add the triggers
|
||||
final Element wrapper_triggers =
|
||||
_wrapper.createControlsWrapper(trigger_insert_before);
|
||||
|
||||
if (wrapper_triggers == trigger_insert_after)
|
||||
if (wrapper_triggers == trigger_insert_before)
|
||||
{
|
||||
//no wrapper
|
||||
formSection.appendChild(trigger_insert_before);
|
||||
@@ -2565,7 +2574,7 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
|
||||
if (insert_parent != null)
|
||||
{
|
||||
insert_parent.appendChild(trigger_insert_before);
|
||||
insert_parent.appendChild(trigger_insert_after);
|
||||
insert_parent.appendChild(trigger_delete);
|
||||
}
|
||||
}
|
||||
@@ -2597,9 +2606,9 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
|
||||
XSTypeDefinition parentType = type.getBaseType();
|
||||
|
||||
if (parentType != null &&
|
||||
type.getTypeCategory() == parentType.getTypeCategory())
|
||||
{
|
||||
if (parentType == null ||
|
||||
type.getTypeCategory() != parentType.getTypeCategory())
|
||||
return;
|
||||
if (type != parentType &&
|
||||
(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
|
||||
if (type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE)
|
||||
{
|
||||
XSComplexTypeDefinition complexType =
|
||||
(XSComplexTypeDefinition) type;
|
||||
if (complexType.getDerivationMethod() == XSConstants.DERIVATION_EXTENSION
|
||||
&& !complexType.getAbstract()
|
||||
&& !descendents.contains(type) //to be tested
|
||||
//&& !descendents.contains(type.getName()) //to be tested
|
||||
)
|
||||
{
|
||||
//newDescendents.add(type.getName());
|
||||
final XSComplexTypeDefinition complexType = (XSComplexTypeDefinition)type;
|
||||
if (complexType.getDerivationMethod() == XSConstants.DERIVATION_EXTENSION &&
|
||||
!complexType.getAbstract() &&
|
||||
!descendents.contains(type))
|
||||
newDescendents.add(type);
|
||||
}
|
||||
}
|
||||
//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.
|
||||
//
|
||||
Element alertElement = (Element)
|
||||
formControl.appendChild(xForm.createElementNS(XFORMS_NS,
|
||||
SchemaFormBuilder.XFORMS_NS_PREFIX + "alert"));
|
||||
this.setXFormsId(alertElement);
|
||||
|
||||
StringBuffer alert =
|
||||
new StringBuffer("Please provide a valid value for '" + caption + "'.");
|
||||
|
||||
Element enveloppe = xForm.getDocumentElement();
|
||||
alert.append(" '" + caption +
|
||||
"' is " + (o.minimum == 0 ? "an optional" : "a required") + " '" +
|
||||
createCaption(this.getXFormsTypeName(enveloppe, controlType)) +
|
||||
"' value.");
|
||||
alertElement.appendChild(xForm.createTextNode(alert.toString()));
|
||||
// Element alertElement = (Element)
|
||||
// formControl.appendChild(xForm.createElementNS(XFORMS_NS,
|
||||
// SchemaFormBuilder.XFORMS_NS_PREFIX + "alert"));
|
||||
// this.setXFormsId(alertElement);
|
||||
//
|
||||
// StringBuffer alert =
|
||||
// new StringBuffer("Please provide a valid value for '" + caption + "'.");
|
||||
//
|
||||
// Element enveloppe = xForm.getDocumentElement();
|
||||
// alert.append(" '" + caption +
|
||||
// "' is " + (o.minimum == 0 ? "an optional" : "a required") + " '" +
|
||||
// createCaption(this.getXFormsTypeName(enveloppe, controlType)) +
|
||||
// "' value.");
|
||||
// alertElement.appendChild(xForm.createTextNode(alert.toString()));
|
||||
return formControl;
|
||||
}
|
||||
|
||||
@@ -2898,11 +2900,13 @@ public abstract class AbstractSchemaFormBuilder implements SchemaFormBuilder {
|
||||
if (namespace != null && namespace.length() != 0)
|
||||
{
|
||||
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));
|
||||
int i=1;
|
||||
prefix = basePrefix;
|
||||
while (namespacePrefixes.containsValue(prefix)) {
|
||||
while (namespacePrefixes.containsValue(prefix))
|
||||
{
|
||||
prefix = basePrefix + (i++);
|
||||
}
|
||||
namespacePrefixes.put(namespace, prefix);
|
||||
|
@@ -445,6 +445,15 @@ dojo.declare("alfresco.xforms.Group",
|
||||
d.style.height = contentDiv.offsetHeight;
|
||||
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()
|
||||
{
|
||||
return false && this.parent != null;
|
||||
@@ -491,8 +500,8 @@ dojo.declare("alfresco.xforms.Repeat",
|
||||
var images = [
|
||||
{ src: "plus", action: this._insertRepeatItem_handler },
|
||||
{ src: "arrow_up", action: this._moveRepeatItemUp_handler },
|
||||
{ src: "arrow_down", action: null },
|
||||
{ src: "minus", action: null }
|
||||
{ src: "arrow_down", action: this._moveRepeatItemDown_handler },
|
||||
{ src: "minus", action: this._removeRepeatItem_handler }
|
||||
];
|
||||
for (var i in images)
|
||||
{
|
||||
@@ -505,20 +514,37 @@ dojo.declare("alfresco.xforms.Repeat",
|
||||
img.repeatItem = child;
|
||||
img.repeat = this;
|
||||
controls.appendChild(img);
|
||||
dojo.event.browser.addListener(img, "onclick", images[i].action);
|
||||
dojo.event.connect(img, "onclick", this, images[i].action);
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
removeChildAt: function(position)
|
||||
{
|
||||
this.inherited("removeChildAt", [ position ]);
|
||||
if (this.selectedIndex == position)
|
||||
this.handleIndexChanged(position);
|
||||
},
|
||||
_insertRepeatItem_handler: function(event)
|
||||
{
|
||||
alert("insert r=" + event.target.repeat.id +
|
||||
" item " + event.target.repeatItem.id);
|
||||
var trigger = _findElementById(this.node.parentNode,
|
||||
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)
|
||||
{
|
||||
alert("moveUp " + event);
|
||||
},
|
||||
_moveRepeatItemDown_handler: function(event)
|
||||
{
|
||||
alert("moveDown " + event);
|
||||
},
|
||||
setFocusedChild: function(child)
|
||||
{
|
||||
if (!child)
|
||||
@@ -535,7 +561,6 @@ dojo.declare("alfresco.xforms.Repeat",
|
||||
this.handleIndexChanged(0);
|
||||
// xforms repeat indexes are 1-based
|
||||
this.xform.setRepeatIndex(this.id, index + 1);
|
||||
|
||||
}
|
||||
},
|
||||
isIndented: function()
|
||||
@@ -552,7 +577,9 @@ dojo.declare("alfresco.xforms.Repeat",
|
||||
d.repeat = this;
|
||||
this.domNode.appendChild(d);
|
||||
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);
|
||||
});
|
||||
@@ -571,10 +598,14 @@ dojo.declare("alfresco.xforms.Repeat",
|
||||
addElement.style.top = "0px";
|
||||
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;
|
||||
repeat.xform.fireAction("trigger_0");
|
||||
var trigger = _findElementById(repeat.node.parentNode,
|
||||
repeat.id + "-insert_before");
|
||||
repeat.xform.fireAction(trigger.getAttribute("id"));
|
||||
});
|
||||
|
||||
return this.domNode;
|
||||
@@ -616,6 +647,11 @@ dojo.declare("alfresco.xforms.Repeat",
|
||||
var w = create_widget(this.xform, clonedPrototype);
|
||||
this.insertChildAt(w, position);
|
||||
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);
|
||||
|
||||
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];
|
||||
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 +
|
||||
" in clone " + dojo.dom.innerXML(clone));
|
||||
break;
|
||||
@@ -879,6 +901,18 @@ dojo.declare("alfresco.xforms.XForm",
|
||||
target.handleItemInserted(clone, position);
|
||||
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:
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user