I have created a custom dashlet class that extends from tabbed dashlet view and implements some methods from the dashable list class to create a tabbed list view:
(If there is a simple way to do this, then I would love to hear it)
The dashlet consists of three files: a javascript file, a php config file and a record.hbs file. Here is the javascript file:
({
extendsFrom: 'TabbedDashletView',
initialize: function (options) {
options.meta = options.meta || {};
options.meta.template = 'tabbed-dashlet';
this._super('initialize', [options]);
},
initDashlet: function() {
this._super("initDashlet");
this.metaFields = this._getColumnsForDisplay();
},
_getColumnsForDisplay: function() {
var columns = [];
var fields = this.getFieldMetaForView(this._getListMeta(this.settings.get('module')));
var moduleMeta = app.metadata.getModule(this.module);
_.each(this.settings.get('display_columns'), function(name) {
var field = _.find(fields, function(field) {
return field.name === name;
}, this);
field = field || app.metadata._patchFields(this.module, moduleMeta, [name]);
//Set the sortable flag to false until sorting is implemented
columns.push(_.extend({sortable: false}, field));
}, this);
return columns;
},
getFieldMetaForView: function(meta) {
meta = _.isObject(meta) ? meta : {};
return !_.isUndefined(meta.panels) ? _.flatten(_.pluck(meta.panels, 'fields')) : [];
},
_getListMeta: function(module) {
return app.metadata.getView(module, 'list');
},
_getCollectionFilters: function(index) {
var tab = this.tabs[index];
var filters = [];
var today = new Date();
_.each(tab.filters, function(condition, field) {
var filter = {};
filter[field] = condition;
filters.push(filter);
});
today.toISOString();
if (this.settings.get('overdue') === 'overdue') {
filters.push({
date_due: {$lt: today}
});
}
return filters;
},
})
We have two custom dashlets that we wish to create that would require the same javascript, but different php config files. I was wondering how I would go about making my javascript file extendable so that I am not duplicating a lot of code.
Thanks for any help.