From 8c812cd427cc9d1190937b9036d2d60dca82efeb Mon Sep 17 00:00:00 2001 From: Sebastian Vetter Date: Wed, 23 Oct 2013 16:56:37 +1100 Subject: [PATCH] Add delete tab function in JS --- fancypages/static/fancypages/js/editor.js | 1 + .../static/fancypages/js/event-handlers.js | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/fancypages/static/fancypages/js/editor.js b/fancypages/static/fancypages/js/editor.js index 8c133f8..566c0d7 100644 --- a/fancypages/static/fancypages/js/editor.js +++ b/fancypages/static/fancypages/js/editor.js @@ -157,6 +157,7 @@ fancypages.editor = { initialiseEventsOnPageContent: function () { // Add a new tab to the selected tabbed block block $(document).on('click', 'a[data-behaviours~=add-tab]', fancypages.eventHandlers.addNewTab); + $(document).on('click', 'a[data-behaviours~=delete-tab]', fancypages.eventHandlers.deleteTab); //load the form to select a new block to add to the container //and display it in a modal $("a[data-behaviours~=load-modal]").click(fancypages.eventHandlers.loadModal); diff --git a/fancypages/static/fancypages/js/event-handlers.js b/fancypages/static/fancypages/js/event-handlers.js index e224b8b..07e596e 100644 --- a/fancypages/static/fancypages/js/event-handlers.js +++ b/fancypages/static/fancypages/js/event-handlers.js @@ -28,6 +28,30 @@ fancypages.eventHandlers = { }); }, + deleteTab: function (ev) { + ev.preventDefault(); + + $.ajax({ + url: $(this).data('action'), + type: 'DELETE', + data: { + content_type: $(this).data('content-type-id'), + object_id: $(this).parents('.block').data('block-id') + }, + beforeSend: function (xhr, settings) { + xhr.setRequestHeader("X-CSRFToken", fancypages.getCsrfToken()); + }, + success: function (data) { + parent.fancypages.editor.reloadPage(); + }, + error: function () { + parent.fancypages.utils.messages.error( + "An error occured trying to add a new tab. Please try it again." + ); + } + }); + }, + loadIframeModal: function (ev) { var iframeId = $(this).data('iframe-id'); if (iframeId === undefined) {