@@ -509,8 +509,9 @@ WHERE
509509 </xsl : param >
510510 <xsl : param name =" request-body" select =" $resources" as =" document-node()" />
511511 <xsl : sequence select =" ixsl:call(ixsl:event(), 'preventDefault', [])" />
512- <xsl : variable name =" container" select =" ancestor::div[@typeof][1]" as =" element()?" /> <!-- no container means the form was modal -->
513- <xsl : variable name =" block" select =" $container" as =" element()?" /> <!-- block has no @about at this stage (before saving it) -->
512+ <xsl : Variable name =" modal" select =" exists(ancestor::div[contains-token(@class, 'modal-constructor')])" as =" xs:boolean" />
513+ <xsl : variable name =" container" select =" ancestor::div[@typeof][1]" as =" element()" />
514+ <xsl : variable name =" block" select =" $container" as =" element()" /> <!-- block has no @about at this stage (before saving it) -->
514515 <xsl : variable name =" form" select =" ." as =" element()" />
515516 <xsl : variable name =" id" select =" ixsl:get($form, 'id')" as =" xs:string" />
516517 <xsl : variable name =" action" select =" ixsl:get($form, 'action')" as =" xs:anyURI" />
@@ -568,6 +569,7 @@ WHERE
568569 <xsl : with-param name =" block" select =" $block" />
569570<!-- <xsl:with-param name="container" select="$container"/>-->
570571 <xsl : with-param name =" form" select =" $form" />
572+ <xsl : with-param name =" modal" select =" $modal" />
571573 <xsl : with-param name =" resources" select =" $resources" />
572574 </xsl : call-template >
573575 </ixsl : schedule-action >
@@ -703,10 +705,14 @@ WHERE
703705 <xsl : context-item as =" map(*)" use =" required" />
704706 <xsl : param name =" doc-uri" as =" xs:anyURI" />
705707 <xsl : param name =" block" as =" element()" />
706- <!-- <xsl:param name="container" as="element()?"/>-->
707708 <xsl : param name =" form" as =" element()?" />
709+ <xsl : param name =" modal" select =" false()" as =" xs:boolean" />
708710 <xsl : param name =" resources" as =" document-node()" />
709711
712+ <xsl : message >
713+ ldh:ResourceUpdated $doc-uri: <xsl : value-of select =" $doc-uri" /> $modal: <xsl : value-of select =" $modal" />
714+ </xsl : message >
715+
710716 <xsl : choose >
711717 <!-- POST data appended successfully -->
712718 <xsl : when test =" ?status = (200, 204)" >
@@ -769,11 +775,10 @@ WHERE
769775 </xsl : when >
770776 <!-- POST or PUT constraint violation response is 422 Unprocessable Entity, bad RDF syntax is 400 Bad Request -->
771777 <xsl : when test =" ?status = (400, 422) and starts-with(?media-type, 'application/rdf+xml')" > <!-- allow 'application/rdf+xml;charset=UTF-8' as well -->
772- <!-- <xsl:variable name="resource" select="key('resources-by-type', $forClass, ?body)[not(key('predicates-by-object', @rdf:nodeID)[not(../rdf:type/@rdf:resource = '&spin;ConstraintViolation')])]" as="element()"/>-->
773778 <xsl : variable name =" body" select =" ?body" as =" document-node()" />
774779 <!-- TO-DO: refactor to use asynchronous HTTP requests -->
775- <xsl : variable name =" types" select =" distinct-values($body/rdf:RDF/*/rdf:type/@rdf:resource)" as =" xs:anyURI*" />
776- <xsl : variable name =" property-uris" select =" distinct-values($body/rdf:RDF/*/concat(namespace-uri(), local-name()))" as =" xs:string*" />
780+ <xsl : variable name =" types" select =" distinct-values($body/rdf:RDF/*[not(@rdf:about = $doc-uri)] /rdf:type/@rdf:resource)" as =" xs:anyURI*" />
781+ <xsl : variable name =" property-uris" select =" distinct-values($body/rdf:RDF/*[not(@rdf:about = $doc-uri)]/* /concat(namespace-uri(), local-name()))" as =" xs:string*" />
777782 <xsl : variable name =" query-string" select =" 'DESCRIBE $Type VALUES $Type { ' || string-join(for $uri in $property-uris return '< ' || $uri || '> ', ' ') || ' }'" as =" xs:string" />
778783 <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/rdf+xml' })" as =" xs:anyURI" />
779784 <xsl : variable name =" property-metadata" select =" document($request-uri)" as =" document-node()" />
@@ -789,7 +794,7 @@ WHERE
789794 <xsl : variable name =" query-string" select =" $constraint-query || ' VALUES $Type { ' || string-join(for $type in $types return '< ' || $type || '> ', ' ') || ' }'" as =" xs:string" />
790795 <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/sparql-results+xml' })" as =" xs:anyURI" />
791796 <xsl : variable name =" constraints" select =" if (exists($types)) then document($request-uri) else ()" as =" document-node()?" />
792-
797+
793798 <xsl : variable name =" query-string" select =" $shape-query || ' VALUES $Type { ' || string-join(for $type in $types return '< ' || $type || '> ', ' ') || ' }'" as =" xs:string" />
794799 <xsl : variable name =" request-uri" select =" ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/rdf+xml' })" as =" xs:anyURI" />
795800 <xsl : variable name =" shapes" select =" document($request-uri)" as =" document-node()" />
@@ -802,26 +807,70 @@ WHERE
802807 $object-uris: <xsl : value-of select =" $object-uris" />
803808 $object-metadata: <xsl : value-of select =" serialize($object-metadata)" />
804809 </xsl : message >
805-
806- <xsl : variable name =" row-form" as =" node()*" >
807- <xsl : apply-templates select =" $body/rdf:RDF/*" mode =" bs2:RowForm" >
808- <xsl : with-param name =" method" select =" $form/@method" />
809- <!-- <xsl:with-param name="type-metadata" select="$type-metadata" tunnel="yes"/>-->
810- <xsl : with-param name =" property-metadata" select =" $property-metadata" tunnel =" yes" />
811- <xsl : with-param name =" constructors" select =" $constructors" tunnel =" yes" />
812- <xsl : with-param name =" constraints" select =" $constraints" tunnel =" yes" />
813- <xsl : with-param name =" shapes" select =" $shapes" tunnel =" yes" />
814- <xsl : with-param name =" object-metadata" select =" $object-metadata" tunnel =" yes" />
815- </xsl : apply-templates >
816- </xsl : variable >
817-
818- <xsl : for-each select =" $block" >
819- <xsl : result-document href =" ?." method =" ixsl:replace-content" >
820- <xsl : copy-of select =" $row-form/*" />
821- </xsl : result-document >
822810
823- <xsl : apply-templates select =" ." mode =" ldh:PostConstruct" />
824- </xsl : for-each >
811+ <xsl : choose >
812+ <xsl : when test =" $modal" >
813+ <xsl : variable name =" form" as =" element()*" >
814+ <xsl : apply-templates select =" $constructed-doc" mode =" bs2:Form" > <!-- document level template -->
815+ <xsl : with-param name =" about" select =" ()" /> <!-- don't set @about on the container until after the resource is saved -->
816+ <xsl : with-param name =" method" select =" 'put'" />
817+ <xsl : with-param name =" action" select =" ldh:href($ldt:base, ac:absolute-path(ldh:base-uri(.)), map{}, $doc-uri)" as =" xs:anyURI" />
818+ <xsl : with-param name =" form-actions-class" select =" 'form-actions modal-footer'" as =" xs:string?" />
819+ <xsl : with-param name =" classes" select =" ()" />
820+ <!-- <xsl:with-param name="type-metadata" select="$type-metadata" tunnel="yes"/>-->
821+ <xsl : with-param name =" property-metadata" select =" $property-metadata" tunnel =" yes" />
822+ <xsl : with-param name =" constructor" select =" $constructed-doc" tunnel =" yes" />
823+ <xsl : with-param name =" constructors" select =" ()" tunnel =" yes" /> <!-- can be empty because modal form is only used to create Container/Item instances -->
824+ <xsl : with-param name =" constraints" select =" $constraints" tunnel =" yes" />
825+ <xsl : with-param name =" shapes" select =" ()" tunnel =" yes" /> <!-- there will be no shapes as modal form is only used to create Container/Item instances -->
826+ <xsl : with-param name =" base-uri" select =" ac:absolute-path(ldh:base-uri(.))" tunnel =" yes" /> <!-- ac:absolute-path(ldh:base-uri(.)) is empty on constructed documents -->
827+ <!-- <xsl:sort select="ac:label(.)"/> -->
828+ </xsl : apply-templates >
829+ </xsl : variable >
830+
831+ <xsl : for-each select =" $block" >
832+ <xsl : result-document href =" ?." method =" ixsl:replace-content" >
833+ <div class =" modal-header" >
834+ <button type =" button" class =" close" >× </button >
835+
836+ <legend >
837+ <!-- <xsl:value-of select="$legend-label"/> -->
838+ </legend >
839+ </div >
840+
841+ <div class =" modal-body" >
842+ <xsl : copy-of select =" $form" />
843+ </div >
844+ </xsl : result-document >
845+ </xsl : for-each >
846+
847+ <xsl : if test =" id($form/@id, ixsl:page())" >
848+ <xsl : apply-templates select =" id($form/@id, ixsl:page())" mode =" ldh:PostConstruct" />
849+ </xsl : if >
850+ </xsl : when >
851+ <xsl : otherwise >
852+ <xsl : variable name =" row-form" as =" node()*" >
853+ <!-- filter out the current document which might be in the constraint violation response attached by an rdf:_N property to a block resource -->
854+ <xsl : apply-templates select =" $body/rdf:RDF/*[not(@rdf:about = $doc-uri)]" mode =" bs2:RowForm" >
855+ <xsl : with-param name =" method" select =" $form/@method" />
856+ <!-- <xsl:with-param name="type-metadata" select="$type-metadata" tunnel="yes"/>-->
857+ <xsl : with-param name =" property-metadata" select =" $property-metadata" tunnel =" yes" />
858+ <xsl : with-param name =" constructors" select =" $constructors" tunnel =" yes" />
859+ <xsl : with-param name =" constraints" select =" $constraints" tunnel =" yes" />
860+ <xsl : with-param name =" shapes" select =" $shapes" tunnel =" yes" />
861+ <xsl : with-param name =" object-metadata" select =" $object-metadata" tunnel =" yes" />
862+ </xsl : apply-templates >
863+ </xsl : variable >
864+
865+ <xsl : for-each select =" $block" >
866+ <xsl : result-document href =" ?." method =" ixsl:replace-content" >
867+ <xsl : copy-of select =" $row-form/*" />
868+ </xsl : result-document >
869+
870+ <xsl : apply-templates select =" ." mode =" ldh:PostConstruct" />
871+ </xsl : for-each >
872+ </xsl : otherwise >
873+ </xsl : choose >
825874
826875 <ixsl : set-style name =" cursor" select =" 'default'" object =" ixsl:page()//body" />
827876 </xsl : when >
0 commit comments