1 <container-dialog id="UploadContentDialog" button-text="Upload Content"> 2 <form-single name="UploadExampleContent" transition="uploadExampleContent"> 3 <field name="exampleId"><default-field><hidden/></default-field></field> 4 <field name="contentFile"><default-field><file/></default-field></field> 5 <!-- <field name="repositoryName"><default-field><text-line size="20" default-value="main"/></default-field></field> --> 6 <field name="purposeEnumId"><default-field title="Purpose"> 7 <drop-down><entity-options><entity-find entity-name="moqui.basic.Enumeration"> 8 <econdition field-name="enumTypeId" value="ExampleContentPurpose"/> 9 <order-by field-name="description"/> 10 </entity-find></entity-options></drop-down> 11 </default-field></field> 12 <field name="locale"><default-field><text-line size="6"/></default-field></field> 13 <field name="submitButton"><default-field title="Add"><submit confirmation="Really Add?"/></default-field></field> 14 </form-single> 15 </container-dialog>
1 <transition name="uploadExampleContent"> 2 <actions><script><![CDATA[ 3 import org.moqui.context.ResourceReference 4 org.moqui.context.ExecutionContext ec = context.ec 5 6 org.apache.commons.fileupload.FileItem contentFile = context.contentFile 7 String fileName = contentFile.getName() 8 ec.logger.info("Uploading file [${fileName}] for Example [${exampleId}] in repository [${repositoryName}] with purpose [${purposeEnumId}] and locale [${locale}]") 9 10 // String contentLocation = "content://${repositoryName}/moqui/example/${exampleId}/${fileName}" 11 String contentLocation = "dbresource://moqui/example/${exampleId}/${fileName}" 12 ResourceReference newRr = ec.resource.getLocationReference(contentLocation) 13 InputStream fileStream = contentFile.getInputStream() 14 newRr.putStream(fileStream) 15 fileStream.close() 16 17 ec.service.sync().name("create", "ExampleContent").parameters([exampleId: exampleId, 18 contentLocation: contentLocation, purposeEnumId: purposeEnumId, locale: locale]).call() 19 ]]></script></actions> 20 <default-response url="."/> 21 </transition>
1 <form-list name="ListExampleContent" transition="updateExampleContent" list="exampleContentList"> 2 <field name="download"><default-field> 3 <link url="downloadContent" text="Download" parameter-map="[exampleId:exampleId, contentLocation:contentLocation]"/> 4 </default-field></field> 5 <field name="exampleId"><default-field><hidden/></default-field></field> 6 <field name="contentLocation"><default-field title="Location"><display/></default-field></field> 7 <field name="purposeEnumId"><default-field title="Purpose"> 8 <drop-down><entity-options><entity-find entity-name="moqui.basic.Enumeration"> 9 <econdition field-name="enumTypeId" value="ExampleContentPurpose"/> 10 <order-by field-name="description"/> 11 </entity-find></entity-options></drop-down> 12 </default-field></field> 13 <field name="locale"><default-field><text-line size="6"/></default-field></field> 14 <field name="submitButton"><default-field title="Update"><submit/></default-field></field> 15 <field name="deleteLink"> 16 <default-field title=" "> 17 <!-- the parameters for this will be auto-mapped: exampleId, contentLocation --> 18 <link url="deleteExampleContent" text="Delete" confirmation="Really Delete?"/> 19 </default-field> 20 </field> 21 </form-list>
1 <transition name="downloadContent"> 2 <actions> 3 <entity-find-one entity-name="ExampleContent" value-field="exampleContent"/> 4 <script>ec.web.sendResourceResponse(exampleContent.contentLocation)</script> 5 </actions> 6 <default-response type="none"/> 7 </transition>