Skip to content

Instantly share code, notes, and snippets.

@avernet
Created March 18, 2011 23:02
Show Gist options
  • Save avernet/877006 to your computer and use it in GitHub Desktop.
Save avernet/877006 to your computer and use it in GitHub Desktop.
<xhtml:html xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
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">
<xhtml:head>
<xforms:model id="model">
<!-- Upon ready, simulate click on button + close dialog for both XBL controls -->
<xforms:action ev:event="xforms-ready">
<xforms:dispatch name="DOMActivate" targetid="my-foo1$foo-trigger"/>
<xxforms:hide dialog="my-dialog"/>
<xforms:dispatch name="DOMActivate" targetid="my-foo2$foo-trigger"/>
<xxforms:hide dialog="my-dialog"/>
</xforms:action>
</xforms:model>
<xbl:xbl>
<xbl:binding element="fr|foo">
<xxbl:global>
<!-- The single global dialog -->
<xxforms:dialog id="my-dialog" level="modal" model="my-dialog-model">
<xforms:label>My Dialog</xforms:label>
<!-- Dialog model -->
<xforms:model id="my-dialog-model">
<xforms:instance id="my-dialog-instance">
<count>0</count>
</xforms:instance>
</xforms:model>
<!-- Dialog keeps track of # of times it is open, and sends current count back to caller -->
<xforms:action ev:event="xxforms-dialog-open">
<xforms:setvalue ref="instance()" value="xs:integer(.) + 1"/>
<xforms:dispatch name="my-callback" targetid="{event('my-id')}">
<xxforms:context name="my-value" select="instance()"/>
</xforms:dispatch>
</xforms:action>
</xxforms:dialog>
</xxbl:global>
<xbl:template>
<!-- Local model state -->
<xforms:model id="model">
<xforms:instance id="instance">
<count/>
</xforms:instance>
</xforms:model>
<xforms:trigger id="foo-trigger">
<xforms:label>Open me</xforms:label>
<!-- Open global dialog upon click -->
<xxforms:show ev:event="DOMActivate" dialog="my-dialog" xxbl:scope="outer">
<xxforms:context name="my-id" select="event('xxforms:effective-targetid')"/>
</xxforms:show>
<!-- Upon callback, store value received -->
<xforms:setvalue ev:event="my-callback" ref="instance()" value="event('my-value')"/>
</xforms:trigger>
</xbl:template>
</xbl:binding>
</xbl:xbl>
</xhtml:head>
<xhtml:body>
<fr:foo id="my-foo1"/>
<fr:foo id="my-foo2"/>
</xhtml:body>
</xhtml:html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment