custom.js 5.3 KB

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