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\">\
|
2015-08-15 21:03:39 +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\">\
|
|
|
|
<i class=\"fa fa-check-circle\"></i> " + message + "</div>"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2015-06-28 00:21:46 +00:00
|
|
|
function modalError(message){
|
|
|
|
$("#modal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
|
|
|
|
<i class=\"fa fa-exclamation-circle\"></i> " + message + "</div>")
|
|
|
|
}
|
|
|
|
|
2015-06-17 04:09:27 +00:00
|
|
|
function query(endpoint, method, data) {
|
2015-06-16 03:51:18 +00:00
|
|
|
return $.ajax({
|
|
|
|
url: "/api" + endpoint + "?api_key=" + user.api_key,
|
|
|
|
async: false,
|
|
|
|
method: method,
|
2015-06-17 03:22:51 +00:00
|
|
|
data: JSON.stringify(data),
|
|
|
|
dataType:"json",
|
|
|
|
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
|
|
|
|
campaigns : {
|
|
|
|
// get() - Queries the API for GET /campaigns
|
|
|
|
get: function(){
|
|
|
|
return query("/campaigns/", "GET", {})
|
|
|
|
},
|
|
|
|
// post() - Posts a campaign to POST /campaigns
|
|
|
|
post: function(data){
|
|
|
|
return query("/campaigns/", "POST", data)
|
|
|
|
}
|
2015-06-16 03:51:18 +00:00
|
|
|
},
|
2015-06-17 04:09:27 +00:00
|
|
|
// campaignId contains the endpoints for /campaigns/:id
|
|
|
|
campaignId : {
|
|
|
|
// get() - Queries the API for GET /campaigns/:id
|
|
|
|
get: function(id){
|
|
|
|
return query("/campaigns/" + id, "GET", {})
|
|
|
|
},
|
|
|
|
// delete() - Deletes a campaign at DELETE /campaigns/:id
|
|
|
|
delete: function(id){
|
|
|
|
return query("/campaigns/" + id, "DELETE", data)
|
|
|
|
}
|
2015-06-16 03:51:18 +00:00
|
|
|
},
|
2015-06-17 04:09:27 +00:00
|
|
|
// groups contains the endpoints for /groups
|
|
|
|
groups : {
|
|
|
|
// get() - Queries the API for GET /groups
|
|
|
|
get: function(){
|
|
|
|
return query("/groups/", "GET", {})
|
|
|
|
},
|
|
|
|
// post() - Posts a campaign to POST /groups
|
|
|
|
post: function(group){
|
|
|
|
return query("/groups/", "POST", group)
|
|
|
|
}
|
2015-06-16 03:51:18 +00:00
|
|
|
},
|
2015-06-17 04:09:27 +00:00
|
|
|
// groupId contains the endpoints for /groups/:id
|
|
|
|
groupId : {
|
|
|
|
// get() - Queries the API for GET /groups/:id
|
|
|
|
get: function(id){
|
|
|
|
return query("/groups/" + id, "GET", {})
|
|
|
|
},
|
|
|
|
// put() - Puts a campaign to PUT /groups/:id
|
|
|
|
put: function (group){
|
2015-08-05 05:23:05 +00:00
|
|
|
return query("/groups/" + group.id, "PUT", group)
|
2015-06-17 04:09:27 +00:00
|
|
|
},
|
|
|
|
// delete() - Deletes a campaign at DELETE /groups/:id
|
|
|
|
delete: function(id){
|
2015-08-05 05:23:05 +00:00
|
|
|
return query("/groups/" + id, "DELETE", {})
|
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
|
|
|
|
templates : {
|
|
|
|
// get() - Queries the API for GET /templates
|
|
|
|
get: function(){
|
|
|
|
return query("/templates/", "GET", {})
|
|
|
|
},
|
|
|
|
// post() - Posts a campaign to POST /templates
|
|
|
|
post: function(template){
|
|
|
|
return query("/templates/", "POST", template)
|
|
|
|
}
|
2015-06-16 03:51:18 +00:00
|
|
|
},
|
2015-06-17 04:09:27 +00:00
|
|
|
// templateId contains the endpoints for /templates/:id
|
|
|
|
templateId : {
|
|
|
|
// get() - Queries the API for GET /templates/:id
|
|
|
|
get: function(id){
|
|
|
|
return query("/templates/" + id, "GET", {})
|
|
|
|
},
|
|
|
|
// put() - Puts a campaign to PUT /templates/:id
|
|
|
|
put: function (template){
|
2015-08-05 05:23:05 +00:00
|
|
|
return query("/templates/" + template.id, "PUT", template)
|
2015-06-17 04:09:27 +00:00
|
|
|
},
|
|
|
|
// delete() - Deletes a campaign at DELETE /templates/:id
|
|
|
|
delete: function(id){
|
2015-08-05 05:23:05 +00:00
|
|
|
return query("/templates/" + id, "DELETE", {})
|
2015-06-17 04:09:27 +00:00
|
|
|
}
|
2015-08-23 20:20:28 +00:00
|
|
|
},
|
|
|
|
// landing_pages contains the endpoints for /landing_pages
|
|
|
|
landing_pages : {
|
|
|
|
// get() - Queries the API for GET /landing_pages
|
|
|
|
get: function(){
|
|
|
|
return query("/landing_pages/", "GET", {})
|
|
|
|
},
|
|
|
|
// post() - Posts a campaign to POST /landing_pages
|
|
|
|
post: function(page){
|
|
|
|
return query("/landing_pages/", "POST", page)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// templateId contains the endpoints for /templates/:id
|
|
|
|
landing_pageId : {
|
|
|
|
// get() - Queries the API for GET /templates/:id
|
|
|
|
get: function(id){
|
|
|
|
return query("/landing_pages/" + id, "GET", {})
|
|
|
|
},
|
|
|
|
// put() - Puts a campaign to PUT /templates/:id
|
|
|
|
put: function (page){
|
|
|
|
return query("/landing_pages/" + page.id, "PUT", page)
|
|
|
|
},
|
|
|
|
// delete() - Deletes a campaign at DELETE /templates/:id
|
|
|
|
delete: function(id){
|
|
|
|
return query("/landing_pages/" + id, "DELETE", {})
|
|
|
|
}
|
2015-06-16 03:51:18 +00:00
|
|
|
}
|
|
|
|
}
|