Last active
May 16, 2017 21:22
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
/* Author: Angel Magaña -- [email protected] | |
* 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