Source: widgets/login/input.js

define('application/widgets/login/input', [
    'application/widgets/login/inputfield',
    'rofl/widgets/label',
    'application/widgets/login/keyboard',
    'antie/widgets/verticallist',
    'application/widgets/button',
    'rofl/widgets/horizontallist'
], function (
    InputField,
    Label,
    Keyboard,
    VerticalList,
    KPNButton,
    HorizontalList
) {
    'use strict';

    var Input;

    Input = VerticalList.extend({

        /**
         * Initialises the input widget.
         *
         * @param {Object} config - The configuration.
         * @param {string} config.title - The input title.
         * @param {Object} config.inputField - The inputfield options.
         * @param {Object} config.inputField.title - The inputfield title.
         * @param {string} config.inputField.type - The input type. TYPES.PASSWORD or TYPES.TEXT.
         * @param {Object} [config.inputField.opts] - The options. Optional.
         */
        init: function init (config) {
            init.base.call(this);

            this.addClass('input');
            this._build(config);
        },

        /**
         * Builds the widget.
         *
         * @param {Object} config - The configuration.
         * @param {string} config.title - The input title.
         * @param {Object} config.inputField - The inputfield options.
         * @param {Object} config.inputField.title - The inputfield title.
         * @param {string} config.inputField.type - The input type. TYPES.PASSWORD or TYPES.TEXT.
         * @param {Object} [config.inputField.opts] - The options. Optional.
         * @private
         */
        _build: function (config) {
            this._buildTitle(config.title || '');
            this._buildInputField(config.inputField);
            this._buildKeyboard(config.inputField);
            this._buildValidateMessage(config.validationMsg || '');

            if (config.nextPageButton && config.backButton && config.forgottenLoginButton) {
                this._buildNextPageButton(config.nextPageButton || '');
                this._buildTwoButtonHorizontalList(config.backButton, config.forgottenLoginButton || '', 'username');
            }

            if (config.backButton && config.loginButton) {
                this._buildLoginButton(config.loginButton || '');
                this._buildTwoButtonHorizontalList(config.backButton, config.forgottenLoginButton || '', 'pin');
            }

            this._inputField.setKeyboard(this._keyboard.getKeyboard());
        },

        /**
         * Builds the title.
         *
         * @param {string} text - The text.
         * @private
         */
        _buildTitle: function (text) {
            var title = this._title = new Label({ text: text, classNames: ['title'] });

            this.appendChildWidget(title);
        },

        /**
         * Builds the NextPageButton.
         *
         * @param {string} text - The text.
         * @private
         */
        _buildNextPageButton: function (text) {
            var button = this._button = new KPNButton(text, 'next');

            button.addClass('next');

            this.appendChildWidget(button);
        },

        /**
         * Builds the Login button.
         *
         * @param {string} text - The text.
         * @private
         */
        _buildLoginButton: function (text) {
            var button = this._button = new KPNButton(text, 'loginbtn');

            button.addClass('loginbtn');

            this.appendChildWidget(button);
        },

        /**
         * Builds horizontall list of buttons.
         *
         * @param {string} text1 - The text for first button.
         * @param {string} text2 - The text for second button.
         * @param {string} screenType - The type of the screen - username / pin.
         */
        _buildTwoButtonHorizontalList: function (text1, text2, screenType) {
            var list = new HorizontalList(),
                backButton = this._backbutton = new KPNButton(text1, 'back'),
                forgottenButtonType = (screenType === 'pin') ? 'forgottenpin' : 'forgotten',
                forgottenButton = this._forgottenbutton = new KPNButton(text2, forgottenButtonType);

            forgottenButton.addClass(['forgotten', 'blurred']);
            backButton.addClass('back');
            list.addClass('buttons-list');

            list.appendChildWidget(backButton);

            list.appendChildWidget(forgottenButton);
            this.appendChildWidget(list);
        },

        /**
         * Builds the input field.
         *
         * @param {Object} config - The inputfield options.
         * @param {Object} config.title - The inputfield title.
         * @param {string} config.type - The input type. TYPES.PASSWORD or TYPES.TEXT.
         * @param {Object} [config.opts] - The options. Optional.
         * @private
         */
        _buildInputField: function (config) {
            var inputField = this._inputField = new InputField(config);

            this.appendChildWidget(inputField);
        },

          /**
         * Builds the validate message.
         *
         * @param {string} text - The validation message.
         * @private
         */
        _buildValidateMessage: function (text) {
            var validationMessage = this._validationMessage = new Label({ id: 'validationmsg', text: text, classNames: ['validationmsg'] });

            this.appendChildWidget(validationMessage);
        },

        /**
         * Builds the keyboard.
         *
         * @param {Object} config - The inputfield options.
         * @param {Object} config.title - The inputfield title.
         * @param {string} config.type - The input type. TYPES.PASSWORD or TYPES.TEXT.
         * @param {Object} [config.opts] - The options. Optional.
         * @private
         */
        _buildKeyboard: function (config) {
            var keyboard = this._keyboard = new Keyboard(config);

            this.appendChildWidget(keyboard);
        },

        /**
         * Returns value of the input.
         *
         * @returns {string} - Value of the inupt.
         */
        getValue: function () {
            return this._inputField.getValue();
        },

        /**
         * Returns inputfield object.
         *
         * @returns {Object} - Inputfield Object.
         */
        getInputField: function () {
            return this._inputField;
        },

        /**
         * Returns the keyboard.
         *
         * @returns {Object} - The keyboard.
         */
        getKeyboard: function () {
            return this._keyboard;
        },

        /**
         * Returns the validation message.
         *
         * @returns {Object} - The validation message.
         */
        getValidationMessage: function () {
            return this._validationMessage;
        },

        /**
         * Returns the button.
         *
         * @returns {Object} - The button.
         */
        getButton: function () {
            return this._button;
        }

    });

    Input.INPUT_FIELD_TYPES = InputField.TYPES;

    return Input;
});