JavaScript
Ext.onReady(function() {
//
Ext.apply(Ext.money.Exchange.defaults,{
rates: [ // override global default rates for demo, these are USD->* exchange rates.
['inr','Rupees','1,000.00 INR',1],
['usd','Dollars','1,000.00 USD',1],
['eur','Euro','1,000.00 EUR',0.73136839],
['chf','Francs','1,000.00 CHF',0.945275],
['gbp','Pounds','1,000.00 GBP',0.615527],
['rub','Rubles','1,000.00 RUB',29.1650],
['crc','Colones','1,000.00 CRC',496]
]
});
var
// create monex instance
monex = new Ext.money.Exchange({
source: 'gbp',
target: 'usd'
}),
// create inline extension for combobox selectors.. saves code
mxCB = Ext.extend(Ext.form.ComboBox,{
width: 100,
store: monex.getStore(),
editable: false,
valueField: 'id',
displayField: 'name',
triggerAction: 'all',
forceSelection: true,
mode: 'local',
listeners: { select: function(p){ updateExample(); } }
}),
updateExample = function(source,target){
source = source || Ext.getCmp('cS').getValue();
target = target || Ext.getCmp('cT').getValue();
// update monex with new settings
monex.setSource( source );
monex.setTarget( target );
// update displayed result
var amount = parseFloat(Ext.get('cA').getValue());
Ext.get('tResult').update( String.format('<b>{0}</b> is equal to <b>{1}</b>',
monex.formatCurrency(amount, monex.getCurrencySource()),
monex.convert(amount)) );
};
// create main calculator panel
new Ext.Panel({
title: 'Example Exchange Rate Calculator',
renderTo: 'exampleExchange',
width: 400,
items: [
{xtype:'panel',id:'tResult',cls:'example'},
{xtype: 'form',padding:10,border:false,labelWidth:50,labelAlign:'right',items:[
// amount to convert
{ xtype: 'textfield', id:'cA',value: 10000,fieldLabel:'Amount',
listeners: { change: function(p){ updateExample(); } } },
// default value to source currency
...