Skip to content

Commit

Permalink
For #4211: remove uses of index()
Browse files Browse the repository at this point in the history
  • Loading branch information
ebruchez committed Jan 23, 2020
1 parent c696dea commit 9668fee
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions form-runner/jvm/src/main/resources/xbl/orbeon/wizard/wizard.xbl
Expand Up @@ -132,6 +132,7 @@
<local>
<current-case-id/>
<current-top-level-case-id/>
<current-index/>
<show-toc/>
<show-body/>
<readwrite/>
Expand All @@ -142,10 +143,11 @@

<xf:var name="local" value="instance('local')"/>

<xf:bind ref="validate" xxf:default="Wizard:normalizeWizardMode(fr:component-param-value('validate'))"/>
<xf:bind ref="separate-toc" type="xs:boolean" xxf:default="Wizard:isWizardSeparateToc()"/>
<xf:bind ref="show-toc" type="xs:boolean" xxf:default="true()"/>
<xf:bind ref="show-body" type="xs:boolean" xxf:default="not(Wizard:isWizardSeparateToc())"/>
<xf:bind ref="validate" xxf:default="Wizard:normalizeWizardMode(fr:component-param-value('validate'))"/>
<xf:bind ref="separate-toc" type="xs:boolean" xxf:default="Wizard:isWizardSeparateToc()"/>
<xf:bind ref="current-index" type="xs:integer" xxf:default="1"/>
<xf:bind ref="show-toc" type="xs:boolean" xxf:default="true()"/>
<xf:bind ref="show-body" type="xs:boolean" xxf:default="not(Wizard:isWizardSeparateToc())"/>

