Source: widgets/warmwelcome/content.js

define('application/widgets/warmwelcome/content', [
    'rofl/widgets/container',
    'rofl/widgets/label',
    'rofl/widgets/image',
    'application/widgets/pointerfocusablebutton'
], function (
    Container,
    Label,
    Image,
    Button
) {
    'use strict';

    return Container.extend({

        /**
         * Initialises the replay component.
         *
         * @param {Object} config - Config.
         */
        init: function init (config) {
            init.base.call(this, config.id);

            this.addClass('content-page');
            this._build(config);
        },

        /**
         * Builds the component.
         *
         * @param {Object} config - Config.
         * @private
         */
        _build: function (config) {
            this._buildContainer();
            this._buildMainText(config.text);

            if (config.image) {
                this._buildLogo(config.image);
            }

            if (config.subtext) {
                this._buildSubtext(config.subtext);
            }

            this._buildButton(config.button);

            if (config.secondImage) {
                this._buildImage(config.secondImage);
            }
        },

        /**
         * Builds the main container.
         *
         * @private
         */
        _buildContainer: function () {
            var container = this._container = new Container();

            container.addClass('main-container');

            this.appendChildWidget(container);
        },

        /**
         * Builds the main text widget.
         *
         * @param {string} text - The text.
         * @private
         */
        _buildMainText: function (text) {
            var container = this.getContainer(),
                mainText = new Label({ text: text, classNames: ['main-text'] });

            container.appendChildWidget(mainText);
        },

        /**
         * Builds the subtext.
         *
         * @param {string} text - The subtext.
         * @private
         */
        _buildSubtext: function (text) {
            var container = this.getContainer(),
                subText = new Label({ text: text, classNames: ['sub-text'], enableHTML: true });

            container.appendChildWidget(subText);
        },

        /**
         * Builds the logo widget.
         *
         * @param {string} image - Image.
         * @private
         */
        _buildLogo: function (image) {
            var container = this.getContainer(),
                logo = new Image();

            logo.addClass('logo-image');
            logo.setSrc(image);

            container.appendChildWidget(logo);
        },

        /**
         * Builds the image widget.
         *
         * @param {string} image - Image.
         * @private
         */
        _buildImage: function (image) {
            var img = new Image();

            img.addClass('image');
            img.setSrc(image);

            this.appendChildWidget(img);
        },

        /**
         * Builds the button.
         *
         * @param {Object} config - The configuration.
         * @private
         */
        _buildButton: function (config) {
            var container = this.getContainer(),
                helper,
                text,
                button,
                icon;

            if (config) {

                helper = new Label({ text: '', classNames: ['v-align-helper'] });
                text = new Label({ text: config.text, classNames: ['v-align-target'] });

                button = new Button();
                button.appendChildWidget(helper);
                button.appendChildWidget(text);
            } else {

                config = {};
                button = new Button('');
                button.addClass('hidden');
            }

            button.addClass('icon-button');

            if (config.icon) {
                icon = new Label({ text: '', classNames: ['icon', config.icon, 'v-align-target'] });
                button.insertChildWidget(1, icon);
            }

            container.appendChildWidget(button);
        },

        /**
         * Returns main container.
         *
         * @returns {Object} - The container widget.
         */
        getContainer: function () {
            return this._container;
        }
    });
});