Created
January 29, 2016 21:00
-
-
Save elchele/46f7f376d0a4c73aec70 to your computer and use it in GitHub Desktop.
Custom RecordView controller for checking if a specific related record(s) exists in a subpanel at time parent record is viewed.
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
({ | |
/* 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 and meet a specific criteria (filter) | |
* You need the "link" field name from vardefs for the specific | |
* subpanel you wish to check. | |
* | |
* This example will check the 'Calls' subpanel for calls where name equals 'Test Call'. | |
*/ | |
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({ | |
filter: [{'name':{'$equals':'Test Call'}}], | |
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