Source: widgets/detail/tablist.js

define('application/widgets/detail/tablist', [
    'rofl/widgets/horizontallist',
    'rofl/widgets/button',
    'rofl/widgets/label',
    'rofl/widgets/verticallist',
    'rofl/widgets/container',
    'rofl/lib/utils'
], function (
    HorizontalList,
    Button,
    Label,
    VerticalList,
    Container,
    Utils
) {
    'use strict';

    return Container.extend({

        /**
         * Initialises the widget.
         */
        init: function init () {
            init.base.call(this);

            this.addClass('tabslist');
            this._build();
        },

        /**
         * Builds the widget.
         *
         * @private
         */
        _build: function () {
            var tabSelector = this._tabSelector = new HorizontalList(),
                tabContainer = this._tabContainer = new Container(),
                list = this._list = new VerticalList();

            tabSelector.addClass('tab-selector');
            tabContainer.addClass('tab-container');

            list.appendChildWidget(tabSelector);
            list.appendChildWidget(tabContainer);

            this.appendChildWidget(list);
        },

        /**
         * Sets the data item.
         *
         * @param {Object} tabs - The tabs to set.
         */
        setDataItem: function (tabs) {
            var tabSelector = this._tabSelector,
                tabContainer = this._tabContainer;

            tabSelector.removeChildWidgets();
            tabContainer.removeChildWidgets();

            this._tabs = tabs;

            Utils.each(tabs, function (tab) {
                tabSelector.appendChildWidget(this._createTabButton(tab.text));
                tabContainer.appendChildWidget(new tab.widget(tab.data, tab.params));
            }, this);
        },

        /**
         * Creates the button.
         *
         * @param {string} text - The text.
         * @returns {Object} - The button.
         * @private
         */
        _createTabButton: function (text) {
            var button = new Button(),
                label = new Label(text);

            button.appendChildWidget(label);
            button.setDisabled(true);

            return button;
        },

        getTab: function (index) {
            return this._tabContainer.getChildWidgetByIndex(index || 0);
        },

        /**
         * Set focus on tab selector.
         **/
        focusSelector: function () {
            this._tabSelector.getChildWidgetByIndex(0).focus();
        },

        /**
         * Set focus on tab container.
         */
        focusTab: function () {
            this._tabContainer.getChildWidgetByIndex(0).focus();
        },

        updateTabData: function (data) {
            this.getTab(0).setDataItem(data);
        }
    });
});