Rahul Pethani

7 months ago · 1 min. reading time · visibility 0 ·

chat Contact the author

thumb_up Relevant message Comment

How to Add Document Rating Functionality in Alfresco

How to Add Document Rating Functionality in Alfresco| |We have developed a custom page in Alfresco to list specific types of documents and to rate each of the listed documents.

The page displays the metadata of each of the documents along with the options to rate the document as shown below.

The pop-up will appear once the user clicks on the option given for rating. The user can rate that particular document from the popup.

The user will be asked for confirmation before a rating is done.

Once the confirmation is done, the rating of that document will be visible to the same page.

Alfresco development Related blog: Create Folders and Sub-folders on Uploading a CSV File in Alfresco

The reference code for the same is given below for the Alfresco developers.

1 /** Code Description: Creating a drop-down with a list of ratings. The user can choose one rating from the drop-down.

function displayDropdown(nodeRef, name, type, value, id) { var data ='<select id="'+type+'" name="'+type+'"     onchange="showPopup(\''+nodeRef+'\', \''+name+'\', \''+type+'\',this.value, \''+id+'\');">' +'<option value="" selected>Select</option>' +'<option value="1" '+((value==1)?('selected=\'selected\''):(''))+'>1</option>' +'<option value="2" '+((value==2)?('selected=\'selected\''):(''))+'>2</option>' +'<option value="3" '+((value==3)?('selected=\'selected\''):(''))+'>3</option>' +'<option value="4" '+((value==4)?('selected=\'selected\''):(''))+'>4</option>' +'<option value="5" '+((value==5)?('selected=\'selected\''):(''))+'>5</option>'; return data; };

2  /** Code Description: This popup is required to get input from the user before submitting a rating. It prevents users to submit the rating by mistake.

// showPopup() method

function showPopup(nodeRef, name, type, value, id){ var disable = false; Alfresco.util.PopupManager.displayPrompt( { title: "Rating Confirmation", text: "Are you sure, you want to submit Rating?", buttons: [ { text: "Submit", handler: function close_screen() { storeValue(nodeRef, name, type, value, id); console.log("After Submit"); this.destroy(); } }, { text: "Cancel", handler: function close_cancel() { document.getElementById(type).value = ""; console.log("Cancel button clicked"); this.destroy(); }, isDefault: true }] }); }

3 /** Code Description: This method will invoke Web script to save the rating in the back-end.

function storeValue(nodeRef, name, type, value, id){ var statusParam = { "type" : type, "nodeRef" : nodeRef, "rating": value, "contentName" : name }; Alfresco.util.Ajax.request({ url : Alfresco.constants.PROXY_URI+ "/trams/changeRating", method : Alfresco.util.Ajax.POST, dataObj : statusParam, requestContentType : Alfresco.util.Ajax.JSON, successCallback : { fn : function(res) { console.log(res); displayResults(id); }, scope : this }, failureCallback : { fn : function(res) { }, scope : this } }); }

4 Web-script Controller

/** Code Description: This method will extract the values from a JSON object and save the rating in the back-end.


function main() { var rating = json.get('rating'); var nodeRef = json.get('nodeRef'); var type = json.get('type'); var contentName = json.get('contentName'); var nodeObject = search.findNode(nodeRef); if(type == contentName+'-manager'){ nodeObject.properties['pc:managersRating'] = rating; } else if(type == contentName+'-editor'){ nodeObject.properties['pc:editorsRating'] = rating; } nodeObject.save(); } main();

If you find any challenge in implementing the same, feel free to contact us.

thumb_up Relevant message Comment

More articles from Rahul Pethani

View blog
6 months ago · 1 min. reading time
Rahul Pethani

Create A Custom Post Login Action in Liferay DXP 7.1

While working in the Liferay DXP 7.1 environment, ...

8 months ago · 1 min. reading time
Rahul Pethani

Alfresco Integration with Chronoscan

Chronoscan Introduction: · Chronoscan is a complet ...

10 months ago · 1 min. reading time
Rahul Pethani

Customer Communication Management- Basic Features You Need to Know

Today’s competitive business scenario has compelle ...