cancel
Showing results for 
Search instead for 
Did you mean: 

How to hide version download link for Consumer

hiten_rastogi1
Star Contributor
Star Contributor

Hi,

I want to hide version download link for consumers. Please let me know what needs to be done in order to hide the link.

9 REPLIES 9

ddraper
World-Class Innovator
World-Class Innovator

Could you provide a more detailed description of what you're trying to achieve? There are lots of places/pages in which a download appears? You refer to "version" download - so I would assume that you want to hide a button or buttons on the document details page in the "Version History" section - is this correct?

HI Dave,

Yes, I want to hide the download link available in the version history

section. I have to hide the link for users with consumer role. I am trying

to override the document-versions.js file's function

"*getDocumentVersionMarkup:

function DocumentVersions_getDocumentVersionMarkup(doc)*." I am calling the

membership webscript to check the role of the user "*var json =

remote.call("/api/sites/" + page.url.templateArgs.site + "/memberships/" +

encodeURIComponent(user.name <http://user.name>));*" and hide the link if

the user role is SiteConsumer.

Is this correct ??

Thanks

Hiten Rastogi

Sr. Software Engineer

Mobile: +91 9899586608

Email: hiten.rastogi@eisenvault.com <vipul.swarup@eisenvault.com>

ddraper
World-Class Innovator
World-Class Innovator

Yes, I would say that this looks to be the correct approach. Is it not working?

I can see an error ""Uncaught ReferenceError: remote is not defined ."

Can you please let me know where I am going wrong ?

Thanks

Hiten Rastogi

Sr. Software Engineer

Mobile: +91 9899586608

Email: hiten.rastogi@eisenvault.com <vipul.swarup@eisenvault.com>

ddraper
World-Class Innovator
World-Class Innovator

Ah... this is because "remote" is a variable that is available in the JavaScript controller of the WebScript - not on the client. You should aim to use this capability in the JavaScript controller to determine whether or not the user is a Site Consumer and then pass that information on to a customized version of the Alfresco.DocumentVersions widget. 

You should follow the principals outlined in this blog post for how to do it: https://community.alfresco.com/community/ecm/blog/2012/05/22/customizing-share-javascript-widget-ins... 

Hi Dave,

I am getting an error while customizing docuement-versions.js

file's getDocumentVersionMarkup: function

DocumentVersions_getDocumentVersionMarkup(doc) method. In this I am getting

response object as null but I can see in the developer console that my

membership webscript is returning the desired result. can you please help

me out.

Here is my custom code - http://pastebin.com/ABQ8BubJ

Thanks

Hiten Rastogi

Sr. Software Engineer

Mobile: +91 9899586608

Email: hiten.rastogi@eisenvault.com <vipul.swarup@eisenvault.com>

ddraper
World-Class Innovator
World-Class Innovator

On first inspection it looks like the problem you have is that you're treating an asynchronous request as being synchronous... so you make the call to Alfresco.util.Ajax.jsonGet and then immediately continue the processing and try to reference the variable "json" before the XHR request has completed and set it - this is why it's being reported as null. The XHR request does successfully complete, but not until after you've tried to reference "json".

As I suggested in my previous answer, your best best here is to determine whether or not the user is a SiteConsumer in the JavaScript controller of the WebScript and not on the client-side - otherwise it's just going to make your client side code that much more complicated. The calls using "remote" in the JavaScript controller are handled synchronously.

Hi Dave,

You were right it was an issue related to synchronization, though my Ajax call was fetching the result, albeit late. For the moment I have moved the Ajax call to the controller document-versions.get.js and fetching the result using remote call then passing the result variable to client side javascript document-versions.js. This is achieved by overriding both the files, which works fine, now I want to move the solution to what you have suggested by extending the widget and overriding the function but I am a bit confused.
In the example you have provided you have extended the function onFilterChanged in your custom widget but in my case I want override the function(getDocumentVersionMarkup: function DocumentVersions_getDocumentVersionMarkup(doc)) and modify the original html object that is sent.
Please advise me on how I can achieve that. Attaching overridden files for reference.

ddraper
World-Class Innovator
World-Class Innovator

The basic principal is exactly the same, except that instead of extending the documentlist.get.js controller you're extending the  document-versions.get.js controller and instead of extending the Alfresco.DocumentList widget you're extending the Alfresco.DocumentVersions widget and instead of overriding the onFilterChanged function you're overriding the getDocumentVersionMarkup function.