custom.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. var epic = getUrlParameter('epic');
  67. var name = getUrlParameter('name');
  68. var weight = getUrlParameter('weight');
  69. var assignee = getUrlParameter('assignee');
  70. var sprint = getUrlParameter('sprint');
  71. if (epic) { $('#id_epic').val(epic); }
  72. if (name) { $('#id_name').val(name); }
  73. if (weight) { $('#id_weight').val(weight); }
  74. if (assignee) { $('#id_assignees').val([assignee]); }
  75. if (sprint) { $('#id_sprints').val([sprint]); }
  76. $(document).on('click', function(event) {
  77. if(!$(event.target).closest('#user-panel').length) {
  78. if($('#user-dropdown').is(":visible")) {
  79. $('#user-dropdown').hide();
  80. }
  81. }
  82. if(!$(event.target).closest('#notif-panel').length) {
  83. if($('#notif-dropdown').is(":visible")) {
  84. $('#notif-dropdown').hide();
  85. }
  86. }
  87. });
  88. $(document).on('click', '#user-show-btn', function(event) {
  89. event.preventDefault();
  90. if($('#user-dropdown').is(":visible")) {
  91. $('#user-dropdown').hide();
  92. }
  93. else {
  94. $('#user-dropdown').show();
  95. }
  96. });
  97. $(document).on('click', '#notif-show-btn', function(event) {
  98. event.preventDefault();
  99. if($('#notif-dropdown').is(":visible")) {
  100. $('#notif-dropdown').hide();
  101. }
  102. else {
  103. $('#notif-dropdown').show();
  104. }
  105. });
  106. $(".notif-seen").click(function(event) {
  107. event.preventDefault();
  108. var notif = $(this).closest('.notif');
  109. var notif_id = notif.data('id');
  110. $.ajax({
  111. type: "POST",
  112. url: "/notif/seen/" + notif_id + "/",
  113. data: '{notif_id:' + notif_id + '}',
  114. contentType: "application/json; charset=utf-8",
  115. dataType: "json",
  116. beforeSend: function(xhr, settings) {
  117. if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
  118. xhr.setRequestHeader("X-CSRFToken", csrftoken);
  119. }
  120. },
  121. success: function (response) {
  122. notif.remove();
  123. },
  124. failure: function (response) {
  125. alert(response.responseText);
  126. },
  127. error: function (response) {
  128. alert(response.responseText);
  129. }
  130. });
  131. });
  132. $(".notif-all-seen").click(function(event) {
  133. event.preventDefault();
  134. var notif_list = $('#notif-dropdown').find('.notif-list');
  135. if (confirm('Êtes vous sûr de vouloir faire disparaitre toutes les notifications ?')) {
  136. $.ajax({
  137. type: "POST",
  138. url: "/notif/allseen/",
  139. contentType: "application/json; charset=utf-8",
  140. dataType: "json",
  141. beforeSend: function(xhr, settings) {
  142. if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
  143. xhr.setRequestHeader("X-CSRFToken", csrftoken);
  144. }
  145. },
  146. success: function (response) {
  147. notif_list.html('');
  148. $('.notif-footer').html('<i>Aucune notification à afficher</i>');
  149. $('.notif-count').html('0');
  150. $('#notif-dropdown').hide();
  151. },
  152. failure: function (response) {
  153. alert(response.responseText);
  154. },
  155. error: function (response) {
  156. alert(response.responseText);
  157. }
  158. });
  159. }
  160. });
  161. });