2015-08-12 02:12:09 +00:00
|
|
|
var map = null
|
2015-07-29 00:31:12 +00:00
|
|
|
|
2015-08-12 02:12:09 +00:00
|
|
|
// statuses is a helper map to point result statuses to ui classes
|
|
|
|
var statuses = {
|
2015-08-05 02:27:04 +00:00
|
|
|
"Email Sent" : {
|
|
|
|
slice: "ct-slice-donut-sent",
|
2015-08-12 02:12:09 +00:00
|
|
|
legend: "ct-legend-sent",
|
|
|
|
label: "label-success"
|
2015-08-05 02:27:04 +00:00
|
|
|
},
|
|
|
|
"Email Opened" : {
|
|
|
|
slice: "ct-slice-donut-opened",
|
2015-08-12 02:12:09 +00:00
|
|
|
legend: "ct-legend-opened",
|
|
|
|
label: "label-warning"
|
2015-08-05 02:27:04 +00:00
|
|
|
},
|
|
|
|
"Clicked Link" : {
|
|
|
|
slice: "ct-slice-donut-clicked",
|
2015-08-12 02:12:09 +00:00
|
|
|
legend: "ct-legend-clicked",
|
|
|
|
label: "label-danger"
|
|
|
|
},
|
|
|
|
"Success" : {
|
|
|
|
slice: "ct-slice-donut-clicked",
|
|
|
|
legend: "ct-legend-clicked",
|
|
|
|
label: "label-danger"
|
2015-08-05 02:27:04 +00:00
|
|
|
},
|
|
|
|
"Error" : {
|
|
|
|
slice: "ct-slice-donut-error",
|
2015-08-12 02:12:09 +00:00
|
|
|
legend: "ct-legend-error",
|
|
|
|
label: "label-default"
|
2015-08-05 02:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-29 00:31:12 +00:00
|
|
|
var campaign = {}
|
|
|
|
|
|
|
|
function dismiss(){
|
|
|
|
$("#modal\\.flashes").empty()
|
|
|
|
$("#modal").modal('hide')
|
2015-07-30 03:31:39 +00:00
|
|
|
$("#resultsTable").dataTable().DataTable().clear().draw()
|
2015-07-29 00:31:12 +00:00
|
|
|
}
|
|
|
|
|
2015-07-30 03:31:39 +00:00
|
|
|
// Deletes a campaign after prompting the user
|
|
|
|
function deleteCampaign(){
|
|
|
|
if (confirm("Are you sure you want to delete: " + campaign.name + "?")){
|
|
|
|
api.campaignId.delete(campaign.id)
|
|
|
|
.success(function(msg){
|
|
|
|
console.log(msg)
|
|
|
|
})
|
|
|
|
.error(function(e){
|
|
|
|
$("#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-07-29 00:31:12 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function(){
|
2015-07-30 03:31:39 +00:00
|
|
|
campaign.id = window.location.pathname.split('/').slice(-1)[0]
|
|
|
|
api.campaignId.get(campaign.id)
|
2015-07-29 00:31:12 +00:00
|
|
|
.success(function(c){
|
|
|
|
campaign = c
|
|
|
|
if (campaign){
|
2015-08-01 20:35:32 +00:00
|
|
|
// Set the title
|
|
|
|
$("#page-title").text("Results for " + c.name)
|
2015-08-12 02:12:09 +00:00
|
|
|
// Setup tooltips
|
|
|
|
$('[data-toggle="tooltip"]').tooltip()
|
2015-07-30 03:31:39 +00:00
|
|
|
// Setup our graphs
|
2015-08-05 02:27:04 +00:00
|
|
|
var timeline_data = {series:[{
|
|
|
|
name: "Events",
|
|
|
|
data: []
|
|
|
|
}]}
|
2015-07-31 04:07:54 +00:00
|
|
|
var email_data = {series:[]}
|
2015-08-05 02:27:04 +00:00
|
|
|
var email_legend = {}
|
2015-08-01 20:35:32 +00:00
|
|
|
var email_series_data = {}
|
2015-07-30 03:31:39 +00:00
|
|
|
var timeline_opts = {
|
|
|
|
axisX: {
|
2015-07-31 04:07:54 +00:00
|
|
|
showGrid: false,
|
2015-08-05 02:27:04 +00:00
|
|
|
type: Chartist.FixedScaleAxis,
|
|
|
|
divisor: 5,
|
|
|
|
labelInterpolationFnc: function(value){
|
|
|
|
return moment(value).format('MMMM Do YYYY h:mm')
|
|
|
|
}
|
2015-07-31 04:07:54 +00:00
|
|
|
},
|
|
|
|
axisY: {
|
|
|
|
type: Chartist.FixedScaleAxis,
|
|
|
|
ticks: [0, 1, 2],
|
|
|
|
low: 0,
|
|
|
|
showLabel: false
|
2015-07-30 03:31:39 +00:00
|
|
|
},
|
2015-08-05 02:27:04 +00:00
|
|
|
showArea: false,
|
2015-07-30 03:31:39 +00:00
|
|
|
plugins: []
|
|
|
|
}
|
|
|
|
var email_opts = {
|
|
|
|
donut : true,
|
|
|
|
donutWidth: 40,
|
|
|
|
chartPadding: 0,
|
|
|
|
showLabel: false
|
|
|
|
}
|
2015-07-31 04:07:54 +00:00
|
|
|
// Setup the results table
|
2015-07-30 03:31:39 +00:00
|
|
|
resultsTable = $("#resultsTable").DataTable();
|
|
|
|
$.each(campaign.results, function(i, result){
|
2015-08-12 02:12:09 +00:00
|
|
|
label = statuses[result.status].label || "label-default";
|
2015-07-30 03:31:39 +00:00
|
|
|
resultsTable.row.add([
|
|
|
|
result.first_name || "",
|
|
|
|
result.last_name || "",
|
|
|
|
result.email || "",
|
|
|
|
result.position || "",
|
|
|
|
"<span class=\"label " + label + "\">" + result.status + "</span>"
|
2015-07-29 00:31:12 +00:00
|
|
|
]).draw()
|
2015-08-01 20:35:32 +00:00
|
|
|
if (!email_series_data[result.status]){
|
|
|
|
email_series_data[result.status] = 1
|
|
|
|
} else {
|
|
|
|
email_series_data[result.status]++;
|
|
|
|
}
|
2015-07-29 00:31:12 +00:00
|
|
|
})
|
2015-07-31 04:07:54 +00:00
|
|
|
// Setup the graphs
|
|
|
|
$.each(campaign.timeline, function(i, event){
|
2015-08-05 02:27:04 +00:00
|
|
|
timeline_data.series[0].data.push({meta : i, x: new Date(event.time), y:1})
|
2015-07-31 04:07:54 +00:00
|
|
|
})
|
2015-08-01 20:35:32 +00:00
|
|
|
$.each(email_series_data, function(status, count){
|
|
|
|
email_data.series.push({meta: status, value: count})
|
|
|
|
})
|
2015-07-31 04:07:54 +00:00
|
|
|
var timeline_chart = new Chartist.Line('#timeline_chart', timeline_data, timeline_opts)
|
|
|
|
// Setup the overview chart listeners
|
|
|
|
$chart = $("#timeline_chart")
|
|
|
|
var $toolTip = $chart
|
|
|
|
.append('<div class="chartist-tooltip"></div>')
|
|
|
|
.find('.chartist-tooltip')
|
|
|
|
.hide();
|
|
|
|
$chart.on('mouseenter', '.ct-point', function() {
|
|
|
|
var $point = $(this)
|
|
|
|
value = $point.attr('ct:value')
|
|
|
|
cidx = $point.attr('ct:meta')
|
|
|
|
html = "Event: " + campaign.timeline[cidx].message
|
|
|
|
if (campaign.timeline[cidx].email) {
|
|
|
|
html += '<br>' + "Email: " + campaign.timeline[cidx].email
|
|
|
|
}
|
|
|
|
$toolTip.html(html).show()
|
|
|
|
});
|
|
|
|
$chart.on('mouseleave', '.ct-point', function() {
|
|
|
|
$toolTip.hide();
|
|
|
|
});
|
|
|
|
$chart.on('mousemove', function(event) {
|
|
|
|
$toolTip.css({
|
|
|
|
left: (event.offsetX || event.originalEvent.layerX) - $toolTip.width() / 2 - 10,
|
2015-08-01 20:35:32 +00:00
|
|
|
top: (event.offsetY + 70 || event.originalEvent.layerY) - $toolTip.height() - 40
|
2015-07-31 04:07:54 +00:00
|
|
|
});
|
|
|
|
});
|
2015-08-01 20:35:32 +00:00
|
|
|
var email_chart = new Chartist.Pie("#email_chart", email_data, email_opts)
|
2015-08-05 02:27:04 +00:00
|
|
|
email_chart.on('draw', function(data){
|
|
|
|
// We don't want to create the legend twice
|
|
|
|
if (!email_legend[data.meta]) {
|
|
|
|
console.log(data.meta)
|
2015-08-12 02:12:09 +00:00
|
|
|
$("#email_chart_legend").append('<li><span class="' + statuses[data.meta].legend + '"></span>' + data.meta + '</li>')
|
2015-08-05 02:27:04 +00:00
|
|
|
email_legend[data.meta] = true
|
|
|
|
}
|
2015-08-12 02:12:09 +00:00
|
|
|
data.element.addClass(statuses[data.meta].slice)
|
2015-08-05 02:27:04 +00:00
|
|
|
})
|
2015-08-01 20:35:32 +00:00
|
|
|
// Setup the average chart listeners
|
|
|
|
$piechart = $("#email_chart")
|
|
|
|
var $pietoolTip = $piechart
|
|
|
|
.append('<div class="chartist-tooltip"></div>')
|
|
|
|
.find('.chartist-tooltip')
|
|
|
|
.hide();
|
|
|
|
|
|
|
|
$piechart.on('mouseenter', '.ct-slice-donut', function() {
|
|
|
|
var $point = $(this)
|
|
|
|
value = $point.attr('ct:value')
|
|
|
|
label = $point.attr('ct:meta')
|
|
|
|
$pietoolTip.html(label + ': ' + value.toString()).show();
|
|
|
|
});
|
|
|
|
|
|
|
|
$piechart.on('mouseleave', '.ct-slice-donut', function() {
|
|
|
|
$pietoolTip.hide();
|
|
|
|
});
|
|
|
|
$piechart.on('mousemove', function(event) {
|
|
|
|
$pietoolTip.css({
|
|
|
|
left: (event.offsetX || event.originalEvent.layerX) - $pietoolTip.width() / 2 - 10,
|
2015-08-05 02:27:04 +00:00
|
|
|
top: (event.offsetY + 40 || event.originalEvent.layerY) - $pietoolTip.height() - 80
|
2015-08-01 20:35:32 +00:00
|
|
|
});
|
|
|
|
});
|
2015-08-05 02:27:04 +00:00
|
|
|
$("#loading").hide()
|
|
|
|
$("#campaignResults").show()
|
2015-07-29 00:31:12 +00:00
|
|
|
}
|
2015-08-12 02:12:09 +00:00
|
|
|
// Load up the map data (only once!)
|
|
|
|
// Slated for 0.2 release - coming soon! :)
|
|
|
|
// $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
|
|
|
// if ($(e.target).attr('href') == "#plugins"){
|
|
|
|
// if (!map){
|
|
|
|
// map = new Datamap({
|
|
|
|
// element: document.getElementById("resultsMap"),
|
|
|
|
// responsive: true,
|
|
|
|
// fills: {
|
|
|
|
// defaultFill: "#34495e"
|
|
|
|
// },
|
|
|
|
// geographyConfig: {
|
|
|
|
// highlightFillColor : "#1abc9c"
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// })
|
2015-07-29 00:31:12 +00:00
|
|
|
})
|
|
|
|
.error(function(){
|
2015-07-30 03:31:39 +00:00
|
|
|
errorFlash(" Campaign not found!")
|
2015-07-29 00:31:12 +00:00
|
|
|
})
|
|
|
|
})
|