custom.js 12 KB

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