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.

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' 
+'1' 
+'2' 
+'3' 
+'4' 
+'5'; 
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

Transform Your Business With Digital Enterprise Solutions

Contact us

Our Offices

AHMEDABAD, INDIA

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

UK

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

GERMANY

Nürnberger Str. 46 90579 Langenzenn Deutschland

AUSTRALIA

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

USA

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

SOUTH AFRICA

Cube Work Space, 24 Hans Strijdom Avenue, Cape Town

Mahindra DUBAI, UAE

B 503 Sama Tower, Sheikh Zayed Road, United Arab Emirates

CANADA

34 Applegrove Ct. Brampton ON L6R 2Y8