Add QueryDialog open/close methods, add error handling

The open and close methods are more transparent to consumers of the
dialog, so they don't have to be aware of the modal plugin. Also, it
enables proper setup and cleanup of the dialog. The `open` method takes
an optional model which is needed for updating existing models so the
modal can be shared for creating and updating.

Error handling has been added in case a model save fails in which case
the modal opens up again prompting the user to try again.