Created
April 22, 2016 10:45
-
-
Save cAstraea/e31b415eff1482e4f4a89653a669fe10 to your computer and use it in GitHub Desktop.
Updates field in Account module from module B. [ Module Accounts <-> Module B in a 1-n relationship ]
This file contains 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
({ extendsFrom: 'RecordView', // extendsFrom: 'CreateView', | |
initialize: function(options) { | |
this._super('initialize', [options]); | |
this.model.on('sync', this.UpdateDateVisite, this); | |
}, | |
UpdateDateVisite : function() { | |
relatedAccId = this.model.get('pca_pack_com_ag_accountsaccounts_ida'); | |
typePack = this.model.get('v_type_pack'); | |
pcaDatVisite = this.model.get('v_date_visite'); | |
if ((typePack == '01') || (typePack == '05')) | |
{ | |
//get the account bean | |
var accountBean = app.data.createBean('Accounts', {id: relAccId}); | |
requestAccount = accountBean.fetch(); | |
requestAccount.xhr.done(function(){ | |
//once you have the Account information compare the visit dates | |
if ( moment(pcaDatVisite).isAfter(accountBean.get('v_der_date_visite_c').substr(0,10))) { | |
//update the date visite of account using api.call | |
app.api.call('update', app.api.buildURL('Accounts/'+relAccId), { "v_der_date_visite_c" : new Date(pcaDatVisite)}, { | |
success: _.bind(function(response) { | |
//response comes back from your api, maybe you want to set some value on your model or alter a response? | |
}, this) | |
}); | |
} | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment