summaryrefslogtreecommitdiffstats
path: root/lbu-controller.lua
blob: 853219b1f06e15e7ba8ac56bac1fb9e8a74adf67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
module(..., package.seeall)

local list_redir = function(self)
    self.conf.action = "status"
    self.conf.type = "redir"
    error(self.conf)
end

local cfgfile

mvc={}
mvc.on_load = function(self, parent)
    cfgfile = self:new("cfgfile")
    if (self.worker[self.conf.action] == nil) or (self.conf.action == "init") then
        self.worker[self.conf.action] = list_redir(self)
    end
end

status = function (self)
	local cmd = self.clientdata.cmd
	local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
	return ( {status = self.model:getstatus(), 
		lbustatus = self.model:list(),
		url = url, } )
end

config = function (self)
	local cmd = self.clientdata.cmd
	local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
	return ( {status = self.model:getstatus(), 
		config = self.model:getconfig(),
		url = url, } )
end

-- ################################################################################
-- OLD FUNCTIONS

--[[
function commit(self)
    local ret = {
        script=ENV["SCRIPT_NAME"],
        prefix=self.conf.prefix,
        controller = self.conf.controller,
	action="commit",
        data={},
	title="LBU",
	text={},
    }
    if self.clientdata.commit then
        local result, report = self.model:commit()
	local label = result and "Report" or "Error"
	ret.text[#ret.text + 1] = { label=label, content=report }
    else
        for i,v in ipairs(self.model:list(nil)) do
	    ret.data[#ret.data + 1] = {
                status = v.status,
		name = v.name,
	    }
	end
    end
    ret.note=getNotes(self)
    return ret
end
--]]

--[[
local function getNotes(self)
    ret = {}
    for k,v in pairs(cfgfile.model:list(nil)) do
        if v.status then
	    ret[#ret + 1] = {
		content = "There are some configuration changes. Please do not forget to save."
	    }
	    break
	end
    end
    return ret
end
--]]
--[[
xxxstatus = function(self)
    return {
        list=cfgfile.model:list(function(x) return x.app == "lbu" end),
        script=ENV["SCRIPT_NAME"],
        prefix=self.conf.prefix,
        controller=self.conf.controller,
        action="update",
	note=getNotes(self),
   }
end

--]]

--[[
update = function(self)
    local id = tonumber(self.clientdata.id) or -1
    local result
    local data

    result, data = cfgfile.model:get(id)
    if not result then return list_redir(self) end

    if self.clientdata.cmd then
        for k,v in pairs (data) do
            if self.clientdata[k] then 
                data[k].value = self.clientdata[k]
            end
        end
        result, data = cfgfile.model:set(id, data)
	if result then return list_redir(self) end
    end
                
    data.cmd = cfe { type="action", value="save", label="action" }
    return cfe{ type="form", 
        option={ script=ENV["SCRIPT_NAME"],
            prefix=self.conf.prefix,
            controller = self.conf.controller,
            action = "update",
            extra = ""},
        value = data}
end
--]]