diff options
author | Ted Trask <ttrask01@yahoo.com> | 2014-04-10 07:23:16 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2014-04-10 07:23:16 +0000 |
commit | 42029e2ecdb3c68f10a567e0724490c726f70f14 (patch) | |
tree | 7d72b173b212fd3df85194c2fa70c5809182b13e | |
parent | 05c8091293f3099354471017801f248f9080bd34 (diff) | |
download | acf-kamailio-42029e2ecdb3c68f10a567e0724490c726f70f14.tar.bz2 acf-kamailio-42029e2ecdb3c68f10a567e0724490c726f70f14.tar.xz |
Changes to use new htmlviewfunctions functions and make searchdatabase a proper form
-rw-r--r-- | kamailio-controller.lua | 2 | ||||
-rw-r--r-- | kamailio-listfiles-html.lsp | 36 | ||||
-rw-r--r-- | kamailio-listusers-html.lsp | 10 | ||||
-rw-r--r-- | kamailio-model.lua | 39 | ||||
-rw-r--r-- | kamailio-searchdatabase-html.lsp | 3 |
5 files changed, 64 insertions, 26 deletions
diff --git a/kamailio-controller.lua b/kamailio-controller.lua index 9397359..985eb39 100644 --- a/kamailio-controller.lua +++ b/kamailio-controller.lua @@ -40,7 +40,7 @@ function mymodule.createdatabase(self) end function mymodule.searchdatabase(self) - return self.model.search_database(self.clientdata.id, self.clientdata.value, self.clientdata.comparison) + return self.handle_form(self, self.model.get_search_database, self.model.search_database, self.clientdata, "Search", "Search Database") end -- Use acf-db to allow editing of the database diff --git a/kamailio-listfiles-html.lsp b/kamailio-listfiles-html.lsp index 564dcce..c2ebfb2 100644 --- a/kamailio-listfiles-html.lsp +++ b/kamailio-listfiles-html.lsp @@ -3,6 +3,20 @@ htmlviewfunctions = require("htmlviewfunctions") html = require("acf.html") %> +<% +function convertsize(size) + if string.find(size, "k$") then + return tonumber(string.match(size, "[%d.]*")) * 1024.0 + elseif string.find(size, "M$") then + return tonumber(string.match(size, "[%d.]*")) * 1024.0 * 1024.0 + elseif string.find(size, "G$") then + return tonumber(string.match(size, "[%d.]*")) + 1024.0 * 1024.0 * 1024.0 + else + return tonumber(string.match(size, "[%d.]*")) + end +end +%> + <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>'); @@ -17,7 +31,7 @@ html = require("acf.html") <script type="text/javascript"> $(document).ready(function() { - $("#list").tablesorter({widgets: ['zebra']}); + $("#list").tablesorter({headers: {0:{sorter: false}}, widgets: ['zebra']}); }); </script> @@ -27,17 +41,25 @@ html = require("acf.html") viewlibrary.dispatch_component("status") end %> -<h1>Configuration</h1> +<% local header_level = htmlviewfunctions.displaysectionstart(cfe({label="Configuration"}), page_info) %> <table id="list" class="tablesorter"><thead> <tr> + <th>Action</th> <th>File</th> <th>Size</th> <th>Last Modified</th> </tr> </thead><tbody> -<% - for k,v in ipairs( view.value ) do - io.write( "<tr><td><a href=\"" .. html.html_escape(page_info.script .. page_info.prefix .. page_info.controller) .. "/edit?filename=" .. html.html_escape(v.filename) .. "&redir=" .. html.html_escape(page_info.orig_action) .. "\">" .. html.html_escape(v.filename) .. "</a></td><td>" .. html.html_escape(v.size) .."</td><td>" .. html.html_escape(v.mtime) .."</td></tr>\n" ) - end -%> +<% local filename = cfe({ type="hidden", value="" }) %> +<% local redir = cfe({ type="hidden", value=page_info.orig_action }) %> +<% for i,file in ipairs( view.value ) do %> + <% filename.value = file.filename %> + <tr> + <td><% htmlviewfunctions.displayitem(cfe({type="link", value={filename=filename, redir=redir}, label="", option="Edit", action="edit"}), page_info, -1) %></td> + <td><%= html.html_escape(file.filename) %></td> + <td><span style="display:none"><%= convertsize(file.size) %>b</span><%= html.html_escape(file.size) %></td> + <td><%= html.html_escape(file.mtime) %></td> + </tr> +<% end %> </tbody></table> +<% htmlviewfunctions.displaysectionend(header_level) %> diff --git a/kamailio-listusers-html.lsp b/kamailio-listusers-html.lsp index 0b7183f..47b7c2d 100644 --- a/kamailio-listusers-html.lsp +++ b/kamailio-listusers-html.lsp @@ -27,7 +27,7 @@ <% htmlviewfunctions.displaycommandresults({"deleteuser", "updateuser"}, session) %> <% htmlviewfunctions.displaycommandresults({"createuser"}, session, true) %> -<h1><%= html.html_escape(form.label) %></h1> +<% local header_level = htmlviewfunctions.displaysectionstart(form, page_info) %> <table id="list" class="tablesorter"><thead> <tr> <% if viewlibrary.check_permission("deleteuser") or viewlibrary.check_permission("updateuser") then %> @@ -37,15 +37,18 @@ <th>Password</th> </tr> </thead><tbody> +<% local username = cfe({ type="hidden", value="" }) %> +<% local redir = cfe({ type="hidden", value=page_info.orig_action }) %> <% for i,user in ipairs(form.value) do %> <tr> + <% username.value = user.username %> <% if viewlibrary.check_permission("deleteuser") or viewlibrary.check_permission("updateuser") then %> <td> <% if viewlibrary.check_permission("updateuser") then %> - <%= html.link{value = "updateuser?username=" .. user.username.."&redir="..page_info.orig_action, label="Update "} %> + <% htmlviewfunctions.displayitem(cfe({type="link", value={username=username, redir=redir}, label="", option="Update", action="updateuser"}), page_info, -1) %> <% end %> <% if viewlibrary.check_permission("deleteuser") then %> - <%= html.link{value = "deleteuser?submit=true&username=" .. user.username, label="Delete "} %> + <% htmlviewfunctions.displayitem(cfe({type="form", value={username=username}, label="", option="Delete", action="deleteuser"}), page_info, -1) %> <% end %> </td> <% end %> @@ -58,6 +61,7 @@ </tr> <% end %> </tbody></table> +<% htmlviewfunctions.displaysectionend(header_level) %> <% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createuser") then viewlibrary.dispatch_component("createuser") diff --git a/kamailio-model.lua b/kamailio-model.lua index 089c465..587f7ad 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -285,12 +285,12 @@ function mymodule.create_database(self, create_db) return create_db end -function mymodule.search_database(id, value, comparison) +function mymodule.get_search_database(self, clientdata) local errtxt retval = {} - retval.id = cfe({type="select", value=id or "", label="Table.Column", option={}, seq=1}) - retval.comparison = cfe({type="select", value=comparison or "=", label="Comparison", option={"=", "!=", "~", "!~", "~*", "!*~"}, seq=2}) - retval.value = cfe({label="Value", value=value or "", descr="Value or SQL regular expression", seq=3}) + retval.id = cfe({type="select", value=clientdata.id or "", label="Table.Column", option={}, seq=1}) + retval.comparison = cfe({type="select", value=clientdata.comparison or "=", label="Comparison", option={"=", "!=", "~", "!~", "~*", "!*~"}, seq=2}) + retval.value = cfe({label="Value", value=clientdata.value or "", descr="Value or SQL regular expression", seq=3}) local res, err = pcall(function() local connected = databaseconnect() local tables = dbkam.listtables() or {} @@ -300,15 +300,6 @@ function mymodule.search_database(id, value, comparison) retval.id.option[#retval.id.option + 1] = t.."."..c end end - -- Get the rows from the DB - if id and modelfunctions.validateselect(retval.id) and modelfunctions.validateselect(retval.comparison) then - retval.result = cfe({type="structure", value={}, label="List of Rows", seq=4 }) - local table, column = string.match(id, "^([^.]*)%.(.*)") - if table then - local sql = "SELECT * FROM "..dbkam.escape(table).." WHERE "..dbkam.escape(column)..dbkam.escape(comparison).."'"..dbkam.escape(value).."'" - retval.result.value = getselectresponse(sql) - end - end if connected then databasedisconnect() end end) if not res and err then @@ -317,6 +308,28 @@ function mymodule.search_database(id, value, comparison) return cfe({type="group", value=retval, label="Database Search", errtxt=errtxt}) end +function mymodule.search_database(self, search) + if modelfunctions.validateselect(search.value.id) and modelfunctions.validateselect(search.value.comparison) then + local res, err = pcall(function() + local connected = databaseconnect() + -- Get the rows from the DB + search.value.result = cfe({type="structure", value={}, label="List of Rows", seq=4 }) + local table, column = string.match(search.value.id.value, "^([^.]*)%.(.*)") + if table then + local sql = "SELECT * FROM "..dbkam.escape(table).." WHERE "..dbkam.escape(column)..dbkam.escape(search.value.comparison.value).."'"..dbkam.escape(search.value.value.value).."'" + search.value.result.value = getselectresponse(sql) + end + if connected then databasedisconnect() end + end) + if not res and err then + search.errtxt = err + end + else + search.errtxt = "Failed to search database" + end + return search +end + for n,f in pairs(dbmodelfunctions) do mymodule[n] = function(...) databasecreate() diff --git a/kamailio-searchdatabase-html.lsp b/kamailio-searchdatabase-html.lsp index 257626d..2c2a71f 100644 --- a/kamailio-searchdatabase-html.lsp +++ b/kamailio-searchdatabase-html.lsp @@ -21,9 +21,8 @@ html = require("acf.html") form.value.fields = nil end %> -<h1><%= html.html_escape(form.label) %></h1> <% form.value.result = nil form.option = "Search" - htmlviewfunctions.displayform(form, nil, nil, page_info, 2) + htmlviewfunctions.displayitem(form, page_info) %> |