diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2008-09-23 00:10:51 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2008-09-23 00:10:51 +0000 |
commit | 6b3985b6be52063c09f779b6bc509bf84eedc660 (patch) | |
tree | cada805afb670f7648932f8c0e3a31ffbf512108 /libs/cbi/luasrc/cbi.lua | |
parent | 225de062447d8e29d927b821b41913723f392379 (diff) |
* luci/libs/cbi:
- implement file upload fields
- change default enctype in forms to multipart/form-data
- add upload template
* luci/libs/web:
- dispatch file uploads to cbi form fields
* luci/i18n:
- add german and english translations for file upload fields
Diffstat (limited to 'libs/cbi/luasrc/cbi.lua')
-rw-r--r-- | libs/cbi/luasrc/cbi.lua | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua index 97c453cf2f..8cde0a1777 100644 --- a/libs/cbi/luasrc/cbi.lua +++ b/libs/cbi/luasrc/cbi.lua @@ -30,6 +30,7 @@ require("luci.template") require("luci.util") require("luci.http") require("luci.uvl") +require("luci.fs") local uci = require("luci.model.uci") local class = luci.util.class @@ -1328,3 +1329,44 @@ function Button.__init__(self, ...) self.inputstyle = nil self.rmempty = true end + + +FileUpload = class(AbstractValue) + +function FileUpload.__init__(self, ...) + AbstractValue.__init__(self, ...) + self.template = "cbi/upload" + if not self.map.upload_fields then + self.map.upload_fields = { self } + else + self.map.upload_fields[#self.map.upload_fields+1] = self + end +end + +function FileUpload.cfgvalue(self, section) + local val = AbstractValue.cfgvalue(self, section) + if val and luci.fs.access(val) then + return val + end + return nil +end + +function FileUpload.formvalue(self, section) + local val = AbstractValue.formvalue(self, section) + if val then + if not luci.http.formvalue("cbi.rlf."..section.."."..self.option) and + not luci.http.formvalue("cbi.rlf."..section.."."..self.option..".x") + then + return val + end + luci.fs.unlink(val) + self.value = nil + end + return nil +end + +function FileUpload.remove(self, section) + local val = AbstractValue.formvalue(self, section) + if val and luci.fs.access(val) then luci.fs.unlink(val) end + return AbstractValue.remove(self, section) +end |