mirror of https://github.com/gophish/gophish
Add/update group target as needed
When user submits a new target, target data table is checked for an existing entry based on target email. If an existing entry is found then it is updated, otherwise a new row is added to table. Target email addresses are now converted to lower case to help prevent duplicates as well.pull/320/head
parent
3996a702fe
commit
21c55c579c
|
@ -171,15 +171,34 @@ $(document).ready(function() {
|
|||
// Setup the event listeners
|
||||
// Handle manual additions
|
||||
$("#targetForm").submit(function() {
|
||||
targets.DataTable()
|
||||
.row.add([
|
||||
escapeHtml($("#firstName").val()),
|
||||
escapeHtml($("#lastName").val()),
|
||||
escapeHtml($("#email").val()),
|
||||
escapeHtml($("#position").val()),
|
||||
'<span style="cursor:pointer;"><i class="fa fa-trash-o"></i></span>'
|
||||
])
|
||||
.draw();
|
||||
// Create new data row.
|
||||
var emailInput = escapeHtml($("#email").val()).toLowerCase();
|
||||
var newRow = [
|
||||
escapeHtml($("#firstName").val()),
|
||||
escapeHtml($("#lastName").val()),
|
||||
emailInput,
|
||||
escapeHtml($("#position").val()),
|
||||
'<span style="cursor:pointer;"><i class="fa fa-trash-o"></i></span>'
|
||||
];
|
||||
|
||||
// Check table to see if email already exists.
|
||||
var targetsTable = targets.DataTable();
|
||||
var existingRowIndex = targetsTable
|
||||
.column(2, {order: "index"}) // Email column
|
||||
.data()
|
||||
.indexOf(emailInput);
|
||||
|
||||
// Update or add new row as necessary.
|
||||
if (existingRowIndex >= 0) {
|
||||
targetsTable
|
||||
.row(existingRowIndex, {order: "index"})
|
||||
.data(newRow);
|
||||
} else {
|
||||
targetsTable.row.add(newRow);
|
||||
}
|
||||
targetsTable.draw();
|
||||
|
||||
// Reset user input.
|
||||
$("#targetForm>div>input").val('');
|
||||
$("#firstName").focus();
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue