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)
-- ################################################################################
-- PUBLIC FUNCTIONS
default_action = "status"
function basicstatus (self)
return self.model.getstatus()
end
function status (self)
return self.model.list()
end
function config (self)
local config = self.model.getconfig()
if self.clientdata.Save then
config.errtxt = nil
for name,value in pairs(config.value) do
value.errtxt = nil
if value.type == "boolean" then
value.value = (self.clientdata[name]~=nil)
else
value.value = self.clientdata[name] or value.value
end
end
config = self.model.setconfig(config)
if not config.errtxt then
config.descr = "Configuration Set"
end
end
config.type = "form"
config.option = "Save"
config.label = "Edit Config"
return config
end
function editincluded (self)
local errtxt, descr
local included = self.model.getincluded()
if self.clientdata.Save then
included.errtxt = nil
included.value = self.clientdata.included
included = self.model.setincluded(included)
if included.errtxt then
errtxt = "Failed to set included files"
else
descr = "Included files set"
redirect_to_referrer(self)
end
end
return cfe({ type="form", value={included=included}, option="Save", label="Edit included files", errtxt=errtxt, descr=descr })
end
function editexcluded (self)
local errtxt, descr
local excluded = self.model.getexcluded()
if self.clientdata.Save then
excluded.errtxt = nil
excluded.value = self.clientdata.excluded
excluded = self.model.setexcluded(excluded)
if excluded.errtxt then
errtxt = "Failed to set excluded files"
else
descr = "Excluded files set"
redirect_to_referrer(self)
end
end
return cfe({ type="form", value={excluded=excluded}, option="Save", label="Edit excluded files", errtxt=errtxt, descr=descr })
end
function commit(self)
local comm = self.model.getcommit()
if self.clientdata.Commit then
comm.errtxt = nil
for name,value in pairs(comm.value) do
value.errtxt = nil
value.value = (self.clientdata[name]~=nil)
end
comm = self.model.commit(comm)
self.sessiondata.commitresult = cfe({ value=comm.descr or "", errtxt=comm.errtxt })
redirect_to_referrer(self)
end
if self.sessiondata.commitresult then
comm.descr = self.sessiondata.commitresult.value
comm.errtxt = self.sessiondata.commitresult.errtxt
self.sessiondata.commitresult = nil
end
comm.type = "form"
comm.option = "Commit"
comm.label = "Commit changes"
return comm
end
function expert (self)
local filedetails = self.model.get_filedetails()
if self.clientdata.Save then
filedetails.value.filecontent.errtxt = nil
filedetails.value.filecontent.value = self.clientdata.filecontent
filedetails.value.filecontent = self.model.set_filecontent(filedetails.value.filecontent)
if filedetails.value.filecontent.errtxt then
filedetails.errtxt = "Failed to save config"
else
filedetails = self.model.get_filedetails()
filedetails.descr = "Saved config"
end
end
filedetails.type = "form"
filedetails.option = "Save"
filedetails.label = "Edit config file"
return filedetails
end
|