<commit_before><!--
  Copyright (C) 2010 Orbeon, Inc.

  This program is free software; you can redistribute it and/or modify it under the terms of the
  GNU Lesser General Public License as published by the Free Software Foundation; either version
  2.1 of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the GNU Lesser General Public License for more details.

  The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
  -->
<!-- This is the Orbeon Forms Form Runner standard summary page -->
<html xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:xf="http://www.w3.org/2002/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events"
      xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
      xmlns:xi="http://www.w3.org/2001/XInclude"
      xmlns:f="http://orbeon.org/oxf/xml/formatting"
      xmlns:xh="http://www.w3.org/1999/xhtml"
      xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
      xmlns:saxon="http://saxon.sf.net/"
      xmlns:frf="java:org.orbeon.oxf.fr.FormRunner"
      xmlns:index="org.orbeon.oxf.fr.relational.Index"
      xmlns:version="java:org.orbeon.oxf.common.Version"
      xmlns="http://www.w3.org/1999/xhtml">

    <head>
        <!-- Make sure to use the source form's title -->
        <xh:title><xf:output value="$source-form-metadata/title[@xml:lang = xxf:lang()], $source-form-metadata/title"/></xh:title>
        <xh:link rel="stylesheet" href="/apps/fr/style/form-runner-summary.css" type="text/css" media="all"/>

        <!-- This page needs access to Form Builder permission -->
        <xi:include href="oxf:/apps/fr/includes/permissions-model.xml" xxi:omit-xml-base="true"/>
        <!-- FR Summary page XForms model -->
        <xf:model id="fr-form-model" xxf:xpath-analysis="true">

            <xf:var name="parameters" value="xxf:instance('fr-parameters-instance')"/>

            <xf:var name="app" as="xs:string" value="xxf:instance('fr-parameters-instance')/app"/>
            <xf:var name="form" as="xs:string" value="xxf:instance('fr-parameters-instance')/form"/>

            <xf:var name="is-fb"        value="$app = 'orbeon' and $form = 'builder'"/>
            <xf:var name="has-fb-roles" value="$is-fb and not(xxf:instance('fb-permissions')/@has-roles = 'false')"/>

            <xf:var name="app-query"         value="if ($has-fb-roles) then instance('fr-search-instance')/query[contains(@path, 'application-name') and @search-field = 'true'] else ()" as="element(query)?"/>
            <xf:var name="form-query"        value="if ($app-query)    then instance('fr-search-instance')/query[contains(@path, 'form-name')        and @search-field = 'true'] else ()" as="element(query)?"/>
            <xf:var name="initial-app-value" value="if ($app-query)    then xxf:instance('fb-permissions')/app[1][not(@name = '*')]/@name else ()" as="xs:string?"/>

            <xf:var name="selection-is-one-document" value="count(xxf:split(instance('fr-selection-instance'))) = 1"/>
            <xf:var name="selection-data-or-draft"   value="if ($selection-is-one-document) then substring-before(instance('fr-selection-instance'), '/') else ()"/>
            <xf:var name="selection-document-id"     value="if ($selection-is-one-document) then substring-after (instance('fr-selection-instance'), '/') else ()"/>

            <!-- Source form -->
            <xf:instance id="fr-source-form-instance" xxf:readonly="false"><!-- Set to false so that xf:insert works -->
                <form xmlns=""/>
            </xf:instance>

            <xf:var
                name="source-form-metadata"
                value="instance('fr-source-form-instance')/xh:head/xf:model/xf:instance[@id = 'fr-form-metadata']/*"/>

            <xf:var
                name="source-form-attachments"
                value="instance('fr-source-form-instance')/xh:head/xf:model/xf:instance[@id = 'fr-form-attachments']/*"/>

            <xf:var
                name="has-pdf-template"
                value="normalize-space($source-form-attachments/pdf)"/>

            <!-- NOTE: use xxf:cache="false" otherwise updates to the form won't work in the summary page -->
            <!-- A solution for this might be for read-form.xpl, which is able to use conditional GET, to run always, or to
                 improve submissions to handle conditional GET as well when using caching. -->
            <xf:submission id="get-source-form-submission"
                    method="get" serialization="none"
                    resource="/fr/service/persistence/crud/{$app}/{$form}/form/form.xhtml"
                    replace="instance" instance="fr-source-form-instance" xxf:readonly="true" xxf:cache="false" xxf:xinclude="true"/>

            <!-- Standard Form Runner data instance -->
            <!-- TODO: Can we remove this? -->
            <xf:instance id="fr-form-instance">
                <dummy/>
            </xf:instance>

            <!-- Standard Form Runner resources instance -->
            <!-- Initially empty, but we copy the source form resources into there during initialization.
                 fr-persistence-model then has access to the form resources as if in the detail page. -->
            <xf:instance id="fr-form-resources">
                <resources xmlns=""/>
            </xf:instance>

            <!-- Instance to control the triggers' appearance -->
            <xf:instance id="fr-summary-triggers-instance">
                <triggers xmlns="">
                    <enabled/>
                    <disabled/>
                </triggers>
            </xf:instance>

            <xf:bind ref="instance('fr-summary-triggers-instance')/disabled" readonly="true()"/>

            <xf:var name="parameters" value="xxf:instance('fr-parameters-instance')"/>

            <xf:action ev:event="fr-summary-create">
                <xf:load resource="/fr/{$app}/{$form}/new{if (property('xxf:noscript')) then '?fr-noscript=true' else ''}"/>
            </xf:action>

            <xf:action ev:event="fr-summary-view" if="$selection-is-one-document">
                <xf:var name="params" value="(
                        if (property('xxf:noscript'))           then 'fr-noscript=true' else (),
                        if ($selection-data-or-draft = 'draft') then 'draft=true'       else ()
                    )"/>
                <xf:load resource="/fr/{$app}/{$form}/view/{$selection-document-id}{if (exists($params)) then concat('?', string-join($params, '&amp;')) else ()}"/>
            </xf:action>

            <!-- Instance to track search results and paging -->
            <!-- NOTE: As of 2011-11-28, `app` and `form` are not set by us. We leave them in for now because the
                 built-in eXist, Oracle and MySQL implementations rely on them in the Form Runner page flow. -->
            <xf:instance id="fr-search-instance">
                <search xmlns="">
                    <query/>
                    <page-size>5</page-size>
                    <page-number>1</page-number>
                    <lang/>
                </search>
            </xf:instance>

            <xf:bind ref="instance('fr-search-instance')">
                <!-- Don't send this to the server -->
                <xf:bind ref="query/(@search-field | @summary-field)" relevant=". = 'true'"/>
                <!-- Set types so the search fields display the proper controls -->
                <xf:bind ref="query[ends-with(@type, ':date')]" type="xf:date"/>
                <xf:bind ref="query[ends-with(@type, ':time')]" type="xf:time"/>
                <xf:bind ref="query[ends-with(@type, ':dateTime')]" type="xf:dateTime"/>

                <!-- Set default value for app and form if needed -->
                <!-- Do this declaratively so we don't depend on order of execution of submissions -->
                <xf:bind ref="$app-query" readonly="false()"
                             calculate="if (normalize-space() = '' and $initial-app-value) then $initial-app-value else ."/>
                <!-- Adjust value for form if there is an app constraint and a form constraint -->
                <xf:bind ref="$form-query" readonly="false()"
                             calculate="(for $a in xxf:instance('fb-permissions')/app[@name = $app-query]
                                             return for $current in . return if ($a/form[@name = ($current, '*')]) then .
                                                 else $a/form[1]/@name, .)[1]"/>
                <!-- Force exact query match if there is an app constraint -->
                <xf:bind ref="$app-query/@match" readonly="false()" calculate="if ($initial-app-value) then 'exact' else ."/>
                <!-- Force exact query match if there is a form constraint -->
                <xf:bind ref="$form-query/@match" readonly="false()" calculate="if (xxf:instance('fb-permissions')/app[@name = $app-query]/form[1][not(@name = '*')]) then 'exact' else ."/>

            </xf:bind>

            <!-- Paging information -->
            <xf:instance id="fr-paging-instance">
                <search xmlns="">
                    <total/>
                    <search-total/>
                    <page-size/>
                    <page-number/><commit_msg>Minor: indent<commit_after><!--
  Copyright (C) 2010 Orbeon, Inc.

  This program is free software; you can redistribute it and/or modify it under the terms of the
  GNU Lesser General Public License as published by the Free Software Foundation; either version
  2.1 of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the GNU Lesser General Public License for more details.

  The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
  -->
