custom.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. success: function (response) {
  119. notif.remove();
  120. },
  121. failure: function (response) {
  122. alert(response.responseText);
  123. },
  124. error: function (response) {
  125. alert(response.responseText);
  126. }
  127. });
  128. });
  129. $(".notif-all-seen").click(function(event) {
  130. event.preventDefault();
  131. var notif_list = $('#notif-dropdown').find('.notif-list');
  132. if (confirm('Êtes vous sûr de vouloir faire disparaitre toutes les notifications ?')) {
  133. $.ajax({
  134. type: "POST",
  135. url: "/notif/allseen/",
  136. contentType: "application/json; charset=utf-8",
  137. dataType: "json",
  138. success: function (response) {
  139. notif_list.html('');
  140. $('.notif-footer').html('<i>Aucune notification à afficher</i>');
  141. $('.notif-count').html('0');
  142. $('#notif-dropdown').hide();
  143. },
  144. failure: function (response) {
  145. alert(response.responseText);
  146. },
  147. error: function (response) {
  148. alert(response.responseText);
  149. }
  150. });
  151. }
  152. });
  153. $("#backlog-editor").on('submit', 'form', function(event) {
  154. event.preventDefault();
  155. var action = $(this).attr('action');
  156. var val_field = $(this).find('input[name=value]');
  157. console.log(action);
  158. console.log(val_field.val())
  159. $.ajax({
  160. type: "POST",
  161. url: action,
  162. data : { value : val_field.val() },
  163. success: function (response) {
  164. val_field.animate({ borderColor: "#009933" }, 1500, function() {
  165. val_field.removeAttr('style'); } );
  166. },
  167. failure: function (response) {
  168. val_field.animate({ borderColor: "#ff0000" }, 1500, function() {
  169. val_field.removeAttr('style'); } );
  170. console.log('Ajax failure: ' + response.responseText);
  171. $("#backlog-editor").unbind('submit'); // Ajax is not working: unbind
  172. $(this).submit();
  173. },
  174. error: function (response) {
  175. val_field.animate({ borderColor: "#ff0000" }, 1500, function() {
  176. val_field.removeAttr('style'); } );
  177. console.log('Ajax error: ' + response.responseText);
  178. $("#backlog-editor").unbind('submit'); // Ajax is not working: unbind
  179. $(this).submit();
  180. }
  181. });
  182. });
  183. $("#backlog-editor").on('click', '.btn-epic-close', function(event) {
  184. event.preventDefault();
  185. var action = $(this).attr('href');
  186. this_btn = $(this);
  187. $.ajax({
  188. type: "POST",
  189. url: action,
  190. success: function (response) {
  191. this_btn.addClass('disabled');
  192. this_btn.closest('tr').find(".epic-name").addClass('story-closed');
  193. },
  194. failure: function (response) {
  195. alert(response.responseText);
  196. },
  197. error: function (response) {
  198. alert(response.responseText);
  199. }
  200. });
  201. });
  202. $("#backlog-editor").on('click', '.btn-epic-reopen', function(event) {
  203. event.preventDefault();
  204. var action = $(this).attr('href');
  205. this_btn = $(this);
  206. name_field = this_btn.closest('tr').find(".epic-name");
  207. $.ajax({
  208. type: "POST",
  209. url: action,
  210. success: function (response) {
  211. this_btn.addClass('disabled');
  212. name_field.removeClass('story-closed');
  213. name_field.html(name_field.html().replace('[Fermée] ', ''));
  214. },
  215. failure: function (response) {
  216. alert(response.responseText);
  217. },
  218. error: function (response) {
  219. alert(response.responseText);
  220. }
  221. });
  222. });
  223. });