Adding a cb to submitkey, delete submissions & don't reload & close #527 (#528)

* Adding a callback to submitkey
* Most deletions in the admin panel no longer cause an entire page reload
* Change border for .btn-info
This commit is contained in:
Kevin Chung
2017-12-16 06:52:08 -05:00
committed by GitHub
parent be6ec51eba
commit dd8e657820
7 changed files with 25 additions and 7 deletions

View File

@@ -154,6 +154,7 @@ function submitkey(chal, key, nonce){
$('.delete-challenge').click(function (e) { $('.delete-challenge').click(function (e) {
var chal_id = $(this).attr('chal-id'); var chal_id = $(this).attr('chal-id');
var td_row = $(this).parent().parent();
ezq({ ezq({
title: "Delete Challenge", title: "Delete Challenge",
@@ -161,7 +162,7 @@ $('.delete-challenge').click(function (e) {
success: function () { success: function () {
$.post(script_root + '/admin/chal/delete', {'id': chal_id, 'nonce': $('#nonce').val()}, function (data) { $.post(script_root + '/admin/chal/delete', {'id': chal_id, 'nonce': $('#nonce').val()}, function (data) {
if (data == 1) { if (data == 1) {
location.reload(); td_row.remove();
} }
else { else {
ezal({ ezal({

View File

@@ -81,6 +81,8 @@ $('.fa-times').click(function(){
var team_name = elem.find('.team').text().trim(); var team_name = elem.find('.team').text().trim();
var key_id = elem.find('.flag').attr('id'); var key_id = elem.find('.flag').attr('id');
var td_row = $(this).parent().parent();
ezq({ ezq({
title: 'Delete Submission', title: 'Delete Submission',
body: "Are you sure you want to delete correct submission from {0} for challenge {1}".format( body: "Are you sure you want to delete correct submission from {0} for challenge {1}".format(
@@ -94,7 +96,7 @@ $('.fa-times').click(function(){
}, function (data) { }, function (data) {
var data = $.parseJSON(JSON.stringify(data)); var data = $.parseJSON(JSON.stringify(data));
if (data == "1") { if (data == "1") {
location.reload(); td_row.remove();
} }
}); });
} }

View File

@@ -325,6 +325,8 @@ $('.fa-times').click(function () {
action : action, action : action,
}; };
var td_row = $(this).parent().parent();
ezq({ ezq({
title: title, title: title,
body: description, body: description,
@@ -335,7 +337,7 @@ $('.fa-times').click(function () {
}, function (data) { }, function (data) {
var data = $.parseJSON(JSON.stringify(data)); var data = $.parseJSON(JSON.stringify(data));
if (data == "1") { if (data == "1") {
location.reload(); td_row.remove();
} }
}); });
} }
@@ -365,6 +367,8 @@ $('.mark-correct').click(function () {
"as solved for team " + "as solved for team " +
"<strong>{0}</strong>?</span>".format(chal_name); "<strong>{0}</strong>?</span>".format(chal_name);
var td_row = $(this).parent().parent();
ezq({ ezq({
title: title, title: title,
body: description, body: description,
@@ -375,7 +379,7 @@ $('.mark-correct').click(function () {
}, function (data) { }, function (data) {
var data = $.parseJSON(JSON.stringify(data)); var data = $.parseJSON(JSON.stringify(data));
if (data == "1") { if (data == "1") {
location.reload(); td_row.remove();
} }
}); });
} }

View File

@@ -316,6 +316,9 @@ $('.fa-times').click(function(){
var elem = $(this).parent().parent().parent(); var elem = $(this).parent().parent().parent();
var team_id = elem.find('.team-id').text().trim(); var team_id = elem.find('.team-id').text().trim();
var name = elem.find('.team-name').text().trim(); var name = elem.find('.team-name').text().trim();
var td_row = $(this).parent().parent().parent();
ezq({ ezq({
title: "Delete User", title: "Delete User",
body: "Are you sure you want to delete {0}".format("<strong>"+name+"</strong>"), body: "Are you sure you want to delete {0}".format("<strong>"+name+"</strong>"),
@@ -326,7 +329,7 @@ $('.fa-times').click(function(){
}, function (data) { }, function (data) {
var data = $.parseJSON(JSON.stringify(data)); var data = $.parseJSON(JSON.stringify(data));
if (data == "1") { if (data == "1") {
location.reload(); td_row.remove();
} }
}); });
} }

View File

@@ -85,6 +85,9 @@ $('.fa-times').click(function () {
var team = elem.find('.team').attr('id'); var team = elem.find('.team').attr('id');
var team_name = elem.find('.team').text().trim(); var team_name = elem.find('.team').text().trim();
var key_id = elem.find('.flag').attr('id'); var key_id = elem.find('.flag').attr('id');
var td_row = $(this).parent().parent();
ezq({ ezq({
title: 'Delete Submission', title: 'Delete Submission',
body: "Are you sure you want to delete incorrect submission from {0} for challenge {1}".format( body: "Are you sure you want to delete incorrect submission from {0} for challenge {1}".format(
@@ -98,7 +101,7 @@ $('.fa-times').click(function () {
}, function (data) { }, function (data) {
var data = $.parseJSON(JSON.stringify(data)); var data = $.parseJSON(JSON.stringify(data));
if (data == "1") { if (data == "1") {
location.reload(); td_row.remove();
} }
}); });
} }

View File

@@ -102,6 +102,7 @@ table > thead > tr > td {
.btn-info { .btn-info {
background-color: #5B7290 !important; background-color: #5B7290 !important;
border-color: #5B7290 !important;
} }
.alert { .alert {

View File

@@ -79,7 +79,7 @@ $("#answer-input").keyup(function(event){
}); });
function submitkey(chal, key, nonce) { function submitkey(chal, key, nonce, cb) {
$('#submit-key').addClass("disabled-button"); $('#submit-key').addClass("disabled-button");
$('#submit-key').prop('disabled', true); $('#submit-key').prop('disabled', true);
$.post(script_root + "/chal/" + chal, { $.post(script_root + "/chal/" + chal, {
@@ -140,6 +140,10 @@ function submitkey(chal, key, nonce) {
$('#submit-key').removeClass("disabled-button"); $('#submit-key').removeClass("disabled-button");
$('#submit-key').prop('disabled', false); $('#submit-key').prop('disabled', false);
}, 3000); }, 3000);
if (cb) {
cb(result);
}
}) })
} }