Ext.namespace("Ext.ux.form.photoUploadField");var photoChooser=function(b){this.config=b};photoChooser.prototype={data:new Object(),cropper:null,show:function(e,g){var h=this.data;if(!this.win){var f={title:"Upload a Profile Picture",id:"photo-uploader-dlg",minWidth:300,minHeight:200,modal:true,autoScroll:false,border:false,bodyStyle:"background:#ffffff none repeat scroll 0 0;",items:[new Ext.FormPanel({cls:"pagelayout",region:"center",border:false,defaultType:"textfield",enctype:"multipart/form-data",autoScroll:false,fileUpload:true,width:"300",minWidth:"300",style:"background:#ffffff none repeat scroll 0 0;margin-left:0px;margin-right:0px;margin-top: 0px;width:300;",bodyStyle:"margin-left:10px;margin-top: 10px;margin-right:auto;width:300;",items:[new Ext.form.FileUploadField({emptyText:"no file selected",buttonCfg:{text:"",iconCls:"useruploadicon"},fieldLabel:"",hideLabel:true,style:"overflow: hidden;",name:"photoupload",id:"photoupload",allowBlank:false,autoScroll:false,width:250,listeners:{fileselected:function(a,c){var b=a.findParentByType("form");b.suspendEvents();b.getForm().submit({clientValidation:false,method:"POST",waitTitle:"Saving picture",waitMsg:"Please wait while your picture is saved",url:"/echo/modules/users/picture.jsp",success:function(d,j){h.fileitem=j.result.file;h.height=j.result.height;h.width=j.result.width;Ext.getCmp("photo-uploader-dlg").remove(Ext.getCmp("photo-uploader-dlg").items.itemAt(0),true);Ext.get(Ext.getCmp("photo-uploader-dlg").body).insertFirst({tag:"img",width:j.result.width,height:j.result.height,id:"photouploadedmedia",src:"./modules/users/getTempPicture.jsp?f="+j.result.file});Ext.getCmp("photo-uploader-dlg").setWidth(parseInt(j.result.width)+10);Ext.getCmp("photo-uploader-dlg").setHeight(j.result.height);Ext.getCmp("photo-uploader-ok-btn").enable();Ext.getCmp("photo-uploader-dlg").cropper=new Cropper.Img("photouploadedmedia",{minHeight:100,maxHeight:100,minWidth:100,maxWidth:100,displayOnInit:true,ratioDim:{x:100,y:100},onEndCrop:function(i,l){h.crop=new Array();h.crop.x1=i.x1;h.crop.y1=i.y1;h.crop.x2=i.x2;h.crop.y2=i.y2;h.crop.width=l.width;h.crop.height=l.height}})},failure:function(d,j){Ext.Msg.alert("Unable to use image",j.result.message)}})}},labelStyle:"label"})]})],buttons:[{id:"photo-uploader-ok-btn",text:"OK",disabled:true,handler:this.doCallback,scope:this},{text:"Cancel",handler:function(){this.win.close();this.win.destroy()},scope:this}]};Ext.apply(f,this.config);this.win=new Ext.Window(f)}this.win.show(e);this.callback=g;this.animateTarget=e;me=this.win},doCallback:function(){var g=this.callback;var e=this.data;var h=this.win;var f=new Ext.data.Connection();f.request({url:"./modules/users/croppicture.jsp",method:"post",params:{fileitem:e.fileitem,x1:e.crop.x1,y1:e.crop.y1,x2:e.crop.x2,y2:e.crop.y2,width:e.crop.width,height:e.crop.height},success:function(b){var a=Ext.util.JSON.decode(b.responseText);e.fileitem=a.file;e.uid=a.uid;h.hide(this.animateTarget,function(){if(g){g(e)}});h.destroy()},failure:function(){}})}};Ext.ux.form.photoUploadField=function(b){Ext.apply(this,b);Ext.ux.form.photoUploadField.superclass.constructor.call(this,{region:"center"})};Ext.extend(Ext.ux.form.photoUploadField,Ext.form.TriggerField,{mediaFile:"",mediaHeight:0,mediaWidth:0,mediaAlign:"Default",triggerClass:"x-form-search-trigger",initComponent:function(){Ext.ux.form.photoUploadField.superclass.initComponent.apply(this,arguments)},onRender:function(d,e){if(this.isRendered){return}this.defaultAutoCreate={tag:"input",type:"hidden",autocomplete:"off"};Ext.ux.form.photoUploadField.superclass.onRender.call(this,d,e);var f=this;this.widthField=this.el.insertSibling({tag:"input",type:"hidden",cls:"x-form-text x-form-field",style:"width:40px;",name:this.el.dom.getAttribute("name")+"_width",id:this.id+"_width"},"after",true);this.heightField=this.el.insertSibling({tag:"input",type:"hidden",cls:"x-form-text x-form-field",style:"width:40px;",name:this.el.dom.getAttribute("name")+"_height",id:this.id+"_height"},"after",true);this.isRendered=true;this.image=this.el.insertSibling({tag:"img",src:"./modules/users/getUserPicture.jsp",style:"height:32px;width:30px;vertical-align:top",name:this.el.dom.getAttribute("name")+"_media",id:this.id+"_media",onclick:this.onTriggerClick},"after",true)},setValue:function(c){if(c.length<3){this.setRawValue("")}else{this.setRawValue(c);var d=this.el.dom.getAttribute("name")+"_media";if(c.indexOf("jpg")!=-1){$(d).src="./modules/users/getTempPicture.jsp?f="+c}else{$(d).src="./modules/users/getUserPicture.jsp?uid="+c}$(d).style.height=100;$(d).style.width=100}},onTriggerClick:function(f){var e=this;var d=new photoChooser({width:400,height:200,style:"background:#ffffff none repeat scroll 0 0;",autoScroll:false});d.show(this,function(a){e.setValue(a.fileitem)})}});