Let's add a new JavaScript file to /packages/cookbook_events/js/list.js
. Add some JavaScript (using the jQuery library) to listen to the clicks on the Delete button:
$(document).ready(function() { $('.delete').on('click', function(e) { return confirm('Are you sure you want to delete this item?'); }); });
Next, we need to make sure this script is included on our list page. Open up the controller for the list page located at /packages/cookbook_events/controllers/dashboard/cookbook_events/list.php
.
Add a new function to include the JavaScript file on the page:
public function on_before_render() { $html = Loader::helper('html'); $this->addHeaderItem($html->javascript('list.js', 'cookbook_events')); }
This function will use the HTML helper to automatically add the <script>
tag to the page's <head>
area.
Now, if you try to delete an event, you should see a confirmation dialog, as shown in the following screenshot:
Perfect! We can consider the backend of the add-on to be complete! All that is left to do is displaying events on the frontend.