You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 line
3.2KB

  1. $(document).ready(function () {
  2. menuToggle();
  3. manageFormContact();
  4. manageFormSearch();
  5. manageFormIndiv();
  6. });
  7. function manageFormIndiv() {
  8. document
  9. .querySelectorAll('.add_item_link')
  10. .forEach(btn => btn.addEventListener("click", addFormToCollection));
  11. }
  12. const addFormToCollection = (e) => {
  13. const collectionHolder = document.querySelector('.' + e.currentTarget.dataset.collectionHolderClass);
  14. const item = document.createElement('li');
  15. item.innerHTML = collectionHolder
  16. .dataset
  17. .prototype
  18. .replace(
  19. /__name__/g,
  20. collectionHolder.dataset.index
  21. );
  22. collectionHolder.appendChild(item);
  23. collectionHolder.dataset.index++;
  24. if (collectionHolder.dataset.index >= 6) {
  25. e.currentTarget.style.visibility = 'hidden';
  26. }
  27. // add a delete link to the new form
  28. addFormDeleteLink(item, e.currentTarget);
  29. };
  30. const addFormDeleteLink = (formLi, currentTarget) => {
  31. const collectionHolder = document.querySelector('.' + currentTarget.dataset.collectionHolderClass);
  32. const removeFormButton = document.createElement('button')
  33. removeFormButton.classList.add('button-green', 'button-remove')
  34. removeFormButton.innerText = 'Supprimer'
  35. formLi.append(removeFormButton);
  36. removeFormButton.addEventListener('click', (e) => {
  37. collectionHolder.dataset.index--;
  38. if (collectionHolder.dataset.index <= 6) {
  39. currentTarget.style.visibility = 'visible';
  40. }
  41. e.preventDefault()
  42. formLi.remove();
  43. });
  44. }
  45. function menuToggle() {
  46. var box = $('.menu-content');
  47. var button = $('.toggle');
  48. button.on('click', function () {
  49. box.toggle('slow');
  50. });
  51. }
  52. function manageFormSearch() {
  53. $(".dropdown-search").on("change", "input[type='checkbox']", function () {
  54. $(this).closest("li").toggleClass("active", this.checked);
  55. });
  56. $(document).on('click', '.allow-focus', function (e) {
  57. e.stopPropagation();
  58. });
  59. $('.pagination a').click(function (e) {
  60. console.log(this.href.split('page=')[1]);
  61. $('.hidden-page').val(this.href.split('page=')[1]);
  62. $('.search-button').click();
  63. return false;
  64. });
  65. }
  66. function manageFormContact() {
  67. $('#contact_lccap').val('blop');
  68. $('#contact-form-btn').on('click', function () {
  69. if (checkFormValidity('#contact-form')) {
  70. $('#contact-form').fadeOut(200);
  71. $form = $('#contact-form');
  72. $.ajax({
  73. url: $form.prop('action'),
  74. method: $form.prop('method'),
  75. data: $form.serialize(),
  76. dataType: "json",
  77. success: function (response) {
  78. $('#contact-form').html('<p class="success-post">Merci pour votre message, nous vous r&eacute;pondrons dans les plus brefs d&eacute;lais.</p>');
  79. $('#contact-form').fadeIn(500);
  80. }
  81. });
  82. }
  83. });
  84. }
  85. function checkFormValidity(formId) {
  86. if (!document.getElementById(formId.substr(1)).checkValidity()) {
  87. document.getElementById(formId.substr(1)).reportValidity()
  88. return false;
  89. } else {
  90. return true;
  91. }
  92. }