custom.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. $(document).ready( function () {
  2. $('[data-url]').on('click', function(e) {
  3. window.location.href = $(this).data('url');
  4. });
  5. $('select[multiple] > option').mousedown(function(e) {
  6. if(e.which==1) {
  7. e.preventDefault();
  8. $(this).prop('selected', !$(this).prop('selected'));
  9. return false;
  10. }
  11. });
  12. var loc_uri = URI.parse(window.location.href);
  13. var loc_qry = URI.parseQuery(loc_uri.query)
  14. $('.filters-bar').children('select[data-filter]').each(function () {
  15. var filter_name = $(this).data('filter');
  16. if(filter_name in loc_qry) {
  17. $(this).val(loc_qry[filter_name]);
  18. }
  19. });
  20. $('#stories').on('change', 'select[data-filter]', function() {
  21. var filters = [];
  22. var filtersbar = $('#stories > .filters-bar');
  23. filtersbar.children('select').each(function () {
  24. if (this.value.length > 0) {
  25. filters.push($(this).data('filter') + "=" + $(this).val());
  26. }
  27. });
  28. var url = document.URL;
  29. var target = url.split('?')[0];
  30. if (filters.length > 0) {
  31. target = target + '?' + filters.join('&');
  32. }
  33. window.location.href = target;
  34. });
  35. $('#stories').on('click', 'a[data-page]', function() {
  36. var filters = [];
  37. var filtersbar = $('#stories > .filters-bar');
  38. filtersbar.children('select').each(function () {
  39. if (this.value.length > 0) {
  40. filters.push($(this).data('filter') + "=" + $(this).val());
  41. }
  42. });
  43. var url = document.URL;
  44. var target = url.split('?')[0];
  45. if (filters.length > 0) {
  46. target = target + '?' + filters.join('&') + '&page=' + $(this).data('page');
  47. } else {
  48. target = target + '?page=' + $(this).data('page');
  49. }
  50. window.location.href = target;
  51. });
  52. $('#new-story').on('click', function(event) {
  53. event.preventDefault();
  54. var filters = [];
  55. var filtersbar = $('#stories > .filters-bar');
  56. filtersbar.children('select').each(function () {
  57. if (this.value.length > 0) {
  58. filters.push($(this).data('filter') + "=" + $(this).val());
  59. }
  60. });
  61. var url = $('#new-story').attr('href');
  62. var target = url.split('?')[0];
  63. if (filters.length > 0) {
  64. target = target + '?' + filters.join('&');
  65. }
  66. window.location.href = target;
  67. });
  68. var getUrlParameter = function getUrlParameter(sParam) {
  69. var sPageURL = window.location.search.substring(1),
  70. sURLVariables = sPageURL.split('&'),
  71. sParameterName,
  72. i;
  73. for (i = 0; i < sURLVariables.length; i++) {
  74. sParameterName = sURLVariables[i].split('=');
  75. if (sParameterName[0] === sParam) {
  76. return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
  77. }
  78. }
  79. };
  80. $('#id_epic').val([getUrlParameter('epic')])
  81. $('#id_name').val([getUrlParameter('name')])
  82. $('#id_weight').val([getUrlParameter('weight')])
  83. $('#id_assignees').val([getUrlParameter('assignee')])
  84. $('#id_sprints').val([getUrlParameter('sprint')])
  85. $(document).on('click', function(event) {
  86. if(!$(event.target).closest('#user-panel').length) {
  87. if($('#user-dropdown').is(":visible")) {
  88. $('#user-dropdown').hide();
  89. }
  90. }
  91. if(!$(event.target).closest('#notif-panel').length) {
  92. if($('#notif-dropdown').is(":visible")) {
  93. $('#notif-dropdown').hide();
  94. }
  95. }
  96. });
  97. $(document).on('click', '#user-show-btn', function(event) {
  98. event.preventDefault();
  99. if($('#user-dropdown').is(":visible")) {
  100. $('#user-dropdown').hide();
  101. }
  102. else {
  103. $('#user-dropdown').show();
  104. }
  105. });
  106. $(document).on('click', '#notif-show-btn', function(event) {
  107. event.preventDefault();
  108. if($('#notif-dropdown').is(":visible")) {
  109. $('#notif-dropdown').hide();
  110. }
  111. else {
  112. $('#notif-dropdown').show();
  113. }
  114. });
  115. function csrfSafeMethod(method) {
  116. // these HTTP methods do not require CSRF protection
  117. return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
  118. }
  119. function getCookie(name) {
  120. var cookieValue = null;
  121. if (document.cookie && document.cookie !== '') {
  122. var cookies = document.cookie.split(';');
  123. for (var i = 0; i < cookies.length; i++) {
  124. var cookie = jQuery.trim(cookies[i]);
  125. // Does this cookie string begin with the name we want?
  126. if (cookie.substring(0, name.length + 1) === (name + '=')) {
  127. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  128. break;
  129. }
  130. }
  131. }
  132. return cookieValue;
  133. }
  134. var csrftoken = getCookie('csrftoken');
  135. $(".notif-seen").click(function(event) {
  136. event.preventDefault();
  137. var notif = $(this).closest('.notif');
  138. var notif_id = notif.data('id');
  139. $.ajax({
  140. type: "POST",
  141. url: "/notif/seen/" + notif_id + "/",
  142. data: '{notif_id:' + notif_id + '}',
  143. contentType: "application/json; charset=utf-8",
  144. dataType: "json",
  145. beforeSend: function(xhr, settings) {
  146. if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
  147. xhr.setRequestHeader("X-CSRFToken", csrftoken);
  148. }
  149. },
  150. success: function (response) {
  151. notif.remove();
  152. },
  153. failure: function (response) {
  154. alert(response.responseText);
  155. },
  156. error: function (response) {
  157. alert(response.responseText);
  158. }
  159. });
  160. });
  161. $(".notif-all-seen").click(function(event) {
  162. event.preventDefault();
  163. var notif_list = $('#notif-dropdown').find('.notif-list');
  164. if (confirm('Êtes vous sûr de vouloir faire disparaitre toutes les notifications ?')) {
  165. $.ajax({
  166. type: "POST",
  167. url: "/notif/allseen/",
  168. contentType: "application/json; charset=utf-8",
  169. dataType: "json",
  170. beforeSend: function(xhr, settings) {
  171. if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
  172. xhr.setRequestHeader("X-CSRFToken", csrftoken);
  173. }
  174. },
  175. success: function (response) {
  176. notif_list.html('');
  177. $('.notif-footer').html('<i>Aucune notification à afficher</i>');
  178. $('.notif-count').html('0');
  179. $('#notif-dropdown').hide();
  180. },
  181. failure: function (response) {
  182. alert(response.responseText);
  183. },
  184. error: function (response) {
  185. alert(response.responseText);
  186. }
  187. });
  188. }
  189. });
  190. });