abonnes.jsp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@ taglib prefix="tag" tagdir="/WEB-INF/tags" %>
  4. <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  5. <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
  6. <c:set var="req" value="${pageContext.request}" />
  7. <c:set var="url">${req.requestURL}</c:set>
  8. <c:set var="base" value="${fn:substring(url, 0, fn:length(url) - fn:length(req.requestURI))}${req.contextPath}/" />
  9. <!DOCTYPE html>
  10. <html>
  11. <head>
  12. <tag:head title="Abonnés" />
  13. </head>
  14. <body class="grey lighten-3">
  15. <!-- Header -->
  16. <tag:header active="abonnes" />
  17. <!-- Main -->
  18. <main class="container">
  19. <div class="row">
  20. <div class="col s12 center-align">
  21. <h3>Abonn&eacute;s</h3>
  22. </div>
  23. </div>
  24. <div class="row">
  25. <div id="abo" class="col s12 center-align"></div>
  26. </div>
  27. <div class="row">
  28. <div id="pagination-abo" class="col s12 center-align"></div>
  29. </div>
  30. </main>
  31. <!-- Footer -->
  32. <tag:footer />
  33. <!-- Confirmation -->
  34. <div id="confirmation" class="modal conf">
  35. <div class="modal-content">
  36. <div class="row">
  37. <div class="col offset-m1 m3 mtop-4">
  38. <i class="material-icons red-text" style="font-size: 8em;">warning</i>
  39. </div>
  40. <div class="col m7 s12 mtop-3">
  41. <h4>Confirmer la suppression de <span id="conf-user"></span> ?</h4>
  42. <p style="font-size:1.2em">La suppression est d&eacute;finitive et aucun retour en arri&egrave;re n'est possible</p>
  43. </div>
  44. </div>
  45. </div>
  46. <div class="modal-footer">
  47. <a href="#!" class="modal-close waves-effect waves-red btn-flat">Annuler</a>
  48. <a href="#!" id="conf-delete" class="modal-close waves-effect waves-light btn">Confirmer</a>
  49. </div>
  50. </div>
  51. <!-- Popup -->
  52. <div id="ok-popup" class="modal popup">
  53. <div class="modal-content" style="overflow: hidden;">
  54. <div class="row">
  55. <div class="col offset-m1 m3 s12">
  56. <i class="material-icons green-text" style="font-size: 8em;">check_circle</i>
  57. </div>
  58. <div class="col m7 s12 mtop-3">
  59. <h4 id="ok-text">Success message</h4>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. <div id="err-popup" class="modal popup">
  65. <div class="modal-content" style="overflow: hidden;">
  66. <div class="row">
  67. <div class="col offset-m1 m3 s12">
  68. <i class="material-icons red-text" style="font-size: 8em;">error</i>
  69. </div>
  70. <div class="col m7 s12 mtop-3">
  71. <h4 id="error-text">Error message</h4>
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76. <!-- Loader -->
  77. <tag:loader name="loader" />
  78. <!-- Script -->
  79. <tag:script />
  80. <script type="text/javascript">
  81. $(document).ready(() => {
  82. const loader = M.Modal.getInstance($('#loader'));
  83. const okPopup = M.Modal.getInstance($('#ok-popup'));
  84. const errPopup = M.Modal.getInstance($('#err-popup'));
  85. const conf = M.Modal.getInstance($('#confirmation'));
  86. const idPagination = 'usager';
  87. const perPage = 5;
  88. var page = 1;
  89. function pagine(numPage) {
  90. numPage = numPage || page;
  91. loader.open();
  92. $.ajax({
  93. type: "GET",
  94. url: "${base}api/usager/page/" + numPage + "/" + perPage + "/formatted/pagination",
  95. error: () => {
  96. loader.close();
  97. pagination(idPagination, numPage, perPage, 0, $('#abo'), $('#pagination-abo'), []);
  98. let html = '<tr>';
  99. html += '<td class="right-align red-text" width="40%"><i class="material-icons" style="font-size:4em;padding-top:.3em;">error</i></td>';
  100. html += '<td class="left-align red-text" width="60%"><h4>Impossible de charger les usager</td>';
  101. html += '</tr>';
  102. $('#pagination-' + idPagination + '-table').html(html);
  103. },
  104. success: (result) => {
  105. loader.close();
  106. if (result.data.list.length > 0) {
  107. pagination(idPagination, numPage, perPage, result.data.total, $('#abo'), $('#pagination-abo'), result.data.list, 'responsive-table striped', 'action');
  108. $('.tooltipped').tooltip();
  109. } else {
  110. pagination(idPagination, numPage, perPage, 0, $('#abo'), $('#pagination-abo'), []);
  111. let html = '<tr>';
  112. html += '<td class="right-align blue-text" width="40%"><i class="material-icons" style="font-size:4em;padding-top:.3em;">info</i></td>';
  113. html += '<td class="left-align blue-text" width="60%"><h4>Aucun usager</td>';
  114. html += '</tr>';
  115. $('#pagination-' + idPagination + '-table').html(html);
  116. }
  117. },
  118. });
  119. };
  120. pagine(page);
  121. // Detection changement page
  122. $('main').on('click', '.pagination-' + idPagination + '-prev', function () {
  123. console.log(idPagination, 'prev', $(this).attr('data-page'));
  124. page = $(this).attr('data-page');
  125. pagine(page);
  126. });
  127. $('main').on('click', '.pagination-' + idPagination + '-next', function () {
  128. console.log('abo', 'next', $(this).attr('data-page'));
  129. page = $(this).attr('data-page');
  130. pagine(page);
  131. });
  132. $('main').on('click', '.pagination-' + idPagination + '-number', function () {
  133. console.log('abo', 'num', $(this).attr('data-page'));
  134. page = $(this).attr('data-page');
  135. pagine(page);
  136. });
  137. // Suppr abonne
  138. $('#abo').on('click', '.delete-usager', function () {
  139. $("#conf-user").html($(this).attr('data-usager'));
  140. $("#conf-delete").attr('data-code', $(this).attr('data-code'));
  141. conf.open();
  142. });
  143. $('#conf-delete').on('click', function () {
  144. loader.open();
  145. $.ajax({
  146. type: "DELETE",
  147. url: "${base}api/usager/" + $(this).attr('data-code'),
  148. error: () => {
  149. loader.close();
  150. $('#error-text').html('Une erreur est survenue');
  151. errPopup.open();
  152. },
  153. success: (result) => {
  154. loader.close();
  155. if (result.success) {
  156. $('#ok-text').html(result.data.msg);
  157. okPopup.open();
  158. pagine();
  159. } else {
  160. $('#error-text').html(result.data);
  161. errPopup.open();
  162. }
  163. },
  164. });
  165. })
  166. });
  167. </script>
  168. </body>
  169. </html>