Skip to content

Instantly share code, notes, and snippets.

@pwin
Last active December 17, 2015 00:59
Show Gist options
  • Save pwin/5524793 to your computer and use it in GitHub Desktop.
Save pwin/5524793 to your computer and use it in GitHub Desktop.
Work in progress on IATI Activities XForm
xquery version "3.0";
declare option exist:serialize "method=xhtml media-type=text/xml indent=yes process-xsl-pi=no";
let $attribute := request:set-attribute("betterform.filter.ignoreResponseBody", "true")
(: look at https://github.com/orbeon/eXist-1.4.x/blob/master/webapp/xforms/tasks/todo-list.xml :)
let $form := <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:inv="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
xmlns:gc="http://docs.oasis-open.org/codelist/ns/genericode/1.0/"
xmlns:javascript="http://www.w3.org/2002/xforms#inline"
xmlns:xi="http://www.w3.org/2001/XInclude">
<head>
<title>IATI Activities</title>
<link type="text/css" rel="stylesheet" href="/exist/rest/db/apps/aidinfo/resources/css/styles-xforms-1.css"/>
<script type="text/javascript"> <![CDATA[
// adding a gmail style function to stop the user from moving away from the page..
function unloadMessage(){
message = "This form has not yet been submitted to the database\nAll data changes will be lost."
return message;
}
function setBunload(on){
window.onbeforeunload = (on) ? unloadMessage : null;
}
setBunload(true);
function dirty() {
setBunload(true);
}
function clean() {
setBunload(false);
}
function lc(s){
return s.toLowerCase();
}
]]>
</script>
<style type="text/css">
<![CDATA[
.xforms-help-icon {
height: 20px;
}
]]>
</style>
<xforms:model id="activities">
<xforms:instance id="activity" xmlns="">
<iati-activities version="1.01" generated-datetime="2013-03-28T16:48:56Z">
<iati-activity xml:lang="en" default-currency="GBP" hierarchy="2">
<reporting-org ref="GB-21" type="10">Scottish Government</reporting-org>
<participating-org ref="GB" type="10" role="Funding">UNITED KINGDOM</participating-org>
<participating-org ref="GB-21" type="10" role="Extending">Department for International Development</participating-org>
<participating-org ref="52000" type="" role="Implementing">Other.</participating-org>
<recipient-country code="MW">MALAWI</recipient-country>
<collaboration-type code="1">Bilateral</collaboration-type>
<default-flow-type code="10">ODA</default-flow-type>
<default-aid-type code="C01">Project-type interventions</default-aid-type>
<default-finance-type code="110">Aid grant excluding debt reorganisation</default-finance-type>
<iati-identifier></iati-identifier>
<other-identifier owner-ref="GB-21" owner-name="Scottish Government"></other-identifier>
<title></title>
<description></description>
<sector code="11220" percentage="100">Primary education</sector>
<activity-date type="end-actual">2009-12-31</activity-date>
<activity-date type="end-planned">2009-12-31</activity-date>
<activity-date type="start-actual">2001-01-01</activity-date>
<activity-date type="start-planned">2001-01-01</activity-date>
<activity-status code="4">Post-completion</activity-status>
<contact-info>
<organisation>Scottish Government</organisation>
<telephone>+44 (0)8457 741 741</telephone>
<email>[email protected]</email>
<mailing-address>General Enquiries, St. Andrew's House, Regent Road, Edinburgh, EH1 3DG, Scotland</mailing-address>
</contact-info>
<default-tied-status code="5">Untied</default-tied-status>
<policy-marker code="1" vocabulary="DAC" significance="1">Gender Equality</policy-marker>
<transaction>
<value value-date="2010-04-01">38557241</value>
<transaction-type code="C">Commitment</transaction-type>
<transaction-date iso-date="2001-01-01">Total Commitment to 31 Dec 2009</transaction-date>
</transaction>
<budget type="Original">
<period-start iso-date="2001-04-01"/>
<period-end iso-date="2002-03-31"/>
<value value-date="2001-04-01" currency="GBP">6024640</value>
</budget>
</iati-activity>
</iati-activities>
</xforms:instance>
<xforms:instance id="myhelp" xmlns="">
<help>
<tied>42</tied>
</help>
</xforms:instance>
<xforms:instance id="country" xmlns="">
<xi:include href="http://datadev.aidinfolabs.org/data/codelist/Country/version/1.0/lang/en.xml"/>
</xforms:instance>
<xforms:instance id="collaboration-type" xmlns="">
<xi:include href="http://datadev.aidinfolabs.org/data/codelist/CollaborationType/version/1.0/lang/en.xml"/>
</xforms:instance>
<xforms:instance id="flow-type" xmlns="">
<xi:include href="http://datadev.aidinfolabs.org/data/codelist/FlowType/version/1.0/lang/en.xml"/>
</xforms:instance>
<xforms:instance id="aid-type" xmlns="">
<xi:include href="http://datadev.aidinfolabs.org/data/codelist/AidType/version/1.0/lang/en.xml"/>
</xforms:instance>
<xforms:instance id="finance-type" xmlns="">
<xi:include href="http://datadev.aidinfolabs.org/data/codelist/FinanceType/version/1.0/lang/en.xml"/>
</xforms:instance>
<xforms:instance id="sector" xmlns="">
<xi:include href="http://datadev.aidinfolabs.org/data/codelist/Sector/version/1.0/lang/en.xml"/>
</xforms:instance>
<xforms:instance id="activity-status" xmlns="">
<xi:include href="http://datadev.aidinfolabs.org/data/codelist/ActivityStatus/version/1.0/lang/en.xml"/>
</xforms:instance>
<xforms:instance id="default-tied-status" xmlns="">
<xi:include href="http://datadev.aidinfolabs.org/data/codelist/TiedStatus/version/1.0/lang/en.xml"/>
</xforms:instance>
<xforms:instance id="policy-marker" xmlns="">
<xi:include href="http://datadev.aidinfolabs.org/data/codelist/PolicyMarker.xml"/>
</xforms:instance>
<xforms:instance id="organisation" xmlns="" src="/exist/apps/aidinfo/data/master-organisation-data.xml">
<null/>
</xforms:instance>
<xforms:instance id="organisation-role" xmlns="">
<xi:include href="http://datadev.aidinfolabs.org/data/codelist/OrganisationRole/version/1.0/lang/en.xml"/>
</xforms:instance>
<xforms:instance id="organisation-type" xmlns="">
<xi:include href="http://datadev.aidinfolabs.org/data/codelist/OrganisationType/version/1.0/lang/en.xml"/>
</xforms:instance>
<xforms:instance id="other-identifier" xmlns="" src="/exist/apps/aidinfo/modules/project-identifiers.xql">
<null/>
</xforms:instance>
<!-- BINDS -->
<xforms:bind ref="instance('activity')/iati-activity/other-identifier" required="true()"/>
<xforms:bind nodeset="instance('activity')/iati-activity/activity-date[@type='end-actual']" constraint=". >= ../activity-date[@type='start-actual']" type="xforms:date" />
<xforms:bind nodeset="instance('activity')/iati-activity/activity-date[@type='end-planned']" constraint=". >= ../activity-date[@type='start-planned']" type="xforms:date" />
<xforms:bind nodeset="instance('activity')/iati-activity/activity-date[@type='start-actual']" type="xforms:date" />
<xforms:bind nodeset="instance('activity')/iati-activity/activity-date[@type='start-planned']" type="xforms:date" />
<xforms:bind nodeset="instance('activity')/iati-activity/iati-identifier" calculate="concat(instance('activity')/iati-activity/reporting-org/@ref,'-',instance('activity')/iati-activity/other-identifier)" />
<xforms:bind nodeset="instance('activity')/iati-activity/sector/@percentage" constraint="sum(../../sector/@percentage) = 100" />
<!-- SUBMISSIONS -->
<xforms:submission id="s01" method="xml-urlencoded-post" show="new" replace="all" action="http://www.cen.eu/cwa/bii/specs/Tools/resources/xforms/echo.php">
<xforms:message level="modeless" ev:event="xforms-submit-error">Submit error.</xforms:message>
</xforms:submission>
<xforms:submission id="s02" method="xml-urlencoded-post" show="new" replace="none" action="http://xformstest.org/cgi-bin/echo.sh">
<xforms:message level="modeless" ev:event="xforms-submit-error">Submit error.</xforms:message>
</xforms:submission>
<xforms:submission id="s03" method="xml-urlencoded-post" show="new" replace="all" action="http://www.agencexml.com/xsltforms/xsltforms/txs.php?exec=beautify.txs">
<xforms:message level="modeless" ev:event="xforms-submit-error">Submit error.</xforms:message>
</xforms:submission>
<xforms:submission id="s04" method="xml-urlencoded-post" replace="none" action="http://www.agencexml.com/xsltforms/xsltforms/txs.php?exec=returnasattachment.txs&amp;file=invoice.xml">
<xforms:message level="modeless" ev:event="xforms-submit-error">Submit error.</xforms:message>
</xforms:submission>
<xforms:submission id="put" method="put" replace="instance" instance="activity">
<xforms:resource value="concat('../data/', instance('activity')/iati-activity/iati-identifier, '.xml')"/>
<xforms:toggle case="save-done" ev:event="xforms-submit-done"/>
</xforms:submission>
<xforms:submission id="get" method="get" replace="instance" instance="activity">
<xforms:resource value="concat('../data/GB-21-', instance('activity')/iati-activity/other-identifier, '.xml')"/>
</xforms:submission>
</xforms:model>
</head>
<!-- START OF THE BODY -->
<body>
<div id="header">
<div id="nav"><span><a href="/exist/apps/aidinfo/index.html">home</a></span><span><a href="mailto:[email protected]">contact</a></span></div>
</div>
<div id="container" >
<xforms:group class="layout-container left">
<xforms:label>Basic Information</xforms:label>
<xforms:output ref="instance('activity')/iati-activity/iati-identifier">
<xforms:label>IATI Identifier</xforms:label>
</xforms:output>
<!-- Project Identifier -->
<xforms:select1 ref="instance('activity')/iati-activity/other-identifier" incremental="true" selection="open">
<xforms:itemset nodeset="instance('other-identifier')/project">
<xforms:label ref="./other-identifier"/>
<xforms:value ref="./other-identifier"/>
</xforms:itemset>
<xforms:label>Project Identifier</xforms:label>
</xforms:select1>
<!-- Organisation -->
<xforms:repeat id="organisation-repeat" nodeset="instance('activity')/iati-activity/participating-org">
<xforms:select1 id="organisation-select" ref=".">
<xforms:label>Participating Organisation</xforms:label>
<xforms:action ev:event="xforms-value-changed">
<xforms:setvalue ref="./@ref"
value="instance('organisation')/organisation[name/pref-name=instance('activity')/iati-activity/participating-org[index('organisation-repeat')]]/oda-input-sector-code"/>
</xforms:action>
<xforms:itemset nodeset="instance('organisation')/organisation/name">
<xforms:label ref="./pref-name"/>
<xforms:value ref="./pref-name"/>
</xforms:itemset>
</xforms:select1>
<xforms:select1 id="organisation-role-select" ref="@role">
<xforms:label>Participating Organisation Role</xforms:label>
<xforms:itemset nodeset="instance('organisation-role')/OrganisationRole">
<xforms:label ref="./name"/>
<xforms:value ref="./code"/>
</xforms:itemset>
</xforms:select1>
<xforms:select1 id="organisation-type-select" ref="@type">
<xforms:label>Participating Organisation Type</xforms:label>
<xforms:itemset nodeset="instance('organisation-type')/OrganisationType">
<xforms:label ref="./name"/>
<xforms:value ref="./code"/>
</xforms:itemset>
</xforms:select1>
<xforms:trigger>
<xforms:label>Del Org</xforms:label>
<xforms:delete nodeset="." at="1" if="count(//participating-org) &gt; 1" ev:event="DOMActivate"/>
</xforms:trigger>
</xforms:repeat>
<xforms:trigger>
<xforms:label>+ Org</xforms:label>
<xforms:insert nodeset="instance('activity')/iati-activity/participating-org" at="index('organisation-repeat')" position="after" ev:event="DOMActivate"/>
</xforms:trigger>
<!-- Project Title -->
<xforms:input ref="instance('activity')/iati-activity/title">
<xforms:label>Title</xforms:label>
</xforms:input>
<!-- Project Description -->
<xforms:textarea ref="instance('activity')/iati-activity/description">
<xforms:label>Description</xforms:label>
</xforms:textarea>
<!-- Recipient Country -->
<xforms:select1 id="recipient-country-select" ref="instance('activity')/iati-activity/recipient-country">
<xforms:label>Recipient Country</xforms:label>
<xforms:itemset nodeset="instance('country')/Country">
<xforms:label ref="./name"/>
<xforms:value ref="./name"/>
</xforms:itemset>
<xforms:action ev:event="xforms-value-changed" ev:observer="recipient-country-select" >
<xforms:setvalue ref="@code" value="instance('country')/Country[name=context()]/code" />
</xforms:action>
</xforms:select1>
<!-- Collaboration Type -->
<xforms:select1 id="collaboration-type-select" ref="instance('activity')/iati-activity/collaboration-type" >
<xforms:label>Collaboration Type</xforms:label>
<xforms:itemset nodeset="instance('collaboration-type')/CollaborationType">
<xforms:label ref="./name"/>
<xforms:value ref="./name"/>
</xforms:itemset>
<xforms:action ev:event="xforms-value-changed" ev:observer="collaboration-type-select">
<xforms:setvalue ref="@code"
value="instance('collaboration-type')/CollaborationType[name=context()]/code"/>
</xforms:action>
<xforms:action ev:event="xforms-value-changed" ev:observer="collaboration-type-select">
</xforms:action>
<xforms:help><xforms:output value="instance('collaboration-type')/CollaborationType[name=instance('activity')/iati-activity/collaboration-type]/description"/></xforms:help>
</xforms:select1>
<!-- Flow Type -->
<xforms:select1 id="default-flow-type-select"
ref="instance('activity')/iati-activity/default-flow-type">
<xforms:label>Default Flow Type</xforms:label>
<xforms:action ev:event="xforms-value-changed">
<xforms:setvalue ref="instance('activity')/iati-activity/default-flow-type/@code"
value="instance('flow-type')/FlowType[name=instance('activity')/iati-activity/default-flow-type]/code"/>
</xforms:action>
<xforms:itemset nodeset="instance('flow-type')/FlowType">
<xforms:label ref="./name"/>
<xforms:value ref="./name"/>
</xforms:itemset>
<xforms:help><xforms:output
value="instance('flow-type')/FlowType[name=instance('activity')/iati-activity/default-flow-type]/description"/></xforms:help>
</xforms:select1>
<!-- Aid Type -->
<xforms:select1 id="default-aid-type-select"
ref="instance('activity')/iati-activity/default-aid-type">
<xforms:label>Default Aid Type</xforms:label>
<xforms:action ev:event="xforms-value-changed">
<xforms:setvalue ref="instance('activity')/iati-activity/default-aid-type/@code"
value="instance('aid-type')/AidType[name=instance('activity')/iati-activity/default-aid-type]/code"/>
</xforms:action>
<xforms:itemset nodeset="instance('aid-type')/AidType">
<xforms:label ref="./name"/>
<xforms:value ref="./name"/>
</xforms:itemset>
<xforms:help><xforms:output
value="instance('aid-type')/AidType[name=instance('activity')/iati-activity/default-aid-type]/description"/></xforms:help>
</xforms:select1>
<!-- Finance Type -->
<xforms:select1 id="default-finance-type-select"
ref="instance('activity')/iati-activity/default-finance-type">
<xforms:label>Default Finance Type</xforms:label>
<xforms:action ev:event="xforms-value-changed">
<xforms:setvalue ref="instance('activity')/iati-activity/default-finance-type/@code"
value="instance('finance-type')/FinanceType[name=instance('activity')/iati-activity/default-finance-type]/code"/>
</xforms:action>
<xforms:itemset nodeset="instance('finance-type')/FinanceType">
<xforms:label ref="./name"/>
<xforms:value ref="./name"/>
</xforms:itemset>
<xforms:help><xforms:output
value="instance('finance-type')/FinanceType[name=instance('activity')/iati-activity/default-finance-type]/category-description"/></xforms:help>
</xforms:select1>
<!-- End Of Group -->
</xforms:group>
<!-- Start Of Group -->
<xforms:group class="layout-container left">
<!-- Start and End Dates -->
<xforms:input ref="instance('activity')/iati-activity/activity-date[@type='start-planned']" incremental="true">
<xforms:label>Start Date (Planned)</xforms:label>
</xforms:input>
<xforms:input ref="instance('activity')/iati-activity/activity-date[@type='start-actual']" incremental="true">
<xforms:label>Start Date (Actual)</xforms:label>
</xforms:input>
<xforms:input ref="instance('activity')/iati-activity/activity-date[@type='end-planned']" incremental="true" >
<xforms:label>End Date (Planned)</xforms:label>
<xforms:alert>Must be after the planned start date</xforms:alert>
</xforms:input>
<xforms:input ref="instance('activity')/iati-activity/activity-date[@type='end-actual']" incremental="true">
<xforms:label>End Date (Actual)</xforms:label>
<xforms:alert>Must be after the actual start date</xforms:alert>
</xforms:input>
<!-- Activity Status -->
<xforms:select1 id="activity-status-select" ref="/iati-activities/iati-activity/activity-status">
<xforms:label>Activity Status</xforms:label>
<xforms:action ev:event="xforms-value-changed">
<xforms:setvalue ref="/iati-activities/iati-activity/activity-status/@code"
value="instance('activity-status')/ActivityStatus[name=instance('activity')/iati-activity/activity-status]/code"/>
</xforms:action>
<xforms:itemset nodeset="instance('activity-status')/ActivityStatus">
<xforms:label ref="./name"/>
<xforms:value ref="./name"/>
</xforms:itemset>
</xforms:select1>
<!-- Tied Status -->
<xforms:select1 id="tied-status-select"
ref="/iati-activities/iati-activity/default-tied-status">
<xforms:label>Default Tied Status</xforms:label>
<xforms:action ev:event="xforms-value-changed">
<xforms:setvalue ref="instance('activity')/iati-activity/default-tied-status/@code"
value="instance('default-tied-status')/TiedStatus[name=instance('activity')/iati-activity/default-tied-status]/code"/>
</xforms:action>
<xforms:itemset nodeset="instance('default-tied-status')/TiedStatus">
<xforms:label ref="./name"/>
<xforms:value ref="./name"/>
</xforms:itemset>
<xforms:help><xforms:output
value="instance('default-tied-status')/TiedStatus[name=instance('activity')/iati-activity/default-tied-status]/description"/></xforms:help>
</xforms:select1>
<!-- Policy Marker -->
<xforms:select1 id="policy-marker-select" ref="instance('activity')/iati-activity/policy-marker">
<xforms:label>Policy Marker</xforms:label>
<xforms:action ev:event="xforms-value-changed">
<xforms:setvalue ref="/iati-activities/iati-activity/policy-marker/@code"
value="instance('policy-marker')/PolicyMarker[name=instance('activity')/iati-activity/policy-marker]/code"/>
</xforms:action>
<xforms:itemset nodeset="instance('policy-marker')/PolicyMarker">
<xforms:label ref="./name"/>
<xforms:value ref="./name"/>
</xforms:itemset>
</xforms:select1>
<!-- Sector -->
<xforms:repeat id="sector-repeat" nodeset="instance('activity')/iati-activity/sector">
<xforms:select1 id="sector-select" ref="." >
<xforms:label>Sector</xforms:label>
<xforms:action ev:event="xforms-value-changed xforms-attribute-changed">
<xforms:setvalue ref="./@code"
value="instance('sector')/Sector[name=.]/code"/>
</xforms:action>
<xforms:itemset nodeset="instance('sector')/Sector">
<xforms:label ref="./name"/>
<xforms:value ref="./name"/>
</xforms:itemset>
<xforms:help><xforms:output
value="instance('sector')/Sector[name=instance('activity')/iati-activity/sector[index('sector-repeat')]]/description"/></xforms:help>
<xforms:alert>The percentages should add to 100</xforms:alert>
<xforms:label>Percentage:
<xforms:input id="sector-percentage" ref="./@percentage" incremental="true"/>
</xforms:label>
</xforms:select1>
<xforms:trigger>
<xforms:label>Del Sector</xforms:label>
<xforms:delete nodeset="." at="1" if="count(//sector) &gt; 1" ev:event="DOMActivate"/>
</xforms:trigger>
</xforms:repeat>
<xforms:trigger>
<xforms:label>+ Sector</xforms:label>
<xforms:insert nodeset="instance('activity')/iati-activity/sector"
at="index('sector-repeat')" position="after" ev:event="DOMActivate"/>
</xforms:trigger>
</xforms:group>
</div>
<!-- Submission Buttons -->
<div id="floating-box">
<div id="box">
<xforms:submit submission="s01">
<xforms:label>s01 View XML</xforms:label>
</xforms:submit>
<xforms:submit submission="s02">
<xforms:label>s02 View XML</xforms:label>
</xforms:submit>
<xforms:submit submission="s03">
<xforms:label>s03 View XML</xforms:label>
</xforms:submit>
<xforms:submit submission="s04">
<xforms:label>s04 View XML file</xforms:label>
</xforms:submit>
<xforms:submit submission="put">
<xforms:label>put Save XML file</xforms:label>
</xforms:submit>
<xforms:submit submission="get">
<xforms:label>get Load XML file</xforms:label>
</xforms:submit>
<xforms:trigger>
<xforms:label>Save Record</xforms:label>
<xforms:action ev:event="DOMActivate">
<xforms:show dialog="confirm"/>
</xforms:action>
</xforms:trigger>
<xforms:dialog id="confirm">
<span>Are you sure?</span>
<xforms:submit submission="put">
<xforms:label>Yes</xforms:label>
</xforms:submit>
<xforms:trigger>
<xforms:label>No</xforms:label>
<xforms:action ev:event="DOMActivate">
<xforms:hide dialog="confirm"/>
</xforms:action>
</xforms:trigger>
</xforms:dialog>
</div>
</div>
</body>
</html>
let $xslt-pi := processing-instruction xml-stylesheet {'type="text/xsl" href="/exist/rest/db/apps/xsltforms/xsltforms.xsl"'}
let $xslt-debug := processing-instruction xsltforms-options {'debug="no"'}
let $xslt-nocss := processing-instruction xsltforms-options {'nocss'}
return ($xslt-pi, $xslt-debug, $form)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment