m-e-conroy / angular-dialog-service

A complete AngularJS service with controllers and templates for generating application modals and dialogs for use with Angular-UI-Bootstrap and Twitter Bootstrap
MIT License
618 stars 228 forks source link

check if dialog is open using isOpen #124

Closed programming-kid closed 9 years ago

programming-kid commented 9 years ago

there should be a function to check if particular dialog is open like isOpen using a dialog name or id specified while creating dialog

niemyjski commented 9 years ago

I've been using this code base since it's creation and haven't had a use case for this. Not saying this isn't a valid request but what behavior are you running into that you need this?

programming-kid commented 9 years ago

i have a login modal which is fired on 401 response so every time user enters wrong credentials another modal is opened so i need isOpen to check if login modal is already open

dougmoscrop commented 9 years ago

So, that's something you can track on your own though - the library provides a promise when it is opened. It can be as simple as having a service, or even just a simple run that keeps a local variable (isDialogOpened) and then only opens it if it is not already opened, etc.

programming-kid commented 9 years ago

yea i know it can be done but its not an elegant solution , i just wanted a clean solution

dlwhiteman commented 9 years ago

I was looking for the same thing, a way to find open dialogs so we don't need to open another instance if one is already open. My use case is the UI is frequently pinging the REST API to see if it's available. If there is a disconnection, an alert dialog is displayed saying the server is unavailable. We want it to keep pinging though, so the UI will wake back up when the server is back online. The problem I'm having is it's creating an infinite number of dialogs with the same message, so I'd like to determine first whether there is already an open dialog. I would rather not have to hook in every time a user closes a dialog to find when I need to update some flag regarding whether the dialog is open.

dougmoscrop commented 9 years ago

You can still track all this in your own service; have your 'offline' or 'connection problem' code/error handler emit an event, and have another piece that listens to those events and raises the dialog. In that place it's as simple as if () ... with a local var.