Main Window & CloseEvent

Hi !

I have a new question :slight_smile:

I need to be able to know when one of the user of my application disconnect his client - when he use the “Disconnect” link I provide, or when he close his browser window.
I even need to be able to warn him if he try to quit while having unsaved work.

Of course, I have no problem doing that if the user quit using the “Disconnect” link. But catching the event of window closure is another matter entirely ^^

Window.CloseEvent seems to be only for child windows, and not for the main application window (or maybe I’m mistaken ?)

JavaScript speaking, if I can access the event
onbeforeunload
, it would be a good start :slight_smile:

Do you have any idea or hindsight on how I can do that ? Or any lead on where I can tweak a bit the framework code to add what I want ? ^^

Thanks a lot,
Quentin.

A valid need indeed.

My first instinct says it should be added as a SystemMessage, something like “Application.CustomizedSystemMessages.setUnloadConfirmationMessage(String message)”.

Then in IView, we would need to register the onbeforeunload listener, which would show that message.

Another option would be to implement a special kind of CloseListener for the main application window, which would show the same onbeforeunload dialog, but post some message to the server just before that, so that the application could respond to the event in some way. But I suppose there is no way to know whether the user clicked the OK or Cancel button. One way might be to send another message to the server on the unload event, confirming that the user actually left the application.

Any other thoughts/suggestions?

-Jouni

Yes, integrating this into SystemMessages would be nice. Some additional thoughts, though:

The unsaved data can be either 1) on the server (e.g. incomplete multi-page form, or save/confirm button not pressed), or 2) on the client (user filled in some fields, but has not pressed any button).
But we do not always want to show the warning - it’s often safe to discard the data. Also, in both cases the client needs to know that it’s supposed to show the warning dialog (we can’t really ask the server, then show the dialog if needed).

So it seems like we need to be able to tell the client (on-the-fly) whether it’s supposed to show the warning always/only if there are pending variable changes/never. Something like
application.setUnloadWarningMode(int mode)
, or perhaps
window.setCloseWarningMode(int mode)
?
(modes being something like WARN_ALWAYS, WARN_NEVER, WARN_PENDINGCHANGES)

Another solution would be to set/unset the two messages - this would allow for dynamic messages (“One of the three XYZ is not saved”), but would potentially be more confusing to use…

…if anyone has a more KISS idea, it would be more than welcome…

Best Regards,
Marc

Created
ticket 2056
for this - it’s currently not targeted for 5.3.0, since it’s a new feature and we’re trying to stabilize&release right now.
You will get a close event for the main window in 5.3.0, though - is that enough for now, or do you absolutely need the warning dialog right now?

Best Regards,
Marc