Commit a1565646 authored by delanoe's avatar delanoe

[FIX] Permissions fix (thanks to Romain Loth).

parent 4ec52443
...@@ -22,13 +22,6 @@ var getCookie = function(name) { ...@@ -22,13 +22,6 @@ var getCookie = function(name) {
} }
return cookieValue; return cookieValue;
} }
var csrftoken = getCookie('csrftoken');
$.ajaxSetup({
beforeSend: function(xhr, settings) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
});
// Resource class // Resource class
var Resource = function(url_path) { var Resource = function(url_path) {
...@@ -65,6 +58,9 @@ var Resource = function(url_path) { ...@@ -65,6 +58,9 @@ var Resource = function(url_path) {
$.ajax({ $.ajax({
url: url, url: url,
type: 'GET', type: 'GET',
beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
},
success: callback success: callback
}); });
}; };
...@@ -73,30 +69,32 @@ var Resource = function(url_path) { ...@@ -73,30 +69,32 @@ var Resource = function(url_path) {
$.ajax({ $.ajax({
url: url_path + '/' + id, url: url_path + '/' + id,
type: 'PATCH', type: 'PATCH',
beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
},
success: callback success: callback
}); });
}; };
// remove an item // remove an item
this.delete = this.remove = function(id, callback) { this.delete = this.remove = function(id, callback) {
if (id.id != undefined) {
id = id.id;
}
$.ajax({ $.ajax({
url: url_path + '/' + id, url: url_path + '/' + id,
type: 'DELETE', type: 'DELETE',
beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
},
success: callback success: callback
}); });
}; };
// add an item // add an item
this.add = this.append = function(value, callback) { this.add = this.append = function(id, callback) {
$.ajax({ $.ajax({
// todo define id // todo define id
url: url_path + '/' + id, url: url_path + '/' + id,
type: 'POST', type: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
},
success: callback success: callback
}); });
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment