// Save attempts to POST to /campaigns/
function save(){
var campaign = {
name: $("#name").val(),
template:{
name: $("#template").val()
},
smtp: {
from_address: $("input[name=from]").val(),
host: $("input[name=host]").val(),
username: $("input[name=username]").val(),
password: $("input[name=password]").val(),
},
groups: [{name : "Morning catch employees"}]
}
// Submit the campaign
api.campaigns.post(campaign)
.success(function(data){
successFlash("Campaign successfully launched!")
load()
})
.error(function(data){
$("#modal\\.flashes").empty().append("
\
" + data.responseJSON.message + "
")
})
}
function dismiss(){
$("#modal\\.flashes").empty()
$("#modal").modal('hide')
}
function groupAdd(name){
groups.append({
name: name
})
}
function load(){
api.campaigns.get()
.success(function(campaigns){
if (campaigns.length > 0){
$("#emptyMessage").hide()
$("#campaignTable").show()
campaignTable = $("#campaignTable").DataTable();
$.each(campaigns, function(i, campaign){
campaignTable.row.add([
campaign.created_date,
campaign.name,
campaign.status
]).draw()
})
}
})
.error(function(){
errorFlash("Error fetching campaigns")
})
}
$(document).ready(function(){
load()
})