Added ability to delete campaign. Fixes #72

pull/75/head
Jordan Wright 2016-01-16 23:50:11 -06:00
parent 66720aa1b8
commit cff666119e
2 changed files with 24 additions and 3 deletions

View File

@ -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() {
"<div class='pull-right'><a class='btn btn-primary' href='/campaigns/" + campaign.id + "'>\
<i class='fa fa-bar-chart'></i>\
</a>\
<button class='btn btn-danger' onclick='alert(\"test\")'>\
<button class='btn btn-danger' onclick='deleteCampaign(" + i + ")'>\
<i class='fa fa-trash-o'></i>\
</button></div>"
]).draw()

View File

@ -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) {