Review Mode

  • 2 replies.
  • This is not yet resolved.
  • This question was started by Lawrence Spear.
  • Last post by Carl.
Lawrence Spear
user
July 2nd 2010
How do I configure Xopus so the user can only add one element and edit the text in that element?

The following sorta works:

function doLoad(evt)
{
//get the XML document that has been loaded
var doc = evt.document;
//attach an event to the document, listening to when element have been inserted
//doc.addEventListener("XopusBeforeSubtreeModified", doNothing);
doc.addEventListener("XopusBeforeNodeValueModified", doNothing);
doc.addEventListener("XopusBeforeChildInserted", doNothingChildNode);
}

function doNothing(evt) {
if (evt.target.getNodeName() == "reviewer.note" || evt.target.getParentNode().getNodeName() == "reviewer.note") {

}
else {
evt.cancelEvent = true;
}
}

function doNothingChildNode(evt) {
if (evt.childNode.getNodeName() != "reviewer.note") {
evt.cancelEvent = true;
}
}

But when I try to insert the reviewer.note, it doesn't let me type in the newly created element. How do I get it to let text nodes inside reviewer.notes to be added?
Lawrence Spear
user
July 2nd 2010

I knew it

I knew as soon as I posted my question I'd figure it out. Here's the roughed in code that gets it to work:

function doLoad(evt)
{
//get the XML document that has been loaded
var doc = evt.document;
//attach an event to the document, listening to when element have been inserted
//doc.addEventListener("XopusBeforeSubtreeModified", doNothing);
doc.addEventListener("XopusBeforeNodeValueModified", doNothing);
doc.addEventListener("XopusBeforeChildInserted", doNothingChildNode);
doc.addEventListener("XopusBeforeNodeSplit", doNothingSplitNode);
}

function doNothing(evt) {
if (evt.target.getNodeName() == "reviewer.note" || evt.target.getParentNode().getNodeName() == "reviewer.note") {

}
else {
evt.cancelEvent = true;
}
}

function doNothingChildNode(evt) {
if (evt.childNode.getNodeName() == "reviewer.note" || evt.target.getNodeName() == "reviewer.note") {

}
else {
evt.cancelEvent = true;
}
}

function doNothingSplitNode(evt) {
if (evt.target.getNodeName() == "reviewer.note" || evt.target.getParentNode().getNodeName() == "reviewer.note") {

}
else {
evt.cancelEvent = true;
}
}

Now I guess my question is... Is there a cleaner way than this?
Carl
Xopus Team
July 2nd 2010
I'd say that this is pretty clean. We wouldn't build it very differently ourselves.

Other options you have are to use the XSL and string() to confuse Xopus about where the contents came from, but this would not prevent splits, or inserts of other elements.

A stronger way of preventing anything from happening is to use " throw new Editor.RevertingException(); ", as this will also revert anything that might have happened before you canceled the event. I am not sure you need it.

React

HTML will be shown as HTML code.
Linebreaks and Links starting with http:// are automatically resolved