summaryrefslogtreecommitdiffhomepage
path: root/libs/cbi
diff options
context:
space:
mode:
Diffstat (limited to 'libs/cbi')
-rw-r--r--libs/cbi/luasrc/cbi.lua42
-rw-r--r--libs/cbi/luasrc/view/cbi/header.htm2
-rw-r--r--libs/cbi/luasrc/view/cbi/upload.htm28
3 files changed, 71 insertions, 1 deletions
diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua
index 97c453cf2..8cde0a177 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
diff --git a/libs/cbi/luasrc/view/cbi/header.htm b/libs/cbi/luasrc/view/cbi/header.htm
index ce5d66d77..3f60baf52 100644
--- a/libs/cbi/luasrc/view/cbi/header.htm
+++ b/libs/cbi/luasrc/view/cbi/header.htm
@@ -14,7 +14,7 @@ $Id$
-%>
<%+header%>
-<form method="post" action="<%=luci.http.getenv("REQUEST_URI")%>">
+<form method="post" action="<%=luci.http.getenv("REQUEST_URI")%>" enctype="multipart/form-data">
<div>
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
<input type="hidden" name="cbi.submit" value="1" />
diff --git a/libs/cbi/luasrc/view/cbi/upload.htm b/libs/cbi/luasrc/view/cbi/upload.htm
new file mode 100644
index 000000000..7e0ab1b50
--- /dev/null
+++ b/libs/cbi/luasrc/view/cbi/upload.htm
@@ -0,0 +1,28 @@
+<%#
+LuCI - Lua Configuration Interface
+Copyright 2008 Steven Barth <steven@midlink.org>
+Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+-%>
+
+<%
+ local t = require("luci.tools.webadmin")
+ local v = self:cfgvalue(section)
+-%>
+<%+cbi/valueheader%>
+ <% if v then %>
+ <%:cbi_upload Uploaded File%> (<%=t.byte_format(luci.fs.stat(v).size or 0)%>)
+ <input type="hidden"<%= attr("value", v) .. attr("name", cbid) .. attr("id", cbid) %> />
+ <input type="image" value="<%:cbi_replace%>" name="cbi.rlf.<%=section .. "." .. self.option%>" alt="<%:cbi_replace%>" title="<%:cbi_replace%>" src="<%=resource%>/cbi/reload.gif" />
+ <% else %>
+ <input type="file"<%= attr("name", cbid) .. attr("id", cbid) %> />
+ <% end %>
+<%+cbi/valuefooter%>