Skip to content

Instantly share code, notes, and snippets.

@tanepiper
Created April 18, 2011 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanepiper/0cb92a60c6c7239cd6b9 to your computer and use it in GitHub Desktop.
Save tanepiper/0cb92a60c6c7239cd6b9 to your computer and use it in GitHub Desktop.
Ext.ns('Client.Components');
/**
* @class Crux.Components.TimespanField
* @namespace Crux.Components
* @extends Ext.Container
* A field for setting time to recover, contains a prefix and suffix field
* @author Tane Piper
* @version 1.0.0
* @xtype cruxComponentsFieldsTimeToRecover
*/
Client.Components.TimespanField = Ext.extend(Ext.form.CompositeField, {
fieldLabel: 'Time Span',
/**
* Method called on component intitialisation
* @method initComponent
*/
//protected
initComponent: function initComponent() {
var config = {
layout: 'hbox',
defaults: {
style: {
marginBottom: '5px'
}
}
};
this.buildConfig(config);
Ext.apply(this, Ext.apply(this.initialConfig, config));
Client.Components.TimespanField.superclass.initComponent.apply(this, arguments);
},
/**
* Calls additional methods with the passed config object to build up the component
* @method buildConfig
* @param {Object} config The configuration object
*/
buildConfig: function buildConfig(config) {
this.buildItems(config);
},
/**
* Creates an array of items to attach to the compsite field
* @method buildItems
* @param {Object} config The configuration object
*/
buildItems: function buildItems(config) {
config.items = [
{
xtype: 'spinnerfield',
name: 'prefix',
ref: 'prefix',
submitValue: false,
flex: 1,
minValue: 1,
maxValue: 999,
allowDecimals: false,
accelerate: true,
allowBlank: true
},
{
xtype: 'combo',
name: 'suffix',
ref: 'suffix',
submitValue: false,
flex: 1,
typeAhead: true,
triggerAction: 'all',
lazyRender:true,
mode: 'local',
editable: false,
store: new Ext.data.ArrayStore({
fields: ['suffix'],
data: [ ['Minutes'], ['Hours'], ['Days'], ['Weeks'], ['Months'], ['Years'] ]
}),
valueField: 'suffix',
displayField: 'suffix'
}
]
},
/**
* Sets the values of the fields, passed from form data
* @method setValue
* @param {Array} value The Array containing the values for each field
*/
setValue: function setValue(value) {
if (value && value.length > 0) {
this.prefix.setValue(value[0]);
this.suffix.setValue(value[1]);
}
},
/**
* Gets the combined values of each field and returns as an array
* @method setValue
* @param {Array} value The Array containing the values for each field
*/
getValue: function getValue() {
return [
this.prefix.getValue(),
this.suffix.getValue()
];
}
});
Ext.reg('timespan', Client.Components.TimespanField);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment