2015-06-16 03:51:18 +00:00
|
|
|
function errorFlash(message) {
|
2015-08-05 05:23:05 +00:00
|
|
|
$("#flashes").empty()
|
2015-06-16 03:51:18 +00:00
|
|
|
$("#flashes").append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
|
2016-01-17 04:59:40 +00:00
|
|
|
<i class=\"fa fa-exclamation-circle\"></i> " + message + "</div>")
|
2015-06-16 03:51:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function successFlash(message) {
|
2015-08-05 05:23:05 +00:00
|
|
|
$("#flashes").empty()
|
2015-06-16 03:51:18 +00:00
|
|
|
$("#flashes").append("<div style=\"text-align:center\" class=\"alert alert-success\">\
|
2016-01-17 04:59:40 +00:00
|
|
|
<i class=\"fa fa-check-circle\"></i> " + message + "</div>")
|
2015-06-16 03:51:18 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 04:59:40 +00:00
|
|
|
function modalError(message) {
|
2015-06-28 00:21:46 +00:00
|
|
|
$("#modal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
|
|
|
|
<i class=\"fa fa-exclamation-circle\"></i> " + message + "</div>")
|
|
|
|
}
|
|
|
|
|
2016-01-25 01:48:15 +00:00
|
|
|
function query(endpoint, method, data, async) {
|
2015-06-16 03:51:18 +00:00
|
|
|
return $.ajax({
|
|
|
|
url: "/api" + endpoint + "?api_key=" + user.api_key,
|
2016-01-25 01:48:15 +00:00
|
|
|
async: async,
|
2015-06-16 03:51:18 +00:00
|
|
|
method: method,
|
2015-06-17 03:22:51 +00:00
|
|
|
data: JSON.stringify(data),
|
2016-01-17 04:59:40 +00:00
|
|
|
dataType: "json",
|
2015-06-17 03:22:51 +00:00
|
|
|
contentType: "application/json"
|
2015-06-16 03:51:18 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Define our API Endpoints
|
|
|
|
*/
|
2015-06-17 04:09:27 +00:00
|
|
|
var api = {
|
|
|
|
// campaigns contains the endpoints for /campaigns
|
2016-01-17 04:59:40 +00:00
|
|
|
campaigns: {
|
2015-06-17 04:09:27 +00:00
|
|
|
// get() - Queries the API for GET /campaigns
|
2016-01-17 04:59:40 +00:00
|
|
|
get: function() {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/campaigns/", "GET", {}, false)
|
2015-06-17 04:09:27 +00:00
|
|
|
},
|
|
|
|
// post() - Posts a campaign to POST /campaigns
|
2016-01-17 04:59:40 +00:00
|
|
|
post: function(data) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/campaigns/", "POST", data, false)
|
2015-06-17 04:09:27 +00:00
|
|
|
}
|
2015-06-16 03:51:18 +00:00
|
|
|
},
|
2015-06-17 04:09:27 +00:00
|
|
|
// campaignId contains the endpoints for /campaigns/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
campaignId: {
|
2015-06-17 04:09:27 +00:00
|
|
|
// get() - Queries the API for GET /campaigns/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
get: function(id) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/campaigns/" + id, "GET", {}, false)
|
2015-06-17 04:09:27 +00:00
|
|
|
},
|
|
|
|
// delete() - Deletes a campaign at DELETE /campaigns/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
delete: function(id) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/campaigns/" + id, "DELETE", {}, false)
|
2015-06-17 04:09:27 +00:00
|
|
|
}
|
2015-06-16 03:51:18 +00:00
|
|
|
},
|
2015-06-17 04:09:27 +00:00
|
|
|
// groups contains the endpoints for /groups
|
2016-01-17 04:59:40 +00:00
|
|
|
groups: {
|
2015-06-17 04:09:27 +00:00
|
|
|
// get() - Queries the API for GET /groups
|
2016-01-17 04:59:40 +00:00
|
|
|
get: function() {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/groups/", "GET", {}, false)
|
2015-06-17 04:09:27 +00:00
|
|
|
},
|
|
|
|
// post() - Posts a campaign to POST /groups
|
2016-01-17 04:59:40 +00:00
|
|
|
post: function(group) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/groups/", "POST", group, false)
|
2015-06-17 04:09:27 +00:00
|
|
|
}
|
2015-06-16 03:51:18 +00:00
|
|
|
},
|
2015-06-17 04:09:27 +00:00
|
|
|
// groupId contains the endpoints for /groups/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
groupId: {
|
2015-06-17 04:09:27 +00:00
|
|
|
// get() - Queries the API for GET /groups/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
get: function(id) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/groups/" + id, "GET", {}, false)
|
2015-06-17 04:09:27 +00:00
|
|
|
},
|
|
|
|
// put() - Puts a campaign to PUT /groups/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
put: function(group) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/groups/" + group.id, "PUT", group, false)
|
2015-06-17 04:09:27 +00:00
|
|
|
},
|
|
|
|
// delete() - Deletes a campaign at DELETE /groups/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
delete: function(id) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/groups/" + id, "DELETE", {}, false)
|
2015-06-17 04:09:27 +00:00
|
|
|
}
|
2015-06-16 03:51:18 +00:00
|
|
|
},
|
2015-06-17 04:09:27 +00:00
|
|
|
// templates contains the endpoints for /templates
|
2016-01-17 04:59:40 +00:00
|
|
|
templates: {
|
2015-06-17 04:09:27 +00:00
|
|
|
// get() - Queries the API for GET /templates
|
2016-01-17 04:59:40 +00:00
|
|
|
get: function() {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/templates/", "GET", {}, false)
|
2015-06-17 04:09:27 +00:00
|
|
|
},
|
|
|
|
// post() - Posts a campaign to POST /templates
|
2016-01-17 04:59:40 +00:00
|
|
|
post: function(template) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/templates/", "POST", template, false)
|
2015-06-17 04:09:27 +00:00
|
|
|
}
|
2015-06-16 03:51:18 +00:00
|
|
|
},
|
2015-06-17 04:09:27 +00:00
|
|
|
// templateId contains the endpoints for /templates/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
templateId: {
|
2015-06-17 04:09:27 +00:00
|
|
|
// get() - Queries the API for GET /templates/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
get: function(id) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/templates/" + id, "GET", {}, false)
|
2015-06-17 04:09:27 +00:00
|
|
|
},
|
|
|
|
// put() - Puts a campaign to PUT /templates/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
put: function(template) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/templates/" + template.id, "PUT", template, false)
|
2015-06-17 04:09:27 +00:00
|
|
|
},
|
|
|
|
// delete() - Deletes a campaign at DELETE /templates/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
delete: function(id) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/templates/" + id, "DELETE", {}, false)
|
2015-06-17 04:09:27 +00:00
|
|
|
}
|
2015-08-23 20:20:28 +00:00
|
|
|
},
|
2015-08-26 02:03:12 +00:00
|
|
|
// pages contains the endpoints for /pages
|
2016-01-17 04:59:40 +00:00
|
|
|
pages: {
|
2015-08-26 02:03:12 +00:00
|
|
|
// get() - Queries the API for GET /pages
|
2016-01-17 04:59:40 +00:00
|
|
|
get: function() {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/pages/", "GET", {}, false)
|
2015-08-23 20:20:28 +00:00
|
|
|
},
|
2015-08-26 02:03:12 +00:00
|
|
|
// post() - Posts a campaign to POST /pages
|
2016-01-17 04:59:40 +00:00
|
|
|
post: function(page) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/pages/", "POST", page, false)
|
2015-08-23 20:20:28 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// templateId contains the endpoints for /templates/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
pageId: {
|
2015-08-23 20:20:28 +00:00
|
|
|
// get() - Queries the API for GET /templates/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
get: function(id) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/pages/" + id, "GET", {}, false)
|
2015-08-23 20:20:28 +00:00
|
|
|
},
|
|
|
|
// put() - Puts a campaign to PUT /templates/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
put: function(page) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/pages/" + page.id, "PUT", page, false)
|
2015-08-23 20:20:28 +00:00
|
|
|
},
|
|
|
|
// delete() - Deletes a campaign at DELETE /templates/:id
|
2016-01-17 04:59:40 +00:00
|
|
|
delete: function(id) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/pages/" + id, "DELETE", {}, false)
|
2015-08-23 20:20:28 +00:00
|
|
|
}
|
2015-08-25 23:56:58 +00:00
|
|
|
},
|
2015-09-15 04:42:29 +00:00
|
|
|
// import handles all of the "import" functions in the api
|
2016-01-17 04:59:40 +00:00
|
|
|
import_email: function(raw) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/import/email", "POST", {}, false)
|
2015-09-15 04:42:29 +00:00
|
|
|
},
|
2016-01-25 01:48:15 +00:00
|
|
|
// clone_site handles importing a site by url
|
2016-01-17 04:59:40 +00:00
|
|
|
clone_site: function(req) {
|
2016-01-25 01:48:15 +00:00
|
|
|
return query("/import/site", "POST", req, false)
|
|
|
|
},
|
|
|
|
// send_test_email sends an email to the specified email address
|
|
|
|
send_test_email: function(req){
|
|
|
|
return query("/util/send_test_email", "POST", req, true)
|
2015-06-16 03:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-03 18:32:09 +00:00
|
|
|
|
|
|
|
// Register our moment.js datatables listeners
|
2016-01-17 04:59:40 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
$.fn.dataTable.moment('MMMM Do YYYY, h:mm:ss a');
|
|
|
|
// Setup tooltips
|
|
|
|
$('[data-toggle="tooltip"]').tooltip()
|
2015-10-03 18:32:09 +00:00
|
|
|
});
|