Skip to content

Instantly share code, notes, and snippets.

@elchele
Last active January 10, 2019 03:39
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/6f3254f2a83856557ab5 to your computer and use it in GitHub Desktop.
Save elchele/6f3254f2a83856557ab5 to your computer and use it in GitHub Desktop.
Custom record view controller, changes CSS on a given field based on number of subpanel child records linked to current record
({
/* File: ./custom/modules/Accounts/clients/base/views/record/record.js */
extendsFrom: 'RecordView',
initialize: function(options){
this._super('initialize', [options]);
this.model.on('data:sync:complete', this.styleType, this);
},
styleType: function(){
/* Check if related module has records linked to current record
* You need the "link" field name from vardefs for the specific
* subpanel you wish to check.
*
* This example will check the 'Calls' subpanel.
*/
var subpanelRecs = this.model.getRelatedCollection('calls');
subpanelRecs.fetch({
relate: true,
success: function(data){
if (data.models.length === 0)
{
this.$('div[data-name=account_type]').addClass('yellow');
}
}
});
},
_dispose: function(){
this._super('_dispose');
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment