I am working in perspective and wondering if there is a way to mimic this in perspective. I have a delete button and want to have user confirmation before deleting.
# If a row is selected, ask for confirmation before deleting the rows.
if system.gui.confirm("Are you sure you want to delete " + str(len(selRows)) + " row(s)?", "Are You Sure?", 0):
There are multiple ways to implement this, depending on the structure of the rest of your project. The easiest is probably a popup. When the button is clicked, display a popup, on the popup, when the confirmation button is clicked use system.perspective.sendMessage() to send a message to a message handler on the view which can then run the delete operation.
I would recommend writing all of your CRUD operations in a script module as pure functions which can then be called from multiple places in the project.
Sure, doesn't really change much. You still need to call the named query, and the view is going to have all of that information readily available. Better not to pass the values around needlessly, just ask for confirmation and then execute only with given that confirmation.
So just do a popup in the delete button script and if confirm is chosen in the popup, send a message to message handler on the delete button component and run the named query ?
Yes, just like that. If you want to make a generic popup button for this kind of duty, parameterize not just the content to display, but also the message handler name, scope, and perhaps a unique key to include in the payload. This makes the message targeting and reception handling very robust.
When the message handler says, "This method will be called when a message with the matching type code arrives at this component". Is 'type code' the value entered in for 'Message Type'.
What about using the One-Shot button? I've been using them in a lot of places in place of normal buttons because it gives you confirmation options and the script you define only runs if the user hits the "Yes" or "Confirm" button. I know I'm derailing the conversation but wanted to bring up another option that I love to use.