12-01-2016 12:53 AM
Hi Guys,
I developing an action the will allow the site manager to delete one or more versions of a document through an action. Right now I am asking user for input in the action through a dialog box but I want show a drop down that will fetch all the versions of the document and display it to user for selection.
I am not user how can I achieve this. Please help me out.
12-01-2016 06:38 AM
It depends on how you are implementing your action, but you may already have a dialog in your custom action client side code.
Within that dialog you can define the template to be a custom webscript (Share tier)
...
templateUrl : Alfresco.constants.URL_SERVICECONTEXT + "yourCustomDialogWebscriptURL?nodeRef=" + file.nodeRef,
...
In that webscript controller, you need to call api/version for your node, something like this
...
var getVersionsURL = "/api/version?nodeRef=" + args.nodeRef;
var connector = remote.connect("alfresco");
var result = connector.get(getVersionsURL);
if(result.status == 200)
{
model.versions = JSON.parse(result);
}
...
And finally you can iterate the versionHistory in the dialog freemarker template, something like this
...
<select name="versionSelect">
<#list versions as version>
<option value="${version.label}">${version.label}</option>
</#list>
</select>
...
finally, this is an example json returned by api/version
[
{
"nodeRef": "versionStore:\/\/version2Store\/ee0c0cde-db24-40eb-835c-a81478da9535",
"name": "Project Contract.pdf",
"label": "2.1",
"description": "I made so many changes to this doc",
"createdDate": "01 dic 2016 12:07:11 GMT+0100 (CET)",
"createdDateISO": "2016-12-01T12:07:11.365+01:00",
"creator":
{
"userName": "admin",
"firstName": "Administrator",
"lastName": ""
}
},
...
]
I hope it helps
12-01-2016 06:54 AM
Thanks Mike. I will try this and post the result.
Thanks
Hiten Rastogi
Sr. Software Engineer
Mobile: +91 9899586608
Email: hiten.rastogi@eisenvault.com <vipul.swarup@eisenvault.com>
On 1 December 2016 at 17:09, mikel_asla_keensoft <community@alfresco.com>
02-13-2017 04:11 AM
Hi Mikel,
Sorry, I know it is a bit late but I got involved in other stuff and kept this on the back-burner. So, I was trying what you suggested above but instead of calling a custom share side webscript which would call the versions webscript I called the versions webscript directly from the ftl script tag. The issue I am facing here is that I am not able to get the nodeRef of the document. I tried getting the nodeRef by form.arguments.itemId as suggested by Alex in my other post here but it gave me version-delete as value Below is the ftl.
<code>
<#include "/org/alfresco/components/form/controls/common/utils.inc.ftl" />
<script type="text/javascript">//<![CDATA[
YAHOO.util.Event.onContentReady("${fieldHtmlId}", function ()
{
Alfresco.util.Ajax.jsonGet({
// supplementing hardcoded noderef just to check if the ftl works; needs to be replaced by object containing noderef. YAY!! it works.
url: encodeURI(Alfresco.constants.PROXY_URI + 'api/version?nodeRef=workspace://SpacesStore/284202aa-e21f-4e23-bf18-b163c4d9fa49'),
successCallback:
{
fn: function loadWebscript_successCallback(response, config)
{
var obj = JSON.parse(response.serverResponse.responseText);
if (obj)
{
for (i = 0; i < obj.length; i++) {
var newOption = document.createElement('option');
newOption.value = obj[i].label;
newOption.text = obj[i].label;
YAHOO.util.Dom.get("${fieldHtmlId}").options.add(newOption);
}
// Current value
var sp = document.getElementById("${fieldHtmlId}");
sp.value = "${field.value}";
}
}
}
});
}, this);
//]]></script>
<#if field.control.params.optionSeparator??>
<#assign optionSeparator=field.control.params.optionSeparator>
<#else>
<#assign optionSeparator=",">
</#if>
<#if field.control.params.labelSeparator??>
<#assign labelSeparator=field.control.params.labelSeparator>
<#else>
<#assign labelSeparator="|">
</#if>
<#assign fieldValue=field.value>
<#if fieldValue?string == "" && field.control.params.defaultValueContextProperty??>
<#if context.properties[field.control.params.defaultValueContextProperty]??>
<#assign fieldValue = context.properties[field.control.params.defaultValueContextProperty]>
<#elseif args[field.control.params.defaultValueContextProperty]??>
<#assign fieldValue = args[field.control.params.defaultValueContextProperty]>
</#if>
</#if>
<div class="form-field">
<#if form.mode == "view">
<div class="viewmode-field">
<#if field.mandatory && !(fieldValue?is_number) && fieldValue?string == "">
<span class="incomplete-warning"><img src="${url.context}/res/components/form/images/warning-16.png" title="${msg("form.field.incomplete")}" /><span>
</#if>
<span class="viewmode-label">${field.label?html}:</span>
<#if fieldValue?string == "">
<#assign valueToShow=msg("form.control.novalue")>
<#else>
<#assign valueToShow=fieldValue>
<#if field.control.params.options?? && field.control.params.options != "">
<#list field.control.params.options?split(optionSeparator) as nameValue>
<#if nameValue?index_of(labelSeparator) == -1>
<#if nameValue == fieldValue?string || (fieldValue?is_number && fieldValue?c == nameValue)>
<#assign valueToShow=nameValue>
<#break>
</#if>
<#else>
<#assign choice=nameValue?split(labelSeparator)>
<#if choice[0] == fieldValue?string || (fieldValue?is_number && fieldValue?c == choice[0])>
<#assign valueToShow=msgValue(choice[1])>
<#break>
</#if>
</#if>
</#list>
</#if>
</#if>
<span class="viewmode-value">${valueToShow?html}</span>
</div>
<#else>
<label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
<select id="${fieldHtmlId}" name="${field.name}" tabindex="0"
<#if field.description??>title="${field.description}"</#if>
<#if field.control.params.size??>size="${field.control.params.size}"</#if>
<#if field.control.params.styleClass??>class="${field.control.params.styleClass}"</#if>
<#if field.control.params.style??>style="${field.control.params.style}"</#if>
<#if field.disabled && !(field.control.params.forceEditable?? && field.control.params.forceEditable == "true")>disabled="true"</#if>>
</select>
<@formLib.renderFieldHelp field=field />
</#if>
</div>
</code>
Thanks
Hiten Rastogi
02-17-2017 12:55 AM
I was able to crack this. For anyone looking for solution please check out this comment.
02-17-2017 06:33 AM
Sorry I didn't read your question on time...
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.