PDA

View Full Version : DialogLayout - bug in setUrl?



lastid
11 Mar 2007, 5:12 AM
Hi,
I think this is strange.I setUrl 4 times to a Panel, and then when it's activated, the 4 urls are loaded.
Shouldnt it load just the last url?
Here is the code


<html>
<head>
<title>Bug?</title>
<link rel="stylesheet" type="text/css" href="ext-all.css" />
<script src="yui-utilities.js" ></script>
<script src="ext-yui-adapter.js" ></script>
<script src="ext-all.js" ></script>
<script>

var DlgExample = {
init : function(){
dlgViewAlbum = new Ext.LayoutDialog("dlgViewAlbum", {
width:600,
height:400,
shadow:true,
minWidth:300,
minHeight:300,
center: {
autoScroll:true,
tabPosition: 'top',
closeOnTab: true,
alwaysShowTabs: true
}
});
dlgViewAlbum.addKeyListener(27, dlgViewAlbum.hide, dlgViewAlbum);
dlgViewAlbum.addButton('Close', dlgViewAlbum.hide, dlgViewAlbum);

var layout = dlgViewAlbum.getLayout();
layout.beginUpdate();
layout.add('center', new Ext.ContentPanel('viewTab',{title:'View'}));
layout.add('center', new Ext.ContentPanel('uploadTab',{title:'Upload'}));
layout.endUpdate();
layout.showPanel('viewTab');
viewPanel = layout.findPanel('viewTab');
viewPanel.setUrl('news1.txt');
viewPanel.setUrl('news2.txt');
viewPanel.setUrl('news1.txt');
viewPanel.setUrl('news2.txt');
dlgViewAlbum.show();
}
}
Ext.EventManager.onDocumentReady(DlgExample.init, DlgExample, true);
</script>


</head>
<body>
<div id='dlgViewAlbum'>
<div id='viewTab'></div>
<div id='uploadTab'></div>
</div>

</body>
</html>


And here is the live example:
http://lastid.free.fr/test.html

Each time I click on the view tab to activate it, firebug shows that there are 4 requests to the 4 urls

tryanDLS
11 Mar 2007, 11:29 AM
You called setUrl 4 times in row. Each time you do this, it adds a handler for the activate event. The events are stacked, they don't overwrite each other. If you only want a call to be made once, pass true as the 3rd arg,which means load on 1st activation only.

lastid
13 Mar 2007, 2:13 AM
Hi, thanks for your answer.
Is there anyway to clear the old urls? For me, the setUrl itself like its name suggested, should just use the last url. What it does now is like "addUrl". But it doesnt make sense to load several urls and just display the last response which may not the one we want.

What I am trying now is the dlgViewAlbum will be the placeholder for many photo albums. When the title of a photo album clicked (I setUrl here), the panel tabView will load photos from a specific url coresponding to the album. Then the user can hide the dlgViewAlbum and choose another one(setUrl again) to display. So loadOnce doesnt solve the problem

Maybe I should try to wire event on('activate') to the tabView.

Thanks.