Commit 57f6d90a authored by Ted Trask's avatar Ted Trask

Remove all calls to 'module' in preparation for move to Lua 5.2

Use mymodule parameter for module definition.
parent 064ab9ab
module(..., package.seeall) local mymodule = {}
function listdatabases(self) function mymodule.listdatabases(self)
return self.model.list_databases(self, self.clientdata) return self.model.list_databases(self, self.clientdata)
end end
function listtables(self) function mymodule.listtables(self)
return self.model.list_tables(self, self.clientdata) return self.model.list_tables(self, self.clientdata)
end end
function viewtable(self) function mymodule.viewtable(self)
return self.model.list_table_entries(self, self.clientdata) return self.model.list_table_entries(self, self.clientdata)
end end
function deletetableentry(self) function mymodule.deletetableentry(self)
return self.handle_form(self, self.model.get_delete_table_entry, self.model.delete_table_entry, self.clientdata, "Delete", "Delete Table Entry", "Table Entry deleted") return self.handle_form(self, self.model.get_delete_table_entry, self.model.delete_table_entry, self.clientdata, "Delete", "Delete Table Entry", "Table Entry deleted")
end end
function updatetableentry(self) function mymodule.updatetableentry(self)
return self.handle_form(self, self.model.get_table_entry, self.model.update_table_entry, self.clientdata, "Update", "Update Table Entry", "Entry updated") return self.handle_form(self, self.model.get_table_entry, self.model.update_table_entry, self.clientdata, "Update", "Update Table Entry", "Entry updated")
end end
function createtableentry(self) function mymodule.createtableentry(self)
return self.handle_form(self, self.model.get_new_table_entry, self.model.create_table_entry, self.clientdata, "Create", "Create New Table Entry", "Entry created") return self.handle_form(self, self.model.get_new_table_entry, self.model.create_table_entry, self.clientdata, "Create", "Create New Table Entry", "Entry created")
end end
return mymodule
module(..., package.seeall) local mymodule = {}
-- Helper library for model functions for viewing and editing database entries -- Helper library for model functions for viewing and editing database entries
-- Relies heavily on the acf-lib/db.lua library (db object passed into each function) -- Relies heavily on the acf-lib/db.lua library (db object passed into each function)
function list_databases(db, self, clientdata) function mymodule.list_databases(db, self, clientdata)
local retval = {} local retval = {}
local errtxt local errtxt
local res, err = pcall(function() local res, err = pcall(function()
...@@ -15,7 +15,7 @@ function list_databases(db, self, clientdata) ...@@ -15,7 +15,7 @@ function list_databases(db, self, clientdata)
return cfe({ type="list", value=retval, label="List of Databases", errtxt=errtxt }) return cfe({ type="list", value=retval, label="List of Databases", errtxt=errtxt })
end end
function list_tables(db, self, clientdata) function mymodule.list_tables(db, self, clientdata)
local retval = {} local retval = {}
local errtxt local errtxt
local res, err = pcall(function() local res, err = pcall(function()
...@@ -30,7 +30,7 @@ function list_tables(db, self, clientdata) ...@@ -30,7 +30,7 @@ function list_tables(db, self, clientdata)
return cfe({ type="list", value=retval, label="List of Database Tables", errtxt=errtxt }) return cfe({ type="list", value=retval, label="List of Database Tables", errtxt=errtxt })
end end
function list_table_entries(db, self, clientdata) function mymodule.list_table_entries(db, self, clientdata)
local table = clientdata.table local table = clientdata.table
local retval = {} local retval = {}
retval.table = cfe({ value=table or "", label="Table" }) retval.table = cfe({ value=table or "", label="Table" })
...@@ -59,7 +59,7 @@ function list_table_entries(db, self, clientdata) ...@@ -59,7 +59,7 @@ function list_table_entries(db, self, clientdata)
return cfe({ type="group", value=retval, label="Database Table Entries", errtxt=errtxt }) return cfe({ type="group", value=retval, label="Database Table Entries", errtxt=errtxt })
end end
function get_new_table_entry(db, self, clientdata) function mymodule.get_new_table_entry(db, self, clientdata)
local retval = {} local retval = {}
retval.table = cfe({ value=clientdata.table or "", label="Table", errtxt="Table does not exist", readonly=true, seq=0 }) retval.table = cfe({ value=clientdata.table or "", label="Table", errtxt="Table does not exist", readonly=true, seq=0 })
local errtxt = "Table does not exist" local errtxt = "Table does not exist"
...@@ -93,8 +93,8 @@ function get_new_table_entry(db, self, clientdata) ...@@ -93,8 +93,8 @@ function get_new_table_entry(db, self, clientdata)
return cfe({ type="group", value=retval, label="Database Table Entry", errtxt=errtxt }) return cfe({ type="group", value=retval, label="Database Table Entry", errtxt=errtxt })
end end
function get_table_entry(db, self, clientdata) function mymodule.get_table_entry(db, self, clientdata)
local retval = get_new_table_entry(db, self, clientdata) local retval = mymodule.get_new_table_entry(db, self, clientdata)
if not retval.value.table.errtxt and retval.value.id then if not retval.value.table.errtxt and retval.value.id then
retval.value.id.type = "text" retval.value.id.type = "text"
local res, err = pcall(function() local res, err = pcall(function()
...@@ -127,11 +127,11 @@ function get_table_entry(db, self, clientdata) ...@@ -127,11 +127,11 @@ function get_table_entry(db, self, clientdata)
return retval return retval
end end
function create_table_entry(db, self, entry, action) function mymodule.create_table_entry(db, self, entry, action)
return update_table_entry(db, self, entry, action, true) return mymodule.update_table_entry(db, self, entry, action, true)
end end
function update_table_entry(db, self, entry, action, create) function mymodule.update_table_entry(db, self, entry, action, create)
local success = true local success = true
local errtxt local errtxt
-- Validate the settings -- Validate the settings
...@@ -203,14 +203,14 @@ function update_table_entry(db, self, entry, action, create) ...@@ -203,14 +203,14 @@ function update_table_entry(db, self, entry, action, create)
return entry return entry
end end
function get_delete_table_entry(db, self, clientdata) function mymodule.get_delete_table_entry(db, self, clientdata)
local retval = {} local retval = {}
retval.table = cfe({ value=clientdata.table or "", label="Table", seq=0 }) retval.table = cfe({ value=clientdata.table or "", label="Table", seq=0 })
retval.id = cfe({ value=clientdata.id or "", label="ID", seq=1 }) retval.id = cfe({ value=clientdata.id or "", label="ID", seq=1 })
return cfe({ type="group", value=retval, label="Delete Database Table Entry" }) return cfe({ type="group", value=retval, label="Delete Database Table Entry" })
end end
function delete_table_entry(db, self, entry) function mymodule.delete_table_entry(db, self, entry)
entry.errtxt = "Failed to delete table entry" entry.errtxt = "Failed to delete table entry"
if entry.value.table.value == "" then if entry.value.table.value == "" then
entry.value.table.errtxt = "Invalid table" entry.value.table.errtxt = "Invalid table"
...@@ -241,3 +241,5 @@ function delete_table_entry(db, self, entry) ...@@ -241,3 +241,5 @@ function delete_table_entry(db, self, entry)
return entry return entry
end end
return mymodule
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