convert luci.fs users to nixio.fs api
[project/luci.git] / libs / cbi / luasrc / view / cbi / filebrowser.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 -%>
15
16 <?xml version="1.0" encoding="UTF-8"?>
17 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
18 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
19 <head>
20 <title>Filebrowser - LuCI</title>
21 <style type="text/css">
22 #path, #listing {
23 font-size: 85%;
24 }
25
26 ul {
27 padding-left: 0;
28 list-style-type: none;
29 }
30
31 li img {
32 vertical-align: bottom;
33 margin-right: 0.2em;
34 }
35 </style>
36
37 <script type="text/javascript">
38 function callback(path) {
39 if( window.opener ) {
40 var input = window.opener.document.getElementById('<%=luci.http.formvalue('field')%>');
41 if( input ) {
42 input.value = path;
43 window.close();
44 }
45 }
46 }
47 </script>
48 </head>
49 <body>
50 <%
51 require("nixio.fs")
52 require("nixio.util")
53 require("luci.http")
54 require("luci.dispatcher")
55
56 local field = luci.http.formvalue('field')
57 local request = luci.dispatcher.context.path
58 local path = { '' }
59
60 for i = 3, #request do
61 if request[i] ~= '..' and #request[i] > 0 then
62 path[#path+1] = request[i]
63 end
64 end
65
66 local filepath = table.concat( path, '/' )
67 local filestat = nixio.fs.stat( filepath )
68 local baseurl = luci.dispatcher.build_url('admin', 'filebrowser')
69
70 if filestat and filestat.type == "reg" then
71 table.remove( path, #path )
72 filepath = table.concat( path, '/' ) .. '/'
73 elseif not ( filestat and filestat.type == "dir" ) then
74 path = { '' }
75 filepath = '/'
76 else
77 filepath = filepath .. '/'
78 end
79
80 local entries = nixio.util.consume((nixio.fs.dir(filepath)))
81 -%>
82 <div id="path">
83 Location:
84 <% for i, dir in ipairs(path) do %>
85 <% if i == 1 then %>
86 <a href="<%=baseurl%>?field=<%=field%>">(root)</a>
87 <% elseif next(path, i) then %>
88 <% baseurl = baseurl .. '/' .. dir %>
89 / <a href="<%=baseurl%>?field=<%=field%>"><%=dir%></a>
90 <% else %>
91 <% baseurl = baseurl .. '/' .. dir %>
92 / <%=dir%>
93 <% end %>
94 <% end %>
95 </div>
96
97 <hr />
98
99 <div id="listing">
100 <ul>
101 <% for _, e in luci.util.vspairs(entries) do
102 local stat = nixio.fs.stat(filepath..e)
103 if stat and stat.type == 'dir' then
104 -%>
105 <li class="dir">
106 <img src="/luci-static/resources/cbi/folder.png" alt="Directory" />
107 <a href="<%=baseurl%>/<%=e%>?field=<%=field%>"><%=e%>/</a>
108 </li>
109 <% end end -%>
110
111 <% for _, e in luci.util.vspairs(entries) do
112 local stat = nixio.fs.stat(filepath..e)
113 if stat and stat.type ~= 'dir' then
114 -%>
115 <li class="file">
116 <img src="/luci-static/resources/cbi/file.png" alt="File" />
117 <a href="#" onclick="callback('<%=filepath..e%>')"><%=e%></a>
118 </li>
119 <% end end -%>
120 </ul>
121 </div>
122 </body>
123 </html>