Skip to content

Commit

Permalink
For #4117: Form Builder UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ebruchez committed Aug 21, 2019
1 parent cc01dd0 commit b665c7a
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 43 deletions.
Expand Up @@ -623,6 +623,9 @@
<label>Explanatory Text</label>
<hint/>
</control-text>
<control-iteration-label>
<label>Iteration Label</label>
</control-iteration-label>
<alert>
<label>Alert Message</label>
<hint>Displayed when the alert is active</hint>
Expand Down Expand Up @@ -1826,6 +1829,9 @@
<label>Text explicatif</label>
<hint/>
</control-text>
<control-iteration-label>
<label>Libellé des itérations</label>
</control-iteration-label>
<alert>
<label>Message d'alerte</label>
<hint>Affiché lorsque l'alerte est active</hint>
Expand Down Expand Up @@ -3013,6 +3019,9 @@
<label todo="true">[Explanatory Text]</label>
<hint/>
</control-text>
<control-iteration-label>
<label todo="true">Iteration Label</label>
</control-iteration-label>
<alert>
<label todo="true">[Feilmelding]</label>
<hint todo="true">[Melding som skal vises når kontrolldata mangler eller er galt]</hint>
Expand Down Expand Up @@ -4226,6 +4235,9 @@
<label todo="true">[Explanatory Text]</label>
<hint/>
</control-text>
<control-iteration-label>
<label todo="true">Iteration Label</label>
</control-iteration-label>
<alert>
<label todo="true">[Сообщение об ошибке]</label>
<hint todo="true">[Сообщение, которое будет показано, если введенное значение некорректно]</hint>
Expand Down Expand Up @@ -5440,6 +5452,9 @@
<label todo="true">[Explanatory Text]</label>
<hint/>
</control-text>
<control-iteration-label>
<label todo="true">Iteration Label</label>
</control-iteration-label>
<alert>
<label>Messaggio di avviso</label>
<hint>Visualizzato quando l'avviso é attivo</hint>
Expand Down Expand Up @@ -6646,6 +6661,9 @@
<label todo="true">[Explanatory Text]</label>
<hint/>
</control-text>
<control-iteration-label>
<label todo="true">Iteration Label</label>
</control-iteration-label>
<alert>
<label>Warnmeldung</label>
<hint>Wird angezeigt, falls die Warnungen aktiviert wurden</hint>
Expand Down Expand Up @@ -7855,6 +7873,9 @@
<label todo="true">[Explanatory Text]</label>
<hint/>
</control-text>
<control-iteration-label>
<label todo="true">Iteration Label</label>
</control-iteration-label>
<alert>
<label>Virheviesti</label>
<hint>Viesti näytetään, kun kontrollidata on väärää tai puuttuu</hint>
Expand Down Expand Up @@ -9061,6 +9082,9 @@
<label todo="true">[Explanatory Text]</label>
<hint/>
</control-text>
<control-iteration-label>
<label todo="true">Iteration Label</label>
</control-iteration-label>
<alert>
<label>Mensaje de Alerta</label>
<hint>Se muestra cuando se activa la alerta</hint>
Expand Down Expand Up @@ -10268,6 +10292,9 @@
<label todo="true">[Explanatory Text]</label>
<hint/>
</control-text>
<control-iteration-label>
<label todo="true">Iteration Label</label>
</control-iteration-label>
<alert>
<label>Waarschuwingsmelding</label>
<hint>Wordt getoond zolang de waarschuwing actief is</hint>
Expand Down Expand Up @@ -11454,6 +11481,9 @@
<label todo="true">[Explanatory Text]</label>
<hint/>
</control-text>
<control-iteration-label>
<label todo="true">Iteration Label</label>
</control-iteration-label>
<alert>
<label>Mensagem de Alerta</label>
<hint>DÉ mostrada quando o alerta está activo</hint>
Expand Down Expand Up @@ -12667,6 +12697,9 @@
<label todo="true">[Explanatory Text]</label>
<hint/>
</control-text>
<control-iteration-label>
<label todo="true">Iteration Label</label>
</control-iteration-label>
<alert>
<label>Avisering</label>
<hint>Visas när avisering är aktiv</hint>
Expand Down
Expand Up @@ -32,7 +32,6 @@

