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(),
|
|
|
|
},
|
2015-07-07 03:26:08 +00:00
|
|
|
groups: [{name : "Test group"}]
|
2015-06-17 03:22:51 +00:00
|
|
|
}
|
|
|
|
// 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
|
|
|
|
2015-06-18 03:44:05 +00:00
|
|
|
function dismiss(){
|
|
|
|
$("#modal\\.flashes").empty()
|
|
|
|
$("#modal").modal('hide')
|
2015-07-07 03:26:08 +00:00
|
|
|
$("#groupTable").dataTable().DataTable().clear().draw()
|
2015-06-18 03:44:05 +00:00
|
|
|
}
|
|
|
|
|
2015-06-30 04:52:26 +00:00
|
|
|
function edit(campaign){
|
2015-07-07 03:26:08 +00:00
|
|
|
// Clear the bloodhound instance
|
|
|
|
bh.clear();
|
2015-06-30 04:52:26 +00:00
|
|
|
if (campaign == "new") {
|
|
|
|
api.groups.get()
|
|
|
|
.success(function(groups){
|
|
|
|
if (groups.length == 0){
|
|
|
|
modalError("No groups found!")
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
2015-07-07 03:26:08 +00:00
|
|
|
bh.add(groups)
|
2015-06-30 04:52:26 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2015-06-17 04:09:27 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 03:26:08 +00:00
|
|
|
$(document).ready(function(){
|
2015-06-17 04:09:27 +00:00
|
|
|
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([
|
2015-07-07 03:26:08 +00:00
|
|
|
moment(campaign.created_date).format('MMMM Do YYYY, h:mm:ss a'),
|
2015-06-17 04:09:27 +00:00
|
|
|
campaign.name,
|
2015-07-07 03:26:08 +00:00
|
|
|
campaign.status,
|
|
|
|
"<div class='pull-right'><button class='btn btn-success' onclick='alert(\"test\")'>\
|
|
|
|
<i class='fa fa-bar-chart'></i>\
|
|
|
|
</button>\
|
|
|
|
<button class='btn btn-danger' onclick='alert(\"test\")'>\
|
|
|
|
<i class='fa fa-trash-o'></i>\
|
|
|
|
</button></div>"
|
2015-06-17 04:09:27 +00:00
|
|
|
]).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-07-07 03:26:08 +00:00
|
|
|
$("#groupForm").submit(function(){
|
|
|
|
groupTable.row.add([
|
|
|
|
$("#groupSelect").val(),
|
|
|
|
'<span style="cursor:pointer;"><i class="fa fa-trash-o"></i></span>'
|
|
|
|
]).draw()
|
|
|
|
$("#groupTable").on("click", "span>i.fa-trash-o", function(){
|
|
|
|
groupTable.row( $(this).parents('tr') )
|
|
|
|
.remove()
|
|
|
|
.draw();
|
|
|
|
})
|
|
|
|
return false;
|
|
|
|
})
|
|
|
|
// Create the group typeahead objects
|
|
|
|
groupTable = $("#groupTable").DataTable()
|
|
|
|
suggestion_template = Hogan.compile('<div>{{name}}</div>')
|
|
|
|
bh = new Bloodhound({
|
|
|
|
datumTokenizer: function(g) { return Bloodhound.tokenizers.whitespace(g.name) },
|
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
local: []
|
|
|
|
})
|
|
|
|
bh.initialize()
|
|
|
|
$("#groupSelect.typeahead.form-control").typeahead({
|
|
|
|
hint: true,
|
|
|
|
highlight: true,
|
|
|
|
minLength: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "groups",
|
|
|
|
source: bh,
|
|
|
|
templates: {
|
|
|
|
empty: function(data) {return '<div class="tt-suggestion">No groups matched that query</div>' },
|
|
|
|
suggestion: function(data){ return '<div>' + data.name + '</div>' }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.bind('typeahead:select', function(ev, group){
|
|
|
|
$("#groupSelect").typeahead('val', group.name)
|
|
|
|
});
|
2015-06-16 03:51:18 +00:00
|
|
|
})
|