Skip to content

Instantly share code, notes, and snippets.

@elchele

elchele/record.js

Last active Jan 10, 2019
Embed
What would you like to do?
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