custom.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. $('#search-bar').select2({
  21. placeholder: 'Rechercher...',
  22. language: "fr",
  23. minimumInputLength: 2,
  24. ajax: {
  25. url: '/search/',
  26. dataType: 'json',
  27. cache: true,
  28. // delay: 100
  29. },
  30. // closeOnSelect: false,
  31. width : '220px',
  32. templateResult: function (state) { return $('<a href="' + state.id + '">' + state.text + '</a>'); },
  33. language: {
  34. inputTooShort: function () { return "Veuillez saisir votre recherche..."; },
  35. errorLoading: function () { return "Erreur de chargement"; },
  36. searching: function () { return "Recherche en cours…"; },
  37. noResults: function () { return "Aucun résultat"; },
  38. loadingMore: function () { return "Chargement de résultats supplémentaires…"; }
  39. }
  40. });
  41. $('#stories').on('change', 'select[data-filter]', function() {
  42. var filters = [];
  43. var filtersbar = $('#stories > .filters-bar');
  44. filtersbar.children('select').each(function () {
  45. if (this.value.length > 0) {
  46. filters.push($(this).data('filter') + "=" + $(this).val());
  47. }
  48. });
  49. var url = document.URL;
  50. var target = url.split('?')[0];
  51. if (filters.length > 0) {
  52. target = target + '?' + filters.join('&');
  53. }
  54. window.location.href = target;
  55. });
  56. $('#stories').on('click', 'a[data-page]', function() {
  57. var filters = [];
  58. var filtersbar = $('#stories > .filters-bar');
  59. filtersbar.children('select').each(function () {
  60. if (this.value.length > 0) {
  61. filters.push($(this).data('filter') + "=" + $(this).val());
  62. }
  63. });
  64. var url = document.URL;
  65. var target = url.split('?')[0];
  66. if (filters.length > 0) {
  67. target = target + '?' + filters.join('&') + '&page=' + $(this).data('page');
  68. } else {
  69. target = target + '?page=' + $(this).data('page');
  70. }
  71. window.location.href = target;
  72. });
  73. $('#new-story').on('click', function(event) {
  74. event.preventDefault();
  75. var filters = [];
  76. var filtersbar = $('#stories > .filters-bar');
  77. filtersbar.children('select').each(function () {
  78. if (this.value.length > 0) {
  79. filters.push($(this).data('filter') + "=" + $(this).val());
  80. }
  81. });
  82. var url = $('#new-story').attr('href');
  83. var target = url.split('?')[0];
  84. if (filters.length > 0) {
  85. target = target + '?' + filters.join('&');
  86. }
  87. window.location.href = target;
  88. });
  89. var epic = getUrlParameter('epic');
  90. var name = getUrlParameter('name');
  91. var weight = getUrlParameter('weight');
  92. var assignee = getUrlParameter('assignee');
  93. var sprint = getUrlParameter('sprint');
  94. if (epic) { $('#id_epic').val(epic); }
  95. if (name) { $('#id_name').val(name); }
  96. if (weight) { $('#id_weight').val(weight); }
  97. if (assignee) { $('#id_assignees').val([assignee]); }
  98. if (sprint) { $('#id_sprints').val([sprint]); }
  99. $(document).on('click', function(event) {
  100. if(!$(event.target).closest('#user-panel').length) {
  101. if($('#user-dropdown').is(":visible")) {
  102. $('#user-dropdown').hide();
  103. }
  104. }
  105. if(!$(event.target).closest('#notif-panel').length) {
  106. if($('#notif-dropdown').is(":visible")) {
  107. $('#notif-dropdown').hide();
  108. }
  109. }
  110. if(!$(event.target).closest('#stories-panel').length) {
  111. if($('#stories-dropdown').is(":visible")) {
  112. $('#stories-dropdown').hide();
  113. }
  114. }
  115. });
  116. $(document).on('click', '#user-show-btn', function(event) {
  117. event.preventDefault();
  118. if($('#user-dropdown').is(":visible")) {
  119. $('#user-dropdown').hide();
  120. }
  121. else {
  122. $('#user-dropdown').show();
  123. }
  124. });
  125. $(document).on('click', '#stories-show-btn', function(event) {
  126. event.preventDefault();
  127. if($('#stories-dropdown').is(":visible")) {
  128. $('#stories-dropdown').hide();
  129. }
  130. else {
  131. $('#stories-dropdown').show();
  132. }
  133. });
  134. $(document).on('click', '#notif-show-btn', function(event) {
  135. event.preventDefault();
  136. if($('#notif-dropdown').is(":visible")) {
  137. $('#notif-dropdown').hide();
  138. }
  139. else {
  140. $('#notif-dropdown').show();
  141. }
  142. });
  143. $(".notif-seen").click(function(event) {
  144. event.preventDefault();
  145. var notif = $(this).closest('.notif');
  146. var notif_id = notif.data('id');
  147. $.ajax({
  148. type: "POST",
  149. url: "/notif/seen/" + notif_id + "/",
  150. data: '{notif_id:' + notif_id + '}',
  151. contentType: "application/json; charset=utf-8",
  152. dataType: "json",
  153. success: function (response) {
  154. notif.remove();
  155. },
  156. failure: function (response) {
  157. alert(response.responseText);
  158. },
  159. error: function (response) {
  160. alert(response.responseText);
  161. }
  162. });
  163. });
  164. $(".notif-all-seen").click(function(event) {
  165. event.preventDefault();
  166. var notif_list = $('#notif-dropdown').find('.notif-list');
  167. if (confirm('Êtes vous sûr de vouloir faire disparaitre toutes les notifications ?')) {
  168. $.ajax({
  169. type: "POST",
  170. url: "/notif/allseen/",
  171. contentType: "application/json; charset=utf-8",
  172. dataType: "json",
  173. success: function (response) {
  174. notif_list.html('');
  175. $('.notif-footer').html('<i>Aucune notification à afficher</i>');
  176. $('.notif-count').html('0');
  177. $('#notif-dropdown').hide();
  178. },
  179. failure: function (response) {
  180. alert(response.responseText);
  181. },
  182. error: function (response) {
  183. alert(response.responseText);
  184. }
  185. });
  186. }
  187. });
  188. $('#backlog-editor form input[name=value]').change(function() {
  189. $(this).closest('form').submit();
  190. });
  191. $("#backlog-editor").on('submit', 'form', function(event) {
  192. event.preventDefault();
  193. var action = $(this).attr('action');
  194. var val_field = $(this).find('input[name=value]');
  195. console.log(action);
  196. console.log(val_field.val())
  197. $.ajax({
  198. type: "POST",
  199. url: action,
  200. data : { value : val_field.val() },
  201. success: function (response) {
  202. val_field.animate({ borderColor: "#009933" }, 1500, function() {
  203. val_field.removeAttr('style'); } );
  204. },
  205. failure: function (response) {
  206. val_field.animate({ borderColor: "#ff0000" }, 1500, function() {
  207. val_field.removeAttr('style'); } );
  208. console.log('Ajax failure: ' + response.responseText);
  209. $("#backlog-editor").unbind('submit'); // Ajax is not working: unbind
  210. $(this).submit();
  211. },
  212. error: function (response) {
  213. val_field.animate({ borderColor: "#ff0000" }, 1500, function() {
  214. val_field.removeAttr('style'); } );
  215. console.log('Ajax error: ' + response.responseText);
  216. $("#backlog-editor").unbind('submit'); // Ajax is not working: unbind
  217. $(this).submit();
  218. }
  219. });
  220. });
  221. $("#backlog-editor").on('click', '.btn-epic-close', function(event) {
  222. event.preventDefault();
  223. var action = $(this).attr('href');
  224. this_btn = $(this);
  225. $.ajax({
  226. type: "POST",
  227. url: action,
  228. success: function (response) {
  229. this_btn.addClass('disabled');
  230. this_btn.closest('tr').find(".epic-name").addClass('story-closed');
  231. },
  232. failure: function (response) {
  233. alert(response.responseText);
  234. },
  235. error: function (response) {
  236. alert(response.responseText);
  237. }
  238. });
  239. });
  240. $("#backlog-editor").on('click', '.btn-epic-reopen', function(event) {
  241. event.preventDefault();
  242. var action = $(this).attr('href');
  243. this_btn = $(this);
  244. name_field = this_btn.closest('tr').find(".epic-name");
  245. $.ajax({
  246. type: "POST",
  247. url: action,
  248. success: function (response) {
  249. this_btn.addClass('disabled');
  250. name_field.removeClass('story-closed');
  251. name_field.html(name_field.html().replace('[Fermée] ', ''));
  252. },
  253. failure: function (response) {
  254. alert(response.responseText);
  255. },
  256. error: function (response) {
  257. alert(response.responseText);
  258. }
  259. });
  260. });
  261. $("#sprint-end .story_close").click(function(event) {
  262. event.preventDefault();
  263. var story_tr = $(this).closest('tr');
  264. var story_id = story_tr.data('id');
  265. $.ajax({
  266. type: "POST",
  267. url: "/stories/close/" + story_id + "/",
  268. data: '{story_id:' + story_id + '}',
  269. contentType: "application/json; charset=utf-8",
  270. dataType: "json",
  271. beforeSend: function(xhr, settings) {
  272. if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
  273. xhr.setRequestHeader("X-CSRFToken", csrftoken);
  274. }
  275. },
  276. success: function (response) {
  277. story_tr.find('.btn-cell').html('<a class="button special icon fa-check tool-btn already-checked"></a>');
  278. story_tr.find('.btn-cell-2').html('<a class="button special icon fa-mail-forward tool-btn disabled"></a>');
  279. },
  280. failure: function (response) {
  281. alert(response.responseText);
  282. },
  283. error: function (response) {
  284. alert(response.responseText);
  285. }
  286. });
  287. });
  288. $("#sprint-end .story_reaffect").click(function(event) {
  289. event.preventDefault();
  290. var story_tr = $(this).closest('tr');
  291. var story_id = story_tr.data('id');
  292. $.ajax({
  293. type: "POST",
  294. url: "/stories/reaffect/" + story_id + "/",
  295. success: function (response) {
  296. story_tr.find('.btn-cell').html('<a class="button special icon fa-check tool-btn disabled"></a>');
  297. story_tr.find('.btn-cell-2').html('<a class="button special icon fa-mail-forward tool-btn already-checked"></a>');
  298. },
  299. failure: function (response) {
  300. alert(response.responseText);
  301. },
  302. error: function (response) {
  303. alert(response.responseText);
  304. }
  305. });
  306. });
  307. $("#sprint-end-table").on('submit', 'form', function(event) {
  308. event.preventDefault();
  309. var action = $(this).attr('action');
  310. var val_field = $(this).find('input[name=time_spent]');
  311. console.log(action);
  312. console.log(val_field.val())
  313. $.ajax({
  314. type: "POST",
  315. url: action,
  316. data : { time_spent : val_field.val() },
  317. success: function (response) {
  318. val_field.animate({ borderColor: "#009933" }, 1500, function() {
  319. val_field.removeAttr('style'); } );
  320. },
  321. failure: function (response) {
  322. val_field.animate({ borderColor: "#ff0000" }, 1500, function() {
  323. val_field.removeAttr('style'); } );
  324. console.log('Ajax failure: ' + response.responseText);
  325. $("#sprint-end-table").unbind('submit'); // Ajax is not working: unbind
  326. $(this).submit();
  327. },
  328. error: function (response) {
  329. val_field.animate({ borderColor: "#ff0000" }, 1500, function() {
  330. val_field.removeAttr('style'); } );
  331. console.log('Ajax error: ' + response.responseText);
  332. $("#sprint-end-table").unbind('submit'); // Ajax is not working: unbind
  333. $(this).submit();
  334. }
  335. });
  336. });
  337. $("#sprint-end .retro-section input").click(function (event) {
  338. if (confirm('Le sprint courant va être marqué comme terminé, continuer?')) {
  339. return true;
  340. }
  341. });
  342. $('.filtered-dropdown').select2();
  343. });