db-viewtable-html.lsp 2.93 KB
Newer Older
1
<% local form, viewlibrary, page_info, session = ... %>
2
<% htmlviewfunctions = require("htmlviewfunctions") %>
3 4
<% html = require("acf.html") %>

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<script type="text/javascript">
	if (typeof jQuery == 'undefined') {
		document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"><\/script>');
	}
</script>

<script type="text/javascript">
	if (typeof $.tablesorter == 'undefined') {
		document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery.tablesorter.js"><\/script>');
	}
</script>

<script type="text/javascript">
	$(document).ready(function() {
		$("#list").tablesorter({widgets: ['zebra']});
		$(".deletetableentry").click(function(){ return confirm("Are you sure you want to delete this entry?")});
	});
</script>

24 25 26
<% htmlviewfunctions.displaycommandresults({"deletetableentry", "updatetableentry"}, session) %>
<% htmlviewfunctions.displaycommandresults({"createtableentry"}, session, true) %>

27 28 29 30
<% form.label = form.label.." - "..form.value.table.value %>
<% local header_level = htmlviewfunctions.displaysectionstart(form, page_info) %>
<table id="list" class="tablesorter"><thead>
	<tr>
31
	<% if viewlibrary.check_permission("deletetableentry") or viewlibrary.check_permission("updatetableentry") then %>
32
		<th>Action</th>
33 34
	<% end %>
	<% for i,f in ipairs(form.value.fields.value) do %>
35
		<th><%= html.html_escape(f) %></th>
36
	<% end %>
37 38 39 40 41
	</tr>
</thead><tbody>
<% local redir = cfe({ type="hidden", value=page_info.orig_action.."?table="..form.value.table.value }) %>
<% local table = cfe({ type="hidden", value=form.value.table.value }) %>
<% local id = cfe({ type="hidden" }) %>
42
<% for i,tableentry in ipairs(form.value.entries.value) do %>
43
	<tr>
44
	<% if viewlibrary.check_permission("deletetableentry") or viewlibrary.check_permission("updatetableentry") then %>
45 46
		<% id.value = tableentry.id %>
		<td>
47
	<% if viewlibrary.check_permission("updatetableentry") then %>
48
		<% htmlviewfunctions.displayitem(cfe({type="link", value={table=table, id=id, redir=redir}, label="", option="Update", action="updatetableentry"}), page_info, -1) %>
49 50
	<% end %>
	<% if viewlibrary.check_permission("deletetableentry") then %>
51
		<% htmlviewfunctions.displayitem(cfe({type="form", value={table=table, id=id}, label="", option="Delete", action="deletetableentry", class="deletetableentry"}), page_info, -1) %>
52
	<% end %>
53
		</td>
54 55
	<% end %>
	<% for i,f in ipairs(form.value.fields.value) do %>
56
		<td><%= html.html_escape(tableentry[f]) %></td>
57
	<% end %>
58
	</tr>
59
<% end %>
60 61
</tbody></table>
<% htmlviewfunctions.displayinfo(form) %>
62 63 64
<% if #form.value.entries.value == 0 then %>
<p>No entries found</p>
<% end %>
65
<% htmlviewfunctions.displaysectionend(header_level) %>
66 67 68 69

<% if page_info.action == "viewtable" and viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createtableentry") then
	viewlibrary.dispatch_component("createtableentry", {table=form.value.table.value})
end %>