Last active
December 24, 2015 10:37
-
-
Save shijinkrishna/6d4c1b11643e0186efa5 to your computer and use it in GitHub Desktop.
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: 'LinkActionField', | |
initialize: function(options) { | |
this._super('initialize', [options]); | |
}, | |
openSelectDrawer: function() { | |
if (this.isDisabled()) { | |
return; | |
} | |
var parentModel = this.context.get('parentModel'), | |
linkModule = this.context.get('module'), | |
link = this.context.get('link'), | |
self = this; | |
var filterOptions = new app.utils.FilterOptions() | |
.config({ | |
'initial_filter': 'filterContactTemplate', | |
'initial_filter_label': 'LBL_FILTER_CONTACT_TEMPLATE', | |
'filter_populate': { | |
'account_id': this.context.get('parentModel').get('account_id'), | |
} | |
}) | |
.format(); | |
var context = { | |
module: linkModule, | |
recParentModel: parentModel, | |
recLink: link, | |
recContext: this.context, | |
recView: this.view | |
} | |
//this code will execute for all contact subpanel,to apply the filter only for opportunities we will give a condition | |
if(_.isEqual(this.context.get('parentModel').get('_module'),"Opportunities")){ | |
context = _.extend(context, { | |
filterOptions: filterOptions | |
}); | |
} | |
app.drawer.open({ | |
layout: 'selection-list', | |
context: context, | |
}, function(model) { | |
if (!model) { | |
return; | |
} | |
var relatedModel = app.data.createRelatedBean(parentModel, model.id, link), | |
options = { | |
showAlerts: true, | |
relate: true, | |
success: function(model) { | |
self.context.get('collection').resetPagination(); | |
self.context.resetLoadFlag(); | |
self.context.set('skipFetch', false); | |
var collectionOptions = self.context.get('collectionOptions') || {}; | |
if (collectionOptions.limit) self.context.set('limit', collectionOptions.limit); | |
self.context.loadData({ | |
success: function() { | |
self.view.layout.trigger('filter:record:linked'); | |
}, | |
error: function(error) { | |
app.alert.show('server-error', { | |
level: 'error', | |
messages: 'ERR_GENERIC_SERVER_ERROR' | |
}); | |
} | |
}); | |
}, | |
error: function(error) { | |
app.alert.show('server-error', { | |
level: 'error', | |
messages: 'ERR_GENERIC_SERVER_ERROR' | |
}); | |
} | |
}; | |
relatedModel.save(null, options); | |
}); | |
}, | |
}) | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment