Commit b38802fa authored by Ted Trask's avatar Ted Trask

Reworked the code to allow passing in connection parameters

parent 375ed538
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<% htmlviewfunctions = require("htmlviewfunctions") %> <% htmlviewfunctions = require("htmlviewfunctions") %>
<% html = require("acf.html") %> <% html = require("acf.html") %>
<% if #form.value>0 then %> <% if form.value.databases and #form.value.databases.value>0 then %>
<script type="text/javascript"> <script type="text/javascript">
if (typeof jQuery == 'undefined') { if (typeof jQuery == 'undefined') {
document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"><\/script>'); document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"><\/script>');
...@@ -23,21 +23,39 @@ ...@@ -23,21 +23,39 @@
<% end %> <% end %>
<% local header_level = htmlviewfunctions.displaysectionstart(form, page_info) %> <% local header_level = htmlviewfunctions.displaysectionstart(form, page_info) %>
<% htmlviewfunctions.displayinfo(form) %> <% if form.value.connection then
<% if #form.value>0 then %> -- hide the database, user, and password, since we don't need them to list databases
form.value.connection.value.database = nil
form.value.connection.value.user = nil
form.value.connection.value.password = nil
end %>
<% if form.value.connection and next(form.value.connection.value) ~= nil then
htmlviewfunctions.displayformstart(form, page_info)
htmlviewfunctions.displayitem(form.value.connection, page_info, htmlviewfunctions.incrementheader(header_level), "connection")
form.option = "Update"
htmlviewfunctions.displayformend(form, htmlviewfunctions.incrementheader(header_level))
end %>
<% if form.value.databases and #form.value.databases.value>0 then %>
<table id="listdatabases" class="tablesorter"><thead> <table id="listdatabases" class="tablesorter"><thead>
<tr> <tr>
<th>Action</th> <th>Action</th>
<th>Database</th> <th>Database</th>
</tr> </tr>
</thead><tbody> </thead><tbody>
<% local database = cfe({ type="hidden" }) %> <% -- We need to pass the connection key values to listtables
<% for i,dbase in ipairs(form.value) do %> local formvalues = {}
<% database.value = dbase %> 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
form.value.connection.value.database = cfe({ type="hidden" })
%>
<% for i,dbase in ipairs(form.value.databases.value) do %>
<% formvalues.connection.value.database.value = dbase %>
<tr> <tr>
<td> <td>
<% if viewlibrary.check_permission("listtables") then %> <% if viewlibrary.check_permission("listtables") then %>
<% htmlviewfunctions.displayitem(cfe({type="link", value={database=database}, label="", option="View", action="listtables"}), page_info, -1) %> <% htmlviewfunctions.displayitem(cfe({type="link", value=formvalues, label="", option="View", action="listtables"}), page_info, -1) %>
<% end %> <% end %>
</td> </td>
<td><%= html.html_escape(dbase) %></td> <td><%= html.html_escape(dbase) %></td>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<% htmlviewfunctions = require("htmlviewfunctions") %> <% htmlviewfunctions = require("htmlviewfunctions") %>
<% html = require("acf.html") %> <% html = require("acf.html") %>
<% if #form.value>0 then %> <% if form.value.tables and #form.value.tables.value>0 then %>
<script type="text/javascript"> <script type="text/javascript">
if (typeof jQuery == 'undefined') { if (typeof jQuery == 'undefined') {
document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"><\/script>'); document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"><\/script>');
...@@ -25,21 +25,33 @@ ...@@ -25,21 +25,33 @@
<% htmlviewfunctions.displaycommandresults({"createdatabase"}, session) %> <% htmlviewfunctions.displaycommandresults({"createdatabase"}, session) %>
<% local header_level = htmlviewfunctions.displaysectionstart(form, page_info) %> <% local header_level = htmlviewfunctions.displaysectionstart(form, page_info) %>
<% htmlviewfunctions.displayinfo(form) %> <% if form.value.connection and next(form.value.connection.value) ~= nil then
<% if #form.value>0 then %> htmlviewfunctions.displayformstart(form, page_info)
htmlviewfunctions.displayitem(form.value.connection, page_info, htmlviewfunctions.incrementheader(header_level), "connection")
form.option = "Update"
htmlviewfunctions.displayformend(form, htmlviewfunctions.incrementheader(header_level))
end %>
<% if form.value.tables and #form.value.tables.value>0 then %>
<table id="listtables" class="tablesorter"><thead> <table id="listtables" class="tablesorter"><thead>
<tr> <tr>
<th>Action</th> <th>Action</th>
<th>Table</th> <th>Table</th>
</tr> </tr>
</thead><tbody> </thead><tbody>
<% local table = cfe({ type="hidden" }) %> <% -- We will reuse the form connection structure to pass key values to viewtable
<% for i,tab in ipairs(form.value) do %> local formvalues = {}
<% table.value = tab %> 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
formvalues.table = cfe({ type="hidden" })
%>
<% for i,tab in ipairs(form.value.tables.value) do %>
<% formvalues.table.value = tab %>
<tr> <tr>
<td> <td>
<% if viewlibrary.check_permission("viewtable") then %> <% if viewlibrary.check_permission("viewtable") then %>
<% htmlviewfunctions.displayitem(cfe({type="link", value={table=table}, label="", option="View", action="viewtable"}), page_info, -1) %> <% htmlviewfunctions.displayitem(cfe({type="link", value=formvalues, label="", option="View", action="viewtable"}), page_info, -1) %>
<% end %> <% end %>
</td> </td>
<td><%= html.html_escape(tab) %></td> <td><%= html.html_escape(tab) %></td>
......
...@@ -21,13 +21,34 @@ ...@@ -21,13 +21,34 @@
}); });
</script> </script>
<% local redir = cfe({ type="hidden", value=page_info.orig_action.."?table="..html.url_encode(form.value.table.value) }) %> <%
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({"deletetableentry", "updatetableentry"}, session) %>
<% htmlviewfunctions.displaycommandresults({"createtableentry"}, session, true) %> <% htmlviewfunctions.displaycommandresults({"createtableentry"}, session, true) %>
<% form.label = form.label.." - "..form.value.table.value %> <% 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_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> <table id="list" class="tablesorter"><thead>
<tr> <tr>
<% if viewlibrary.check_permission("deletetableentry") or viewlibrary.check_permission("updatetableentry") then %> <% if viewlibrary.check_permission("deletetableentry") or viewlibrary.check_permission("updatetableentry") then %>
...@@ -38,18 +59,32 @@ ...@@ -38,18 +59,32 @@
<% end %> <% end %>
</tr> </tr>
</thead><tbody> </thead><tbody>
<% local table = cfe({ type="hidden", value=form.value.table.value }) %> <% -- We will reuse the form connection structure to pass key values to updatetableentry and deletetableentry
<% local id = cfe({ type="hidden" }) %> 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.fields then
formvalues.fields = cfe({ type="group", value={} })
for i,f in ipairs(form.value.fields.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 %> <% for i,tableentry in ipairs(form.value.entries.value) do %>
<tr> <tr>
<% if viewlibrary.check_permission("deletetableentry") or viewlibrary.check_permission("updatetableentry") then %> <% if viewlibrary.check_permission("deletetableentry") or viewlibrary.check_permission("updatetableentry") then %>
<% id.value = tableentry.id %> <% formvalues.fields.value.id.value = tableentry.id %>
<td> <td>
<% if viewlibrary.check_permission("updatetableentry") then %> <% if viewlibrary.check_permission("updatetableentry") then %>
<% htmlviewfunctions.displayitem(cfe({type="link", value={table=table, id=id, redir=redir}, label="", option="Update", action="updatetableentry"}), page_info, -1) %> <% htmlviewfunctions.displayitem(cfe({type="link", value=formvalues, label="", option="Update", action="updatetableentry"}), page_info, -1) %>
<% end %> <% end %>
<% if viewlibrary.check_permission("deletetableentry") then %> <% if viewlibrary.check_permission("deletetableentry") then %>
<% htmlviewfunctions.displayitem(cfe({type="form", value={table=table, id=id, redir=redir}, label="", option="Delete", action="deletetableentry", class="deletetableentry"}), page_info, -1) %> <% htmlviewfunctions.displayitem(cfe({type="form", value=formvalues, label="", option="Delete", action="deletetableentry", class="deletetableentry"}), page_info, -1) %>
<% end %> <% end %>
</td> </td>
<% end %> <% end %>
...@@ -66,5 +101,5 @@ ...@@ -66,5 +101,5 @@
<% htmlviewfunctions.displaysectionend(header_level) %> <% htmlviewfunctions.displaysectionend(header_level) %>
<% if page_info.action == "viewtable" and viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createtableentry") then <% 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, redir=redir.value}) viewlibrary.dispatch_component("createtableentry", keyvalues)
end %> end %>
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment