Skip to content

Commit

Permalink
For #2437: dialog to prefix/suffix control names
Browse files Browse the repository at this point in the history
  • Loading branch information
ebruchez committed Oct 25, 2017
1 parent f8b1ccb commit 4412312
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 24 deletions.
Expand Up @@ -30,14 +30,18 @@
<xbl:handler event="fb-show-dialog" phase="target" defaultAction="cancel">
<xf:setvalue iterate="*[not(*)]" ref="."/> <!-- Clear all local values -->
<xf:setvalue ref="container-id" value="event('container-id')"/>
<xf:setvalue ref="action" value="event('action')"/>
<xxf:show dialog="dialog"/>
</xbl:handler>
<xbl:handler event="DOMActivate" observer="cancel-trigger" >
<xxf:hide dialog="dialog"/>
</xbl:handler>
<xbl:handler event="DOMActivate" observer="save-trigger prefix-input suffix-input" if="valid($i)">
<xf:action type="xpath">
fbf:containerMerge($i/container-id, string($i/prefix), string($i/suffix))
if ($i/action = 'merge') then
fbf:containerMerge($i/container-id, string($i/prefix), string($i/suffix))
else
fbf:pasteSectionGridFromClipboard(string($i/prefix), string($i/suffix))
</xf:action>
<xxf:hide dialog="dialog"/>
</xbl:handler>
Expand All @@ -52,6 +56,7 @@
<xf:instance id="i">
<local>
<container-id/>
<action/>
<prefix/>
<suffix/>
</local>
Expand Down Expand Up @@ -107,7 +112,15 @@
</xh:tr>
</xh:thead>
<xh:tbody>
<xf:repeat ref="if (valid($i)) then fbf:idsToRenameForMergingSectionTemplate($i/container-id, string($i/prefix), string($i/suffix)) else ()">
<xf:repeat
ref="
if (valid($i)) then
if ($i/action = 'merge') then
fbf:namesToRenameForMergingSectionTemplate($i/container-id, string($i/prefix), string($i/suffix))
else
fbf:namesToRenameForClipboard(string($i/prefix), string($i/suffix))
else
()">
<xh:tr class="{if (array:get(., 3)) then 'warning' else 'success'}">
<xh:td><xf:output value="array:get(., 1)"/></xh:td>
<xh:td><xf:output value="array:get(., 2)"/></xh:td>
Expand Down
Expand Up @@ -186,7 +186,7 @@ object FormBuilderRpcApiImpl extends FormBuilderRpcApi {
XFormsAPI.dispatch(
name = "fb-show-dialog",
targetId = "dialog-ids",
properties = Map("container-id" Some(containerId))
properties = Map("container-id" Some(containerId), "action" Some("merge"))
)
}

Expand Down
Expand Up @@ -14,7 +14,7 @@
package org.orbeon.oxf.fb

import org.orbeon.datatypes.MediatypeRange
import org.orbeon.oxf.fb.FormBuilder._
import org.orbeon.oxf.fb.FormBuilder.{containerById, _}
import org.orbeon.oxf.fr.FormRunner
import org.orbeon.oxf.fr.FormRunner.{controlNameFromId, createFormDataBasePath, createFormDefinitionBasePath, getControlName, putWithAttachments, _}
import org.orbeon.oxf.fr.NodeInfoCell._
Expand All @@ -30,6 +30,7 @@ import org.orbeon.oxf.xml.SaxonUtils
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 Expand Up @@ -175,8 +176,12 @@ object FormBuilderXPathApi {
// things around, otherwise if the XForms document is recreated new automatic ids
// are generated for objects without id.

debugDumpDocument("before")

FormBuilder.annotateGridsAndCells(ctx.bodyElem)

debugDumpDocument("after")

// 2. Select the first td if any
ctx.bodyElem descendant GridTest descendant CellTest take 1 foreach selectCell
}
Expand Down Expand Up @@ -507,14 +512,8 @@ object FormBuilderXPathApi {
FormRunner.findControlByNameOrEmpty(ctx.formDefinitionRootElem, controlName)
}

