Trigger Panel notification message from field

Short question to all the people who have been in touch with the panel core code: is there a possibility to trigger the message notification (which is shown on a page save for example) by a custom field’s javascript code? In the field a button is clicked which triggers an API call, and if the return is successful I’d like to return the common success message.

If you can, setting a notification on the backend would be the most reliable and easiest way:

panel()->notify(':)');

If you can’t, I believe you have to manually add the notification to the DOM. A “template” for this can be found in the Panel code.

Thanks for the fast answer. Currently, the backend-solution is no option. The API call creates a file for the current page, which should be shown as well in the files section, so I am reloading the whole page with app.content.reload(). Afterwards, the message should be shown – when I build it via JS, I have to listen for the successful reload in a way, but I think this is not possible yet, so currently there is a very hacky timeout…

Can I maybe just reload the file section separately? Or do you have another idea? A custom message would work as well, but the common would be better as the panel users are already used to it.

How does the file get created? Some kind of backend code will run, won’t it?

Through a custom route which is currently placed in a usual plugin file. If I fire the message there, nothing happens… but it would also be replaced when the content is reloaded, or am I wrong here?

You don’t have access to the panel() function there, but you can also set the notification manually:

s::set('message', array(
  'type' => 'notification', 
  'text' => ':)',
));

Alternatively, you can require the Panel bootstrap.php from your plugin (panel/app/bootstrap.php), which will give you access to the proper method. Whatever you prefer.

Hah, this works perfectly. Just what I was looking for! Thank you so much!

1 Like