Skip to content

Instantly share code, notes, and snippets.

@elchele
Created January 29, 2016 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elchele/7db513a63dd18f61c974 to your computer and use it in GitHub Desktop.
Save elchele/7db513a63dd18f61c974 to your computer and use it in GitHub Desktop.
Custom RecordView controller for checking number of records in a subpanel at time parent record is viewed.
({
/* File: ./custom/modules/<Module>/clients/base/views/record/record.js */
extendsFrom: 'RecordView',
initialize: function(options){
/* 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.
*/
this.once('init', function(){
var subpanelRecs = this.model.getRelatedCollection('calls');
subpanelRecs.once('reset', function(collection){
//Check how many records are in subpanel, if 0, show an alert
var numRecs = collection.length;
if (numRecs === 0)
{
app.alert.show('NoRecs', {
level: 'warning',
title: app.lang.get('LBL_ALERT_TITLE', this.module),
messages: app.lang.get('LBL_ALERT_MESSAGE', this.module),
autoClose: false
});
}
}, this);
subpanelRecs.fetch({relate:true});
}, this);
this._super('initialize', [options]);
},
_dispose: function(){
this._super('_dispose');
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment