2015-07-28 02:31:08 +00:00
|
|
|
// labels is a map of campaign statuses to
|
|
|
|
// CSS classes
|
|
|
|
var labels = {
|
2016-01-17 04:59:40 +00:00
|
|
|
"In progress": "label-primary",
|
|
|
|
"Queued": "label-info",
|
|
|
|
"Completed": "label-success",
|
|
|
|
"Emails Sent": "label-success",
|
|
|
|
"Error": "label-danger"
|
2015-07-28 02:31:08 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 05:50:11 +00:00
|
|
|
var campaigns = []
|
|
|
|
|
2016-02-02 02:42:46 +00:00
|
|
|
// Launch attempts to POST to /campaigns/
|
2016-01-21 01:00:32 +00:00
|
|
|
function launch() {
|
|
|
|
if (!confirm("This will launch the campaign. Are you sure?")) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-16 03:57:47 +00:00
|
|
|
groups = []
|
2016-01-17 04:59:40 +00:00
|
|
|
$.each($("#groupTable").DataTable().rows().data(), function(i, group) {
|
|
|
|
groups.push({
|
|
|
|
name: group[0]
|
|
|
|
})
|
|
|
|
})
|
2015-06-17 03:22:51 +00:00
|
|
|
var campaign = {
|
2016-02-02 02:42:46 +00:00
|
|
|
name: $("#name").val(),
|
|
|
|
template: {
|
|
|
|
name: $("#template").val()
|
|
|
|
},
|
|
|
|
url: $("#url").val(),
|
|
|
|
page: {
|
|
|
|
name: $("#page").val()
|
|
|
|
},
|
|
|
|
smtp: {
|
2016-02-21 17:13:28 +00:00
|
|
|
name: $("#profile").val()
|
2016-02-02 02:42:46 +00:00
|
|
|
},
|
|
|
|
groups: groups
|
|
|
|
}
|
|
|
|
launchHtml = $("launchButton").html()
|
|
|
|
$("launchButton").html('<i class="fa fa-spinner fa-spin"></i> Launching Campaign')
|
2016-01-17 04:59:40 +00:00
|
|
|
// Submit the campaign
|
2015-06-17 04:09:27 +00:00
|
|
|
api.campaigns.post(campaign)
|
2016-01-17 04:59:40 +00:00
|
|
|
.success(function(data) {
|
|
|
|
successFlash("Campaign successfully launched!")
|
2016-02-02 02:42:46 +00:00
|
|
|
$("launchButton").html('<i class="fa fa-spinner fa-spin"></i> Redirecting')
|
2016-01-18 17:53:27 +00:00
|
|
|
window.location = "/campaigns/" + data.id.toString()
|
2016-01-17 04:59:40 +00:00
|
|
|
})
|
|
|
|
.error(function(data) {
|
|
|
|
$("#modal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
|
2015-06-17 03:22:51 +00:00
|
|
|
<i class=\"fa fa-exclamation-circle\"></i> " + data.responseJSON.message + "</div>")
|
2016-02-02 02:42:46 +00:00
|
|
|
$("#launchButton").html(launchHtml)
|
2016-01-17 04:59:40 +00:00
|
|
|
})
|
2015-06-17 03:22:51 +00:00
|
|
|
}
|
2015-06-17 04:09:27 +00:00
|
|
|
|
2016-01-25 02:03:53 +00:00
|
|
|
// Attempts to send a test email by POSTing to /campaigns/
|
|
|
|
function sendTestEmail() {
|
|
|
|
var test_email_request = {
|
|
|
|
template: {
|
|
|
|
name: $("#template").val()
|
|
|
|
},
|
|
|
|
first_name: $("input[name=to_first_name]").val(),
|
|
|
|
last_name: $("input[name=to_last_name]").val(),
|
|
|
|
email: $("input[name=to_email]").val(),
|
|
|
|
position: $("input[name=to_position]").val(),
|
|
|
|
url: $("#url").val(),
|
|
|
|
page: {
|
|
|
|
name: $("#page").val()
|
|
|
|
},
|
|
|
|
smtp: {
|
2016-02-21 17:13:28 +00:00
|
|
|
name: $("#profile").val()
|
2016-01-25 02:03:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
btnHtml = $("#sendTestModalSubmit").html()
|
|
|
|
$("#sendTestModalSubmit").html('<i class="fa fa-spinner fa-spin"></i> Sending')
|
|
|
|
// Send the test email
|
|
|
|
api.send_test_email(test_email_request)
|
|
|
|
.success(function(data) {
|
|
|
|
$("#sendTestEmailModal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-success\">\
|
2016-01-25 02:07:46 +00:00
|
|
|
<i class=\"fa fa-check-circle\"></i> Email Sent!</div>")
|
2016-01-25 02:03:53 +00:00
|
|
|
$("#sendTestModalSubmit").html(btnHtml)
|
|
|
|
})
|
|
|
|
.error(function(data) {
|
|
|
|
$("#sendTestEmailModal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
|
|
|
|
<i class=\"fa fa-exclamation-circle\"></i> " + data.responseJSON.message + "</div>")
|
|
|
|
$("#sendTestModalSubmit").html(btnHtml)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:59:40 +00:00
|
|
|
function dismiss() {
|
2015-06-18 03:44:05 +00:00
|
|
|
$("#modal\\.flashes").empty()
|
2016-02-21 22:51:01 +00:00
|
|
|
$("#name").val("")
|
|
|
|
$("#template").val("")
|
|
|
|
$("#page").val("")
|
|
|
|
$("#url").val("")
|
|
|
|
$("#profile").val("")
|
|
|
|
$("#groupSelect").val("")
|
2015-06-18 03:44:05 +00:00
|
|
|
$("#modal").modal('hide')
|
2015-07-07 03:26:08 +00:00
|
|
|
$("#groupTable").dataTable().DataTable().clear().draw()
|
2015-06-18 03:44:05 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 05:50:11 +00:00
|
|
|
function deleteCampaign(idx) {
|
|
|
|
if (confirm("Delete " + campaigns[idx].name + "?")) {
|
|
|
|
api.campaignId.delete(campaigns[idx].id)
|
|
|
|
.success(function(data) {
|
|
|
|
successFlash(data.message)
|
2016-01-21 01:00:32 +00:00
|
|
|
location.reload()
|
2016-01-17 05:50:11 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:59:40 +00:00
|
|
|
function edit(campaign) {
|
2015-07-07 03:26:08 +00:00
|
|
|
// Clear the bloodhound instance
|
2015-09-16 03:57:47 +00:00
|
|
|
group_bh.clear();
|
|
|
|
template_bh.clear();
|
2015-10-23 03:29:10 +00:00
|
|
|
page_bh.clear();
|
2016-02-21 17:13:28 +00:00
|
|
|
profile_bh.clear();
|
2015-06-30 04:52:26 +00:00
|
|
|
if (campaign == "new") {
|
|
|
|
api.groups.get()
|
2016-01-17 04:59:40 +00:00
|
|
|
.success(function(groups) {
|
|
|
|
if (groups.length == 0) {
|
|
|
|
modalError("No groups found!")
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
group_bh.add(groups)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
api.templates.get()
|
|
|
|
.success(function(templates) {
|
|
|
|
if (templates.length == 0) {
|
|
|
|
modalError("No templates found!")
|
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
template_bh.add(templates)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
api.pages.get()
|
|
|
|
.success(function(pages) {
|
|
|
|
if (pages.length == 0) {
|
|
|
|
modalError("No pages found!")
|
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
page_bh.add(pages)
|
|
|
|
}
|
|
|
|
})
|
2016-02-21 17:13:28 +00:00
|
|
|
api.SMTP.get()
|
|
|
|
.success(function(profiles) {
|
|
|
|
if (profiles.length == 0){
|
|
|
|
modalError("No profiles found!")
|
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
profile_bh.add(profiles)
|
|
|
|
}
|
|
|
|
})
|
2015-06-30 04:52:26 +00:00
|
|
|
}
|
2015-06-17 04:09:27 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 04:59:40 +00:00
|
|
|
$(document).ready(function() {
|
2016-01-25 02:03:53 +00:00
|
|
|
// Setup multiple modals
|
|
|
|
// Code based on http://miles-by-motorcycle.com/static/bootstrap-modal/index.html
|
|
|
|
$('.modal').on('hidden.bs.modal', function(event) {
|
|
|
|
$(this).removeClass('fv-modal-stack');
|
|
|
|
$('body').data('fv_open_modals', $('body').data('fv_open_modals') - 1);
|
|
|
|
});
|
|
|
|
$('.modal').on('shown.bs.modal', function(event) {
|
|
|
|
// Keep track of the number of open modals
|
|
|
|
if (typeof($('body').data('fv_open_modals')) == 'undefined') {
|
|
|
|
$('body').data('fv_open_modals', 0);
|
|
|
|
}
|
|
|
|
// if the z-index of this modal has been set, ignore.
|
|
|
|
if ($(this).hasClass('fv-modal-stack')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$(this).addClass('fv-modal-stack');
|
|
|
|
// Increment the number of open modals
|
|
|
|
$('body').data('fv_open_modals', $('body').data('fv_open_modals') + 1);
|
|
|
|
// Setup the appropriate z-index
|
|
|
|
$(this).css('z-index', 1040 + (10 * $('body').data('fv_open_modals')));
|
|
|
|
$('.modal-backdrop').not('.fv-modal-stack').css('z-index', 1039 + (10 * $('body').data('fv_open_modals')));
|
|
|
|
$('.modal-backdrop').not('fv-modal-stack').addClass('fv-modal-stack');
|
|
|
|
});
|
|
|
|
$.fn.modal.Constructor.prototype.enforceFocus = function() {
|
|
|
|
$(document)
|
|
|
|
.off('focusin.bs.modal') // guard against infinite focus loop
|
|
|
|
.on('focusin.bs.modal', $.proxy(function(e) {
|
|
|
|
if (
|
|
|
|
this.$element[0] !== e.target && !this.$element.has(e.target).length
|
|
|
|
// CKEditor compatibility fix start.
|
|
|
|
&& !$(e.target).closest('.cke_dialog, .cke').length
|
|
|
|
// CKEditor compatibility fix end.
|
|
|
|
) {
|
|
|
|
this.$element.trigger('focus');
|
|
|
|
}
|
|
|
|
}, this));
|
|
|
|
};
|
2015-06-17 04:09:27 +00:00
|
|
|
api.campaigns.get()
|
2016-01-17 05:50:11 +00:00
|
|
|
.success(function(cs) {
|
2016-01-21 01:00:32 +00:00
|
|
|
campaigns = cs
|
2016-01-17 21:27:11 +00:00
|
|
|
campaignTable = $("#campaignTable").DataTable({
|
2016-01-21 03:53:12 +00:00
|
|
|
columnDefs: [{
|
|
|
|
orderable: false,
|
|
|
|
targets: "no-sort"
|
|
|
|
}]
|
2016-01-17 21:27:11 +00:00
|
|
|
});
|
2016-01-17 04:59:40 +00:00
|
|
|
$("#loading").hide()
|
|
|
|
if (campaigns.length > 0) {
|
|
|
|
$("#campaignTable").show()
|
|
|
|
campaignTable = $("#campaignTable").DataTable();
|
|
|
|
$.each(campaigns, function(i, campaign) {
|
|
|
|
label = labels[campaign.status] || "label-default";
|
|
|
|
campaignTable.row.add([
|
|
|
|
campaign.name,
|
|
|
|
moment(campaign.created_date).format('MMMM Do YYYY, h:mm:ss a'),
|
|
|
|
"<span class=\"label " + label + "\">" + campaign.status + "</span>",
|
2016-01-18 04:20:38 +00:00
|
|
|
"<div class='pull-right'><a class='btn btn-primary' href='/campaigns/" + campaign.id + "' data-toggle='tooltip' data-placement='left' title='View Results'>\
|
2015-07-07 03:26:08 +00:00
|
|
|
<i class='fa fa-bar-chart'></i>\
|
2015-08-05 02:27:04 +00:00
|
|
|
</a>\
|
2016-01-18 04:20:38 +00:00
|
|
|
<button class='btn btn-danger' onclick='deleteCampaign(" + i + ")' data-toggle='tooltip' data-placement='left' title='Delete Campaign'>\
|
2015-07-07 03:26:08 +00:00
|
|
|
<i class='fa fa-trash-o'></i>\
|
|
|
|
</button></div>"
|
2016-01-17 04:59:40 +00:00
|
|
|
]).draw()
|
2016-01-18 04:20:38 +00:00
|
|
|
$('[data-toggle="tooltip"]').tooltip()
|
2016-01-17 04:59:40 +00:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
$("#emptyMessage").show()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.error(function() {
|
|
|
|
$("#loading").hide()
|
|
|
|
errorFlash("Error fetching campaigns")
|
|
|
|
})
|
|
|
|
$("#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();
|
2015-06-17 04:09:27 +00:00
|
|
|
})
|
2016-01-17 04:59:40 +00:00
|
|
|
return false;
|
2015-07-07 03:26:08 +00:00
|
|
|
})
|
2016-01-17 04:59:40 +00:00
|
|
|
// Create the group typeahead objects
|
2016-01-17 21:27:11 +00:00
|
|
|
groupTable = $("#groupTable").DataTable({
|
2016-01-21 03:53:12 +00:00
|
|
|
columnDefs: [{
|
|
|
|
orderable: false,
|
|
|
|
targets: "no-sort"
|
|
|
|
}]
|
2016-01-17 21:27:11 +00:00
|
|
|
})
|
2015-09-16 03:57:47 +00:00
|
|
|
group_bh = new Bloodhound({
|
2016-01-17 04:59:40 +00:00
|
|
|
datumTokenizer: function(g) {
|
|
|
|
return Bloodhound.tokenizers.whitespace(g.name)
|
|
|
|
},
|
2015-07-07 03:26:08 +00:00
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
local: []
|
|
|
|
})
|
2015-09-16 03:57:47 +00:00
|
|
|
group_bh.initialize()
|
2015-07-07 03:26:08 +00:00
|
|
|
$("#groupSelect.typeahead.form-control").typeahead({
|
2016-01-17 04:59:40 +00:00
|
|
|
hint: true,
|
|
|
|
highlight: true,
|
|
|
|
minLength: 1
|
|
|
|
}, {
|
|
|
|
name: "groups",
|
|
|
|
source: group_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)
|
|
|
|
})
|
|
|
|
.bind('typeahead:autocomplete', function(ev, group) {
|
|
|
|
$("#groupSelect").typeahead('val', group.name)
|
|
|
|
});
|
2015-09-16 03:57:47 +00:00
|
|
|
// Create the template typeahead objects
|
|
|
|
template_bh = new Bloodhound({
|
2016-01-17 04:59:40 +00:00
|
|
|
datumTokenizer: function(t) {
|
|
|
|
return Bloodhound.tokenizers.whitespace(t.name)
|
|
|
|
},
|
2015-09-16 03:57:47 +00:00
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
local: []
|
|
|
|
})
|
|
|
|
template_bh.initialize()
|
|
|
|
$("#template.typeahead.form-control").typeahead({
|
2016-01-17 04:59:40 +00:00
|
|
|
hint: true,
|
|
|
|
highlight: true,
|
|
|
|
minLength: 1
|
|
|
|
}, {
|
|
|
|
name: "templates",
|
|
|
|
source: template_bh,
|
|
|
|
templates: {
|
|
|
|
empty: function(data) {
|
|
|
|
return '<div class="tt-suggestion">No templates matched that query</div>'
|
|
|
|
},
|
|
|
|
suggestion: function(data) {
|
|
|
|
return '<div>' + data.name + '</div>'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.bind('typeahead:select', function(ev, template) {
|
|
|
|
$("#template").typeahead('val', template.name)
|
|
|
|
})
|
|
|
|
.bind('typeahead:autocomplete', function(ev, template) {
|
|
|
|
$("#template").typeahead('val', template.name)
|
|
|
|
});
|
2015-10-23 03:29:10 +00:00
|
|
|
// Create the landing page typeahead objects
|
|
|
|
page_bh = new Bloodhound({
|
2016-01-17 04:59:40 +00:00
|
|
|
datumTokenizer: function(p) {
|
|
|
|
return Bloodhound.tokenizers.whitespace(p.name)
|
|
|
|
},
|
2015-10-23 03:29:10 +00:00
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
local: []
|
|
|
|
})
|
|
|
|
page_bh.initialize()
|
|
|
|
$("#page.typeahead.form-control").typeahead({
|
2016-01-17 04:59:40 +00:00
|
|
|
hint: true,
|
|
|
|
highlight: true,
|
|
|
|
minLength: 1
|
|
|
|
}, {
|
|
|
|
name: "pages",
|
|
|
|
source: page_bh,
|
|
|
|
templates: {
|
|
|
|
empty: function(data) {
|
|
|
|
return '<div class="tt-suggestion">No pages matched that query</div>'
|
|
|
|
},
|
|
|
|
suggestion: function(data) {
|
|
|
|
return '<div>' + data.name + '</div>'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.bind('typeahead:select', function(ev, page) {
|
|
|
|
$("#page").typeahead('val', page.name)
|
|
|
|
})
|
|
|
|
.bind('typeahead:autocomplete', function(ev, page) {
|
|
|
|
$("#page").typeahead('val', page.name)
|
|
|
|
});
|
2016-02-21 17:13:28 +00:00
|
|
|
// Create the sending profile typeahead objects
|
|
|
|
profile_bh = new Bloodhound({
|
|
|
|
datumTokenizer: function(s) {
|
|
|
|
return Bloodhound.tokenizers.whitespace(s.name)
|
|
|
|
},
|
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
local: []
|
|
|
|
})
|
|
|
|
profile_bh.initialize()
|
|
|
|
$("#profile.typeahead.form-control").typeahead({
|
|
|
|
hint: true,
|
|
|
|
highlight: true,
|
|
|
|
minLength: 1
|
|
|
|
}, {
|
|
|
|
name: "profiles",
|
|
|
|
source: profile_bh,
|
|
|
|
templates: {
|
|
|
|
empty: function(data) {
|
|
|
|
return '<div class="tt-suggestion">No profiles matched that query</div>'
|
|
|
|
},
|
|
|
|
suggestion: function(data) {
|
|
|
|
return '<div>' + data.name + '</div>'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.bind('typeahead:select', function(ev, profile) {
|
|
|
|
$("#profile").typeahead('val', profile.name)
|
|
|
|
})
|
|
|
|
.bind('typeahead:autocomplete', function(ev, profile) {
|
|
|
|
$("#profile").typeahead('val', profile.name)
|
|
|
|
});
|
2015-06-16 03:51:18 +00:00
|
|
|
})
|