custom.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. $('.filters-bar').children('select[data-filter]').each(function () {
  13. var filter_name = $(this).data('filter');
  14. if(filter_name in loc_qry) {
  15. $(this).val(loc_qry[filter_name]);
  16. }
  17. });
  18. $('#stories').on('change', 'select[data-filter]', function() {
  19. var filters = [];
  20. var filtersbar = $('#stories > .filters-bar');
  21. filtersbar.children('select').each(function () {
  22. if (this.value.length > 0) {
  23. filters.push($(this).data('filter') + "=" + $(this).val());
  24. }
  25. });
  26. var url = document.URL;
  27. var target = url.split('?')[0];
  28. if (filters.length > 0) {
  29. target = target + '?' + filters.join('&');
  30. }
  31. window.location.href = target;
  32. });
  33. $('#stories').on('click', 'a[data-page]', function() {
  34. var filters = [];
  35. var filtersbar = $('#stories > .filters-bar');
  36. filtersbar.children('select').each(function () {
  37. if (this.value.length > 0) {
  38. filters.push($(this).data('filter') + "=" + $(this).val());
  39. }
  40. });
  41. var url = document.URL;
  42. var target = url.split('?')[0];
  43. if (filters.length > 0) {
  44. target = target + '?' + filters.join('&') + '&page=' + $(this).data('page');
  45. } else {
  46. target = target + '?page=' + $(this).data('page');
  47. }
  48. window.location.href = target;
  49. });
  50. $('#new-story').on('click', function(event) {
  51. event.preventDefault();
  52. var filters = [];
  53. var filtersbar = $('#stories > .filters-bar');
  54. filtersbar.children('select').each(function () {
  55. if (this.value.length > 0) {
  56. filters.push($(this).data('filter') + "=" + $(this).val());
  57. }
  58. });
  59. var url = $('#new-story').attr('href');
  60. var target = url.split('?')[0];
  61. if (filters.length > 0) {
  62. target = target + '?' + filters.join('&');
  63. }
  64. window.location.href = target;
  65. });
  66. $('#id_epic').val([getUrlParameter('epic')])
  67. $('#id_name').val([getUrlParameter('name')])
  68. $('#id_weight').val([getUrlParameter('weight')])
  69. $('#id_assignees').val([getUrlParameter('assignee')])
  70. $('#id_sprints').val([getUrlParameter('sprint')])
  71. $(document).on('click', function(event) {
  72. if(!$(event.target).closest('#user-panel').length) {
  73. if($('#user-dropdown').is(":visible")) {
  74. $('#user-dropdown').hide();
  75. }
  76. }
  77. if(!$(event.target).closest('#notif-panel').length) {
  78. if($('#notif-dropdown').is(":visible")) {
  79. $('#notif-dropdown').hide();
  80. }
  81. }
  82. });
  83. $(document).on('click', '#user-show-btn', function(event) {
  84. event.preventDefault();
  85. if($('#user-dropdown').is(":visible")) {
  86. $('#user-dropdown').hide();
  87. }
  88. else {
  89. $('#user-dropdown').show();
  90. }
  91. });
  92. $(document).on('click', '#notif-show-btn', function(event) {
  93. event.preventDefault();
  94. if($('#notif-dropdown').is(":visible")) {
  95. $('#notif-dropdown').hide();
  96. }
  97. else {
  98. $('#notif-dropdown').show();
  99. }
  100. });
  101. $(".notif-seen").click(function(event) {
  102. event.preventDefault();
  103. var notif = $(this).closest('.notif');
  104. var notif_id = notif.data('id');
  105. $.ajax({
  106. type: "POST",
  107. url: "/notif/seen/" + notif_id + "/",
  108. data: '{notif_id:' + notif_id + '}',
  109. contentType: "application/json; charset=utf-8",
  110. dataType: "json",
  111. beforeSend: function(xhr, settings) {
  112. if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
  113. xhr.setRequestHeader("X-CSRFToken", csrftoken);
  114. }
  115. },
  116. success: function (response) {
  117. notif.remove();
  118. },
  119. failure: function (response) {
  120. alert(response.responseText);
  121. },
  122. error: function (response) {
  123. alert(response.responseText);
  124. }
  125. });
  126. });
  127. $(".notif-all-seen").click(function(event) {
  128. event.preventDefault();
  129. var notif_list = $('#notif-dropdown').find('.notif-list');
  130. if (confirm('Êtes vous sûr de vouloir faire disparaitre toutes les notifications ?')) {
  131. $.ajax({
  132. type: "POST",
  133. url: "/notif/allseen/",
  134. contentType: "application/json; charset=utf-8",
  135. dataType: "json",
  136. beforeSend: function(xhr, settings) {
  137. if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
  138. xhr.setRequestHeader("X-CSRFToken", csrftoken);
  139. }
  140. },
  141. success: function (response) {
  142. notif_list.html('');
  143. $('.notif-footer').html('<i>Aucune notification à afficher</i>');
  144. $('.notif-count').html('0');
  145. $('#notif-dropdown').hide();
  146. },
  147. failure: function (response) {
  148. alert(response.responseText);
  149. },
  150. error: function (response) {
  151. alert(response.responseText);
  152. }
  153. });
  154. }
  155. });
  156. });