I have a application where on dubbleclick on a row in a listgrid a window is oped in a windowarea with a taskbar. I want to prevent a window to be opened twice. I've got this working but there is one problem. Once a window has been opened and the window is closed by clicking the x button, the window doesn't seem to be destroyed, just hidden. So when I'm checking if the object with id="id" exists and the window with this id has been opened and and closed, the window with id="id" still exists and I'm unable to open it again.
This is the handler in the listgrid that opens the window.
<![CDATA[
var iWindows = 0;
var iSelected = this.getProperty('selectedIndex');
var oSource = this.getProperty('dataSource');
var sId = btl.dataSource.getValue(oSource, iSelected, 'id');
var sVoornaam = btl.dataSource.getValue(oSource, iSelected, 'voornaam');
var sAchternaam = btl.dataSource.getValue(oSource, iSelected, 'achternaam');
var sUrl = '<?= $show->printUrl(DIR_MODULE_USERMANAGER."userData.html.php");?>&userid='+sId;
var sMode = 'lastChild';
var sMethod = 'GET';
var iWindowId = 'window_'+sId;
var oWindowArea = bb.document.getElementById('WindowArea');
var oWindow = bb.document.getElementById(iWindowId);
if(oWindow == null)
{
function load(url) {
var xhr_object = new XMLHttpRequest;
xhr_object.open("GET", url, false);
xhr_object.send(null);
return xhr_object.responseText;
}
var sWindowData = load(sUrl);
iWindows++;
var oXml = bb.xml.parse('<b:window xmlns:b="http://www.backbase.com/2006/btl" width="535px" height="438px" icon="icon-user" label="' +sVoornaam+ ' ' +sAchternaam+ '" id="' +iWindowId+ '" open="true" dragConstraint=".." padding="0px" top="' + (30 + 25*iWindows) + 'px" left="' + 25*iWindows + 'px">' +sWindowData+ '</b:window>').documentElement;
bb.command.create(oXml, oWindowArea, 'appendChild');
}
]]>
</e:handler>
What should I do to fix this. Can a window be completely closed so the id doesn't exist anymore? That would be the prefered method for me because the contend of the window would be reloaded.
On more 'problem' is that when a window is already opened and the user doubleclicks the entry again in the listgrid (thus the window is prevented to be opened again) I want to set the focus to that window. But I don't know how to address the 'active' property of a window based on the window id and can't find it anywhere.

If the window exists after
20 May, 2008 - 13:34 — ZappelIf the window exists after you closed it with the [x]-button you can reopen ist with (js):
myWindow.open();
and you can activate it with:
myWindowArea.activate(myWindow);
To completly close a window you can bb.command.destroy(myWindow), but im not sure how to make the [x]-Button do this. (You could remove the button and add a "close" button to the window which destroys the window)
Matthias
Perfect!
20 May, 2008 - 14:42 — BramThank you! It's working now :)
But there is one problem that's most likely a bug. Sometimes the windows appear in the taskbar twice and in some cases because of that I can't reopen a window.
This could happen if you
20 May, 2008 - 14:54 — ZappelThis could happen if you doubleclick an entry in the listgrid and before you get the response of the first doubleclick you doubleclick again. So the second doubleclick event won't find a window object and will also load a new window.
Matthias
I've found the cause
20 May, 2008 - 15:42 — BramMy code wasn't like posted in the startpost anymore. The source of the problem was that I was treating the result of....
...as a bool. But in fact it returns a sting "true" or "false".
So this won't work as expected...
if( !theWindowObj.getAttribute("open") )
theWindowObj.open();
...or...
if( theWindowObj.getAttribute("open") == false )
theWindowObj.open();
...but this will...
if( theWindowObj.getAttribute("open") == "false" )
theWindowObj.open();
Not quite what you'd expect.