Skip to content

Commit

Permalink
Implement xf:input type="xs:dateTime" with XBL, fix #2221
Browse files Browse the repository at this point in the history
  • Loading branch information
avernet committed Nov 13, 2015
1 parent 1785815 commit 43bd574
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/resources-packaged/config/properties-form-builder.xml
Expand Up @@ -40,7 +40,7 @@
oxf:/forms/orbeon/builder/xbl/date-time-controls.xbl
oxf:/forms/orbeon/builder/xbl/date-time-date.xbl
oxf:/forms/orbeon/builder/xbl/date-time-time.xbl
oxf:/forms/orbeon/builder/xbl/date-time-date-time.xbl
oxf:/xbl/orbeon/datetime/datetime.xbl
oxf:/xbl/orbeon/dropdown-date/dropdown-date.xbl
oxf:/xbl/orbeon/fields-date/fields-date.xbl
</property>
Expand Down
129 changes: 129 additions & 0 deletions src/resources-packaged/xbl/orbeon/datetime/datetime.xbl
@@ -0,0 +1,129 @@
<!--
Copyright (C) 2015 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
-->
<xbl:xbl xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:xbl="http://www.w3.org/ns/xbl"
xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner">

<xbl:binding id="fr-datetime"
element="
fr|datetime,
xf|input:xxf-type('xs:dateTime')"
xxbl:mode="lhha binding value focus"
xxbl:label-for="date">

<metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
<display-name lang="en">Date and Time</display-name>
<display-name lang="es">Fecha y Hora</display-name>
<display-name lang="fi">Päivämäärä ja kellonaika</display-name>
<display-name lang="fr">Date et heure</display-name>
<display-name lang="ru">Дата и время</display-name>
<display-name lang="de">Datum und Uhrzeit</display-name>
<display-name lang="it">Data e ora</display-name>
<display-name lang="nl">Datum en tijd</display-name>
<display-name lang="sv">Datum och tid</display-name>
<display-name lang="pt">Data e Hora</display-name>
<icon lang="en">
<small-icon>/apps/fr/style/images/silk/clock_link.png</small-icon>
<large-icon>/apps/fr/style/images/silk/clock_link.png</large-icon>
</icon>
<templates>
<bind type="xf:dateTime"/>
<view>
<fr:datetime id="" ref="" xmlns="">
<xf:label ref=""/>
<xf:hint ref=""/>
<xf:help ref=""/>
<xf:alert ref=""/>
</fr:datetime>
</view>
</templates>
</metadata>

<xbl:implementation>

<xf:model id="datetime-model">
<xf:instance id="orbeon-resources" xxf:readonly="true">
<resources>
<resource xml:lang="en"><date>Date</date> <time>Time</time></resource>
<resource xml:lang="es"><date>Fecha</date> <time>Hora</time></resource>
<resource xml:lang="fi"><date>Päivämäärä</date><time>kellonaika</time></resource>
<resource xml:lang="fr"><date>Date</date> <time>Heure</time></resource>
<resource xml:lang="ru"><date>Дата</date> <time>время</time></resource>
<resource xml:lang="de"><date>Datum</date> <time>Uhrzeit</time></resource>
<resource xml:lang="it"><date>Data</date> <time>Ora</time></resource>
<resource xml:lang="nl"><date>Datum</date> <time>Tijd</time></resource>
<resource xml:lang="sv"><date>Datum</date> <time>Tid</time></resource>
<resource xml:lang="pt"><date>Data</date> <time>Hora</time></resource>
</resources>
</xf:instance>
<xf:instance id="datetime-instance">
<datetime>
<date/>
<time/>
</datetime>
</xf:instance>
<xf:bind ref="instance('datetime-instance')">
<xf:bind ref="date" type="xf:date"/>
<xf:bind ref="time" type="xf:time"/>
</xf:bind>
</xf:model>

</xbl:implementation>
<xbl:template>

<xf:var name="binding" value="xxf:binding('fr-datetime')"/>
<xf:var name="local-date" value="instance('datetime-instance')/date"/>
<xf:var name="local-time" value="instance('datetime-instance')/time"/>

<!-- Update local date and time from bound node -->
<xf:var name="value" as="xs:string" value="$binding/string()">
<xf:action event="xforms-value-changed xforms-enabled">
<xf:var name="is-valid" value="$value castable as xs:dateTime"/>
<xf:action if="$is-valid">
<xf:setvalue ref="$local-date" value="xs:date($binding)"/>
<xf:setvalue ref="$local-time" value="xs:time($binding)"/>
</xf:action>
<xf:action if="not($is-valid)">
<xf:var name="parts" value="tokenize($value, 'T')"/>
<xf:setvalue ref="$local-date" value="$parts[1]"/>
<xf:setvalue ref="$local-time" value="$parts[2]"/>
</xf:action>
</xf:action>
</xf:var>

<!-- Update bound node from local date and time -->
<xf:action
event="xforms-value-changed"
observer="date time">
<xf:setvalue
ref="$binding"
value="if ($local-date/string() = '' and
$local-time/string() = '')
then ''
else
concat(translate($local-date/string(), 'T', ''),
'T',
translate($local-time/string(), 'T', ''))"/>
</xf:action>

<xf:input ref="$local-date" id="date" xxf:title="{xxf:r('date')}"/>
<xf:input ref="$local-time" id="time" xxf:title="{xxf:r('time')}"/>
</xbl:template>

</xbl:binding>

</xbl:xbl>
49 changes: 0 additions & 49 deletions src/resources/forms/orbeon/builder/xbl/date-time-date-time.xbl

This file was deleted.

0 comments on commit 43bd574

Please sign in to comment.