Added campaign table

Created save() method for campaigns
pull/24/head
unknown 2015-06-16 22:22:51 -05:00
parent da1216aaf7
commit 22a4d3f923
4 changed files with 70 additions and 55 deletions

View File

@ -39,6 +39,7 @@ div.dataTables_info {
div.dataTables_paginate ul.pagination {
margin: 2px 0;
white-space: nowrap;
float: right !important;
}
@media screen and (max-width: 767px) {

View File

@ -1,12 +1,44 @@
$(document).ready(function(){
campaigns.get()
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(),
},
groups: [{name : "Morning catch employees"}]
}
// Submit the campaign
campaigns.post(campaign)
.success(function(data){
successFlash("worked!")
successFlash("submitted!")
console.log(data)
})
.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>")
})
}
$(document).ready(function(){
var campaignData = {}
campaigns.get()
.success(function(data){
successFlash("worked!")
campaignData = data
})
.error(function(data){
errorFlash("No work")
console.log(data)
})
$("#table_id").DataTable();
campaignTable = $("#campaignTable").DataTable();
$.each(campaignData, function(i, campaign){
campaignTable.row.add([
campaign.created_date,
campaign.name,
campaign.status
]).draw()
})
})

View File

@ -15,8 +15,9 @@ function api(endpoint, method, data) {
url: "/api" + endpoint + "?api_key=" + user.api_key,
async: false,
method: method,
data: data,
dataType:"json"
data: JSON.stringify(data),
dataType:"json",
contentType: "application/json"
})
}
@ -27,11 +28,11 @@ Define our API Endpoints
var campaigns = {
// get() - Queries the API for GET /campaigns
get: function(){
return api("/campaigns", "GET", {})
return api("/campaigns/", "GET", {})
},
// post() - Posts a campaign to POST /campaigns
post: function(data){
return api("/campaigns", "POST", data)
return api("/campaigns/", "POST", data)
}
}
@ -59,11 +60,11 @@ var campaignId = {
var groups = {
// get() - Queries the API for GET /groups
get: function(){
return api("/groups", "GET", {})
return api("/groups/", "GET", {})
},
// post() - Posts a campaign to POST /groups
post: function(group){
return api("/groups", "POST", group)
return api("/groups/", "POST", group)
}
}
@ -91,11 +92,11 @@ var groupId = {
var templates = {
// get() - Queries the API for GET /templates
get: function(){
return api("/templates", "GET", {})
return api("/templates/", "GET", {})
},
// post() - Posts a campaign to POST /templates
post: function(template){
return api("/templates", "POST", template)
return api("/templates/", "POST", template)
}
}

View File

@ -21,44 +21,29 @@
</div>
</div>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" ng-controller="CampaignCtrl">
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">
Campaigns
</h1>
<div id="flashes" class="row">
<!-- <div ng-repeat="flash in flashes.main" style="text-align:center" class="alert alert-flash.type">
<i class="fa flash.icon"></i> flash.message
</div> -->
</div>
<div id="flashes" class="row"></div>
<div class="row">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal"><i class="fa fa-plus"></i> New Campaign</button>
</div>
&nbsp;
<div ng-show="!campaigns.length">
<div class="row">
<div class="alert alert-info">
No campaigns created yet. Let's create one!
</div>
</div>
</div>
<div ng-show="campaigns.length" class="row">
<table id="campaignTable" class="table">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Created Date</th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
</tbody>
</table>
<!-- <table ng-table="mainTableParams" class="table table-hover table-striped table-bordered">
@ -97,11 +82,7 @@
<h4 class="modal-title" id="campaignModalLabel">New Campaign</h4>
</div>
<div class="modal-body">
<div class="row">
<!-- <div style="text-align:center" class="alert alert-flash.type">
<i class="fa flash.icon"></i> flash.message
</div> -->
</div>
<div class="row" id="modal.flashes"></div>
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" placeholder="Campaign name" autofocus>
@ -118,22 +99,22 @@
<div class="panel-collapse collapse" id="smtpPanel" role="tabpanel">
<div class="panel-body">
<label class="control-label" for="from">From:</label>
<input type="text" class="form-control" placeholder="First Last <test@example.com>" id="form">
<input type="text" class="form-control" placeholder="First Last <test@example.com>" value="" name="from">
<br />
<label class="control-label" for="smtp_server">Host:</label>
<input type="text" class="form-control" placeholder="smtp.example.com:25" id="smtp_server">
<input type="text" class="form-control" placeholder="smtp.example.com:25" value="" name="host">
<br />
<label class="control-label" for="smtp_server">Username:</label>
<input type="text" class="form-control" placeholder="Username" id="smtp_server">
<input type="text" class="form-control" placeholder="Username" value="" name="username">
<br />
<label class="control-label" for="smtp_server">Password:</label>
<input type="password" class="form-control" placeholder="Password" id="smtp_server">
<input type="password" class="form-control" placeholder="Password" value="" name="password">
<br />
</div>
</div>
</div>
<label class="control-label" for="users">Groups:</label>
<form ng-submit="addGroup(group)">
<form>
<div class="input-group">
<input type="text" class="form-control" placeholder="Group Name" id="users" typeahead="group.name for group in groups | filter:{name:$viewValue}" typeahead-editable="false" ng-model="group.name" />
<span class="input-group-btn">