PHP Code:
define('custom:opportunity-dynamic-handler', ['dynamic-handler'], function (Dep) {
return Dep.extend({
init: function () {
this.recordView.listenTo(
this.recordView,
'after:render',
this.afterRender.bind(this)
);
this.recordView.listenTo(this.model, 'after:save', (model, options) => {
this.refreshMyModel();
});
},
afterRender: function() {
this.setupBottomPanelCollectionHandlers();
},
setupBottomPanelCollectionHandlers: function() {
let bottomPanelCollections = this.getBottomPanelCollections();
for (let key in bottomPanelCollections) {
let collection = bottomPanelCollections[key];
this.recordView.listenToOnce(collection, 'sync', (collection, data, obj) => {
this.recordView.listenTo(collection, 'update', (collection, o) => {
console.log('update');
this.refreshMyModel();
});
this.recordView.listenTo(collection, 'change', (model, o) => {
console.log('change');
this.refreshMyModel();
});
});
}
},
/**
* Return a object of collections in the bottom panels
* @return {Object<Collection>|{}}
*/
getBottomPanelCollections: function() {
let bottomPanelCollections = {};
let bottomView = this.recordView.getView('bottom') || null;
if (!bottomView) {
return null;
}
let bottomPanelViews = bottomView.nestedViews;
for (let key in bottomPanelViews) {
if (!bottomPanelViews[key].collection) {
continue;
}
bottomPanelCollections[key] = bottomPanelViews[key].collection;
}
return bottomPanelCollections;
},
refreshMyModel: function() {
this.model.save()
},
});
});
Leave a comment: