define('application/widgets/pin/input', [
'application/widgets/pin/inputfield',
'rofl/widgets/label',
'application/widgets/login/keyboard',
'antie/widgets/verticallist'
], function (
InputField,
Label,
Keyboard,
VerticalList
) {
'use strict';
var Input;
Input = VerticalList.extend({
/**
* Initialises the input widget.
*
* @param {Object} config - The configuration.
*/
init: function init (config) {
init.base.call(this);
this.addClass('input');
this._build(config);
},
/**
* Builds the widget.
*
* @param {Object} config - The configuration.
* @private
*/
_build: function (config) {
this._buildInputField(config.inputField);
this._buildErrorMessage(config.errorMessage || '');
this._buildKeyboard(config.inputField);
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 });
title.addClass('title');
this.appendChildWidget(title);
},
/**
* 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 error message.
*
* @param {string} text - The error message.
* @private
*/
_buildErrorMessage: function (text) {
var errorMessage = new Label({ text: text });
errorMessage.addClass('error-msg');
this.appendChildWidget(errorMessage);
},
/**
* 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();
},
/**
* Clears the input field value.
*/
clearInputField: function () {
this._inputField.clearInputField();
},
/**
* Returns inputfield object.
*
* @returns {Object} - Inputfield Object.
*/
getInputField: function () {
return this._inputField;
},
/**
* Returns the keyboard.
*
* @returns {Object} - The keyboard.
*/
getKeyboard: function () {
return this._keyboard;
},
/**
* Shows incorrect error message.
*/
showError: function () {
this.addClass('error');
},
/**
* Hides incorrect error message.
*/
hideError: function () {
this.removeClass('error');
}
});
Input.INPUT_FIELD_TYPES = InputField.TYPES;
return Input;
});