<!-- Clear all local values -->
<xf:setvalue iterate="$i//*[not(*)] | $i/*//@*" ref="."/>
<xf:delete ref="$i/(label, help)/fr:param"/>

<xf:var name="control" value="event('container')"/>

Expand Down Expand Up @@ -89,21 +88,34 @@
<xf:insert context="$i" origin="frf:findBindByNameOrEmpty($form, $i/control-name)/namespace::node()"/>

<!-- Read Label/Help if we are a section -->
<xf:action iterate="$i/(label, help)[$i/container-type = 'section']">
<xf:action iterate="$i/(label, help, iteration-label)">

<xf:var name="lhh" value="local-name()"/>
<xf:delete ref="fr:param"/>

<xf:setvalue
ref="value"
value="fbf:getControlLhhOrEmpty($i/control-name, $lhh)"/>
ref="@supported"
value="$i/container-type = 'section'"/>

<xf:setvalue
ref="@isHTML"
value="if (fbf:isControlLhhatHtmlMediatype($i/control-name, $lhh)) then 'true' else ''"/>
value="false()"/>

<xf:insert
ref="value"
origin="fbf:getControlLhhtParams($i/control-name, $lhh)"/>
<xf:action if="@supported = 'true'">

<xf:var name="lhh" value="local-name()"/>

<xf:setvalue
ref="value"
value="fbf:getControlLhhOrEmpty($i/control-name, $lhh)"/>

<xf:setvalue
ref="@isHTML"
value="if (fbf:isControlLhhatHtmlMediatype($i/control-name, $lhh)) then 'true' else ''"/>

<xf:insert
ref="value"
origin="fbf:getControlLhhtParams($i/control-name, $lhh)"/>
</xf:action>

</xf:action>

