Skip to content

Instantly share code, notes, and snippets.

@AjayKumar01
Last active April 26, 2022 19:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AjayKumar01/86a02bf56ef96e6f0844df56dfd3fc03 to your computer and use it in GitHub Desktop.
Save AjayKumar01/86a02bf56ef96e6f0844df56dfd3fc03 to your computer and use it in GitHub Desktop.
Limiting the subpanel records based on parent module
({
/**
* Purpose:Limiting the subpanel records based on parent module
* Here we are limiting contacts module records based on parent module(Opporunities,Accounts and other module) *
* Path : sugar/custom/modules/contacts/clients/base/views/subpanel-list/subpanel-list.js
* Written by: Ajay Kumar
* Dated: 31 May 2016
*/
extendsFrom:'RecordlistView',
fallbackFieldTemplate: 'list',
plugins: ['ErrorDecoration', 'Editable', 'SugarLogic', 'Pagination', 'LinkedModel', 'ResizableColumns'],
contextEvents: {
"list:editall:fire": "toggleEdit",
"list:editrow:fire": "editClicked",
"list:unlinkrow:fire": "warnUnlink"
},
initialize:function(options){
this._super("initialize", [options]);
var parentModule=this.context.parent.get('model').module;
var subModule=this.context.get('model').module;
var collectionOptions = this.context.has('collectionOptions') ? this.context.get('collectionOptions') : {};
//limiting 20 contacts for parent module opportunities
if((_.isEqual(parentModule,'Opportunities')) && (_.isEqual(subModule,'Contacts'))){
this.context.set('collectionOptions', _.extend(collectionOptions, {
limit: 20
}));
}
else if((_.isEqual(parentModule,'Accounts')) && (_.isEqual(subModule,'Contacts'))){
//limiting 3 contacts for parent module Accounts
this.context.set('collectionOptions', _.extend(collectionOptions, {
limit: 3
}));
}
else{
//Sugar default
this.context.set('collectionOptions', _.extend(collectionOptions, {
limit: app.config.maxSubpanelResult
}));
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment