2015-06-24 04:02:29 +00:00
|
|
|
// Save attempts to POST to /groups/
|
2015-06-17 04:09:27 +00:00
|
|
|
function save(){
|
2015-06-24 04:02:29 +00:00
|
|
|
var targets = []
|
|
|
|
$.each($("#targetsTable").DataTable().rows().data(), function(i, target){
|
|
|
|
targets.push({
|
|
|
|
first_name : target[0],
|
|
|
|
last_name: target[1],
|
|
|
|
email: target[2],
|
|
|
|
position: target[3]
|
|
|
|
})
|
|
|
|
})
|
2015-06-17 04:09:27 +00:00
|
|
|
var group = {
|
|
|
|
name: $("#name").val(),
|
|
|
|
targets: targets
|
|
|
|
}
|
2015-06-24 04:02:29 +00:00
|
|
|
console.log(group)
|
|
|
|
// Submit the group
|
2015-06-17 04:09:27 +00:00
|
|
|
api.groups.post(group)
|
|
|
|
.success(function(data){
|
2015-06-24 04:02:29 +00:00
|
|
|
successFlash("Group added successfully!")
|
2015-06-17 04:09:27 +00:00
|
|
|
load()
|
2015-06-18 03:44:05 +00:00
|
|
|
dismiss()
|
2015-06-17 04:09:27 +00:00
|
|
|
})
|
|
|
|
.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>")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-06-18 03:44:05 +00:00
|
|
|
function dismiss(){
|
|
|
|
$("#modal\\.flashes").empty()
|
|
|
|
$("#modal").modal('hide')
|
|
|
|
}
|
|
|
|
|
|
|
|
function edit(group){
|
|
|
|
if (group == "new") {
|
|
|
|
group = {}
|
|
|
|
}
|
|
|
|
targets = $("#targetsTable").dataTable()
|
|
|
|
// Handle Addition
|
|
|
|
$("#targetForm").submit(function(){
|
|
|
|
targets.DataTable()
|
|
|
|
.row.add([
|
|
|
|
$("#firstName").val(),
|
|
|
|
$("#lastName").val(),
|
|
|
|
$("#email").val(),
|
|
|
|
$("#position").val(),
|
2015-06-19 18:53:47 +00:00
|
|
|
'<span style="cursor:pointer;"><i class="fa fa-trash-o"></i></span>'
|
2015-06-18 03:44:05 +00:00
|
|
|
])
|
|
|
|
.draw()
|
|
|
|
$("#targetForm>div>input").val('')
|
|
|
|
$("#firstName").focus()
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
// Handle Deletion
|
|
|
|
$("#targetsTable").on("click", "span>i.fa-trash-o", function(){
|
|
|
|
targets.DataTable()
|
|
|
|
.row( $(this).parents('tr') )
|
|
|
|
.remove()
|
|
|
|
.draw();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-06-17 04:09:27 +00:00
|
|
|
function load(){
|
|
|
|
api.groups.get()
|
|
|
|
.success(function(groups){
|
|
|
|
if (groups.length > 0){
|
|
|
|
$("#emptyMessage").hide()
|
|
|
|
$("#groupTable").show()
|
|
|
|
groupTable = $("#groupTable").DataTable();
|
|
|
|
$.each(groups, function(i, group){
|
|
|
|
groupTable.row.add([
|
2015-06-24 04:02:29 +00:00
|
|
|
group.name,
|
|
|
|
group.targets.join(),
|
2015-06-17 04:09:27 +00:00
|
|
|
group.modified_date
|
|
|
|
]).draw()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.error(function(){
|
|
|
|
errorFlash("Error fetching groups")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function(){
|
|
|
|
load()
|
2015-06-17 04:23:02 +00:00
|
|
|
$("#fileUpload").hover(function(){$("#fileUpload").tooltip('toggle')})
|
2015-06-17 04:09:27 +00:00
|
|
|
})
|