Skip to content

Commit

Permalink
For #4195: place loads last
Browse files Browse the repository at this point in the history
  • Loading branch information
ebruchez committed Oct 1, 2019
1 parent bf0259f commit 5bb18a7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 22 deletions.
Expand Up @@ -361,6 +361,7 @@
<data type="string"/>
</element>
</zeroOrMore>
<!-- Only for `javascript:` loads -->
<zeroOrMore>
<element name="xxf:load">
<attribute name="resource"/>
Expand Down Expand Up @@ -429,6 +430,29 @@
</optional>
</element>
</optional>
<!-- Only for non-`javascript:` loads -->
<zeroOrMore>
<element name="xxf:load">
<attribute name="resource"/>
<attribute name="show">
<choice>
<value>replace</value>
<value>new</value>
</choice>
</attribute>
<optional>
<attribute name="target"/>
</optional>
<optional>
<attribute name="show-progress">
<choice>
<value>true</value>
<value>false</value>
</choice>
</attribute>
</optional>
</element>
</zeroOrMore>
</element>
<optional>
<element name="xxf:errors">
Expand Down
Expand Up @@ -116,7 +116,9 @@ object XFormsContainingDocumentSupport {

case class Message(message: String, level: String)

case class Load(resource: String, target: Option[String], urlType: UrlType, isReplace: Boolean, isShowProgress: Boolean)
case class Load(resource: String, target: Option[String], urlType: UrlType, isReplace: Boolean, isShowProgress: Boolean) {
def isJavaScript: Boolean = resource.trim.startsWith("javascript:")
}

abstract class XFormsContainingDocumentSupport(var disableUpdates: Boolean)
extends XBLContainer(
Expand Down
Expand Up @@ -215,7 +215,7 @@ object XFormsLoadAction {

// Force no progress indication if this is a JavaScript URL
val effectiveIsShowProgress =
if (externalURL.startsWith("javascript:"))
if (externalURL.trim.startsWith("javascript:"))
false
else
isShowProgress
Expand Down
Expand Up @@ -238,7 +238,7 @@ object ScriptBuilder {
dialogControl

val javascriptLoads =
containingDocument.getLoadsToRun.asScala filter (_.resource.startsWith("javascript:"))
containingDocument.getLoadsToRun.asScala filter (_.isJavaScript)

val mustRunAnyScripts =
errorsToShow.nonEmpty ||
Expand Down
Expand Up @@ -245,15 +245,16 @@ object XFormsServer {
if (messages.nonEmpty)
outputMessagesInfo(messages)

// Output loads
val loads = containingDocument.getLoadsToRun.asScala
if (loads.nonEmpty)
outputLoadsInfo(containingDocument, loads)
// `javascript:` loads only
outputLoadsInfo(
doc = containingDocument,
loads = containingDocument.getLoadsToRun.asScala filterNot (isPortletLoadMatch(containingDocument, _)) filter (_.isJavaScript)
)

// Output scripts
val scripts = containingDocument.getScriptsToRun.asScala
if (scripts.nonEmpty)
outputScriptInvocations(containingDocument, scripts)
outputScriptInvocations(
doc = containingDocument,
scriptInvocations = containingDocument.getScriptsToRun.asScala
)

// Output focus instruction
locally {
Expand Down Expand Up @@ -297,6 +298,11 @@ object XFormsServer {
NetUtils.getExternalContext.getResponse // would be better to pass this to `outputAjaxResponse`
)

// Non-`javascript:` loads only
outputLoadsInfo(
doc = containingDocument,
loads = containingDocument.getLoadsToRun.asScala filterNot (isPortletLoadMatch(containingDocument, _)) filterNot (_.isJavaScript)
)
}
}

Expand Down Expand Up @@ -459,11 +465,11 @@ object XFormsServer {
)

def outputLoadsInfo(
containingDocument : XFormsContainingDocument,
loads : Seq[Load])(implicit
xmlReceiver : XMLReceiver)
doc : XFormsContainingDocument,
loads : Seq[Load])(implicit
xmlReceiver : XMLReceiver)
: Unit =
for (load loads if ! isPortletLoadMatch(containingDocument, load))
for (load loads)
element(
localName = "load",
prefix = "xxf",
Expand All @@ -479,10 +485,8 @@ object XFormsServer {
doc : XFormsContainingDocument,
scriptInvocations : Seq[ScriptInvocation])(implicit
receiver : XMLReceiver
): Unit = {

for (script scriptInvocations) {

): Unit =
for (script scriptInvocations)
withElement(
"script",
prefix = "xxf",
Expand All @@ -504,8 +508,6 @@ object XFormsServer {
)
}
}
}
}

def outputFocusInfo(
containingDocument : XFormsContainingDocument,
Expand Down
Expand Up @@ -69,7 +69,7 @@ object XFormsToXHTML {
XFormsAPI.withContainingDocument(containingDocument) { // scope because dynamic properties can cause lazy XPath evaluations

val nonJavaScriptLoads =
containingDocument.getLoadsToRun.asScala filterNot (_.resource.startsWith("javascript:"))
containingDocument.getLoadsToRun.asScala filterNot (_.isJavaScript)

if (containingDocument.isGotSubmissionReplaceAll) {
// 1. Got a submission with replace="all"
Expand Down

0 comments on commit 5bb18a7

Please sign in to comment.