Environment: Alfresco 4.2.1 Enterprise Version
Recently we had requirement to have web-preview of the content on work flow task form.
Actually, in out of the box web-preview is an independent component and form itself is an independent component.
On form we can have only different types of controls not the component.
So there is no direct way to display web-preview of the content on any form as we don't have direct facility to render component on form.
One possible solution is make a custom control and render the response of the web-preview component in custom control.
That is what exactly I did.
Let's have brief idea what we are going to do.
we will create one custom control for that we need to create one ftl and one client side java-script file.
In ftl we will just add div in which we will render web-preview component response.
From ftl file, we will call client side js file.
From onReady method of client side js, we will call web-preview component and will embed its response in div which is defined in ftl.
I created custom control and added the following code in ftl file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <@script type="text/javascript" src="${page.url.context}/res/components/form/custom-web-preview.js"></@script> <@script type="text/javascript" src="${page.url.context}/res/components/preview/web-preview.js"></@script> <@script src="${url.context}/res/components/preview/web-preview.js" /> <@script src="${url.context}/res/components/preview/WebPreviewer.js" /> <@script src="${url.context}/res/js/flash/extMouseWheel.js" /> <@script src="${url.context}/res/components/preview/StrobeMediaPlayback.js" /> <@script src="${url.context}/res/components/preview/Video.js" /> <@script src="${url.context}/res/components/preview/Audio.js" /> <@script src="${url.context}/res/components/preview/Flash.js" /> <@script src="${url.context}/res/components/preview/Image.js" /> <script type="text/javascript">//<![CDATA[ ( function() { new Alfresco.customControl("${fieldHtmlId}").setMessages(${messages}); } ) (); //]]></script> <div id="${fieldHtmlId}"> <div id="web-preview"> </div> </div> |
Here, I have added dependences java-script files and added Div with id as "web-preview" which will be used to render response of the web-preview component.
In onReady method of client js, I called ootb web-preview component and added its response in to defined "web-preview" div.
Following code I added in onReady method of client side java-script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Alfresco.util.Ajax.request( { method: "GET", url: Alfresco.constants.URL_SERVICECONTEXT + "components/preview/web-preview?nodeRef=${NODEREF}&htmlid=${ID}",, successCallback: { fn: function(o) { Dom.get("web-preview").innerHTML = o.serverResponse.responseText; }, scope: this }, failureMessage: "Failed" }); } |
That's it we are done.Now we need to just add this custom control on any form and it will display web-preview of content on form UI.