Call Us India :- +91 9925144200       US :- +1 (732) 927-5544       Email us : hello@contcentric.com

Blog

Jan 24

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.

document management system

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.

document management system

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

document management system

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

document management system

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.

Prachi Shah

About The Author

1 Comment

  1. Ramesh Chauhan
    January 28, 2019 at 6:44 am · Reply

    Nice feature. It would be good if the rating numbers are configurable instead of hard-coded. For example, instead of 1, 2,3, 4 if someone wants to do 1-star, 2-star, 3-star or Excellent, good, fair and so on…then having the options configurable would be helpful.

Leave a reply

Your email address will not be published. Required fields are marked *