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 the 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 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 user 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.
*/

//change-rating.post.js
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  

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

contact us.
A Preparation Guide for Alfresco Certified Engineer Test

Alfresco

A Preparation Guide for Alfresco Certified Engineer Test

This blog serves as a comprehensive preparation guide for individuals planning to take the Alfresco Certified Engineer test, offering valuable insights, resources, and tips to help them succeed in the certification exam.

Alfresco

Running Alfresco AngularJS Application (0.5.1) without Activiti Explorer

This blog may explain how to run an Alfresco AngularJS application version 0.5.1 independently without the need for Activiti Explorer, offering insights for developers on deploying and utilizing the application in a standalone fashion.

Transform Your Business With Digital Enterprise Solutions

Contact us

Our Offices

INDIA AHMEDABAD, INDIA

401, One World West, Nr. Ambli T-Junction 200, S P Ring Road, Bopal, Ahmedabad, Gujarat 380058

UK
UK

Kemp House 160 City Road, London, United Kingdom EC1V 2NX

GERMANY GERMANY

Nürnberger Str. 46 90579 Langenzenn Deutschland

AUSTRALIA AUSTRALIA

Level 36 Riparian Plaza, 71 Eagle Street, Brisbane, QLD 4000

USA USA

4411 Suwanee Dam road, Bld. 300 Ste. 350 Suwanee GA, 30024

SOUTH AFRICA SOUTH AFRICA

Cube Work Space, 24 Hans Strijdom Avenue, Cape Town

UAE DUBAI, UAE

101-Yes Business Tower, AI Barsha 1 - Dubai United Arab Emirates