Show confirm dialog before deleting problem

This commit is contained in:
James Wang 2016-04-07 23:41:35 -04:00
parent a94df0dd49
commit 765f6e0ec1
No known key found for this signature in database
GPG key ID: 5B80C0B3F263CD5B
2 changed files with 32 additions and 16 deletions

View file

@ -56,23 +56,27 @@ var update_problem = function(form_id) {
};
var delete_problem = function(form_id) {
var input = "#" + form_id + " input";
var pid = form_id.split("_")[1];
$(input).attr("disabled", "disabled");
api_call("POST", "/api/problem/delete", {"pid": pid}, function(result) {
if (result["success"] == 1) {
display_message(pid + "_status", "success", result["message"], function() {
$('#confirm').modal("show", { backdrop: 'static', keyboard: false })
.one('click', '#delete', function() {
var input = "#" + form_id + " input";
var pid = form_id.split("_")[1];
$(input).attr("disabled", "disabled");
api_call("POST", "/api/problem/delete", {"pid": pid}, function(result) {
if (result["success"] == 1) {
display_message(pid + "_status", "success", result["message"], function() {
$(input).removeAttr("disabled");
});
} else {
display_message(pid + "_status", "danger", result["message"], function() {
$(input).removeAttr("disabled");
});
}
}, function(jqXHR, status, error) {
var result = jqXHR["responseText"];
display_message(pid + "_status", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
$(input).removeAttr("disabled");
});
} else {
display_message(pid + "_status", "danger", result["message"], function() {
$(input).removeAttr("disabled");
});
}
}, function(jqXHR, status, error) {
var result = jqXHR["responseText"];
display_message(pid + "_status", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
$(input).removeAttr("disabled");
});
});
});
}

View file

@ -73,6 +73,18 @@
</div>
</div>
<div id="confirm" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">Are you sure you want to delete this problem?</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-primary" id="delete">Delete</button>
<button type="button" data-dismiss="modal" class="btn">Cancel</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$(".selectpicker").selectpicker();