PDA

View Full Version : Two Ext.Window Show Problem



scusyxx_xx
19 Feb 2010, 7:17 AM
Hi to all,
I am newbie in ExtJS. My problem is I have 2 Ext.windows. When I click to show one of these windows it works after closing this one when i click on other's show it doesn't work. Interesting thing is, when I reclick the first windows show button it shows both windows. What could be the problem. The sample code is below.




if (win_edit == null) {

win_edit = new Ext.Window({
id:'win_edit',

applyTo:'edit_win',
width:720,
height:150,
closeAction:'hide',
plain: true,
modal: true,
items: [{tag:'div',
id:'edit_div'
}],

buttons: [
{text:"Cancel",
handler: function(){win_edit.hide();}
},
{text:"Update",
handler: editButtonHandler.createDelegate(this, count, true)}
]
});
Ext.getCmp('win_edit').show();
}

if (win_add == null) {

win_add = new Ext.Window({
id: 'win_add',
applyTo:'add_win',
width:720,
height:300,
closeAction:'hide',
plain: true,
autoScroll: true,
modal: true,
items: [{tag:'div',
id:'add_div'

}],

buttons: [{text:"Add",
handler: addButtonHandler.createDelegate(this, win_add, true)

},
{text:"Cancel",
handler: function(){win_add.hide();}
},
{text:"Update",
handler: updateButtonHandler.createDelegate(this, win_add, true)}
]
});
Ext.getCmp('win_add').show();
}

fay
19 Feb 2010, 7:39 AM
Don't create the windows each time, that only needs to be done once, so:


if (win_edit == null) {
// Create window
}
win_edit.show();


if (win_add == null) {
// Create window
}
win_add.show();

As you've only posted the creation code (and not how/where you are calling it from), it's hard to say why you are getting your "click-once, click-twice" errors from.

scusyxx_xx
19 Feb 2010, 7:51 AM
Hi,
No I don't create windows each time user clicks. The elses of the code is simply

else{
win_add.show();
}

The call function is called by button, the whole code is below.



function show_edit_Div(){
if (win_edit == null) {

win_edit = new Ext.Window({
id:'win_edit',

applyTo:'edit_win',
width:720,
height:150,
closeAction:'hide',
plain: true,
modal: true,
items: [{tag:'div',
id:'edit_div'
}],

buttons: [
{text:"Cancel",
handler: function(){win_edit.hide();}
},
{text:"Update",
handler: editButtonHandler.createDelegate(this, count, true)}
]
});
win_edit.show();
}else {
win_edit.show();
}

}

fay
19 Feb 2010, 7:59 AM
At face value I don't see anything wrong with that. Post a working showcase (http://www.extjs.com/learn/Ext_Forum_Help#Posting_a_working_showcase).

Animal
19 Feb 2010, 8:09 AM
What's this applyTo business? Why have you put that there?

Animal
19 Feb 2010, 8:10 AM
And "tag" is not a valid config for Panel. You can remove it, it does nothing.

scusyxx_xx
19 Feb 2010, 8:36 AM
I removed applyTo field and it worked, I didn't understand why?
Thanks Animal.

Animal
19 Feb 2010, 11:12 AM
http://www.extjs.com/deploy/dev/docs/?class=Ext.Panel&member=applyTo

It indicates that you have already built the complex structure that a Panel uses, and the new instance is just to use what's there. Very few people will use that option!