Adding Attachment Buttons
Using the <vdl-attachment-button> element, you can create, upload, edit, manage and download both app and scenario attachments.
When you add an attachment button to a view, you must specify an
action attribute - the available values are:
- upload-scenario-attachments - open an upload scenario attachment dialog.
- upload-project-attachment - opens an upload app attachment dialog.
- download-scenario-attachment - downloads a scenario attachment.
- download-project-attachment - downloads an app attachment.
- manage-scenario-attachments - opens a manage scenario attachment dialog.
- manage-project-attachments - opens a manage app attachment dialog.
- edit-scenario-attachment-properties - opens the edit scenario attachment dialog.
- edit-project-attachment-properties - opens the edit app attachment dialog.
You must also specify a filename or tag. A message - displayed to the user when the dialog opens - can also be specified.
In this example, the
Edit button opens the attachment edit dialog for a scenario attachment. It finds the attachment by tag name -
result-sheet.
<vdl-attachment-button scenario="=s.id" action="edit-scenario-attachment-properties" tag="result-sheet" field="description"> Edit </vdl-attachment-button>Alternatively, the next example defines a button that downloads an attachment.
<vdl-attachment-button action="download-scenario-attachment" tag="result-sheet"> Download </vdl-attachment-button>
Creating New Attachments
The
<vdl-attachment-button> element can be used to create new file attachments and it supports two values for its
action attribute:
- create-project-attachment
- create-scenario-attachment
These values create app and scenario attachments respectively.
Three optional attributes affect behavior when creating attachments this way:
- editor - allows you to specify an attachment editor and hence define what type of file attachment to create.
- filename - allows you to specify a file name. The attachment is created when the button is pressed, taking the user directly into the relevant editor.
- tag - a single tag can be applied to the file attachment using this attribute.
Launching an Editor
You can open an existing file attachment as follows:
<vdl-attachment-button action="edit-scenario-attachment" editor="<EDITOR NAME"> filename="README.txt"where editor can be one of:
- CTAttachmentEditor - a decision tree editor.
- TextAttachmentEditor - a simple text attachment editor.
- DMNAttachmentEditor - a Decision Modeling Notation (DMN) attachment editor.
- DecisionTableAttachmentEditor - a decision table attachment editor.
Intercepting Editor Closing Events
The
on-close attribute of the
<vdl-attachment-button> element allows you to provide a callback function which is invoked when the user closes an attachment editor after it is created or edited. The callback has one parameter -
result - which has properties representing the attachment and a status property. The
status property will be either the string
saved or
unmodified, to reflect what happened to the attachment in the editor. If the callback is defined inline, then it has direct access to the
result variable.
<vdl-attachment-button action="edit-scenario-attachment" filename="bacon.csv" editor="TextAttachmentEditor" on-close="=alert('saved:' + result.status + '. Last modified date: ' + result.attachment.lastModifiedDate)"> Edit attachment </vdl-attachment-button>