<!-- This is the Orbeon Forms Form Runner standard summary page -->
<html xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:xf="http://www.w3.org/2002/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events"
      xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
      xmlns:xi="http://www.w3.org/2001/XInclude"
      xmlns:f="http://orbeon.org/oxf/xml/formatting"
      xmlns:xh="http://www.w3.org/1999/xhtml"
      xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
      xmlns:saxon="http://saxon.sf.net/"
      xmlns:frf="java:org.orbeon.oxf.fr.FormRunner"
      xmlns:index="org.orbeon.oxf.fr.relational.Index"
      xmlns:version="java:org.orbeon.oxf.common.Version"
      xmlns="http://www.w3.org/1999/xhtml">

    <head>
        <!-- Make sure to use the source form's title -->
        <xh:title><xf:output value="$source-form-metadata/title[@xml:lang = xxf:lang()], $source-form-metadata/title"/></xh:title>
        <xh:link rel="stylesheet" href="/apps/fr/style/form-runner-summary.css" type="text/css" media="all"/>

        <!-- This page needs access to Form Builder permission -->
        <xi:include href="oxf:/apps/fr/includes/permissions-model.xml" xxi:omit-xml-base="true"/>
        <!-- FR Summary page XForms model -->
        <xf:model id="fr-form-model" xxf:xpath-analysis="true">

            <xf:var name="parameters" value="xxf:instance('fr-parameters-instance')"/>

            <xf:var name="app" as="xs:string" value="xxf:instance('fr-parameters-instance')/app"/>
            <xf:var name="form" as="xs:string" value="xxf:instance('fr-parameters-instance')/form"/>

            <xf:var name="is-fb"        value="$app = 'orbeon' and $form = 'builder'"/>
            <xf:var name="has-fb-roles" value="$is-fb and not(xxf:instance('fb-permissions')/@has-roles = 'false')"/>

            <xf:var name="app-query"         value="if ($has-fb-roles) then instance('fr-search-instance')/query[contains(@path, 'application-name') and @search-field = 'true'] else ()" as="element(query)?"/>
            <xf:var name="form-query"        value="if ($app-query)    then instance('fr-search-instance')/query[contains(@path, 'form-name')        and @search-field = 'true'] else ()" as="element(query)?"/>
            <xf:var name="initial-app-value" value="if ($app-query)    then xxf:instance('fb-permissions')/app[1][not(@name = '*')]/@name else ()" as="xs:string?"/>

            <xf:var name="selection-is-one-document" value="count(xxf:split(instance('fr-selection-instance'))) = 1"/>
            <xf:var name="selection-data-or-draft"   value="if ($selection-is-one-document) then substring-before(instance('fr-selection-instance'), '/') else ()"/>
            <xf:var name="selection-document-id"     value="if ($selection-is-one-document) then substring-after (instance('fr-selection-instance'), '/') else ()"/>

            <!-- Source form -->
            <xf:instance id="fr-source-form-instance" xxf:readonly="false"><!-- Set to false so that xf:insert works -->
                <form xmlns=""/>
            </xf:instance>

            <xf:var
                name="source-form-metadata"
                value="instance('fr-source-form-instance')/xh:head/xf:model/xf:instance[@id = 'fr-form-metadata']/*"/>

            <xf:var
                name="source-form-attachments"
                value="instance('fr-source-form-instance')/xh:head/xf:model/xf:instance[@id = 'fr-form-attachments']/*"/>

            <xf:var
                name="has-pdf-template"
                value="normalize-space($source-form-attachments/pdf)"/>

            <!-- NOTE: use xxf:cache="false" otherwise updates to the form won't work in the summary page -->
            <!-- A solution for this might be for read-form.xpl, which is able to use conditional GET, to run always, or to
                 improve submissions to handle conditional GET as well when using caching. -->
            <xf:submission id="get-source-form-submission"
                    method="get" serialization="none"
                    resource="/fr/service/persistence/crud/{$app}/{$form}/form/form.xhtml"
                    replace="instance" instance="fr-source-form-instance" xxf:readonly="true" xxf:cache="false" xxf:xinclude="true"/>

            <!-- Standard Form Runner data instance -->
            <!-- TODO: Can we remove this? -->
            <xf:instance id="fr-form-instance">
                <dummy/>
            </xf:instance>

            <!-- Standard Form Runner resources instance -->
            <!-- Initially empty, but we copy the source form resources into there during initialization.
                 fr-persistence-model then has access to the form resources as if in the detail page. -->
            <xf:instance id="fr-form-resources">
                <resources xmlns=""/>
            </xf:instance>

            <!-- Instance to control the triggers' appearance -->
            <xf:instance id="fr-summary-triggers-instance">
                <triggers xmlns="">
                    <enabled/>
                    <disabled/>
                </triggers>
            </xf:instance>

            <xf:bind ref="instance('fr-summary-triggers-instance')/disabled" readonly="true()"/>

            <xf:var name="parameters" value="xxf:instance('fr-parameters-instance')"/>

            <xf:action ev:event="fr-summary-create">
                <xf:load resource="/fr/{$app}/{$form}/new{if (property('xxf:noscript')) then '?fr-noscript=true' else ''}"/>
            </xf:action>

            <xf:action ev:event="fr-summary-view" if="$selection-is-one-document">
                <xf:var name="params" value="(
                        if (property('xxf:noscript'))           then 'fr-noscript=true' else (),
                        if ($selection-data-or-draft = 'draft') then 'draft=true'       else ()
                    )"/>
                <xf:load resource="/fr/{$app}/{$form}/view/{$selection-document-id}{if (exists($params)) then concat('?', string-join($params, '&amp;')) else ()}"/>
            </xf:action>

            <!-- Instance to track search results and paging -->
            <!-- NOTE: As of 2011-11-28, `app` and `form` are not set by us. We leave them in for now because the
                 built-in eXist, Oracle and MySQL implementations rely on them in the Form Runner page flow. -->
            <xf:instance id="fr-search-instance">
                <search xmlns="">
                    <query/>
                    <page-size>5</page-size>
                    <page-number>1</page-number>
                    <lang/>
                </search>
            </xf:instance>

            <xf:bind ref="instance('fr-search-instance')">
                <!-- Don't send this to the server -->
                <xf:bind ref="query/(@search-field | @summary-field)" relevant=". = 'true'"/>
                <!-- Set types so the search fields display the proper controls -->
                <xf:bind ref="query[ends-with(@type, ':date')]" type="xf:date"/>
                <xf:bind ref="query[ends-with(@type, ':time')]" type="xf:time"/>
                <xf:bind ref="query[ends-with(@type, ':dateTime')]" type="xf:dateTime"/>

                <!-- Set default value for app and form if needed -->
                <!-- Do this declaratively so we don't depend on order of execution of submissions -->
                <xf:bind ref="$app-query" readonly="false()"
                             calculate="if (normalize-space() = '' and $initial-app-value) then $initial-app-value else ."/>
                <!-- Adjust value for form if there is an app constraint and a form constraint -->
                <xf:bind ref="$form-query" readonly="false()"
                         calculate="(for $a in xxf:instance('fb-permissions')/app[@name = $app-query]
                                         return for $current in . return if ($a/form[@name = ($current, '*')]) then .
                                             else $a/form[1]/@name, .)[1]"/>
                <!-- Force exact query match if there is an app constraint -->
                <xf:bind ref="$app-query/@match" readonly="false()" calculate="if ($initial-app-value) then 'exact' else ."/>
                <!-- Force exact query match if there is a form constraint -->
                <xf:bind ref="$form-query/@match" readonly="false()" calculate="if (xxf:instance('fb-permissions')/app[@name = $app-query]/form[1][not(@name = '*')]) then 'exact' else ."/>

            </xf:bind>

            <!-- Paging information -->
            <xf:instance id="fr-paging-instance">
                <search xmlns="">
                    <total/>
                    <search-total/>
                    <page-size/>
                    <page-number/>
{'fraction_non_alphanumeric': 0.16528099347505787, 'fraction_numerical': 0.00589349610608293, 'mean_word_length': 2.1559282630355363, 'pattern_counts': {'":': 0, '<': 197, '<?xml version=': 0, '>': 197, 'https://': 0, 'lorem ipsum': 0, 'www.': 16, 'xml': 56}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5095143', 'n_tokens_mistral': 5598, 'n_tokens_neox': 5285, 'n_words': 1248}