From cff666119e54536ddfc736599c09fb5a9ed45474 Mon Sep 17 00:00:00 2001 From: Jordan Wright Date: Sat, 16 Jan 2016 23:50:11 -0600 Subject: [PATCH] Added ability to delete campaign. Fixes #72 --- static/js/app/campaigns.js | 18 +++++++++++++++--- static/js/app/dashboard.js | 9 +++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/static/js/app/campaigns.js b/static/js/app/campaigns.js index c3a64ee0..1cf81a17 100644 --- a/static/js/app/campaigns.js +++ b/static/js/app/campaigns.js @@ -8,6 +8,8 @@ var labels = { "Error": "label-danger" } +var campaigns = [] + // Save attempts to POST to /campaigns/ function save() { groups = [] @@ -16,7 +18,6 @@ function save() { name: group[0] }) }) - console.log(groups) var campaign = { name: $("#name").val(), template: { @@ -52,6 +53,16 @@ function dismiss() { $("#groupTable").dataTable().DataTable().clear().draw() } +function deleteCampaign(idx) { + if (confirm("Delete " + campaigns[idx].name + "?")) { + api.campaignId.delete(campaigns[idx].id) + .success(function(data) { + successFlash(data.message) + load() + }) + } +} + function edit(campaign) { // Clear the bloodhound instance group_bh.clear(); @@ -90,7 +101,8 @@ function edit(campaign) { $(document).ready(function() { api.campaigns.get() - .success(function(campaigns) { + .success(function(cs) { + campaigns = cs $("#loading").hide() if (campaigns.length > 0) { $("#campaignTable").show() @@ -104,7 +116,7 @@ $(document).ready(function() { "
\ \ \ -
" ]).draw() diff --git a/static/js/app/dashboard.js b/static/js/app/dashboard.js index 23ed7752..59a03c29 100644 --- a/static/js/app/dashboard.js +++ b/static/js/app/dashboard.js @@ -9,6 +9,15 @@ var labels = { "Error": "label-danger" } +function deleteCampaign(idx) { + if (confirm("Delete " + campaigns[idx].name + "?")) { + api.campaignId.delete(campaigns[idx].id) + .success(function(data) { + successFlash(data.message) + }) + } +} + $(document).ready(function() { api.campaigns.get() .success(function(cs) {