FLOE-194: Improved the function that clicking anywhere outside the dialog closes the dialog.
FLOE-194: Check if the dialog is open before closing it.