You may want to to have a menu command that pulls an image to the computer they are working on in a specific resolution. In this case, it would create a Web variant if it doesn’t exist and then allow the user to open or save it to their computer.
The menu entry, where in the pars you need to specify the variant name and the attribute containing the original, that is “low” for img objects, and “data” for image objects:
<menuItem
text="Download Img Web variant"
iconUrl="do.ashx?Cmd=Icon&Name=tlb_Publish&Size=16&Default=t"
navigateUrl="javascript:this.menuWebPart.showDialog('WFForm.aspxwf=downloadVariant&Ids='+this.menuWebPart.selectedIdList()+'&pars=variantName:jpg-400;dataAttrName:low;',null,820,650);"
enable="Some"
/>
The result is a zip file if user selected multiple img items, or the link to the single one selected.
Variants are created if not already there.
1.Create a new text file and save it as wf_downloadVariant.xml. 2.Expand the Workflow section of this topic, select all code and paste it in a wf_downloadVariant.xml. 3.Save the wf_downloadVariant.xml file. 4.Load the workflow in the database as explained in Loading a workflow in database. |
<?xml version="1.0" encoding="utf-8"?> <wfres:workFlow xmlns:inopt="http://www.teradp.com/schemas/GN4/1/XmlImportOptions.xsd" xmlns:wfres="http://www.teradp.com/schemas/GN4/1/WFRes.xsd">
<NavigatorWorkflow x:Name="mainWorkflow" StartWith="init" xmlns="http://www.teradp.com/schemas/GN4/1/Workflow/Activity" xmlns:gn4wf="http://www.teradp.com/schemas/GN4/1/Workflow" xmlns:common="http://www.teradp.com/schemas/GN4/1/Common" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wf="http://schemas.microsoft.com/winfx/2006/xaml/workflow" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:coll="clr-namespace:System.Collections;assembly=mscorlib">
<Execute x:Name="init"> <LoadObjects x:Name="loadObjects" ObjectIds="{wf:ActivityBind mainWorkflow, ObjectIds}"/> <!-- process the objects one by one --> <ObjectsReplicator x:Name="replicator" ObjectIds="{wf:ActivityBind mainWorkflow, ObjectIds}">
<LoadData x:Name="loadBinary" ObjectIds="{wf:ActivityBind replicator, Path=ObjectIdsOut}" AttributeName='{wf:ActivityBind mainWorkflow, Path=ParValue["dataAttrName"]}'>
<!-- create the variants binary --> <Variant x:Name="createVariant" ObjectIds="{wf:ActivityBind replicator, Path=ObjectIdsOut}" Data="{wf:ActivityBind loadBinary, Path=DataOut}" CreateAlways="false" VariantTypeNames='{wf:ActivityBind mainWorkflow, Path=ParValueAsStrings["variantName"]}'>
<!-- compute the variant id and output file name (from the object XML) --> <LoadObjects x:Name="loadFileNames" ObjectIds="{wf:ActivityBind replicator, ObjectIdsOut}"> <!-- extract the variant id and output file name --> <TransformXml x:Name="getFileNames" XmlIn="{wf:ActivityBind loadFileNames, Path=XmlOut}" XmlOut="{wf:ActivityBind mainWorkflow, Path=ExecutionLog}" > <TransformXml.XmlValues> <XmlDataArray> <XmlValue Key="variantId" XPath="/*/variantId" /> <XmlValue Key="variantFileName" XPath="/*/variantFileName" /> <XmlValue Key="downloadFileName" XPath="/*/downloadFileName" /> </XmlDataArray> </TransformXml.XmlValues> </TransformXml>
<!-- load the variant - setting its source paths, that will be used as the name in the ZIP --> <LoadData x:Name="loadVariant" DataIds='{wf:ActivityBind getFileNames, Path=XmlValues["variantId"].Value}' SrcPaths='{wf:ActivityBind getFileNames, Path=XmlValues["variantFileName"].Value}'/>
<!-- append the variant to the 'Data' list in the main workflow activity --> <DataOp x:Name="appendVariant" Data="{wf:ActivityBind loadVariant, Path=DataOut}" DataOut="{wf:ActivityBind mainWorkflow, Path=Data}" />
</LoadObjects> </Variant> </LoadData> </ObjectsReplicator>
<wf:IfElseActivity x:Name="objectsCountTest"> <wf:IfElseBranchActivity x:Name="isObjectsError"> <wf:IfElseBranchActivity.Condition> <gn4wf:XPathCondition XmlIn="{wf:ActivityBind loadObjects,Path=XmlOut}" Expression="//gn4:objects" /> </wf:IfElseBranchActivity.Condition>
<!-- create the ZIP from the 'Data' list in the main workflow activity --> <Zip x:Name="zip" Data="{wf:ActivityBind mainWorkflow, Path=Data}"/>
<!-- save the ZIP file --> <Save x:Name="saveZip" Data="{wf:ActivityBind zip, Path=DataOut}" UseLoginTemp="true">
<TransformXml x:Name="prepareLogScreenZip" XmlIn="{wf:ActivityBind mainWorkflow, Path=ExecutionLog}"> <TransformXml.Pars> <wf:WorkflowParameterBinding wf:ParameterName="filePath" wf:Value="{wf:ActivityBind saveZip, Path=ToOut}" /> </TransformXml.Pars> </TransformXml> <!-- Show a message linking to the temp file, the temp file will be removed when the session ends --> <Log x:Name="logSuccessZip" Format="Html" XmlMessages="{wf:ActivityBind prepareLogScreenZip, Path=XmlOut}"> </Log> </Save> </wf:IfElseBranchActivity>
<!-- single file --> <wf:IfElseBranchActivity> <Save x:Name="saveSingle" Data="{wf:ActivityBind mainWorkflow, Path=Data}" UseLoginTemp="true">
<TransformXml x:Name="prepareLogScreenSingle" XmlIn="{wf:ActivityBind mainWorkflow, Path=ExecutionLog}"> <TransformXml.Pars> <wf:WorkflowParameterBinding wf:ParameterName="filePath" wf:Value="{wf:ActivityBind saveSingle, Path=ToOut}" /> </TransformXml.Pars> </TransformXml> <!-- Show a message linking to the temp file, the temp file will be removed when the session ends --> <Log x:Name="logSuccessSingle" Format="Html" XmlMessages="{wf:ActivityBind prepareLogScreenSingle, Path=XmlOut}"> </Log> </Save> </wf:IfElseBranchActivity> </wf:IfElseActivity> </Execute> </NavigatorWorkflow>
<eop:XmlExportOptions wfres:activityName="loadFileNames" xmlns:eop="http://www.teradp.com/schemas/GN4/1/XmlExportOptions.xsd" DataMaxSize="0" AccessStrict="false" MimeType="application/xml"> <eop:Xslt> <root xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:variable name="regExInvalidChars"><![CDATA[[ '?:\\/*""<>|]]]></xsl:variable> <xsl:variable name="variantName" select="$pars/*/add[@key='variantName']/@value"/> <xsl:variable name="variant" select="gn4:variants/gn4:ref[nav:refObject/gn4:*/@name=$variantName]"/> <variantId> <xsl:value-of select="fn:dataIdFromString($variant/gn4:data/@id)"/> </variantId> <variantFileName> <xsl:choose> <xsl:when test="local-name()='image'"> <xsl:value-of select="concat(fn:replace(gn4:title,$regExInvalidChars,'_'),$variant/gn4:data/@nav:mimeExt)" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat(fn:replace(@name,$regExInvalidChars,'_'),$variant/gn4:data/@nav:mimeExt)" /> </xsl:otherwise> </xsl:choose> </variantFileName> </root> </eop:Xslt> </eop:XmlExportOptions>
<topt:XmlTransformOptions wfres:activityName="getFileName" xmlns:topt="http://www.teradp.com/schemas/GN4/1/XmlTransformOptions.xsd" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <topt:Xslt> <root> <xsl:variable name="filePath" select="$pars/*/add[@key='filePath']/@value" /> <xsl:variable name="variantName" select="$pars/*/add[@key='varinatName']/@value" /> <tempFileName> <xsl:value-of select="fn:pathFileName($filePath)" /> </tempFileName>
</root> </topt:Xslt> </topt:XmlTransformOptions>
<topt:XmlTransformOptions wfres:activityName="prepareLogScreenSingle" xmlns:topt="http://www.teradp.com/schemas/GN4/1/XmlTransformOptions.xsd" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <topt:Xslt> <LogEntry> <xsl:variable name="filePath" select="$pars/*/add[@key='filePath']/@value" /> <Message> <![CDATA[ <div style="background:#E8F0F6;position:absolute;width:1000px;height:1000;left:0px;top:0px;padding:20px;vertical-align:middle;"> <h3><img width=100 src='./do.ashx?cmd=TempFile&name=]]><xsl:value-of select="$filePath"/><![CDATA['/> <a href='./do.ashx?cmd=TempFile&name=]]><xsl:value-of select="$filePath"/><![CDATA['>Click to download the image web variant<img src='do.ashx?cmd=icon&name=tlb_Import&size=16'/></a> </h3> </div>]]> </Message> </LogEntry> </topt:Xslt> </topt:XmlTransformOptions> <topt:XmlTransformOptions wfres:activityName="prepareLogScreenZip" xmlns:topt="http://www.teradp.com/schemas/GN4/1/XmlTransformOptions.xsd" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <topt:Xslt> <LogEntry> <xsl:variable name="filePath" select="$pars/*/add[@key='filePath']/@value" /> <Message> <![CDATA[ <div style="background:#E8F0F6;position:absolute;width:1000px;height:1000;left:0px;top:0px;padding:20px;vertical-align:middle;"> <h3> <a href='./do.ashx?cmd=TempFile&fn=images.zip&name=]]><xsl:value-of select="$filePath"/><![CDATA['>Click to download the zip archive <img src='do.ashx?cmd=icon&name=tlb_Import&size=16'/></a> </h3> </div>]]> </Message> </LogEntry> </topt:Xslt> </topt:XmlTransformOptions> </wfres:workFlow>
|