Skip to content

Instantly share code, notes, and snippets.

@tanepiper tanepiper/ExtJS3.js Secret
Created Apr 18, 2011

Embed
What would you like to do?
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
You can’t perform that action at this time.