Smart View Config
Smart View refers to the formatting and display of file content referenced via a URI in a Platform 6 document or the Platform 6 document itself.
Configuration requires editing the view XML definition.
In particular the <Viewables>
and <SmartTags>
elements of this XML file.
For example:
<Viewables> <Viewable> <Name>PIDX</Name> <Description> <EN>PIDX</EN> <FR>Accès doc.</FR> </Description> <XPath>MessageInfo/CurrentDocumentURI</XPath> <Type key="View_Document_${BusinessDocumentName}_${CurrentDocumentFormat}">SURI</Type> </Viewable> <Viewable> <Name>DocumentFormEdit</Name> <Description> <EN>Doc. Form</EN> </Description> <XPath/> <Type key="Document_Form_${BusinessDocumentName}_${CurrentDocumentFormat}">SDOC</Type> </Viewable> </Viewables>
Here the <Type>
is set to SURI
(Smart URI) or SDOC
(Smart Document) and a key attribute is used to specify the name of a script to run to format the content of the URI or document.
If the key attribute contains ${tokens}
then the name of the script will be constructed via SmartTag Resolution.
SmartTag Resolution¶
SmartTags are general name/value pairs associated with a <Document>
.
When used with the key attribute of an SURI type <Viewable>
the SmartTag values must be XPaths to current document text elements.
For example:
<View> <Name>MessageInfo</Name> <Description> <EN>Invoices and Exceptions</EN> </Description> <SmartTags> <BusinessDocumentName>MessageInfo/BusinessDocName</BusinessDocumentName> <CurrentDocumentFormat>MessageInfo/CurrentDocumentFormat</CurrentDocumentFormat> </SmartTags> <ConceptName>MessageInfo</ConceptName> </View>
Therefore resolution of SmartTags in this case will involve additional XPath lookup of text nodes and their text values replacing the SmartTag tokens.
The above key attribute value may therefore be resolved to: View_Document_Invoice_PIDX
.
Smart View Display¶
Once one or more SURI/SDOC <Viewables>
have been configured in this way, the standard documents View/Edit links will cause a script to be called to produce the content to display.
Both raw and html formatted data will be displayed on a panel tab allowing the user to switch between Display and Source views.
Note
The script will be executed with the URI or document content as the text
input pipeline variable and it must return formatted html in a pipeline variable called html
.
If the ‘raw’ (Source data) is modified, the formatting script is called once again when any changes are saved.
Smart View Edit Forms¶
An SURI/SDOC script than returns form pipeline variables will cause an additional Edit view to be displayed in addition to the Display And Source views.
Once a form is edited and submitted (saved) the configured form script will be called with the JSON encoded form data as it’s input pipeline variable.
This allows elements of the underlying source document to be updated in a controlled manner.
Form pipeline variables | Description |
---|---|
form-js |
A very specialised javascript class using Extjs 4.2 to render a form. |
form-id |
The name given to the Ext form object in the form-js . |
form-data |
JSON encoded data object used to pre-populate the form fields before display. |
form-script |
The name of a script to call once the Edit form is saved. |
Example¶
View_Document_FTPInvoice_pidx
Extjs 4.2 help on forms: http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.form.Panel
def formjs = ''' var amalto = amalto || {}; amalto.b2box = amalto.b2box || {}; amalto.b2box.formjs = amalto.b2box.formjs || {}; ( function() { amalto.b2box.formjs.Test123 = function() { var anchor = '80%'; this.form = new Ext.FormPanel({ trackResetOnLoad : true, anchor : '100%', bodyStyle : 'padding:5px', items : [ { xtype : 'textfield', fieldLabel : 'Last Name', labelWidth : 180, name : 'lastname', anchor : anchor }, { xtype : 'textfield', fieldLabel : 'First Name', labelWidth : 180, name : 'firstname', anchor : anchor }, { xtype : 'textfield', fieldLabel : 'Email', labelWidth : 180, name : 'email', anchor : anchor }, { xtype : 'textfield', fieldLabel : 'Company', labelWidth : 180, name : 'company', anchor : anchor } ] }); }; amalto.b2box.formjs.Test123.prototype.getForm = function () { return this.form; }; } )(); ''' pipeline.put 'form-js', formjs pipeline.put 'form-id', "Test123" // Must correspond to the name of the js class // JSON form data. FieldName:Value def formdata = '''{ "lastname": "Temple", "firstname": "Simon", "email": "simon.temple@amalto.com", "company": "Amalto Technologies" }''' pipeline.put 'form-data', formdata // The script to process the form save. pipeline.put 'form-transformer', "Update_Document_Invoice_PIDX"
Update_Document_Invoice_PIDX
import groovy.json.JsonSlurper def slurper = new JsonSlurper() def result = slurper.parseText( pipeline.get('text') ) println "Last Name : " + result.lastname println "First Name: " + result.firstname println "Email : " + result.email println "Company : " + result.company