luci-app-travelmate: enhancements & fixes
[project/luci.git] / applications / luci-app-travelmate / luasrc / model / cbi / travelmate / configuration_tab.lua
1 -- Copyright 2017 Dirk Brenken (dev@brenken.org)
2 -- This is free software, licensed under the Apache License, Version 2.0
3
4 local fs = require("nixio.fs")
5 local util = require("luci.util")
6 local trminput = "/etc/config/travelmate"
7
8 if not nixio.fs.access(trminput) then
9         m = SimpleForm("error", nil, translate("Input file not found, please check your configuration."))
10         m.reset = false
11         m.submit = false
12         return m
13 end
14
15 m = SimpleForm("input", nil)
16 m:append(Template("travelmate/config_css"))
17 m.reset = false
18
19 s = m:section(SimpleSection, nil,
20         translate("This form allows you to modify the content of the main travelmate configuration file (/etc/config/travelmate)."))
21
22 f = s:option(TextValue, "data")
23 f.rows = 20
24 f.rmempty = true
25
26 function f.cfgvalue()
27         return nixio.fs.readfile(trminput) or ""
28 end
29
30 function f.write(self, section, data)
31         return nixio.fs.writefile(trminput, "\n" .. util.trim(data:gsub("\r\n", "\n")) .. "\n")
32 end
33
34 function s.handle(self, state, data)
35         return true
36 end
37
38 return m