//@XPathFunction
def idsToRenameForMergingSectionTemplate(
containerId : String,
prefix : String,
suffix : String
): SequenceIterator = {
implicit val ctx = FormBuilderDocContext()
ToolboxOps.idsToRenameForMergingSectionTemplate(containerId, prefix, suffix).toList.flatten map {
private def renamingDetails(renamingDetails: Option[Seq[(String, String, Boolean)]]): List[ObjectValue] =
renamingDetails.toList.flatten map {
case (oldId, newId, isAutomaticId)
ArrayFunctions.createValue(
Vector(
Expand All @@ -524,6 +523,24 @@ object FormBuilderXPathApi {
)
)
}

//@XPathFunction
def namesToRenameForMergingSectionTemplate(
containerId : String,
prefix : String,
suffix : String
): SequenceIterator = {
implicit val ctx = FormBuilderDocContext()
renamingDetails(ToolboxOps.namesToRenameForMergingSectionTemplate(containerId, prefix, suffix))
}

//@XPathFunction
def namesToRenameForClipboard(
prefix : String,
suffix : String
): SequenceIterator = {
implicit val ctx = FormBuilderDocContext()
renamingDetails(ToolboxOps.namesToRenameForClipboard(prefix, suffix))
}

//@XPathFunction
Expand All @@ -535,4 +552,13 @@ object FormBuilderXPathApi {
implicit val ctx = FormBuilderDocContext()
ToolboxOps.containerMerge(containerId, prefix, suffix)
}

//@XPathFunction
def pasteSectionGridFromClipboard(
prefix : String,
suffix : String
): Unit = {
implicit val ctx = FormBuilderDocContext()
ToolboxOps.pasteSectionGridFromXcv(ToolboxOps.readXcvFromClipboard, prefix, suffix)
}
}
37 changes: 27 additions & 10 deletions form-builder/jvm/src/main/scala/org/orbeon/oxf/fb/ToolboxOps.scala
Expand Up @@ -471,6 +471,7 @@ object ToolboxOps {
deleteControlWithinCell(cellElem, updateTemplates = true)
}

// TODO: Return `Option[NodeInfo]`
def readXcvFromClipboard(implicit ctx: FormBuilderDocContext): NodeInfo = {
val clipboard = ctx.clipboardXcvRootElem
val clone = elementInfo("xcv", Nil)
Expand Down Expand Up @@ -504,17 +505,24 @@ object ToolboxOps {
xcv foreach (pasteSingleControlFromXcv(targetCellElem, _))
}

def idsToRenameForMergingSectionTemplate(
def namesToRenameForMergingSectionTemplate(
containerId : String,
prefix : String,
suffix : String)(implicit
ctx : FormBuilderDocContext
): Option[Seq[(String, String, Boolean)]] =
xcvFromSectionWithTemplate(containerId) map { xcvElem
idsToRenameForPaste(xcvElem, prefix, suffix)
namesToRenameForPaste(xcvElem, prefix, suffix)
}

def idsToRenameForPaste(
def namesToRenameForClipboard(
prefix : String,
suffix : String)(implicit
ctx : FormBuilderDocContext
): Option[Seq[(String, String, Boolean)]] =
Some(namesToRenameForPaste(readXcvFromClipboard, prefix, suffix))

private def namesToRenameForPaste(
xcvElem : NodeInfo,
prefix : String,
suffix : String)(implicit
Expand Down Expand Up @@ -542,7 +550,7 @@ object ToolboxOps {
val containerElem = containerById(containerId)

// Check this is a section template section
if (IsSection(containerElem) && (containerElem / * exists isSectionTemplateContent)) {
if (isSectionWithTemplateContent(containerElem)) {

val head = ctx.formDefinitionRootElem / XHHeadTest head

Expand Down Expand Up @@ -660,26 +668,35 @@ object ToolboxOps {
val xcvElem = readXcvFromClipboard
val controlElem = xcvElem / XcvEntry.Control.entryName / * head

if (IsGrid(controlElem) || IsSection(controlElem))
pasteSectionGridFromXcv(xcvElem, "", "")
else
if (IsGrid(controlElem) || IsSection(controlElem)) {

if (namesToRenameForPaste(xcvElem, "", "") forall (! _._3))
pasteSectionGridFromXcv(xcvElem, "", "")
else
XFormsAPI.dispatch(
name = "fb-show-dialog",
targetId = "dialog-ids",
properties = Map("container-id" Some(controlElem.id), "action" Some("paste"))
)
} else
pasteSingleControlFromXcv(targetCellElem, xcvElem)
}

private val ControlResourceNames = Set.empty ++ LHHAInOrder + "itemset"

private def pasteSectionGridFromXcv(
def pasteSectionGridFromXcv(
xcvElem : NodeInfo,
prefix : String,
suffix : String)(implicit
ctx : FormBuilderDocContext): Unit = {
ctx : FormBuilderDocContext
): Unit = {

val containerControlElem = xcvElem / XcvEntry.Control.entryName / * head

// Rename if needed
locally {

val oldToNewNames = idsToRenameForPaste(xcvElem, prefix, suffix) map (t (t._1, t._2)) toMap
val oldToNewNames = namesToRenameForPaste(xcvElem, prefix, suffix) map (t (t._1, t._2)) toMap

if (oldToNewNames.nonEmpty) {

Expand Down
Expand Up @@ -14,6 +14,7 @@
package org.orbeon.oxf.fr

import org.orbeon.dom.saxon.DocumentWrapper
import org.orbeon.oxf.fr.FormRunner.IsSection
import org.orbeon.oxf.fr.XMLNames._
import org.orbeon.oxf.util.CollectionUtils.collectByErasedType
import org.orbeon.oxf.xforms.control.XFormsComponentControl
Expand Down Expand Up @@ -65,8 +66,11 @@ trait FormRunnerContainerOps extends FormRunnerControlOps {
def controlRequiresNestedIterationElement(node: NodeInfo) =
isRepeat(node)

def isSectionTemplateContent(container: NodeInfo) =
(container parent * exists IsSection) && ComponentURI.findFirstIn(container.namespaceURI).nonEmpty
def isSectionWithTemplateContent(containerElem: NodeInfo): Boolean =
IsSection(containerElem) && (containerElem / * exists isSectionTemplateContent)

def isSectionTemplateContent(containerElem: NodeInfo): Boolean =
(containerElem parent * exists IsSection) && ComponentURI.findFirstIn(containerElem.namespaceURI).nonEmpty

def sectionTemplateBindingName(section: NodeInfo): Option[URIQualifiedName] =
section / * filter isSectionTemplateContent map (_.uriQualifiedName) headOption
Expand Down

0 comments on commit 4412312

Please sign in to comment.