Ext.BLANK_IMAGE_URL='./ext/resources/images/default/s.gif';Ext.onReady(function(){Ext.app.REMOTING_API.enableBuffer=100;Ext.Direct.addProvider(Ext.app.REMOTING_API);Ext.QuickTips.init();function updateList(){var typefield=theform.findField('type');var listfield=theform.findField('list[]');var amountfield=theform.findField('amount');if(typefield.getValue()=='drink'){var number=listfield.getValueEx().length;amountfield.setRawValue(number+' x 0.50');}else if(typefield.getValue()=='lunch'){var number=listfield.getValueEx().length;amountfield.setRawValue(number+' x 2.14');}} function userChanged(combo,record,index){var listfield=theform.findField('list[]');if(record&&listfield.getValueEx().length===0){listfield.setValue([record.get('id')]);}} function typeChanged(combo,record,index){var amountfield=theform.findField('amount');var descfield=theform.findField('description');if(combo.getValue()=='drink'){amountfield.disable();descfield.setValue("Random Drinks");}else if(combo.getValue()=='lunch'){amountfield.disable();descfield.setValue("DUTRacing Lunch");}else{amountfield.enable();amountfield.reset();descfield.reset();} updateList();} function clearStatus(){var el=Ext.get('turfresult');el.hide();} function updateStatus(status,text,anim){if(!text){text=' ';} var el=Ext.get('turfresult');el.update(text);el.removeClass(["icon-none","icon-info","icon-warning","icon-loading"]);el.addClass("icon-"+status);el.show(anim);clearStatus.defer(25000);} function turfStart(form,action){updateStatus('loading');} function turfComplete(form,action){Ext.ux.Sound.play('media/goat-bleet.wav');var msg=action.result?action.result.message:"";var el=Ext.get('turfresult');updateStatus('info',msg,{duration:0.5});theform.findField('user').focus();theform.reset();} function turfFailed(form,action){var msg=action.result?action.result.message:"Something went wrong...";var el=Ext.get('turfresult');updateStatus('warning',msg,{duration:0.5});} var userStore=new Ext.data.DirectStore({storeId:'userstore-id',autoLoad:true,remoteSort:false,paramsAsHash:false,api:{read:Ext.app.User.read},idProperty:'id',fields:[{name:'id',type:'int'},{name:'group',type:'string'},{name:'name',type:'string'}]});var turfform=new Ext.form.FormPanel({border:false,autoHeight:true,bodyStyle:'padding:0 0 0 10px',labelAlign:'top',api:{submit:Ext.app.Transaction.submit},listeners:{'beforeaction':{fn:turfStart,scope:this},'actioncomplete':{fn:turfComplete,scope:this},'actionfailed':{fn:turfFailed,scope:this}},items:[{layout:'column',border:false,defaults:{layout:'form',border:false},items:[{columnWidth:.4,items:[{xtype:'combo',hiddenName:'user',fieldLabel:'Your Name',anchor:'-10',tabIndex:1,allowBlank:false,store:userStore,mode:'local',displayField:'name',valueField:'id',triggerAction:'all',listeners:{'select':{fn:userChanged,scope:this}}}]},{columnWidth:.3,items:[{xtype:'combo',hiddenName:'type',fieldLabel:'What',anchor:'-10',allowBlank:false,store:[['general','General']],editable:false,triggerAction:'all',listeners:{'select':{fn:typeChanged,scope:this}}}]},{columnWidth:.3,items:[{xtype:'numberfield',name:'amount',fieldLabel:'Amount (Total)',anchor:'-8',allowBlank:false,allowNegative:false,style:'text-align: right',decimalPrecision:2}]}]},{layout:'column',border:false,defaults:{layout:'form',border:false},items:[{columnWidth:.4,items:[{xtype:'datefield',name:'date',fieldLabel:'Date (As on receipt!)',anchor:'-10',allowBlank:false,format:'D d-m-y',value:new Date()}]},{columnWidth:.60,items:[{xtype:'textfield',name:'description',fieldLabel:'Description',anchor:'-10',allowBlank:false}]}]},{xtype:'superboxselect',name:'list[]',fieldLabel:'People to Turf',anchor:'-10',allowBlank:false,store:userStore,mode:'local',displayField:'name',valueField:'id',removeValuesFromStore:false,preventDuplicates:false,renderFieldBtns:false,navigateItemsWithTab:false,resizable:true,listeners:{'additem':{fn:updateList,scope:this},'removeitem':{fn:updateList,scope:this}}}],buttons:[{xtype:'box',autoEl:{id:'turfresult',cls:'formstatus',tag:'div',html:''}},{text:'Turf',scope:this,handler:function(){theform.submit();}},{text:"Reset",scope:this,handler:function(){theform.reset();theform.findField('user').focus();updateStatus();}}]});var cp=new Ext.Panel({layout:'ux.center',renderTo:'container',border:false,margins:'60 0 0 0',width:'100%',items:[{baseCls:'x-bubble',frame:true,padding:5,width:450,autoHeight:true,items:[turfform]}]});var theform=turfform.getForm();});