summaryrefslogtreecommitdiffstats
path: root/lib/db-viewtable-html.lsp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/db-viewtable-html.lsp')
-rw-r--r--lib/db-viewtable-html.lsp111
1 files changed, 111 insertions, 0 deletions
diff --git a/lib/db-viewtable-html.lsp b/lib/db-viewtable-html.lsp
new file mode 100644
index 0000000..3bde35e
--- /dev/null
+++ b/lib/db-viewtable-html.lsp
@@ -0,0 +1,111 @@
+<% local form, viewlibrary, page_info, session = ... %>
+<% htmlviewfunctions = require("htmlviewfunctions") %>
+<% html = require("acf.html") %>
+
+<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>
+
+<%
+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
+%>
+
+<% htmlviewfunctions.displaycommandresults({"deletetableentry", "updatetableentry"}, session) %>
+<% htmlviewfunctions.displaycommandresults({"createtableentry"}, session, true) %>
+
+<% if form.value.table.value ~= "" then form.label = form.label.." - "..form.value.table.value end %>
+<% local header_level = htmlviewfunctions.displaysectionstart(form, page_info) %>
+<%
+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))
+%>
+<table id="list" class="tablesorter"><thead>
+ <tr>
+ <% if viewlibrary.check_permission("deletetableentry") or viewlibrary.check_permission("updatetableentry") then %>
+ <th>Action</th>
+ <% end %>
+ <% for i,f in ipairs(form.value.fields.value) do %>
+ <th><%= html.html_escape(f) %></th>
+ <% end %>
+ </tr>
+</thead><tbody>
+<% -- 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
+if form.value.keyfields then
+ formvalues.fields = cfe({ type="group", value={} })
+ for i,f in ipairs(form.value.keyfields.value) do
+ formvalues.fields.value[f] = cfe({ type="hidden" })
+ end
+end
+formvalues.table = form.value.table
+form.value.table.type = "hidden"
+formvalues.redir = redir
+%>
+<% for i,tableentry in ipairs(form.value.entries.value) do %>
+ <tr>
+ <% if viewlibrary.check_permission("deletetableentry") or viewlibrary.check_permission("updatetableentry") then %>
+ <%
+ if formvalues.fields then
+ for i,f in ipairs(form.value.keyfields.value) do
+ formvalues.fields.value[f].value = tableentry[f]
+ end
+ end
+ %>
+ <td>
+ <% if viewlibrary.check_permission("updatetableentry") then %>
+ <% htmlviewfunctions.displayitem(cfe({type="link", value=formvalues, label="", option="Update", action="updatetableentry"}), page_info, -1) %>
+ <% end %>
+ <% if viewlibrary.check_permission("deletetableentry") then %>
+ <% htmlviewfunctions.displayitem(cfe({type="form", value=formvalues, label="", option="Delete", action="deletetableentry", class="deletetableentry"}), page_info, -1) %>
+ <% end %>
+ </td>
+ <% end %>
+ <% for i,f in ipairs(form.value.fields.value) do %>
+ <td><%= html.html_escape(tableentry[f]) %></td>
+ <% end %>
+ </tr>
+<% end %>
+</tbody></table>
+<% htmlviewfunctions.displayinfo(form) %>
+<% if #form.value.entries.value == 0 then %>
+<p>No entries found</p>
+<% end %>
+<% htmlviewfunctions.displaysectionend(header_level) %>
+
+<% if page_info.action == "viewtable" and viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createtableentry") then
+ viewlibrary.dispatch_component("createtableentry", keyvalues)
+end %>