Modular Confirmation Dialog

It is likely the lazy programmer in me, but has anyone sorted out a way to display a confirmation dialog in web that is modular? I am coming across quite a few workflows that probably should have a confirmation, for example, “deleting” a schedule entry. I foresee my app becoming quite bloated with various confirmations if we have to create a new one for each workflow. I know it’s no problem to dim a new web dialog, but how do you modularize having a method wait on user response?

https://forum.xojo.com/48750-creating-a-web-message-box-a-la-desktop

I use the MBS CallMethodMBS solution. When I need a modal dialog in my Windows apps I use a generic Yes/No dialog and pass it three parameters:

  1. web page/container holding the method to run if the Yes button is clicked
  2. the name of the method to be run
  3. the alert message question to be shown to the user

eg on the WebAlerts WebPage I have dropped a copy of my generic YesNoWAD dialog which has a method doCreateDialog() to set itself up. When I need to ask a boolean question I call

WebAlerts.YesNoWAD.doCreateDialog(WebAlerts, "doDeleteSelected", "Do you really want to delete the selected Alerts (note this cannot be undone)?")

If they click No, the dialog will close, running nothing. If they click Yes, the dialog runs the method provided from the WebPage/container provided eg

Call CallMethodMBS(myWebPage, myMethod) 'run the method from its web page

If the method to run is in the same location as where you are loading the WebDialog, you can pass Self as the location of the method.

David, i have never use the CallMethodMBS before. is there any sample on the example from MBS?? if it does what is the name of the example?

Come on Trisha, do I look like Christian? You can Google as well as I can!

https://www.monkeybreadsoftware.net/process-calls-method.shtml

[quote=396895:@David Cox]I use the MBS CallMethodMBS solution. When I need a modal dialog in my Windows apps I use a generic Yes/No dialog and pass it three parameters:

  1. web page/container holding the method to run if the Yes button is clicked
  2. the name of the method to be run
  3. the alert message question to be shown to the user

eg on the WebAlerts WebPage I have dropped a copy of my generic YesNoWAD dialog which has a method doCreateDialog() to set itself up. When I need to ask a boolean question I call

WebAlerts.YesNoWAD.doCreateDialog(WebAlerts, "doDeleteSelected", "Do you really want to delete the selected Alerts (note this cannot be undone)?")

If they click No, the dialog will close, running nothing. If they click Yes, the dialog runs the method provided from the WebPage/container provided eg

Call CallMethodMBS(myWebPage, myMethod) 'run the method from its web page

If the method to run is in the same location as where you are loading the WebDialog, you can pass Self as the location of the method.[/quote]
I’m curious, why wouldn’t you just use delegates for this?Just add a delegate object to the dialog which defines the pattern of the callback method callbackDelegate(caption as String), a property buttonCallback as callbackDelegate and in the setup method, set buttonCallback to the AddressOf the target method. Instead of passing the page and method to Setup, just pass AddressOf handleButtonPressed Then on the dialog, you could do something like:

if buttonCallback<>Nil then ButtonCallback.invoke(“Yes”) End If
That allows your dialog to have buttons whose captions change and it’s very clear to the receiver which button was pressed ( like in the case of Yes, No or Cancel )… and it doesn’t require a plug-in.

@Greg O’Lone Horses for courses, the MBS technique is simple (two lines) and is working for me, others are free to choose another path. Now we have at least two methods available.

[quote=396901:@David Cox]Come on Trisha, do I look like Christian? You can Google as well as I can!

https://www.monkeybreadsoftware.net/process-calls-method.shtml[/quote]

i already read that page and still don’t understand.

[quote=396906:@Greg O’Lone]I’m curious, why wouldn’t you just use delegates for this?Just add a delegate object to the dialog which defines the pattern of the callback method callbackDelegate(caption as String), a property buttonCallback as callbackDelegate and in the setup method, set buttonCallback to the AddressOf the target method. Instead of passing the page and method to Setup, just pass AddressOf handleButtonPressed Then on the dialog, you could do something like:

if buttonCallback<>Nil then ButtonCallback.invoke(“Yes”) End If
That allows your dialog to have buttons whose captions change and it’s very clear to the receiver which button was pressed ( like in the case of Yes, No or Cancel )… and it doesn’t require a plug-in.[/quote]

Forgive my ignorance Greg, what you mean by add a delegate object?

Disregard this, I was speed reading the documentation.

@Greg O’Lone Would I be adding the delegate and property to the calling window or to the confirmation dialog? I added them to the confirmation dialog and set it up in code on the calling window like this:

[quote]Dim d As New confirmationDialog
d.buttonCallback = AddressOf handlebuttonpressed
d.messageTextLabel.Text = “Are you sure?”
d.titleLabel.Text = “Confirm”
d.yesButton.Caption = “Continue”
d.show[/quote]

But I get a type mismatch error:
Type mismatch error. Expected delegate confirmationDialog.confirmationDialog.callbackDelegate, but got delegate Delegate( confirmationDialog.confirmationDialog, String )

Sorry, I’m just a little confused