Convert admin_history template to use AJAX applicator in custom.js

This commit is contained in:
Ivan Filippov 2016-04-22 19:46:02 -06:00
parent fb4d5b3f56
commit c95fd6ffec
2 changed files with 28 additions and 20 deletions

View File

@ -0,0 +1,27 @@
function applyChanges(data, url, showResult) {
var success = false;
$.ajax({
type : "POST",
url : url,
data : JSON.stringify(data),// now data come in this function
contentType : "application/json; charset=utf-8",
crossDomain : true,
dataType : "json",
success : function(data, status, jqXHR) {
console.log("Applied changes successfully.")
if (showResult) {
var modal = $("#modal_success");
modal.find('.modal-body p').text("Applied changes successfully");
modal.modal('show');
}
},
error : function(jqXHR, status) {
console.log(jqXHR);
var modal = $("#modal_error");
modal.find('.modal-body p').text(jqXHR["responseText"]);
modal.modal('show');
}
});
}

View File

@ -78,25 +78,6 @@
modal.find('.modal-body p').text(info);
modal.modal('show');
});
// ajax call to clear history table
function clearHistoryTable() {
$.ajax({
type : "POST",
url : '/admin/history',
data : '',
contentType : "application/json; charset=utf-8",
crossDomain : true,
dataType : "json",
success : function(data, status, jqXHR) {
},
error : function(jqXHR, status) {
}
});
}
</script>
{% endblock %}
{% block modals %}
@ -117,7 +98,7 @@
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left"
data-dismiss="modal">Close</button>
<button type="button" class="btn btn-danger" onclick="clearHistoryTable();location.reload();">Clear
<button type="button" class="btn btn-danger" onclick="applyChanges('', '/admin/history');location.reload();">Clear
History</button>
</div>
</div>