New Posts New Posts RSS Feed: Does DialogManager have access to the button that is clicked?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Does DialogManager have access to the button that is clicked?

 Post Reply Post Reply Page  <12
Author
JohnBloom View Drop Down
Groupie
Groupie
Avatar

Joined: 30-Nov-2010
Location: Topeka, KS
Posts: 95
Post Options Post Options   Quote JohnBloom Quote  Post ReplyReply Direct Link To This Post Topic: Does DialogManager have access to the button that is clicked?
    Posted: 12-Apr-2012 at 12:37pm
Thanks Marcel! You have been very quick with answers and we appreciate it.
-John Bloom
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 12-Apr-2012 at 12:20pm
The proper way to do this is to override CanClose in your ViewModel and perform the save, then let your VM close if the save was successful or prevent the closing if the save failed. This approach properly allows you to save asynchronously, wait for the completion and then let the dialog close if successful. Same way you have access to the buttons you have access to the DialogResult to find out what button the user clicked and go down a different path in your CanClose method. Here's a simple example which always lets the dialog close if the user clicked "Cancel", but if they click "Ok", the dialog only closes if IsComplete is true.
 
        public override void CanClose(Action<bool> callback)
        {
            if (!this.DialogHost().DialogResult.Equals(DialogResult.Cancel))
            {
                callback(IsComplete);
            }
            else
                base.CanClose(callback);
        }
 
 
Here's an example of a CanClose method from TempHire, that performs a Save or RejectChanges. This is not from a dialog, but it's gonna be the same thing for you, except you won't ask the user first if they want to save.
 
        public override void CanClose(Action<bool> callback)
        {
            if (UnitOfWork.HasChanges())
            {
                var dialogResult =
                    _dialogManager.ShowMessage("There are unsaved changes. Would you like to save your changes?",
                                               DialogResult.Yes, DialogResult.Cancel, DialogButtons.YesNoCancel);
                dialogResult.OnComplete(delegate
                                            {
                                                if (dialogResult.DialogResult == DialogResult.Yes)
                                                {
                                                    Busy.AddWatch();
                                                    UnitOfWork.CommitAsync(saveResult => callback(true),
                                                                           _errorHandler.HandleError)
                                                        .OnComplete(args => Busy.RemoveWatch());
                                                }
 
                                                if (dialogResult.DialogResult == DialogResult.No)
                                                {
                                                    UnitOfWork.Rollback();
                                                    callback(true);
                                                }
 
                                                if (dialogResult.DialogResult == DialogResult.Cancel)
                                                    callback(false);
                                            });
            }
            else
                base.CanClose(callback);
        }
Back to Top
JohnBloom View Drop Down
Groupie
Groupie
Avatar

Joined: 30-Nov-2010
Location: Topeka, KS
Posts: 95
Post Options Post Options   Quote JohnBloom Quote  Post ReplyReply Direct Link To This Post Posted: 12-Apr-2012 at 11:29am
We have been moving over our popups to cocktail and we have a question.
 
Question:
The DialogManager has access to the IsEnabled property of the button so that it can disable the ok button. Is it possible to tie into the button clicked event too?
 
Example:
We have a popup that is an island. We want to be able to pop it up from anywhere and let it save if the user clicks ok or call rejectchanges if the user clicks cancel. It doesnt appear, from what we can see, that the DialogManager allows the view that is being shown to know about the button click. This would require that everywhere we show this box we have implement what happens with ok and what happens when cancelled. Rather we would like the view model that is being shown in the popup to manage its own button clicks.
-John Bloom
Back to Top
 Post Reply Post Reply Page  <12

Forum Jump Forum Permissions View Drop Down