Changed status of new targets to "Sending" instead of "Unknown". Fixes #112

pull/138/head
Jordan Wright 2016-02-01 20:42:46 -06:00
parent c73a78bbdf
commit ce8a9e5456
5 changed files with 32 additions and 21 deletions

View File

@ -226,14 +226,14 @@ func PostCampaign(c *Campaign, uid int64) error {
for _, g := range c.Groups { for _, g := range c.Groups {
// Insert a result for each target in the group // Insert a result for each target in the group
for _, t := range g.Targets { for _, t := range g.Targets {
r := Result{Email: t.Email, Status: STATUS_UNKNOWN, CampaignId: c.Id, UserId: c.UserId, FirstName: t.FirstName, LastName: t.LastName} r := &Result{Email: t.Email, Status: STATUS_SENDING, CampaignId: c.Id, UserId: c.UserId, FirstName: t.FirstName, LastName: t.LastName}
r.GenerateId() r.GenerateId()
err = db.Save(&r).Error err = db.Save(r).Error
if err != nil { if err != nil {
Logger.Printf("Error adding result record for target %s\n", t.Email) Logger.Printf("Error adding result record for target %s\n", t.Email)
Logger.Println(err) Logger.Println(err)
} }
c.Results = append(c.Results, r) c.Results = append(c.Results, *r)
} }
} }
return nil return nil

View File

@ -34,6 +34,7 @@ const (
EVENT_OPENED string = "Email Opened" EVENT_OPENED string = "Email Opened"
EVENT_CLICKED string = "Clicked Link" EVENT_CLICKED string = "Clicked Link"
STATUS_SUCCESS string = "Success" STATUS_SUCCESS string = "Success"
STATUS_SENDING string = "Sending"
STATUS_UNKNOWN string = "Unknown" STATUS_UNKNOWN string = "Unknown"
ERROR string = "Error" ERROR string = "Error"
) )

View File

@ -44,6 +44,12 @@ var statuses = {
label: "label-default", label: "label-default",
icon: "fa-question" icon: "fa-question"
}, },
"Sending": {
slice: "ct-slice-donut-error",
legend: "ct-legend-error",
label: "label-primary",
icon: "fa-spinner"
},
"Campaign Created": { "Campaign Created": {
label: "label-success", label: "label-success",
icon: "fa-rocket" icon: "fa-rocket"

View File

@ -10,7 +10,7 @@ var labels = {
var campaigns = [] var campaigns = []
// Save attempts to POST to /campaigns/ // Launch attempts to POST to /campaigns/
function launch() { function launch() {
if (!confirm("This will launch the campaign. Are you sure?")) { if (!confirm("This will launch the campaign. Are you sure?")) {
return false; return false;
@ -22,31 +22,35 @@ function launch() {
}) })
}) })
var campaign = { var campaign = {
name: $("#name").val(), name: $("#name").val(),
template: { template: {
name: $("#template").val() name: $("#template").val()
}, },
url: $("#url").val(), url: $("#url").val(),
page: { page: {
name: $("#page").val() name: $("#page").val()
}, },
smtp: { smtp: {
from_address: $("input[name=from]").val(), from_address: $("input[name=from]").val(),
host: $("input[name=host]").val(), host: $("input[name=host]").val(),
username: $("input[name=username]").val(), username: $("input[name=username]").val(),
password: $("input[name=password]").val(), password: $("input[name=password]").val(),
}, },
groups: groups groups: groups
} }
launchHtml = $("launchButton").html()
$("launchButton").html('<i class="fa fa-spinner fa-spin"></i> Launching Campaign')
// Submit the campaign // Submit the campaign
api.campaigns.post(campaign) api.campaigns.post(campaign)
.success(function(data) { .success(function(data) {
successFlash("Campaign successfully launched!") successFlash("Campaign successfully launched!")
$("launchButton").html('<i class="fa fa-spinner fa-spin"></i> Redirecting')
window.location = "/campaigns/" + data.id.toString() window.location = "/campaigns/" + data.id.toString()
}) })
.error(function(data) { .error(function(data) {
$("#modal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\ $("#modal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
<i class=\"fa fa-exclamation-circle\"></i> " + data.responseJSON.message + "</div>") <i class=\"fa fa-exclamation-circle\"></i> " + data.responseJSON.message + "</div>")
$("#launchButton").html(launchHtml)
}) })
} }

View File

@ -122,7 +122,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" onclick="launch()"><i class="fa fa-rocket"></i> Launch Campaign</button> <button type="button" id="launchButton" class="btn btn-primary" onclick="launch()"><i class="fa fa-rocket"></i> Launch Campaign</button>
</div> </div>
</div> </div>
</div> </div>