Advertisement
Martupi8

Untitled

Apr 5th, 2022
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. <%--
  2. - list.tag
  3. -
  4. - Copyright (C) 2012-2022 Rafael Corchuelo.
  5. -
  6. - In keeping with the traditional purpose of furthering education and research, it is
  7. - the policy of the copyright owner to permit non-commercial use and redistribution of
  8. - this software. It has been tested carefully, but it is not guaranteed for any particular
  9. - purposes. The copyright owner does not offer any warranties or representations, nor do
  10. - they accept any liabilities with respect to them.
  11. --%>
  12.  
  13. <%@tag language="java" import="java.util.Collection,java.util.ArrayList,java.util.Map,acme.framework.helpers.JspHelper"%>
  14.  
  15. <%@taglib prefix="jstl" uri="http://java.sun.com/jsp/jstl/core"%>
  16. <%@taglib prefix="acme" uri="urn:jsptagdir:/WEB-INF/tags"%>
  17.  
  18. <%@attribute name="readonly" required="false" type="java.lang.Boolean"%>
  19.  
  20. <jstl:if test="${readonly == null}">
  21. <jstl:set var="readonly" value="false"/>
  22. </jstl:if>
  23.  
  24. <%
  25. Collection<Map<String, Object>> dataTableColumns;
  26. String mapName;
  27.  
  28. dataTableColumns = new ArrayList<Map<String, Object>>();
  29. request.setAttribute("__data_table_columns", dataTableColumns);
  30. %>
  31.  
  32. <table id="list" class="table table-striped table-condensed table-hover nowrap w-100">
  33. <jsp:doBody var="body"/>
  34. <thead>
  35. <tr>
  36. <th><%-- Placeholder for details button --%></th>
  37. <jstl:set var="aoColumns" value="'aoColumns': [ {'bSortable': false}"/>
  38. <jstl:forEach var="column" items="${__data_table_columns}">
  39. <th style="width: ${column.width}">
  40. <jstl:if test="${column.code != null}">
  41. <acme:message code="${column.code}"/>
  42. </jstl:if>
  43. <jstl:set var="aoColumns" value="${aoColumns}, {'bSortable': ${column.sortable}}"/>
  44. </th>
  45. </jstl:forEach>
  46. <jstl:set var="aoColumns" value="${aoColumns} ]"/>
  47. </tr>
  48. </thead>
  49. <tbody>
  50. <jstl:if test="${list$size >= 1}">
  51. <jstl:forEach var="index" begin="${0}" end="${list$size - 1}">
  52. <jstl:set var="index_id" value="id[${index}]"/>
  53. <tr data-item-id="${requestScope[index_id]}">
  54. <td><%-- Placeholder for details button --%></td>
  55. <jstl:forEach var="column" items="${__data_table_columns}">
  56. <jstl:set var="path" value="${column.path}"/>
  57. <jstl:set var="format" value="${column.format}"/>
  58. <jstl:set var="index_path" value="${path}[${index}]"/>
  59. <jstl:set var="dataSort" value="${JspHelper.computeDataSort(requestScope[index_path])}"/>
  60. <jstl:set var="dataText" value="${JspHelper.computeDataText(requestScope[index_path], format)}"/>
  61. <td ${dataSort}>
  62. <acme:print value="${dataText}"/>
  63. </td>
  64. </jstl:forEach>
  65. </tr>
  66. </jstl:forEach>
  67. </jstl:if>
  68. </tbody>
  69. </table>
  70.  
  71. <acme:return/>
  72.  
  73. <acme:message var="i18nFileUri" code="default.datatables.language"/>
  74. <jstl:set var="language" value="'language': { 'url': getAbsoluteUrl('${i18nFileUri}') }"/>
  75.  
  76. <script type="text/javascript">
  77. $(document).ready(function() {
  78. var table;
  79.  
  80. table = $("#list").dataTable({
  81. "lengthMenu": [5, 10, 25, 50],
  82. "pageLength": 5,
  83. "pagingType": "numbers",
  84. "stateSave": true,
  85. "responsive": { details: { type: "column" } },
  86. "columnDefs": [ { className: "control", orderable: false, targets: 0 } ],
  87. "dom": "<'row'<'col'f><'col'i>>" +
  88. "<'row'<'col'tr>>" +
  89. "<'row'<'col'l><'col'p>>",
  90. "order": [[ 0, "asc" ]],
  91. <jstl:out value="${language}" escapeXml="false"/>,
  92. <jstl:out value="${aoColumns}" escapeXml="false"/>,
  93. });
  94.  
  95. <jstl:if test="${!readonly}">
  96. $("#list tbody").on("click", "td", function () {
  97. var id, row, column, singleColumn;
  98.  
  99. row = $(this).parent().parent().children().index($(this).parent());
  100. column = $(this).parent().children().index($(this));
  101. singleColumn = $(this).parent().children().length == 1;
  102.  
  103. if (singleColumn || column >= 1) {
  104. id = $(this).parent().attr("data-item-id")
  105. if (typeof(id) != 'undefined') {
  106. pushReturnUrl("<%=JspHelper.getRequestUrl(request)%>");
  107. redirect("show?id={0}".format(id));
  108. }
  109. }
  110. });
  111. </jstl:if>
  112. });
  113. </script>
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement