mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-20 23:12:15 +00:00
Working asset edit/create template
This commit is contained in:
73
static/js/ajax_form.js
Normal file
73
static/js/ajax_form.js
Normal file
@@ -0,0 +1,73 @@
|
||||
function filterAssetTable() {
|
||||
$.ajax({
|
||||
url : "/asset/filter/", // the endpoint
|
||||
type : "POST", // http method
|
||||
data : {
|
||||
form: $('#asset-filter-form').serialize()
|
||||
},
|
||||
traditional: true,
|
||||
|
||||
success : function(data) {
|
||||
// console.log(data);
|
||||
$('#asset_table_body').html(data)
|
||||
},
|
||||
|
||||
error : function(xhr) {console.log(xhr.status + ": " + xhr.responseText)}
|
||||
});
|
||||
}
|
||||
|
||||
function updateAsset() {
|
||||
$.ajax({
|
||||
url : "/asset/update/", // the endpoint
|
||||
type : "POST", // http method
|
||||
data : {
|
||||
form: $('#asset_update_form').serialize()
|
||||
},
|
||||
traditional: true,
|
||||
|
||||
success : function(data) {
|
||||
// console.log(data);
|
||||
window.location.href = data['url'];
|
||||
},
|
||||
|
||||
error : function(xhr) {console.log(xhr.status + ": " + xhr.responseText)}
|
||||
});
|
||||
}
|
||||
|
||||
function formAssetSearch() {
|
||||
$.ajax({
|
||||
url : "/asset/filter/", // the endpoint
|
||||
type : "POST", // http method
|
||||
data : {
|
||||
sender: 'asset_update',
|
||||
form: "csrfmiddlewaretoken=" + $('input[name=csrfmiddlewaretoken]').val() + "&asset_id=" + $('#parent_search').val()
|
||||
},
|
||||
traditional: true,
|
||||
|
||||
success : function(data) {
|
||||
// console.log(data);
|
||||
$('#formAssetSearchResult').html(data);
|
||||
// window.location.href = data['url'];
|
||||
},
|
||||
|
||||
error : function(xhr) {console.log(xhr.status + ": " + xhr.responseText)}
|
||||
});
|
||||
}
|
||||
|
||||
function deleteAsset(asset_id) {
|
||||
$.ajax({
|
||||
url : "/asset/delete/", // the endpoint
|
||||
type : "POST", // http method
|
||||
data : {
|
||||
asset_id: asset_id
|
||||
},
|
||||
traditional: true,
|
||||
|
||||
success : function(data) {
|
||||
// console.log(data);
|
||||
window.location.href = data['url'];
|
||||
},
|
||||
|
||||
error : function(xhr) {console.log(xhr.status + ": " + xhr.responseText)}
|
||||
});
|
||||
}
|
||||
23
static/js/csrf.js
Normal file
23
static/js/csrf.js
Normal file
@@ -0,0 +1,23 @@
|
||||
$.ajaxSetup({
|
||||
beforeSend: function(xhr, settings) {
|
||||
function getCookie(name) {
|
||||
var cookieValue = null;
|
||||
if (document.cookie && document.cookie != '') {
|
||||
var cookies = document.cookie.split(';');
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
var cookie = jQuery.trim(cookies[i]);
|
||||
// Does this cookie string begin with the name we want?
|
||||
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
}
|
||||
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
|
||||
// Only send the token to relative URLs i.e. locally.
|
||||
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user