|
|
@@ -95,5 +95,80 @@ $(document).ready( function () {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ function csrfSafeMethod(method) {
|
|
|
+ // these HTTP methods do not require CSRF protection
|
|
|
+ return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ var csrftoken = getCookie('csrftoken');
|
|
|
+
|
|
|
+ $(".notif-seen").click(function(event) {
|
|
|
+ event.preventDefault();
|
|
|
+ var notif = $(this).closest('.notif');
|
|
|
+ var notif_id = notif.data('id');
|
|
|
+
|
|
|
+ $.ajax({
|
|
|
+ type: "POST",
|
|
|
+ url: "/notif/seen/" + notif_id + "/",
|
|
|
+ data: '{notif_id:' + notif_id + '}',
|
|
|
+ contentType: "application/json; charset=utf-8",
|
|
|
+ dataType: "json",
|
|
|
+ beforeSend: function(xhr, settings) {
|
|
|
+ if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
|
|
|
+ xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ success: function (response) {
|
|
|
+ notif.remove();
|
|
|
+ },
|
|
|
+ failure: function (response) {
|
|
|
+ alert(response.responseText);
|
|
|
+ },
|
|
|
+ error: function (response) {
|
|
|
+ alert(response.responseText);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ $(".notif-all-seen").click(function(event) {
|
|
|
+ event.preventDefault();
|
|
|
+ var notif_list = $('#notif-dropdown').find('.notif-list');
|
|
|
+ if (confirm('Êtes vous sûr de vouloir faire disparaitre toutes les notifications ?')) {
|
|
|
+ $.ajax({
|
|
|
+ type: "POST",
|
|
|
+ url: "/notif/allseen/",
|
|
|
+ contentType: "application/json; charset=utf-8",
|
|
|
+ dataType: "json",
|
|
|
+ beforeSend: function(xhr, settings) {
|
|
|
+ if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
|
|
|
+ xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ success: function (response) {
|
|
|
+ notif_list.html('');
|
|
|
+ },
|
|
|
+ failure: function (response) {
|
|
|
+ alert(response.responseText);
|
|
|
+ },
|
|
|
+ error: function (response) {
|
|
|
+ alert(response.responseText);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
});
|