<xf:instance id="available-top-level-sections" xxf:expose-xpath-types="true">
<available-top-level-sections/>
Expand Down Expand Up @@ -613,7 +615,7 @@
if ($current-section-uses-paging) then
let $section-id := Wizard:sectionIdFromCaseIdOpt($current-nav-case-id),
$repeat-id := concat($section-id, '-repeater-repeat'),
$current-index := index($repeat-id)
$current-index := xxf:instance('local')/current-index/data(.)
return
if ($current-index gt 1) then
($repeat-id, $current-index - 1)
Expand All @@ -629,8 +631,9 @@
if ($current-section-uses-paging) then
let $section-id := Wizard:sectionIdFromCaseIdOpt($current-nav-case-id),
$repeat-id := concat($section-id, '-repeater-repeat'),
$current-index := index($repeat-id),
$last-index := count(xxf:binding($section-id)/*)
$current-index := xxf:instance('local')/current-index/data(.),
$section-bind := bind(frf:bindId(frf:controlNameFromId($section-id))),
$last-index := count($section-bind/*)
return
if ($current-index lt $last-index) then
($repeat-id, $current-index + 1)
Expand Down Expand Up @@ -694,7 +697,6 @@
exists($next-nested-case-id-opt)
"/>


<xf:var
id="fr-wizard-is-first-nav"
name="is-first-nav"
Expand Down Expand Up @@ -789,6 +791,7 @@
<xh:ul class="nav nav-list" role="navigation">
<xsl:apply-templates mode="toc-sections"/>
</xh:ul>

<xh:div class="fr-wizard-navigation{{if (xxf:instance('local')/separate-toc/data(.)) then ' xforms-hidden' else ''}}">

<xf:action event="xforms-enabled" target="#observer">
Expand Down Expand Up @@ -878,19 +881,27 @@
<xf:action event="DOMActivate">
<xf:action if="$allow-prev">
<xf:action if="exists($prev-repeat-id-and-index-opt)">
<xf:var name="new-index" value="$prev-repeat-id-and-index-opt[2]"/>
<xf:setvalue
ref="xxf:instance('local')/current-index"
value="$new-index"/>
<xf:setindex
repeat="{{$prev-repeat-id-and-index-opt[1]}}"
index="$prev-repeat-id-and-index-opt[2]"/>
index="$new-index"/>
</xf:action>
<xf:action if="empty($prev-repeat-id-and-index-opt)">
<xf:var name="prev-case-id" value="$prev-nav-case-ids[last()]"/>
<xf:toggle
case="{{$prev-case-id}}"/>
<xf:action if="$prev-case-id = $sections-with-paging-case-ids">
<xf:var name="section-id" value="Wizard:sectionIdFromCaseIdOpt($prev-case-id)"/>
<xf:var name="new-index" value="count(xxf:binding($section-id)/*)"/>
<xf:setvalue
ref="xxf:instance('local')/current-index"
value="$new-index"/>
<xf:setindex
repeat="{{concat($section-id, '-repeater-repeat')}}"
index="count(xxf:binding($section-id)/*)"/>
index="$new-index"/>
</xf:action>
<xf:setfocus
control="{{$prev-case-id}}"
Expand Down Expand Up @@ -950,19 +961,27 @@
targetid="fr-wizard-visit-all-to-current"/>
<xf:action if="$allow-next">
<xf:action if="exists($next-repeat-id-and-index-opt)">
<xf:var name="new-index" value="$next-repeat-id-and-index-opt[2]"/>
<xf:setvalue
ref="xxf:instance('local')/current-index"
value="$new-index"/>
<xf:setindex
repeat="{{$next-repeat-id-and-index-opt[1]}}"
index="$next-repeat-id-and-index-opt[2]"/>
index="$new-index"/>
</xf:action>
<xf:action if="empty($next-repeat-id-and-index-opt)">
<xf:var name="next-case-id" value="$next-nav-case-ids[1]"/>
<xf:toggle
case="{{$next-case-id}}"/>
<xf:action if="$next-case-id = $sections-with-paging-case-ids">
<xf:var name="section-id" value="Wizard:sectionIdFromCaseIdOpt($next-case-id)"/>
<xf:var name="new-index" value="1"/>
<xf:setvalue
ref="xxf:instance('local')/current-index"
value="$new-index"/>
<xf:setindex
repeat="{{concat($section-id, '-repeater-repeat')}}"
index="1"/>
index="$new-index"/>
</xf:action>
<xf:setfocus
control="{{$next-case-id}}"
Expand All @@ -980,6 +999,7 @@
</xf:trigger>
</xh:li>
</xh:ul>

<!-- We put these here so that `$do-next-handler` has the right variables in scope -->
<!-- NOTE: This shouldn't be in the outer scope ideally. -->
<xf:group id="fr-wizard-update-validity" appearance="xxf:internal">
Expand Down Expand Up @@ -1127,13 +1147,13 @@
value="
not($separate-toc-mode) and
$current-top-level-case-id = '{$static-section-id}-case' and
xxf:repeat-position() = index('{$static-section-id}-repeater-repeat')"/>
xxf:repeat-position() = xxf:instance('local')/current-index/data(.)"/>
<xf:var
name="section-active"
value="
not($separate-toc-mode) and
$current-nav-case-id = '{$static-section-id}-case' and
xxf:repeat-position() = index('{$static-section-id}-repeater-repeat')"/>
xxf:repeat-position() = xxf:instance('local')/current-index/data(.)"/>
</xsl:when>
<xsl:otherwise>
<xf:var
Expand Down Expand Up @@ -1272,9 +1292,13 @@
case="'{$static-nav-section-id}-case'"/>

<xsl:if test="$use-paging">
<xf:var name="new-index" value="xxf:repeat-position()"/>
<xf:setvalue
ref="xxf:instance('local')/current-index"
value="$new-index"/>
<xf:setindex
repeat="{$static-section-id}-repeater-repeat"
index="xxf:repeat-position()"/>
index="$new-index"/>
</xsl:if>

<!-- ...and always focus on specific sub-section -->
Expand Down

0 comments on commit 9668fee

Please sign in to comment.