summaryrefslogtreecommitdiffhomepage
path: root/libs/cbi/luasrc/view
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2008-10-10 21:52:22 +0000
committerJo-Philipp Wich <jow@openwrt.org>2008-10-10 21:52:22 +0000
commitb618361bf1c7ea160f3e0ef18aa8f409f7a21eff (patch)
tree2765d22f35d710e806be8a23f7f5efdad9100949 /libs/cbi/luasrc/view
parent720295d973b44cdad4cd4a0e0b0b0f7f79ff6c3a (diff)
* luci/libs/cbi: implement file browse fields
* luci/modules/admin-full: add file browse controller
Diffstat (limited to 'libs/cbi/luasrc/view')
-rw-r--r--libs/cbi/luasrc/view/cbi/browser.htm23
-rw-r--r--libs/cbi/luasrc/view/cbi/filebrowser.htm122
2 files changed, 145 insertions, 0 deletions
diff --git a/libs/cbi/luasrc/view/cbi/browser.htm b/libs/cbi/luasrc/view/cbi/browser.htm
new file mode 100644
index 0000000000..1982fcb053
--- /dev/null
+++ b/libs/cbi/luasrc/view/cbi/browser.htm
@@ -0,0 +1,23 @@
+<%#
+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%>
+ <input class="cbi-input-text" type="text"<%= attr("value", v) .. attr("name", cbid) .. attr("id", cbid) %> />
+ <input class="cbi-input-image" type="image" value="<%:cbi_browser%>" onclick="cbi_filebrowser('<%=cbid%>','<%=luci.dispatcher.build_url("admin", "filebrowser")%>'<%=self.default_path and ", '"..self.default_path.."'"%>);return false" alt="<%:cbi_browser%>" title="<%:cbi_browser%>" src="<%=resource%>/cbi/folder.png" style="vertical-align:bottom" />
+<%+cbi/valuefooter%>
diff --git a/libs/cbi/luasrc/view/cbi/filebrowser.htm b/libs/cbi/luasrc/view/cbi/filebrowser.htm
new file mode 100644
index 0000000000..0e223a933f
--- /dev/null
+++ b/libs/cbi/luasrc/view/cbi/filebrowser.htm
@@ -0,0 +1,122 @@
+<%#
+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$
+
+-%>
+
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>Filebrowser - LuCI</title>
+ <style type="text/css">
+ #path, #listing {
+ font-size: 85%;
+ }
+
+ ul {
+ padding-left: 0;
+ list-style-type: none;
+ }
+
+ li img {
+ vertical-align: bottom;
+ margin-right: 0.2em;
+ }
+ </style>
+
+ <script type="text/javascript">
+ function callback(path) {
+ if( window.opener ) {
+ var input = window.opener.document.getElementById('<%=luci.http.formvalue('field')%>');
+ if( input ) {
+ input.value = path;
+ window.close();
+ }
+ }
+ }
+ </script>
+</head>
+<body>
+ <%
+ require("luci.fs")
+ require("luci.http")
+ require("luci.dispatcher")
+
+ local field = luci.http.formvalue('field')
+ local request = luci.dispatcher.context.path
+ local path = { '' }
+
+ for i = 3, #request do
+ if request[i] ~= '..' and #request[i] > 0 then
+ path[#path+1] = request[i]
+ end
+ end
+
+ local filepath = table.concat( path, '/' )
+ local filestat = luci.fs.stat( filepath )
+ local baseurl = luci.dispatcher.build_url('admin', 'filebrowser')
+
+ if filestat and filestat.type == "regular" then
+ table.remove( path, #path )
+ filepath = table.concat( path, '/' ) .. '/'
+ elseif not ( filestat and filestat.type == "directory" ) then
+ path = { '' }
+ filepath = '/'
+ else
+ filepath = filepath .. '/'
+ end
+
+ local entries = luci.fs.dir(filepath)
+ -%>
+ <div id="path">
+ Location:
+ <% for i, dir in ipairs(path) do %>
+ <% if i == 1 then %>
+ <a href="<%=baseurl%>?field=<%=field%>">(root)</a>
+ <% elseif next(path, i) then %>
+ <% baseurl = baseurl .. '/' .. dir %>
+ / <a href="<%=baseurl%>?field=<%=field%>"><%=dir%></a>
+ <% else %>
+ <% baseurl = baseurl .. '/' .. dir %>
+ / <%=dir%>
+ <% end %>
+ <% end %>
+ </div>
+
+ <hr />
+
+ <div id="listing">
+ <ul>
+ <% for _, e in luci.util.vspairs(entries) do
+ local stat = luci.fs.stat(filepath..e)
+ if e ~= '.' and e ~= '..' and stat and stat.type == 'directory' then
+ -%>
+ <li class="dir">
+ <img src="/luci-static/resources/cbi/folder.png" alt="Directory" />
+ <a href="<%=baseurl%>/<%=e%>?field=<%=field%>"><%=e%>/</a>
+ </li>
+ <% end end -%>
+
+ <% for _, e in luci.util.vspairs(entries) do
+ local stat = luci.fs.stat(filepath..e)
+ if stat and stat.type ~= 'directory' then
+ -%>
+ <li class="file">
+ <img src="/luci-static/resources/cbi/file.png" alt="File" />
+ <a href="#" onclick="callback('<%=filepath..e%>')"><%=e%></a>
+ </li>
+ <% end end -%>
+ </ul>
+ </div>
+</body>
+</html>