Last active
November 19, 2023 17:38
-
-
Save Dellos7/fb116b2352e78c87a4747bd003e0aa2c to your computer and use it in GitHub Desktop.
SugarCRM - Open selection-list drawer with custom collection
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
initialize: function(options) { | |
this.plugins = _.union(this.plugins, ['LinkedModel']); | |
this._super('initialize', [options]); | |
//Example of use | |
this.search( 'ProductTemplates', 'revenuelineitem_templates','what I want to search' ); | |
}, | |
/** | |
@param module: The module of the collection you want to retrieve records from | |
@param linkModelRelName: the name of the relationship between the module you are opening the drawer from and the module of the drawer you are opening | |
@param query: the query you want to search in the globalsearch endpoint | |
**/ | |
search: function(module, linkModelRelName, query) { | |
var self = this; | |
var model = self.model; | |
var pt = app.data.createBeanCollection(module); | |
//Set the endpoint from which the collection will fetch the data | |
pt.setOption('endpoint', function(method, collection, options, callbacks) { | |
//Filters on the 'selection-list' view will not work depending on your endpoint | |
var params = options.params; | |
//This way I concatenate in the query to the globalsearch endpoint the 'name' filter that I'm using | |
//in the selection-list view - rest of the filters don't work for this endpoint | |
if (params.filter && params.filter[0].$or[0].name.$starts) { | |
params.q = query + " " + params.filter[0].$or[0].name.$starts; | |
} else { | |
params.q = query; | |
} | |
var url = app.api.buildURL(module, 'globalsearch', null, params); | |
return app.api.call('get', url, null, callbacks); | |
}); | |
app.drawer.open({ | |
layout: 'selection-list', | |
context: { | |
module: module, | |
parent: self.context, | |
model: self.createLinkModel(model, linkModelRelName), | |
collection: pt, | |
} | |
}, _.bind(self.recordSelected, { | |
model: model | |
})); | |
}, | |
//Here you will retrieve the record selected in the 'selection-list' view | |
recordSelected: function(recordSelected) { | |
console.log('RECORD SELECTED! ' + recordSelected); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment