Skip to content

Instantly share code, notes, and snippets.

@elchele
Last active May 16, 2017 21:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elchele/2418b2fe894d87b0e4cc to your computer and use it in GitHub Desktop.
Save elchele/2418b2fe894d87b0e4cc to your computer and use it in GitHub Desktop.
Custom controller for subpanels layout, hides specific subpanels based on parent record data
({
/* Author: Angel Magaña -- cheleguanaco@cheleguanaco.com
* File: ./custom/modules/<Module>/clients/base/layouts/subpanels/subpanels.js
*
* Extended subpanels layout controller for hiding
* subpanels upon record load and based on parent record data
*
*/
extendsFrom: 'SubpanelsLayout',
initialize: function(options) {
this._super('initialize', [options]);
//Perform check of parent data once parent record finishes loading
this.model.on('data:sync:complete', this.doRecordCheck, this);
},
doRecordCheck: function() {
var sRecType = this.model.get('lead_source');
var oHidden = [];
//Set the list of subpanels to be hidden, based on Lead Source value
switch(sRecType) {
case 'Cold Call':
oHidden = ['calls', 'meetings'];
break;
}
if (sRecType === 'Cold Call')
{
_.each(this._components, function(component) {
//Get link name (relationship)
var link = component.context.get('link');
//Hide subpanels if in list of subpanels to be hidden
if (oHidden.indexOf(link) > -1)
{
component.remove();
}
});
}
},
_dispose: function(){
this._super('_dispose');
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment