2015-06-17 04:09:27 +00:00
|
|
|
// Save attempts to POST to /campaigns/
|
2015-06-17 03:22:51 +00:00
|
|
|
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
|
2015-06-17 04:09:27 +00:00
|
|
|
api.campaigns.post(campaign)
|
2015-06-17 03:22:51 +00:00
|
|
|
.success(function(data){
|
2015-06-17 04:09:27 +00:00
|
|
|
successFlash("Campaign successfully launched!")
|
|
|
|
load()
|
2015-06-17 03:22:51 +00:00
|
|
|
})
|
|
|
|
.error(function(data){
|
|
|
|
$("#modal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
|
|
|
|
<i class=\"fa fa-exclamation-circle\"></i> " + data.responseJSON.message + "</div>")
|
|
|
|
})
|
|
|
|
}
|
2015-06-17 04:09:27 +00:00
|
|
|
|
|
|
|
function groupAdd(name){
|
|
|
|
groups.append({
|
|
|
|
name: name
|
2015-06-16 03:51:18 +00:00
|
|
|
})
|
2015-06-17 04:09:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
})
|
|
|
|
}
|
2015-06-16 03:51:18 +00:00
|
|
|
})
|
2015-06-17 04:09:27 +00:00
|
|
|
.error(function(){
|
|
|
|
errorFlash("Error fetching campaigns")
|
2015-06-17 03:22:51 +00:00
|
|
|
})
|
2015-06-17 04:09:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function(){
|
|
|
|
load()
|
2015-06-16 03:51:18 +00:00
|
|
|
})
|