| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- $(document).ready( function () {
-
- $('[data-url]').on('click', function(e) {
- window.location.href = $(this).data('url');
- });
-
- $('option').mousedown(function(e) {
- e.preventDefault();
- $(this).prop('selected', !$(this).prop('selected'));
- return false;
- });
-
- var loc_uri = URI.parse(window.location.href);
- var loc_qry = URI.parseQuery(loc_uri.query)
-
- $('.filters-bar').children('select[data-filter]').each(function () {
- var filter_name = $(this).data('filter');
- if(filter_name in loc_qry) {
- $(this).val(loc_qry[filter_name]);
- }
- });
-
- $('#stories').on('change', 'select[data-filter]', function() {
-
- var filters = [];
- var filtersbar = $('#stories > .filters-bar');
-
- filtersbar.children('select').each(function () {
- if (this.value.length > 0) {
- filters.push($(this).data('filter') + "=" + $(this).val());
- }
- });
-
- var url = document.URL;
- var target = url.split('?')[0];
- if (filters.length > 0) {
- target = target + '?' + filters.join('&');
- }
- window.location.href = target;
- });
- $('#stories').on('click', 'a[data-page]', function() {
-
- var filters = [];
- var filtersbar = $('#stories > .filters-bar');
-
- filtersbar.children('select').each(function () {
- if (this.value.length > 0) {
- filters.push($(this).data('filter') + "=" + $(this).val());
- }
- });
-
- var url = document.URL;
- var target = url.split('?')[0];
- if (filters.length > 0) {
- target = target + '?' + filters.join('&') + '&page=' + $(this).data('page');
- } else {
- target = target + '?page=' + $(this).data('page');
- }
- window.location.href = target;
- });
-
-
- $(document).on('click', function(event) {
- if(!$(event.target).closest('#user-panel').length) {
- if($('#user-dropdown').is(":visible")) {
- $('#user-dropdown').hide();
- }
- }
- if(!$(event.target).closest('#notif-panel').length) {
- if($('#notif-dropdown').is(":visible")) {
- $('#notif-dropdown').hide();
- }
- }
- });
-
- $(document).on('click', '#user-show-btn', function(event) {
- event.preventDefault();
- if($('#user-dropdown').is(":visible")) {
- $('#user-dropdown').hide();
- }
- else {
- $('#user-dropdown').show();
- }
- });
-
- $(document).on('click', '#notif-show-btn', function(event) {
- event.preventDefault();
- if($('#notif-dropdown').is(":visible")) {
- $('#notif-dropdown').hide();
- }
- else {
- $('#notif-dropdown').show();
- }
- });
-
- 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);
- }
- });
- }
- });
-
- });
|