Ext.define("MyApp.view.Upload",{extend:Ext.form.Panel,itemId:"myform",bodyPadding:10,title:"Upload",layout:{type:"vbox",align:"stretch"},initComponent:function(){var a=this;Ext.applyIf(a,{items:[{xtype:"container",layout:"hbox",items:[{xtype:"filefield",itemId:"fileUpload",fieldLabel:"Choose file to upload",labelSeparator:" ",labelWidth:130,name:"datafile",size:60,buttonMargin:0,buttonOnly:true,clearOnSubmit:false,buttonConfig:{xtype:"filebutton",padding:5,icon:"../gfx/search.png",text:"Browse..."}}]},{xtype:"tbspacer",height:5},{xtype:"textfield",itemId:"filename",maxWidth:500,fieldLabel:"Filename",labelSeparator:" ",labelWidth:130,readOnly:true,grow:true},{xtype:"tbspacer",height:10},{xtype:"container",items:[{xtype:"button",disabled:true,itemId:"btnUpload",padding:5,icon:"../../../common/gfx/upload.png",scale:"medium",text:"Perform upload"}]},{xtype:"tbspacer",height:10},{xtype:"fieldset",flex:5,margin:0,padding:"3 10 5 10",title:"Upload log",layout:{type:"vbox",align:"stretch"},items:[{xtype:"textareafield",flex:1,itemId:"logText",fieldLabel:"",submitValue:false,readOnly:true}]}]});a.callParent(arguments)}});Ext.define("MyApp.controller.UploadController",{extend:Ext.app.Controller,views:["Upload"],refs:[{ref:"fileUpload",selector:"#fileUpload"},{ref:"btnUpload",selector:"#btnUpload"},{ref:"uploadForm",selector:"#myform"},{ref:"logText",selector:"#logText"},{ref:"filename",selector:"#filename"}],init:function(a){this.control({"#uploadType":{change:this.manageUploadButton},"#fileUpload":{change:function(d,c,b){var e=c.replace(/^.*[\\\/]/,"");this.getFilename().setValue(e);this.manageUploadButton()}},"#fldOrigin":{change:this.manageUploadButton},"#btnUpload":{click:this.beginUpload}})},onLaunch:function(){this.checkLastUpload()},checkLastUpload:function(){var b=Ext.Object.fromQueryString(document.location.search);var a=this.getLogText();a.setLoading("Updating...");Ext.Ajax.request({url:"../../service/upload.php",method:"GET",params:b,success:function(e,f){var i=false;var h=e.responseText;var c=Ext.JSON.decode(h);if(c.result.status>1){a.setValue(c.result.log)}else{if(c.result.status===0){a.setValue(CCS.Translator.getText("Upload task queued..."));i=true}else{if(c.result.status===1){if(c.result.log.length>0){a.setValue(c.result.log+"\n"+CCS.Translator.getText("Upload task running..."))}else{a.setValue(CCS.Translator.getText("Upload task running..."))}i=true}}}var g=a.getEl().down("textarea");g.dom.scrollTop=99999;a.setLoading(false);if(i){var d=new Ext.util.DelayedTask(this.checkLastUpload,this);d.delay(3000)}},failure:function(c,d){var e=c.responseText;a.setValue("Failed to get task status: "+e);a.setLoading(false)},scope:this})},manageUploadButton:function(){var b=true;var a=this.getFileUpload().getValue();if(!a||a.length===0){b=false}if(b){this.getBtnUpload().enable()}else{this.getBtnUpload().disable()}},beginUpload:function(){var d=this.getLogText();var b=this;var a=this.checkLastUpload;d.setValue("");var c=this.getUploadForm().getForm();if(c.isValid()){c.submit({url:"../../service/upload.php",params:Ext.Object.fromQueryString(document.location.search),waitMsg:CCS.Translator.getText("Uploading file..."),success:function(f,g){d.setValue(CCS.Translator.getText("Upload task started..."));var e=new Ext.util.DelayedTask(a,b);e.delay(2000)},failure:function(e,f){switch(f.failureType){case Ext.form.action.Action.CLIENT_INVALID:Ext.Msg.alert("Failure","Form fields may not be submitted with invalid values",this.closeDialog,this);break;case Ext.form.action.Action.CONNECT_FAILURE:Ext.Msg.alert("Failure","Ajax communication failed",this.closeDialog,this);break;case Ext.form.action.Action.SERVER_INVALID:Ext.Msg.alert("Upload failed","error: "+f.failureType,this.closeDialog,this);break;default:Ext.Msg.alert("Upload failed","error: "+f.failureType,this.closeDialog,this)}}})}}});