cartodb-4.42/lib/assets/javascripts/builder/components/tab-pane/create-template-tab-pane.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
var _ = require('underscore');
var cdb = require('internal-carto.js');
var TabPaneView = require('./tab-pane-view.js');
var TabPaneCollection = require('./tab-pane-collection');
var TemplateView = require('./tab-pane-template-view');
/**
* Creates a tab pane, where the menu consists of text labels.
*
* Example usage:
* {
* label: 'My label',
* createContentView: cdb.core.View(),
* selected: false
* }
*
* @param {Array} paneItems
* @param {Object} options
* @return {Object} instance of cdb.core.View
*/
module.exports = function (paneItems, options) {
options = options || {};
var tabPaneTemplateOptions = options.tabPaneTemplateOptions;
var items = paneItems.map(function (paneItem) {
['label', 'name', 'createContentView'].forEach(function (check) {
if (!paneItem[check]) {
throw new Error(check + ' should be provided');
}
});
return {
name: paneItem.name,
selected: paneItem.selected,
label: paneItem.label,
createButtonView: function () {
return new TemplateView(_.extend({ model: this }, tabPaneTemplateOptions));
},
createContentView: function () {
return paneItem.createContentView && paneItem.createContentView() || new cdb.core.View();
}
};
});
var collection = new TabPaneCollection(items);
var tabPaneOptions = options.tabPaneOptions;
return new TabPaneView(
_.extend(
{ collection: collection },
tabPaneOptions
)
);
};