db-viewtable-html.lsp 4.29 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 27 28 29 30 31 32 33 34 35
<%
local redir = cfe({ type="hidden", value=page_info.orig_action.."?table="..html.url_encode(form.value.table.value) })
local keyvalues = {table=form.value.table.value}
if form.value.connection then
	keyvalues.connection = {}
	for n,v in pairs(form.value.connection.value) do
		redir.value = redir.value.."&connection."..n.."="..html.url_encode(v.value)
		keyvalues.connection[n] = v.value
	end
end
keyvalues.redir = redir.value
%>
36

37 38 39
<% htmlviewfunctions.displaycommandresults({"deletetableentry", "updatetableentry"}, session) %>
<% htmlviewfunctions.displaycommandresults({"createtableentry"}, session, true) %>

40
<% if form.value.table.value ~= "" then form.label = form.label.." - "..form.value.table.value end %>
41
<% local header_level = htmlviewfunctions.displaysectionstart(form, page_info) %>
42 43 44 45 46 47 48 49 50 51
<%
local header_level2 = htmlviewfunctions.incrementheader(header_level)
htmlviewfunctions.displayformstart(form, page_info)
if form.value.connection and next(form.value.connection.value) ~= nil then
	htmlviewfunctions.displayitem(form.value.connection, page_info, header_level2, "connection")
end
htmlviewfunctions.displayitem(form.value.table, page_info, header_level2, "table")
form.option = "Update"
htmlviewfunctions.displayformend(form, htmlviewfunctions.incrementheader(header_level))
%>
52 53
<table id="list" class="tablesorter"><thead>
	<tr>
54
	<% if viewlibrary.check_permission("deletetableentry") or viewlibrary.check_permission("updatetableentry") then %>
55
		<th>Action</th>
56 57
	<% end %>
	<% for i,f in ipairs(form.value.fields.value) do %>
58
		<th><%= html.html_escape(f) %></th>
59
	<% end %>
60 61
	</tr>
</thead><tbody>
62 63 64 65 66 67
<% -- We will reuse the form connection structure to pass key values to updatetableentry and deletetableentry
local formvalues = {}
if form.value.connection then
	formvalues.connection = form.value.connection
	for n,v in pairs(form.value.connection.value) do v.type="hidden" end
end
68
if form.value.keyfields then
69
	formvalues.fields = cfe({ type="group", value={} })
70
	for i,f in ipairs(form.value.keyfields.value) do
71 72 73 74 75 76 77
		formvalues.fields.value[f] = cfe({ type="hidden" })
	end
end
formvalues.table = form.value.table
form.value.table.type = "hidden"
formvalues.redir = redir
%>
78
<% for i,tableentry in ipairs(form.value.entries.value) do %>
79
	<tr>
80
	<% if viewlibrary.check_permission("deletetableentry") or viewlibrary.check_permission("updatetableentry") then %>
81 82 83 84 85 86 87
		<%
		if formvalues.fields then
			for i,f in ipairs(form.value.keyfields.value) do
				formvalues.fields.value[f].value = tableentry[f]
			end
		end
		%>
88
		<td>
89
	<% if viewlibrary.check_permission("updatetableentry") then %>
90
		<% htmlviewfunctions.displayitem(cfe({type="link", value=formvalues, label="", option="Update", action="updatetableentry"}), page_info, -1) %>
91 92
	<% end %>
	<% if viewlibrary.check_permission("deletetableentry") then %>
93
		<% htmlviewfunctions.displayitem(cfe({type="form", value=formvalues, label="", option="Delete", action="deletetableentry", class="deletetableentry"}), page_info, -1) %>
94
	<% end %>
95
		</td>
96 97
	<% end %>
	<% for i,f in ipairs(form.value.fields.value) do %>
98
		<td><%= html.html_escape(tableentry[f]) %></td>
99
	<% end %>
100
	</tr>
101
<% end %>
102 103
</tbody></table>
<% htmlviewfunctions.displayinfo(form) %>
104 105 106
<% if #form.value.entries.value == 0 then %>
<p>No entries found</p>
<% end %>
107
<% htmlviewfunctions.displaysectionend(header_level) %>
108 109

<% if page_info.action == "viewtable" and viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createtableentry") then
110
	viewlibrary.dispatch_component("createtableentry", keyvalues)
111
end %>