custom.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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 form input[name=value]').change(function() {
  168. $(this).closest('form').submit();
  169. });
  170. $("#backlog-editor").on('submit', 'form', function(event) {
  171. event.preventDefault();
  172. var action = $(this).attr('action');
  173. var val_field = $(this).find('input[name=value]');
  174. console.log(action);
  175. console.log(val_field.val())
  176. $.ajax({
  177. type: "POST",
  178. url: action,
  179. data : { value : val_field.val() },
  180. success: function (response) {
  181. val_field.animate({ borderColor: "#009933" }, 1500, function() {
  182. val_field.removeAttr('style'); } );
  183. },
  184. failure: function (response) {
  185. val_field.animate({ borderColor: "#ff0000" }, 1500, function() {
  186. val_field.removeAttr('style'); } );
  187. console.log('Ajax failure: ' + response.responseText);
  188. $("#backlog-editor").unbind('submit'); // Ajax is not working: unbind
  189. $(this).submit();
  190. },
  191. error: function (response) {
  192. val_field.animate({ borderColor: "#ff0000" }, 1500, function() {
  193. val_field.removeAttr('style'); } );
  194. console.log('Ajax error: ' + response.responseText);
  195. $("#backlog-editor").unbind('submit'); // Ajax is not working: unbind
  196. $(this).submit();
  197. }
  198. });
  199. });
  200. $("#backlog-editor").on('click', '.btn-epic-close', function(event) {
  201. event.preventDefault();
  202. var action = $(this).attr('href');
  203. this_btn = $(this);
  204. $.ajax({
  205. type: "POST",
  206. url: action,
  207. success: function (response) {
  208. this_btn.addClass('disabled');
  209. this_btn.closest('tr').find(".epic-name").addClass('story-closed');
  210. },
  211. failure: function (response) {
  212. alert(response.responseText);
  213. },
  214. error: function (response) {
  215. alert(response.responseText);
  216. }
  217. });
  218. });
  219. $("#backlog-editor").on('click', '.btn-epic-reopen', function(event) {
  220. event.preventDefault();
  221. var action = $(this).attr('href');
  222. this_btn = $(this);
  223. name_field = this_btn.closest('tr').find(".epic-name");
  224. $.ajax({
  225. type: "POST",
  226. url: action,
  227. success: function (response) {
  228. this_btn.addClass('disabled');
  229. name_field.removeClass('story-closed');
  230. name_field.html(name_field.html().replace('[Fermée] ', ''));
  231. },
  232. failure: function (response) {
  233. alert(response.responseText);
  234. },
  235. error: function (response) {
  236. alert(response.responseText);
  237. }
  238. });
  239. });
  240. $("#sprint-end .story_close").click(function(event) {
  241. event.preventDefault();
  242. var story_tr = $(this).closest('tr');
  243. var story_id = story_tr.data('id');
  244. $.ajax({
  245. type: "POST",
  246. url: "/stories/close/" + story_id + "/",
  247. data: '{story_id:' + story_id + '}',
  248. contentType: "application/json; charset=utf-8",
  249. dataType: "json",
  250. beforeSend: function(xhr, settings) {
  251. if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
  252. xhr.setRequestHeader("X-CSRFToken", csrftoken);
  253. }
  254. },
  255. success: function (response) {
  256. story_tr.find('.btn-cell').html('<a class="button special icon fa-check tool-btn already-checked"></a>');
  257. story_tr.find('.btn-cell-2').html('<a class="button special icon fa-mail-forward tool-btn disabled"></a>');
  258. },
  259. failure: function (response) {
  260. alert(response.responseText);
  261. },
  262. error: function (response) {
  263. alert(response.responseText);
  264. }
  265. });
  266. });
  267. $("#sprint-end .story_reaffect").click(function(event) {
  268. event.preventDefault();
  269. var story_tr = $(this).closest('tr');
  270. var story_id = story_tr.data('id');
  271. $.ajax({
  272. type: "POST",
  273. url: "/stories/reaffect/" + story_id + "/",
  274. success: function (response) {
  275. story_tr.find('.btn-cell').html('<a class="button special icon fa-check tool-btn disabled"></a>');
  276. story_tr.find('.btn-cell-2').html('<a class="button special icon fa-mail-forward tool-btn already-checked"></a>');
  277. },
  278. failure: function (response) {
  279. alert(response.responseText);
  280. },
  281. error: function (response) {
  282. alert(response.responseText);
  283. }
  284. });
  285. });
  286. $("#sprint-end-table").on('submit', 'form', function(event) {
  287. event.preventDefault();
  288. var action = $(this).attr('action');
  289. var val_field = $(this).find('input[name=time_spent]');
  290. console.log(action);
  291. console.log(val_field.val())
  292. $.ajax({
  293. type: "POST",
  294. url: action,
  295. data : { time_spent : val_field.val() },
  296. success: function (response) {
  297. val_field.animate({ borderColor: "#009933" }, 1500, function() {
  298. val_field.removeAttr('style'); } );
  299. },
  300. failure: function (response) {
  301. val_field.animate({ borderColor: "#ff0000" }, 1500, function() {
  302. val_field.removeAttr('style'); } );
  303. console.log('Ajax failure: ' + response.responseText);
  304. $("#sprint-end-table").unbind('submit'); // Ajax is not working: unbind
  305. $(this).submit();
  306. },
  307. error: function (response) {
  308. val_field.animate({ borderColor: "#ff0000" }, 1500, function() {
  309. val_field.removeAttr('style'); } );
  310. console.log('Ajax error: ' + response.responseText);
  311. $("#sprint-end-table").unbind('submit'); // Ajax is not working: unbind
  312. $(this).submit();
  313. }
  314. });
  315. });
  316. $("#sprint-end .retro-section input").click(function (event) {
  317. if (confirm('Le sprint courant va être marqué comme terminé, continuer?')) {
  318. return true;
  319. }
  320. });
  321. $('.filtered-dropdown').select2();
  322. });