Code:
Ext.ux.InsertPictureWindow=Ext.extend(Ext.Window ,{
xtype:"window",
title:"Insertar Imagen",
width:430,
height:160,
layout:"fit",
initComponent: function(){
this.on_change={
change:{
scope:this,fn:function(){this.generate_code();}
}
};
this.buttons=[
{
xtype:'progress',
width:220,hidden:true
},
{
text:'Insertar',scope:this,
handler:function(){
if(this.callback){
this.callback.call(this.scope||this,this.get_code_value());
}
this.hide();
}
},{
text:'Cancelar',scope:this,handler:
function(){
this.hide();
}
}]
this.items=[
{
xtype:'form',border:false,layout:'vbox',
id : 'attachimg',fileUpload: true,
layoutConfig:{
align:"stretch",
padding:"0"
},
defaults:{
layout:"hbox",border:false,xtype:'panel',
layoutConfig:{
padding:"5"
},
defaults:{
margins:'0 5 0 0',
xtype:"textfield"
}
},
items:[
{
items:[
{
xtype:"label",
text:"URL:",
style:"line-height:22px;",
width:70
},
{
width:200,name:'src',
listeners:this.on_change
},
{
xtype:"button",
text:"Galeria...",scope:this,
handler:function(){
if(!this.pic_view)
{
this.pic_view = new Ext.ux.PicView({
url: this.downloadUrl,
closeAction:'hide',
scope:this,
callback:function(o){
var f=this.findByType('form')[0];
o.width+='px';o.height+='px';
f.form.setValues(o);
this.generate_code();
}
});
}
this.pic_view.show();
}
},{
xtype:"fileuploadfield",
buttonOnly: true,
buttonText: 'Examinar...',
name:'file',
id:'fileup',
scope:this,
callback:function(o){
var f=this.findByType('form')[0];
f.form.findField('src').setValue('?do=filetools.getImage&id='+o);
this.generate_code();
},
listeners: {
'fileselected': function(fb, v){
Ext.getCmp('attachimg').getForm().findField('src').setValue(v);
//subimos archivo
var pbar = Ext.Msg.progress('Espere unos instantes', 'cargando datos', 'actualizando datos . . .');
Ext.getCmp('attachimg').getForm().submit({
url: String.format('?do=awejson.request&what={0}&which={1}', 'files', 'setImages'),
waitTitle: 'Por favor, espere',
waitMsg: 'espere unos instantes ...',
method: 'POST',
params: {
'mode' : 'new',
'label': 'insertado desde editor',
'description': 'insertado desde editor'
},
reset: false,
failure: function(form, response) {
pbar.hide();
Ext.MessageBox.show({
title: 'Error',
msg: response.result.message,
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR // Ext.MessageBox.WARNING
});
},
success: function(form, response) {
pbar.hide();
//this.generate_code();
var callback = this.callback;
callback.call(this.scope||this,response.result.message);
}
,scope: this
});
}
}
}
]
},
{
items:[
{
xtype:"label",
text:"Codigo:",
style:"line-height:22px;",
width:70
},{
width:320,
name:'code',
readOnly:true
}
]
}
]
}
]
Ext.ux.InsertPictureWindow.superclass.initComponent.call(this);
this.on('show',function(){
var f=this.findByType('form')[0];
f.form.reset();
this.generate_code();
},this);
},
generate_code:function(){
var f=this.findByType('form')[0];
var o = this.get_form_real_values();
if(typeof(o.src)!='string' || o.src.trim().length<1){
this.buttons[1].setDisabled(true);return;
}
this.buttons[1].setDisabled(false);
var str='<img src="'+o.src+'"'+' />';
f.form.setValues({code:str});
},
get_form_real_values:function(){
var form=this.findByType('form')[0].form;
var values = {};
form.items.each(function(f){
if('code'!=f.getName())
values[f.getName()] = f.getValue();
});
return values;
},
get_code_value:function(){
var ret=null;
var form=this.findByType('form')[0].form;
form.items.each(function(f){
if('code'==f.getName()){
var v=f.getValue();
if(typeof(v)=='string' && v.trim().length>0)
ret=v;
}
});
return ret;
}
})