custom.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. if(!$(event.target).closest('#stories-panel').length) {
  90. if($('#stories-dropdown').is(":visible")) {
  91. $('#stories-dropdown').hide();
  92. }
  93. }
  94. });
  95. $(document).on('click', '#user-show-btn', function(event) {
  96. event.preventDefault();
  97. if($('#user-dropdown').is(":visible")) {
  98. $('#user-dropdown').hide();
  99. }
  100. else {
  101. $('#user-dropdown').show();
  102. }
  103. });
  104. $(document).on('click', '#stories-show-btn', function(event) {
  105. event.preventDefault();
  106. if($('#stories-dropdown').is(":visible")) {
  107. $('#stories-dropdown').hide();
  108. }
  109. else {
  110. $('#stories-dropdown').show();
  111. }
  112. });
  113. $(document).on('click', '#notif-show-btn', function(event) {
  114. event.preventDefault();
  115. if($('#notif-dropdown').is(":visible")) {
  116. $('#notif-dropdown').hide();
  117. }
  118. else {
  119. $('#notif-dropdown').show();
  120. }
  121. });
  122. $(".notif-seen").click(function(event) {
  123. event.preventDefault();
  124. var notif = $(this).closest('.notif');
  125. var notif_id = notif.data('id');
  126. $.ajax({
  127. type: "POST",
  128. url: "/notif/seen/" + notif_id + "/",
  129. data: '{notif_id:' + notif_id + '}',
  130. contentType: "application/json; charset=utf-8",
  131. dataType: "json",
  132. success: function (response) {
  133. notif.remove();
  134. },
  135. failure: function (response) {
  136. alert(response.responseText);
  137. },
  138. error: function (response) {
  139. alert(response.responseText);
  140. }
  141. });
  142. });
  143. $(".notif-all-seen").click(function(event) {
  144. event.preventDefault();
  145. var notif_list = $('#notif-dropdown').find('.notif-list');
  146. if (confirm('Êtes vous sûr de vouloir faire disparaitre toutes les notifications ?')) {
  147. $.ajax({
  148. type: "POST",
  149. url: "/notif/allseen/",
  150. contentType: "application/json; charset=utf-8",
  151. dataType: "json",
  152. success: function (response) {
  153. notif_list.html('');
  154. $('.notif-footer').html('<i>Aucune notification à afficher</i>');
  155. $('.notif-count').html('0');
  156. $('#notif-dropdown').hide();
  157. },
  158. failure: function (response) {
  159. alert(response.responseText);
  160. },
  161. error: function (response) {
  162. alert(response.responseText);
  163. }
  164. });
  165. }
  166. });
  167. $("#backlog-editor").on('submit', 'form', function(event) {
  168. event.preventDefault();
  169. var action = $(this).attr('action');
  170. var val_field = $(this).find('input[name=value]');
  171. console.log(action);
  172. console.log(val_field.val())
  173. $.ajax({
  174. type: "POST",
  175. url: action,
  176. data : { value : val_field.val() },
  177. success: function (response) {
  178. val_field.animate({ borderColor: "#009933" }, 1500, function() {
  179. val_field.removeAttr('style'); } );
  180. },
  181. failure: function (response) {
  182. val_field.animate({ borderColor: "#ff0000" }, 1500, function() {
  183. val_field.removeAttr('style'); } );
  184. console.log('Ajax failure: ' + response.responseText);
  185. $("#backlog-editor").unbind('submit'); // Ajax is not working: unbind
  186. $(this).submit();
  187. },
  188. error: function (response) {
  189. val_field.animate({ borderColor: "#ff0000" }, 1500, function() {
  190. val_field.removeAttr('style'); } );
  191. console.log('Ajax error: ' + response.responseText);
  192. $("#backlog-editor").unbind('submit'); // Ajax is not working: unbind
  193. $(this).submit();
  194. }
  195. });
  196. });
  197. $("#backlog-editor").on('click', '.btn-epic-close', function(event) {
  198. event.preventDefault();
  199. var action = $(this).attr('href');
  200. this_btn = $(this);
  201. $.ajax({
  202. type: "POST",
  203. url: action,
  204. success: function (response) {
  205. this_btn.addClass('disabled');
  206. this_btn.closest('tr').find(".epic-name").addClass('story-closed');
  207. },
  208. failure: function (response) {
  209. alert(response.responseText);
  210. },
  211. error: function (response) {
  212. alert(response.responseText);
  213. }
  214. });
  215. });
  216. $("#backlog-editor").on('click', '.btn-epic-reopen', function(event) {
  217. event.preventDefault();
  218. var action = $(this).attr('href');
  219. this_btn = $(this);
  220. name_field = this_btn.closest('tr').find(".epic-name");
  221. $.ajax({
  222. type: "POST",
  223. url: action,
  224. success: function (response) {
  225. this_btn.addClass('disabled');
  226. name_field.removeClass('story-closed');
  227. name_field.html(name_field.html().replace('[Fermée] ', ''));
  228. },
  229. failure: function (response) {
  230. alert(response.responseText);
  231. },
  232. error: function (response) {
  233. alert(response.responseText);
  234. }
  235. });
  236. });
  237. $("#sprint-end .story_close").click(function(event) {
  238. event.preventDefault();
  239. var story_tr = $(this).closest('tr');
  240. var story_id = story_tr.data('id');
  241. $.ajax({
  242. type: "POST",
  243. url: "/stories/close/" + story_id + "/",
  244. data: '{story_id:' + story_id + '}',
  245. contentType: "application/json; charset=utf-8",
  246. dataType: "json",
  247. beforeSend: function(xhr, settings) {
  248. if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
  249. xhr.setRequestHeader("X-CSRFToken", csrftoken);
  250. }
  251. },
  252. success: function (response) {
  253. story_tr.find('.btn-cell').html('<a class="button special icon fa-check tool-btn already-checked"></a>');
  254. story_tr.find('.btn-cell-2').html('<a class="button special icon fa-mail-forward tool-btn disabled"></a>');
  255. },
  256. failure: function (response) {
  257. alert(response.responseText);
  258. },
  259. error: function (response) {
  260. alert(response.responseText);
  261. }
  262. });
  263. });
  264. $("#sprint-end .story_reaffect").click(function(event) {
  265. event.preventDefault();
  266. var story_tr = $(this).closest('tr');
  267. var story_id = story_tr.data('id');
  268. $.ajax({
  269. type: "POST",
  270. url: "/stories/reaffect/" + story_id + "/",
  271. success: function (response) {
  272. story_tr.find('.btn-cell').html('<a class="button special icon fa-check tool-btn disabled"></a>');
  273. story_tr.find('.btn-cell-2').html('<a class="button special icon fa-mail-forward tool-btn already-checked"></a>');
  274. },
  275. failure: function (response) {
  276. alert(response.responseText);
  277. },
  278. error: function (response) {
  279. alert(response.responseText);
  280. }
  281. });
  282. });
  283. $("#sprint-end .retro-section input").click(function (event) {
  284. if (confirm('Le sprint courant va être marqué comme terminé, continuer?')) {
  285. return true;
  286. }
  287. });
  288. });