Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Ethan Anwar on Jun 14, 2009 12:11
open dhtmlx forum
dhtmlxWindow check if window is closed?

Hi!
I'm doing a sort of Settings window. I have a div/button that once clicked creates and displays my window.
Ex.
<div onDblclick="zSets()"> Settings</div>

and

function zSets() {
    
    var w5= dhxWins.createWindow("w5", 200, 150, 400, 350);
    w5.setText("Setingss");
w5.attachObject(sets);    
    }

The 'sets' object I attached contains a HTML select form where the user can select the background image , font size and color etc.

My problem is that i want this window to be created only once , so when the user clicks again on the button nothing happens. And then , if the user closes the window from the 'x' , then i want the button to be able again to create the window.
Basically i want to know if there's a isClosed() method available similar to the isHidden().

Further more, in the select form, i know how to save into variables the selected data . How can i upload those variables (very simply)on the server, so that the next time the user opens the window, or refreshes the whole page for that matter, the information is saved.
I only need 3 simple variables like
var background=3;
var size=12;
car color= "FF0000";
I need to store them in an .xml and then read them each time the settings window is created.
I know this may sound overcomplicated but I hope I made some sense.

Thanx a lot for the support so far, you guys are doing a great job with dhtmlX!
Answer posted by Alex (support) on Jun 14, 2009 23:45

Hello, 

there is isWindow(winId) method that allows to know if a window with a certain id exists. It returns true if the window is open (exists) and false- in the other case: 

var isOpen = dhxWins.isWindow("w5");

Answer posted by Roger W. Barros on Jun 16, 2009 09:14
not to open two windows equal...

var nw = new Array();

function zSets(m,t,x,y,w,h,s) {
    if(!(nw[m])) {
        nw[m] = 1;
        var win = dhxWins.createWindow(m,x,y,w,h);
        win.setText(t);
        win.attachObject(s);
    }
}

zSets("w5","Setingss",200,150,400,350,sets);

:D
Answer posted by Roger W. Barros on Jun 16, 2009 09:30
Ops! forgot...

to open the window again add: win.attachEvent("onClose",function(win){ nw[m]=null; return true; });

var nw = new Array();
function zSets(m,t,x,y,w,h,s) {
    if(!(nw[m])) {
        nw[m] = 1;
        var win = dhxWins.createWindow(m,x,y,w,h);
        win.setText(t);
        win.attachObject(s);
        win.attachEvent("onClose",function(win){ nw[m]=null; return true; });
    }
}
zSets("w5","Setingss",200,150,400,350,sets);
Answer posted by Alex (support) on Jun 17, 2009 02:29

Hello, 

so, it seems that you have found own solution to solve the issue... Am I right ?

Answer posted by Ethan Anwar on Jun 17, 2009 03:28
Well kinda Alex.
Soon after posting the question I found a solution.
I only create the window the first time i click the button and attach to the onClose() of the window a hide() action.
Then, whenever the user clicks the 'x' to close the window he only hides it.
So the next time the user clicks on the button to open the window i only use show().
Here's the code I used :

    function zSets() {   
    var isOpen = dhxWins.isWindow("w5");
                         if(!isOpen) {
    var w5= dhxWins.createWindow("w5", 200, 150, 400, 350);
    w5.setText("Setari");
    w5.attachObject(setari);
    dhxWins.window('w5').attachEvent("onClose", function(w5) { w5.hide(); return false;});
                                          }
                           else {
                dhxWins.window('w5').show();
                                  }
    }

Thanx a lot Alex , and Roger, although I didn't use your solution that may come in handy along the way.
And, about the second part of my initial question.The actual Ajax part.
I need to have these settings saved on the server, so that the next time the user enters my page , the settings made in the settings window are the same.
I would need three variables. x,y,and z that once set by the user are sent to the server. How can i do that and how could i read them everytime the page loads?
Thanks again guys!
Answer posted by Alex (support) on Jun 17, 2009 06:58

Hello, 

there is dhtmlxAjax component - it allows to send information to the server and get responses using Ajax. Please, see its sample dhtmlxAjax/samples/samples_of_usage/send_request.html ( http://dhtmlx.com/docs/products/dhtmlxAjax/samples/samples_of_usage/send_request.html )