Skip to content

Commit

Permalink
For #2437: bug-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ebruchez committed Oct 25, 2017
1 parent 032b811 commit 43213a3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
23 changes: 13 additions & 10 deletions form-builder/jvm/src/main/scala/org/orbeon/oxf/fb/ControlOps.scala
Expand Up @@ -48,9 +48,11 @@ trait ControlOps extends SchemaOps with ResourcesOps {
private val MIPsToRewrite = Model.AllMIPs - Model.Type - Model.Required - Model.Whitespace
private val RewrittenMIPs = MIPsToRewrite map (mip mip QName.get(mip.name, XMLNames.FBPrefix, XMLNames.FB)) toMap

private val topLevelBindTemplate: NodeInfo =
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')"
xmlns:xf="http://www.w3.org/2002/xforms"/>
private val TopLevelBindTemplate: NodeInfo =
<xf:bind
id="fr-form-binds"
ref="instance('fr-form-instance')"
xmlns:xf="http://www.w3.org/2002/xforms"/>

// Find data holders (there can be more than one with repeats)
def findDataHolders(controlName: String)(implicit ctx: FormBuilderDocContext): List[NodeInfo] =
Expand Down Expand Up @@ -80,8 +82,8 @@ trait ControlOps extends SchemaOps with ResourcesOps {
// with a name (there might not be one).
val controlsWithName =
precedingSiblingOrSelfContainers(grid, includeSelf) flatMap {
case grid if grid attValueOpt "bind" isEmpty grid descendant CellTest child * filter hasName lastOption
case other Some(other)
case grid if ! grid.hasAtt("bind") grid descendant CellTest child * filter hasName lastOption
case other Some(other)
}

// Take the first result
Expand All @@ -99,7 +101,7 @@ trait ControlOps extends SchemaOps with ResourcesOps {
insert(
into = ctx.modelElem,
after = ctx.dataInstanceElem,
origin = topLevelBindTemplate
origin = TopLevelBindTemplate
).head
}

Expand All @@ -112,10 +114,11 @@ trait ControlOps extends SchemaOps with ResourcesOps {
case _

val newBind: Seq[NodeInfo] =
<xf:bind id={bindId(bindName)}
ref={bindName}
name={bindName}
xmlns:xf="http://www.w3.org/2002/xforms"/>
<xf:bind
id={bindId(bindName)}
ref={bindName}
name={bindName}
xmlns:xf="http://www.w3.org/2002/xforms"/>

insert(into = container, after = container / XFBindTest, origin = newBind).head
}
Expand Down
Expand Up @@ -15,9 +15,9 @@ package org.orbeon.oxf.fb

import org.orbeon.datatypes.MediatypeRange
import org.orbeon.oxf.fb.FormBuilder._
import org.orbeon.oxf.fr.{FormRunner, Names}
import org.orbeon.oxf.fr.NodeInfoCell._
import org.orbeon.oxf.fr.XMLNames.{FR, XF}
import org.orbeon.oxf.fr.{FormRunner, Names}
import org.orbeon.oxf.util.CoreUtils._
import org.orbeon.oxf.util.PathUtils.encodeSimpleQuery
import org.orbeon.oxf.util.StringUtils._
Expand All @@ -28,7 +28,6 @@ import org.orbeon.oxf.xml.{SaxonUtils, TransformerUtils}
import org.orbeon.saxon.ArrayFunctions
import org.orbeon.saxon.function.Property
import org.orbeon.saxon.om.{NodeInfo, SequenceIterator}
import org.orbeon.saxon.value.ObjectValue
import org.orbeon.scaxon.Implicits._
import org.orbeon.scaxon.NodeConversions._
import org.orbeon.scaxon.SimplePath._
Expand Down
32 changes: 17 additions & 15 deletions form-builder/jvm/src/main/scala/org/orbeon/oxf/fb/ToolboxOps.scala
Expand Up @@ -747,7 +747,10 @@ object ToolboxOps {
// Rename control names if needed
locally {

val oldToNewNames = namesToRenameForPaste(xcvElem, prefix, suffix) map (t (t._1, t._2)) toMap
val oldToNewNames =
namesToRenameForPaste(xcvElem, prefix, suffix) collect {
case (oldName, newName, _) if oldName != newName oldName newName
} toMap

if (oldToNewNames.nonEmpty) {

Expand Down Expand Up @@ -893,20 +896,19 @@ object ToolboxOps {
resourceHolders = resourceHolders,
precedingControlName = precedingContainerNameOpt
)

// Insert the bind element
val newBindOrNot = ensureBinds(findContainerNamesForModel(newContainerElem, includeSelf = true))

val newBindElem =
if (newContainerElem attValueOpt "bind" nonEmpty) {
// Element has a `bind` so the bind is newly-created
val result = insert(after = newBindOrNot, origin = xcvElem / XcvEntry.Bind.entryName / *)
delete(newBindOrNot)
result.head
} else {
// Element doesn't have a `bind` so the bind was already there
insert(into = newBindOrNot, origin = xcvElem / XcvEntry.Bind.entryName / *).head
}
val xcvBinds = xcvElem / XcvEntry.Bind.entryName / *

if (newContainerElem.hasAtt("bind")) {
// Insert the bind element for the container and descendants
val tmpBind = ensureBinds(findContainerNamesForModel(newContainerElem, includeSelf = true))
insert(after = tmpBind, origin = xcvBinds)
delete(tmpBind)
} else if (xcvBinds.nonEmpty) {
// There are descendant binds (case of an unbound non-repeated grid containing at least one control)
val tmpBind = ensureBinds(findContainerNamesForModel(newContainerElem, includeSelf = false) :+ getControlName(xcvBinds.head))
insert(after = tmpBind, origin = xcvBinds)
delete(tmpBind)
}

// Insert template for repeated grids/sections
(getControlNameOpt(containerControlElem).isDefined iterator containerControlElem) ++
Expand Down
Expand Up @@ -129,7 +129,7 @@ trait FormRunnerContainerOps extends FormRunnerControlOps {
// Repeated sections add an intermediary iteration element
val namesFromLeaf =
namesWithContainers flatMap {
case (name, container)
case (name, _)
findRepeatIterationName(descendant, name).toList ::: name :: Nil
}

Expand Down
1 change: 1 addition & 0 deletions src/main/scala/org/orbeon/scaxon/SimplePath.scala
Expand Up @@ -156,6 +156,7 @@ object SimplePath {
def attClasses = attTokens("class")
def id = attValue("id")
def hasId = att("id").nonEmpty && attValue("id").trimAllToEmpty != ""
def hasAtt(attName: String) = att(attName).nonEmpty

def attValueOpt(attName: String) = /@(attName) match {
case Seq() None
Expand Down

0 comments on commit 43213a3

Please sign in to comment.