Expand Down Expand Up @@ -188,7 +200,7 @@
$i/apply-defaults = true(),
if ($i/initial-iterations = true()) then 'first' else ''
),
for $lh in $i/(label, help)[$i/container-type = 'section'] return
for $lh in $i/(label, help, iteration-label)[@supported = 'true'] return
fbf:setControlLabelHintHelpOrText(
$i/control-name,
local-name($lh),
Expand Down Expand Up @@ -314,14 +326,18 @@

<save-button/>

<label isHTML="">
<label isHTML="" supported="">
<value/>
<!--<fr:param/>-->
</label>
<help isHTML="">
<help isHTML="" supported="">
<value/>
<!--<fr:param/>-->
</help>
<iteration-label isHTML="" supported="">
<value/>
<!--<fr:param/>-->
</iteration-label>

<prev-control-id/>
<next-control-id/>
Expand Down Expand Up @@ -446,8 +462,14 @@
readonly="xxf:is-blank()"/>

<xf:bind
ref="label | help"
readonly="$i/container-type = 'grid'"/>
ref="label | help | iteration-label"
readonly="not(@supported = 'true')"/>

<!-- We could do this but the issue is that things will look inconsistent when switching between repeated and
non-repeated in the settings until the changes are saved. -->
<!-- <xf:bind-->
<!-- ref="iteration-label"-->
<!-- readonly="../is-repeat = false()"/>-->

<xf:bind
ref="(label | help)/value"
Expand Down Expand Up @@ -688,7 +710,7 @@
</xf:group>
</fr:tab>

<fr:tab id="label-help-tab" ref="label, help">
<fr:tab id="label-help-tab" ref="(label, help, iteration-label)[true() or @supported = 'true']">
<fr:label
ref="
$resources/dialog-control-details/*[
Expand Down
Expand Up @@ -27,7 +27,7 @@ import org.orbeon.oxf.xforms.analysis.controls.LHHAAnalysis._
import org.orbeon.oxf.xforms.analysis.model.Model._
import org.orbeon.oxf.xforms.analysis.model.ValidationLevel._
import org.orbeon.oxf.xforms.analysis.model.{Model, ValidationLevel}
import org.orbeon.oxf.xforms.function.xxforms.{ExcludedDatesValidation, UploadMediatypesValidation, ValidationFunction}
import org.orbeon.oxf.xforms.function.xxforms.{ExcludedDatesValidation, UploadMediatypesValidation}
import org.orbeon.oxf.xforms.xbl.BindingDescriptor
import org.orbeon.oxf.xml.SaxonUtils.parseQName
import org.orbeon.oxf.xml.{XMLConstants, XMLUtils}
Expand Down Expand Up @@ -227,7 +227,7 @@ trait AlertsAndConstraintsOps extends ControlOps {
val newAlertElements =
ensureCleanLHHAElements(
controlName = controlName,
lhha = LHHA.Alert,
lhhaName = LHHA.Alert.entryName,
count = alertsWithResources.size,
replace = true
)
Expand All @@ -241,7 +241,7 @@ trait AlertsAndConstraintsOps extends ControlOps {

// Write global default alert if needed
if (defaultAlert.global) {
val newGlobalAlert = ensureCleanLHHAElements(controlName, LHHA.Alert, count = 1, replace = false).head
val newGlobalAlert = ensureCleanLHHAElements(controlName, LHHA.Alert.entryName, count = 1, replace = false).head
setvalue(newGlobalAlert /@ "ref", OldStandardAlertRef)
}
}
Expand Down
31 changes: 20 additions & 11 deletions form-builder/jvm/src/main/scala/org/orbeon/oxf/fb/ControlOps.scala
Expand Up @@ -54,7 +54,18 @@ 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(mip.name, XMLNames.FBPrefix, XMLNames.FB)) toMap
private val PossibleResourcePointerNames: Set[String] = (LHHA.values map (_.entryName)).to[Set] + "itemset" + "text"

private val FRResourceElemLocalNamesToQNames = List(FRTextQName, FRIterationLabelQName) map (v v.localName v) toMap

private val PossibleResourcePointerNames: Set[String] =
(LHHA.values map (_.entryName)).to[Set] ++
FRResourceElemLocalNamesToQNames.keys +
"itemset"

private def controlLHHATQName(lhhaName: String): QName =
FRResourceElemLocalNamesToQNames.get(lhhaName) orElse
(LHHA.withNameOption(lhhaName) map LHHA.QNameForValue) getOrElse
(throw new IllegalArgumentException(lhhaName))

private val TopLevelBindTemplate: NodeInfo =
<xf:bind
Expand Down Expand Up @@ -605,7 +616,7 @@ trait ControlOps extends SchemaOps with ResourcesOps {
}

def lhhatChildrenParams(lhhatNodes: Seq[NodeInfo]): Seq[NodeInfo] =
lhhatNodes child (FR "param")
lhhatNodes child FRParamQName

private def setControlLHHATParams(
controlName : String,
Expand Down Expand Up @@ -649,8 +660,8 @@ trait ControlOps extends SchemaOps with ResourcesOps {
}

// Find a control's LHHAT (there can be more than one for alerts)
def getControlLhhat(controlName: String, lhha: String)(implicit ctx: FormBuilderDocContext): Seq[NodeInfo] =
findControlByName(ctx.formDefinitionRootElem, controlName).toList child ((if (lhha == "text") FR else XF) lhha)
def getControlLhhat(controlName: String, lhhaName: String)(implicit ctx: FormBuilderDocContext): Seq[NodeInfo] =
findControlByName(ctx.formDefinitionRootElem, controlName).toList child controlLHHATQName(lhhaName)

// For a given control and LHHAT type, whether the mediatype on the LHHAT is HTML
def isControlLhhatHtmlMediatype(controlName: String, lhha: String)(implicit ctx: FormBuilderDocContext): Boolean =
Expand Down Expand Up @@ -681,21 +692,19 @@ trait ControlOps extends SchemaOps with ResourcesOps {

def ensureCleanLHHAElements(
controlName : String,
lhha : LHHA,
lhhaName : String,
count : Int,
replace : Boolean)(implicit
ctx : FormBuilderDocContext
): Seq[NodeInfo] = {

val inDoc = ctx.formDefinitionRootElem

val lhhaName = lhha.entryName

val control = findControlByName(inDoc, controlName).get
val existing = getControlLhhat(controlName, lhhaName)
val params = lhhatChildrenParams(existing)

val lhhaQName = LHHA.QNameForValue(lhha)
val lhhaQName = controlLHHATQName(lhhaName)

if (replace)
delete(existing)
Expand Down Expand Up @@ -732,14 +741,14 @@ trait ControlOps extends SchemaOps with ResourcesOps {

def removeLHHAElementAndResources(
controlName : String,
lhha : LHHA)(implicit
lhhaName : String)(implicit
ctx : FormBuilderDocContext
): Seq[NodeInfo] = {

val control = findControlByName(ctx.formDefinitionRootElem, controlName).get

val removedHolders = delete(lhhaHoldersForAllLangsUseDoc(controlName, lhha.entryName))
val removedLHHA = delete(control child LHHA.QNameForValue(lhha))
val removedHolders = delete(lhhaHoldersForAllLangsUseDoc(controlName, lhhaName))
val removedLHHA = delete(control child controlLHHATQName(lhhaName))

removedHolders ++ removedLHHA
}
Expand Down
Expand Up @@ -167,14 +167,18 @@ object FormBuilderXPathApi {

implicit val ctx = FormBuilderDocContext()

// Make sure the `xf:help` element is there while we set content or attributes.
if (lhht == "help")
FormBuilder.ensureCleanLHHAElements(controlName, LHHA.Help, count = 1, replace = true)
val isOptionalLHHAT =
lhht == LHHA.Help.entryName || lhht == fr.XMLNames.FRIterationLabelQName.localName

// Make sure an optional element is present while we set content or attributes
if (isOptionalLHHAT)
FormBuilder.ensureCleanLHHAElements(controlName, lhht, count = 1, replace = true)

FormBuilder.setControlLabelHintHelpOrText(controlName, lhht, value, Some(params), isHTML)

if (lhht == "help" && hasBlankOrMissingLHHAForAllLangsUseDoc(controlName, LHHA.Help))
FormBuilder.removeLHHAElementAndResources(controlName, LHHA.Help)
// If an optional element turns out to be empty, then remove it
if (isOptionalLHHAT && hasBlankOrMissingLHHAForAllLangsUseDoc(controlName, lhht))
FormBuilder.removeLHHAElementAndResources(controlName, lhht)
}

// Set the control's items for all languages
Expand Down Expand Up @@ -280,7 +284,7 @@ object FormBuilderXPathApi {

val allUnneededHolders =
allHelpElements collect {
case (lhhaElement, controlName) if hasBlankOrMissingLHHAForAllLangsUseDoc(controlName, lhha)
case (lhhaElement, controlName) if hasBlankOrMissingLHHAForAllLangsUseDoc(controlName, lhha.entryName)
lhhaHoldersForAllLangsUseDoc(controlName, lhha.entryName) :+ lhhaElement
}

Expand Down
Expand Up @@ -266,28 +266,28 @@ trait ResourcesOps extends BaseOps {

def lhhaHoldersForAllLangsUseDoc(
controlName : String,
lhha : String)(implicit
lhhaName : String)(implicit
ctx : FormBuilderDocContext
): Seq[NodeInfo] =
for {
(_, controlHolder) findResourceHoldersWithLangUseDoc(ctx.formDefinitionRootElem, controlName)
lhhaHolder controlHolder child lhha
lhhaHolder controlHolder child lhhaName
} yield
lhhaHolder

// NOTE: Also return `false` if there are any children `fr:param`.
def hasBlankOrMissingLHHAForAllLangsUseDoc(
controlName : String,
lhha : LHHA)(implicit
lhhaName : String)(implicit
ctx : FormBuilderDocContext
): Boolean = {

val hasParams =
FormBuilder.lhhatChildrenParams(FormBuilder.getControlLhhat(controlName, lhha.entryName)).nonEmpty
FormBuilder.lhhatChildrenParams(FormBuilder.getControlLhhat(controlName, lhhaName)).nonEmpty

! hasParams && {
findResourceHoldersWithLangUseDoc(ctx.formDefinitionRootElem, controlName) forall
{ case (_, holder) (holder child lhha.entryName stringValue).isBlank }
{ case (_, holder) (holder child lhhaName stringValue).isBlank }
}
}
}

0 comments on commit b665c7a

Please sign in to comment.