Source: widgets/settings/button.js

define('application/widgets/settings/button', [
    'application/widgets/pointerfocusablebutton',
    'rofl/widgets/label',
    'rofl/lib/l10n'
], function (
    PointerFocusableButton,
    Label,
    L10N
) {
    'use strict';

    var l10n = L10N.getInstance();

    return PointerFocusableButton.extend({

        /**
         * Initialises the button.
         *
         * @param {string} text - The button text.
         * @param {string} [id] - The id. Optional.
         */
        init: function init (text, id) {
            init.base.call(this, id);
            this.addClass('settings-button');

            this._build(text);
        },

        /**
         * Builds the widget.
         *
         * @param {string} text - The text to set.
         * @private
         */
        _build: function (text) {
            var label = this._label = new Label({ text: text || '', classNames: ['action-label'] }),
                labelIcon = this._labelIcon = new Label({ text: '', classNames: ['label-icon'] }),
                onOff = this._onOffValue = new Label({ text: '', classNames: ['on-off'] });

            this.appendChildWidget(labelIcon);
            this.appendChildWidget(label);
            this.appendChildWidget(onOff);
        },

        /**
         * Return button label.
         *
         * @returns {Label} Label of this button.
         */
        getLabel: function () {
            return this._label;
        },

        /**
         * Return button label icon.
         *
         * @returns {Label} Label of this button.
         */
        getLabelIcon: function () {
            return this._labelIcon;
        },

        /**
         * Sets onoff label.
         *
         * @param {boolean} onOff - On off.
         */
        setOnOffValue: function (onOff) {

            this._onOffValue.setText(onOff ? l10n.get('settings.modal.on_off_button.on') : l10n.get('settings.modal.on_off_button.off'));
        },

        /**
         * Return button text.
         *
         * @returns {string} Text of this button.
         */
        getText: function () {
            return this._label.getText();
        }
    });
});