custom.js 13 KB

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