In Servoy 6 how does a dialog close just itself ? In 5 there was the application.closeform() and in 6 there’s closeallwindows.
Am I missing the obvious .
In Servoy 6 how does a dialog close just itself ? In 5 there was the application.closeform() and in 6 there’s closeallwindows.
Am I missing the obvious .
Have a look at the hide() and destroy() methods of the JSWindow
If you are on the same form, that is shown, in a dialog or window:
controller.getWindow().hide()
Thanks Harjo. I was just looking for that. Looks like we’re on the same refactoring job
Thanks Harjo. Now I know how to do this on the same form.
But what about from a different form? For instance, how should I write a global method that ‘on close’ makes sure that all NON-MODAL forms are close first?
For example, I have this form that open in a window as non-modal so that the users can see a “Find Commands Sheet” while searching for something. It remains open until the user closes it.
function show_finds_commands_sheet(event) {
//application.showFormInDialog(forms.dlg_find_commands,100,100,550,650,"Find Commands Sheet",true,false,"Find Commands Sheet",false);
var finds_commands_sheet_Window = application.createWindow("dw_dlg_find_commands", JSWindow.DIALOG);
finds_commands_sheet_Window.show(forms.dlg_find_commands);
}
Then, I used to have this to close this and other non-modal windows (formerly ‘forms in dialog’).
function closeExit()
{
//dw_ stands for dialof window and source name or function
application.closeForm(“dw_fcpa_matters”);
application.closeForm(“dw_fcpa_entities”);
application.closeForm(“dw_fcpa_companies”);
application.closeForm(“dw_enforcement_agencies”);
application.closeForm(“dw_dlg_find_commands”);
application.closeForm(“dw_fcpa_matters_entities”);
application.closeForm(“dw_gov_proceeding_sanctions”);
application.closeForm(“dw_proceedings_methods_of_bribery”);
application.exit();
}
I tried ti use this now:
application.getWindow(dw_dlg_find_commands).hide();.
But it gives me a error because “dw_dlg_find_commands” is not defined. I thought I defined it in this line:
var finds_commands_sheet_Window = application.createWindow(dw_dlg_find_commands, JSWindow.DIALOG);.
But I definitely did not.
Any help will be appreciated.
Thanks! Carlos
Like so:
application.getWindow( 'myWindowName' ) .destroy()
I don’t believe it matters whether the window is modal or not.
I hope this helps!
Thanks Kim. When I saw your code I thought that I made the mistake because I forgot to quoted the windowName (which in my code the windowName is dw_dlg_find_commands).
Well I put the quotes within the windowName (as specified in the example syntax and your example):
/**
* @properties={typeid:24,uuid:"77E3B1B6-9FD7-4422-9858-99FC230ACC72"}
*/
function closeExit(event)
{
//dw_ stands for dialof window and source name or function
application.getWindow("dw_fcpa_matters").destroy();
application.getWindow("dw_fcpa_entities").destroy();
application.getWindow("dw_fcpa_companies").destroy();
application.getWindow("dw_enforcement_agencies").destroy();
application.getWindow("dw_dlg_find_commands").destroy();
application.getWindow("dw_fcpa_matters_entities").destroy();
application.getWindow("dw_gov_proceeding_sanctions").destroy();
application.getWindow("dw_proceedings_methods_of_bribery").destroy();
application.exit();
}
But still I have a problem. When I close the application this function closeExit(event) is triggered, as it closes all open dialog windows, the debugger triggers and throws an error:
TypeError: Cannot call method “destroy” of (C:\Users\JCarlos\workspace\srms_workspace\FCPAC\globals.js#131)
Note that I have this as a Global function. It used to work as such. (See the function closeExit() of my above post). I think that from the global scope, Servoy 6.1 cannot recognize the window’s name (although it used to).
I need to fix this or figure out a way around. This is important because in my solution there are a few NON-MODAL windows that a user might keep open while working. All of the windows in dialogs need to be closed (destroyed or hidden) when the user exit the application. If they are not closed, they will open the next time the user opens the solution. This creates a problem.
Am I doing something wrong or should I report this as a bug?
Best,
Carlos
I think that from the global scope, Servoy 6.1 cannot recognize the window’s name (although it used to).
I use the code sample I posted in 6.1 with no problems, but it is within the scope of a module (not global). I presume you are calling closeExit() from the solution’s onClose() method. Is your call prefixed with the new ‘scopes’ attribute?
scopes.globals.closeExit()
Perhaps, Servoy has already closed the windows (because you say it is saving/restoring the state of the non-modal windows) before the closeExit() method is executed? Since your code worked before (prior to 6.1), it probably is a bug and should be reported.
kwpsd:
I use the code sample I posted in 6.1 with no problems, but it is within the scope of a module (not global).
yep, that had worked for me too. The problem is from the Global scope…
kwpsd:
I presume you are calling closeExit() from the solution’s onClose() method. Is your call prefixed with the new ‘scopes’ attribute?
Yes, it is. See below:
[attachment=0]onClose.JPG[/attachment]
kwpsd:
Perhaps, Servoy has already closed the windows (because you say it is saving/restoring the state of the non-modal windows) before the closeExit() method is executed? Since your code worked before (prior to 6.1), it probably is a bug and should be reported.
Perhaps, I said it wrong. The closeExit(event) method is triggered onClose() event, and it seems then to close all open dialog windows. In other words, the method seems to be working. I suspect that it is working because If I don’t use this in the onClose() event, the open non-modal windows remain open after exit/close the application. The issue is that I get this error message TypeError: Cannot call method “destroy”, and therefore I am not 100% sure if the onClose()/closeExit event/method works.
I’ll report this as a bug unless we see a new post stating something different soon. Thanks. Carlos
you are just calling destroy on all kinds of windows
But how do you know those windows are there??
You need to check that, just calling getWindow(“xxxx”) and then calling destroy() on it without checking if the getWindow call really returns something is not a good idea
You have to make sure that the window does exists
jcompagner:
you are just calling destroy on all kinds of windows
But how do you know those windows are there??
You need to check that, just calling getWindow(“xxxx”) and then calling destroy() on it without checking if the getWindow call really returns something is not a good idea
You have to make sure that the window does exists
Can you help me out here?
I tried this:
var dw_fcpa_matters_open = application.getWindow("dw_fcpa_matters");
if(dw_fcpa_matters_open.isVisible() == true)
{application.getWindow("dw_fcpa_matters").hide()}
else{};
And I still get an error:
TypeError: Cannot call method “isVisible” of (C:\Users\JCarlos\workspace\srms_workspace\FCPAC\globals.js#133)
A way around this would be to create global (or form) variable that is set to 1 when the of the window opens, and to zero when it closes. Then I’ll evaluate against this variable if the window exists before trying to hide it or destroy it.
However, I was expecting that by getting the JSWindow with the ‘isVisible()’, it would tell me if the window does exists. Can you tell me what is wrong in my code? I would rather do all in this function rather than using the work-around approach.
Thank you!
When Johan says ‘You have to make sure that the window does exists’, he means is it null or undefined?
What you can do is:
var dw_fcpa_matters_open = application.getWindow("dw_fcpa_matters");
if (dw_fcpa_matters_open) {
dw_fcpa_matters_open.destroy();
}
And I would do that in a loop, like this:
var windowNames = [
"dw_fcpa_matters",
"dw_fcpa_entities",
"dw_fcpa_companies",
"dw_enforcement_agencies",
"dw_dlg_find_commands",
"dw_fcpa_matters_entities",
"dw_gov_proceeding_sanctions",
"dw_proceedings_methods_of_bribery"
];
for (var i in windowNames) {
var win = application.getWindow(windowNames[i]);
if (win) {
win.destroy();
}
}
Thank you very much Patrick!