Skip to content

Commit 5df9317

Browse files
committed
Unified form response callbacks
1 parent 938d687 commit 5df9317

2 files changed

Lines changed: 20 additions & 45 deletions

File tree

  • src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/client

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/client/block/query.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ exclude-result-prefixes="#all"
400400
ixsl:http-request($context('request')) (: Step 1: send initial request :)
401401
=> ixsl:then(ldh:rethread-response($context, ?)) (: Step 2: attach response to context :)
402402
=> ixsl:then(ldh:handle-response#1) (: Step 3: handle 429s, etc. :)
403-
=> ixsl:then(ldh:row-form-patch-response#1)
403+
=> ixsl:then(ldh:row-form-response#1)
404404
"/>
405405
</xsl:template>
406406

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/client/form.xsl

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,21 @@ WHERE
575575
<ixsl:set-style name="cursor" select="'default'" object="ixsl:page()//body"/>
576576
</xsl:template>
577577

578-
<!-- submit instance creation row-form using POST or modal form using PUT -->
578+
<!-- submit instance creation modal form using PUT -->
579+
580+
<xsl:template match="div[contains-token(@class, 'modal-constructor')]//form[contains-token(@class, 'form-horizontal')][upper-case(@method) = 'PUT']" mode="ixsl:onsubmit" priority="2">
581+
<xsl:next-match>
582+
<xsl:with-param name="callback" select="ldh:modal-form-response#1"/>
583+
</xsl:next-match>
584+
</xsl:template>
585+
586+
<!-- submit instance creation row-form using POST -->
579587

580588
<xsl:template match="form[ancestor::div[@typeof]][contains-token(@class, 'form-horizontal')]" mode="ixsl:onsubmit">
581589
<xsl:param name="block" select="ancestor::div[@typeof][1]" as="element()"/> <!-- block has no @about at this stage (before saving it) -->
582590
<xsl:param name="form" select="." as="element()"/>
583591
<xsl:param name="method" select="upper-case(@method)" as="xs:string"/>
592+
<xsl:param name="callback" select="ldh:row-form-response#1" as="function(map(*)) as item()*"/>
584593
<xsl:param name="elements" select=".//input | .//textarea | .//select" as="element()*"/>
585594
<xsl:param name="triples" select="ldh:parse-rdf-post($elements)" as="element()*"/>
586595
<xsl:param name="resources" as="document-node()">
@@ -592,7 +601,6 @@ WHERE
592601
</xsl:param>
593602
<xsl:param name="request-body" select="$resources" as="document-node()"/>
594603
<xsl:sequence select="ixsl:call(ixsl:event(), 'preventDefault', [])"/>
595-
<xsl:variable name="modal" select="exists(ancestor::div[contains-token(@class, 'modal-constructor')])" as="xs:boolean"/>
596604
<xsl:variable name="id" select="ixsl:get($form, 'id')" as="xs:string"/>
597605
<xsl:variable name="action" select="ixsl:get($form, 'action')" as="xs:anyURI"/>
598606
<xsl:variable name="enctype" select="ixsl:get($form, 'enctype')" as="xs:string"/>
@@ -631,15 +639,14 @@ WHERE
631639
'doc-uri': $doc-uri,
632640
'block': $block,
633641
'form': $form,
634-
'modal': $modal,
635642
'resources': $resources
636643
}"/>
637644

638645
<ixsl:promise select="
639646
ixsl:http-request($context('request')) (: Step 1: send initial request :)
640647
=> ixsl:then(ldh:rethread-response($context, ?)) (: Step 2: attach response to context :)
641648
=> ixsl:then(ldh:handle-response#1) (: Step 3: handle 429s, etc. :)
642-
=> ixsl:then(ldh:form-horizontal-response#1)
649+
=> ixsl:then($callback)
643650
" on-failure="ldh:promise-failure#1"/>
644651
</xsl:otherwise>
645652
</xsl:choose>
@@ -652,7 +659,6 @@ WHERE
652659
<xsl:sequence select="ixsl:call(ixsl:event(), 'preventDefault', [])"/>
653660
<xsl:variable name="form" select="." as="element()"/>
654661
<xsl:variable name="method" select="upper-case(@method)" as="xs:string"/>
655-
<xsl:variable name="modal" select="false()" as="xs:boolean"/>
656662
<xsl:variable name="id" select="ixsl:get($form, 'id')" as="xs:string"/>
657663
<xsl:variable name="action" select="ixsl:get($form, 'action')" as="xs:anyURI"/>
658664
<xsl:variable name="enctype" select="ixsl:get($form, 'enctype')" as="xs:string"/>
@@ -754,25 +760,23 @@ WHERE
754760
'doc-uri': ac:absolute-path(ldh:base-uri(.)),
755761
'block': $block,
756762
'form': $form,
757-
'modal': $modal,
758763
'resources': $resources
759764
}"/>
760765
<ixsl:promise select="
761766
ixsl:http-request($context('request')) (: Step 1: send initial request :)
762767
=> ixsl:then(ldh:rethread-response($context, ?)) (: Step 2: attach response to context :)
763768
=> ixsl:then(ldh:handle-response#1) (: Step 3: handle 429s, etc. :)
764-
=> ixsl:then(ldh:modal-form-patch-response#1)
769+
=> ixsl:then(ldh:modal-form-response#1)
765770
" on-failure="ldh:promise-failure#1"/>
766771
</xsl:template>
767772

768-
<!-- submit instance update block-form using PATCH -->
773+
<!-- submit instance update row-form using PATCH -->
769774

770775
<xsl:template match="div[contains-token(@class, 'block')]//form[contains-token(@class, 'form-horizontal')][upper-case(@method) = 'PATCH']" mode="ixsl:onsubmit" priority="1">
771776
<xsl:param name="block" select="ancestor::div[contains-token(@class, 'block')][1]" as="element()"/>
772777
<xsl:sequence select="ixsl:call(ixsl:event(), 'preventDefault', [])"/>
773778
<xsl:variable name="form" select="." as="element()"/>
774779
<xsl:variable name="method" select="upper-case(@method)" as="xs:string"/>
775-
<xsl:variable name="modal" select="false()" as="xs:boolean"/>
776780
<xsl:variable name="id" select="ixsl:get($form, 'id')" as="xs:string"/>
777781
<xsl:variable name="action" select="ixsl:get($form, 'action')" as="xs:anyURI"/>
778782
<xsl:variable name="enctype" select="ixsl:get($form, 'enctype')" as="xs:string"/>
@@ -808,14 +812,13 @@ WHERE
808812
'doc-uri': ac:absolute-path(ldh:base-uri(.)),
809813
'block': $block,
810814
'form': $form,
811-
'modal': $modal,
812815
'resources': $resources
813816
}"/>
814817
<ixsl:promise select="
815818
ixsl:http-request($context('request')) (: Step 1: send initial request :)
816819
=> ixsl:then(ldh:rethread-response($context, ?)) (: Step 2: attach response to context :)
817820
=> ixsl:then(ldh:handle-response#1) (: Step 3: handle 429s, etc. :)
818-
=> ixsl:then(ldh:row-form-patch-response#1)
821+
=> ixsl:then(ldh:row-form-response#1)
819822
" on-failure="ldh:promise-failure#1"/>
820823
</xsl:template>
821824

@@ -881,35 +884,13 @@ WHERE
881884
<ixsl:set-style name="cursor" select="'default'" object="ixsl:page()//body"/>
882885
</xsl:template>
883886

884-
<xsl:function name="ldh:modal-form-patch-response" ixsl:updating="yes">
885-
<xsl:param name="context" as="map(*)"/>
886-
887-
<xsl:message>ldh:modal-form-patch-response</xsl:message>
888-
889-
<xsl:variable name="response" select="$context('response')" as="map(*)"/>
890-
<xsl:variable name="status" select="$response?status" as="xs:double"/>
891-
<xsl:variable name="media-type" select="$response?media-type" as="xs:string?"/>
892-
893-
<xsl:choose>
894-
<xsl:when test="$status = (200, 204)">
895-
<xsl:sequence select="ldh:modal-form-submit-success($context)"/>
896-
</xsl:when>
897-
<xsl:when test="$status = (400, 422) and starts-with($media-type, 'application/rdf+xml')">
898-
<xsl:sequence select="ldh:modal-form-submit-violation($context)"/>
899-
</xsl:when>
900-
<xsl:otherwise>
901-
<xsl:sequence select="ldh:error-response-alert($context)"/>
902-
</xsl:otherwise>
903-
</xsl:choose>
904-
</xsl:function>
905-
906-
<xsl:function name="ldh:row-form-patch-response" ixsl:updating="yes">
887+
<xsl:function name="ldh:row-form-response" ixsl:updating="yes">
907888
<xsl:param name="context" as="map(*)"/>
908889
<xsl:variable name="response" select="$context('response')" as="map(*)"/>
909890
<xsl:variable name="status" select="$response?status" as="xs:double"/>
910891
<xsl:variable name="media-type" select="$response?media-type" as="xs:string?"/>
911892

912-
<xsl:message>ldh:row-form-patch-response</xsl:message>
893+
<xsl:message>ldh:row-form-response</xsl:message>
913894

914895
<xsl:choose>
915896
<xsl:when test="$status = (200, 204)">
@@ -924,14 +905,13 @@ WHERE
924905
</xsl:choose>
925906
</xsl:function>
926907

927-
<xsl:function name="ldh:form-horizontal-response" ixsl:updating="yes">
908+
<xsl:function name="ldh:modal-form-response" ixsl:updating="yes">
928909
<xsl:param name="context" as="map(*)"/>
929910
<xsl:variable name="response" select="$context('response')" as="map(*)"/>
930911
<xsl:variable name="status" select="$response?status" as="xs:double"/>
931912
<xsl:variable name="media-type" select="$response?media-type" as="xs:string?"/>
932-
<xsl:variable name="modal" select="map:get($context, 'modal')" as="xs:boolean"/>
933913

934-
<xsl:message>ldh:form-horizontal-response</xsl:message>
914+
<xsl:message>ldh:modal-form-response</xsl:message>
935915

936916
<xsl:choose>
937917
<xsl:when test="$status = (200, 204)">
@@ -955,7 +935,6 @@ WHERE
955935
<xsl:variable name="doc-uri" select="$context('doc-uri')" as="xs:anyURI"/>
956936
<xsl:variable name="block" select="$context('block')" as="element()"/>
957937
<xsl:variable name="form" select="$context('form')" as="element()?"/>
958-
<xsl:variable name="modal" select="$context('modal')" as="xs:boolean"/>
959938
<xsl:variable name="resources" select="$context('resources')" as="document-node()"/>
960939

961940
<xsl:message>ldh:form-horizontal-submit-success</xsl:message>
@@ -1052,8 +1031,6 @@ WHERE
10521031
<xsl:variable name="doc-uri" select="$context('doc-uri')" as="xs:anyURI"/>
10531032
<xsl:variable name="block" select="$context('block')" as="element()"/>
10541033
<xsl:variable name="form" select="$context('form')" as="element()?"/>
1055-
<xsl:variable name="modal" select="$context('modal')" as="xs:boolean"/>
1056-
<!-- <xsl:variable name="resources" select="$context('resources')" as="document-node()"/>-->
10571034

10581035
<xsl:message>ldh:modal-form-submit-violation</xsl:message>
10591036

@@ -1140,8 +1117,6 @@ WHERE
11401117
<xsl:variable name="doc-uri" select="$context('doc-uri')" as="xs:anyURI"/>
11411118
<xsl:variable name="block" select="$context('block')" as="element()"/>
11421119
<xsl:variable name="form" select="$context('form')" as="element()?"/>
1143-
<xsl:variable name="modal" select="$context('modal')" as="xs:boolean"/>
1144-
<!-- <xsl:variable name="resources" select="$context('resources')" as="document-node()"/>-->
11451120

11461121
<xsl:message>ldh:row-form-submit-violation</xsl:message>
11471122

@@ -1958,7 +1933,7 @@ WHERE
19581933
'form': $form,
19591934
'resources': $resources
19601935
}"/>
1961-
<xsl:sequence select="ldh:form-horizontal-response($context)"/>
1936+
<xsl:sequence select="ldh:modal-form-response($context)"/>
19621937
</xsl:template>
19631938

19641939
</xsl:stylesheet>

0 commit comments

Comments
 (0)