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 { div.dataTables_paginate ul.pagination {
margin: 2px 0; margin: 2px 0;
white-space: nowrap; white-space: nowrap;
float: right !important;
} }
@media screen and (max-width: 767px) { @media screen and (max-width: 767px) {

View File

@ -1,12 +1,44 @@
$(document).ready(function(){ function save(){
campaigns.get() 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){ .success(function(data){
successFlash("worked!") successFlash("submitted!")
console.log(data) console.log(data)
}) })
.error(function(data){ .error(function(data){
errorFlash("No work") $("#modal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
console.log(data) <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")
})
campaignTable = $("#campaignTable").DataTable();
$.each(campaignData, function(i, campaign){
campaignTable.row.add([
campaign.created_date,
campaign.name,
campaign.status
]).draw()
}) })
$("#table_id").DataTable();
}) })

View File

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

View File

@ -21,46 +21,31 @@
</div> </div>
</div> </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"> <h1 class="page-header">
Campaigns Campaigns
</h1> </h1>
<div id="flashes" class="row"> <div id="flashes" class="row"></div>
<!-- <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 class="row"> <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> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal"><i class="fa fa-plus"></i> New Campaign</button>
</div> </div>
&nbsp; &nbsp;
<div ng-show="!campaigns.length">
<div class="row"> <div class="row">
<div class="alert alert-info"> <div class="alert alert-info">
No campaigns created yet. Let's create one! No campaigns created yet. Let's create one!
</div> </div>
</div> </div>
</div>
<div ng-show="campaigns.length" class="row">
<table id="campaignTable" class="table"> <table id="campaignTable" class="table">
<thead> <thead>
<tr> <tr>
<th>Column 1</th> <th>Created Date</th>
<th>Column 2</th> <th>Name</th>
<th>Status</th>
</tr> </tr>
</thead> </thead>
<tbody> <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> </tbody>
</table> </table>
<!-- <table ng-table="mainTableParams" class="table table-hover table-striped table-bordered"> <!-- <table ng-table="mainTableParams" class="table table-hover table-striped table-bordered">
<tbody> <tbody>
<tr ng-repeat="campaign in $data | orderBy:modified_date:true" class="editable-row"> <tr ng-repeat="campaign in $data | orderBy:modified_date:true" class="editable-row">
@ -97,11 +82,7 @@
<h4 class="modal-title" id="campaignModalLabel">New Campaign</h4> <h4 class="modal-title" id="campaignModalLabel">New Campaign</h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="row"> <div class="row" id="modal.flashes"></div>
<!-- <div style="text-align:center" class="alert alert-flash.type">
<i class="fa flash.icon"></i> flash.message
</div> -->
</div>
<div class="form-group"> <div class="form-group">
<label for="name">Name:</label> <label for="name">Name:</label>
<input type="text" class="form-control" id="name" placeholder="Campaign name" autofocus> <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-collapse collapse" id="smtpPanel" role="tabpanel">
<div class="panel-body"> <div class="panel-body">
<label class="control-label" for="from">From:</label> <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 /> <br />
<label class="control-label" for="smtp_server">Host:</label> <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 /> <br />
<label class="control-label" for="smtp_server">Username:</label> <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 /> <br />
<label class="control-label" for="smtp_server">Password:</label> <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 /> <br />
</div> </div>
</div> </div>
</div> </div>
<label class="control-label" for="users">Groups:</label> <label class="control-label" for="users">Groups:</label>
<form ng-submit="addGroup(group)"> <form>
<div class="input-group"> <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" /> <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"> <span class="input-group-btn">