libs/web: repair and modernize FileBrowser widget, patches by Kevin Locke <klocke...
authorJo-Philipp Wich <jow@openwrt.org>
Sat, 5 Mar 2011 06:35:26 +0000 (06:35 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sat, 5 Mar 2011 06:35:26 +0000 (06:35 +0000)
libs/web/htdocs/luci-static/resources/cbi.js
libs/web/htdocs/luci-static/resources/cbi/file.gif [new file with mode: 0644]
libs/web/htdocs/luci-static/resources/cbi/folder.gif [new file with mode: 0644]
libs/web/luasrc/view/cbi/browser.htm
libs/web/luasrc/view/cbi/filebrowser.htm

index 2bcfb8c..be0a5a8 100644 (file)
@@ -402,6 +402,23 @@ function cbi_filebrowser(id, url, defpath) {
        browser.focus();
 }
 
        browser.focus();
 }
 
+function cbi_browser_init(id, respath, url, defpath)
+{
+       function cbi_browser_btnclick(e) {
+               cbi_filebrowser(id, url, defpath);
+               return false;
+       }
+
+       var field = document.getElementById(id);
+
+       var btn = document.createElement('img');
+       btn.className = 'cbi-image-button';
+       btn.src = respath + '/cbi/folder.gif';
+       field.parentNode.insertBefore(btn, field.nextSibling);
+
+       cbi_bind(btn, 'click', cbi_browser_btnclick);
+}
+
 function cbi_dynlist_init(name, respath)
 {
        function cbi_dynlist_renumber(e)
 function cbi_dynlist_init(name, respath)
 {
        function cbi_dynlist_renumber(e)
@@ -587,6 +604,7 @@ function cbi_dynlist_init(name, respath)
        for( var i = 0; i < inputs.length; i++ )
        {
                var btn = document.createElement('img');
        for( var i = 0; i < inputs.length; i++ )
        {
                var btn = document.createElement('img');
+                       btn.className = 'cbi-image-button';
                        btn.src = respath + (
                                (i+1) < inputs.length ? '/cbi/remove.gif' : '/cbi/add.gif'
                        );
                        btn.src = respath + (
                                (i+1) < inputs.length ? '/cbi/remove.gif' : '/cbi/add.gif'
                        );
diff --git a/libs/web/htdocs/luci-static/resources/cbi/file.gif b/libs/web/htdocs/luci-static/resources/cbi/file.gif
new file mode 100644 (file)
index 0000000..3b1217d
Binary files /dev/null and b/libs/web/htdocs/luci-static/resources/cbi/file.gif differ
diff --git a/libs/web/htdocs/luci-static/resources/cbi/folder.gif b/libs/web/htdocs/luci-static/resources/cbi/folder.gif
new file mode 100644 (file)
index 0000000..22b583b
Binary files /dev/null and b/libs/web/htdocs/luci-static/resources/cbi/folder.gif differ
index 3b7b23f..08df483 100644 (file)
@@ -14,10 +14,11 @@ $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) %> />
        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="<%:Search file...%>" onclick="cbi_filebrowser('<%=cbid%>','<%=luci.dispatcher.build_url("admin", "filebrowser")%>'<%=self.default_path and ", '"..self.default_path.."'"%>);return false" alt="<%:Search file...%>" title="<%:Search file...%>" src="<%=resource%>/cbi/folder.png" style="vertical-align:bottom" />
+       <script type="text/javascript">
+cbi_browser_init('<%=cbid%>', '<%=resource%>', '<%=luci.dispatcher.build_url("admin", "filebrowser")%>'<%=self.default_path and ", '"..self.default_path.."'"%>);
+       </script>
 <%+cbi/valuefooter%>
 <%+cbi/valuefooter%>
index f829572..40480ec 100644 (file)
@@ -54,10 +54,10 @@ $Id$
                require("luci.dispatcher")
 
                local field   = luci.http.formvalue('field')
                require("luci.dispatcher")
 
                local field   = luci.http.formvalue('field')
-               local request = luci.dispatcher.context.path
+               local request = luci.dispatcher.context.args
                local path    = { '' }
 
                local path    = { '' }
 
-               for i = 3, #request do
+               for i = 1, #request do
                        if request[i] ~= '..' and #request[i] > 0 then
                                path[#path+1] = request[i]
                        end
                        if request[i] ~= '..' and #request[i] > 0 then
                                path[#path+1] = request[i]
                        end
@@ -103,7 +103,7 @@ $Id$
                                if stat and stat.type == 'dir' then
                        -%>
                                <li class="dir">
                                if stat and stat.type == 'dir' then
                        -%>
                                <li class="dir">
-                                       <img src="/luci-static/resources/cbi/folder.png" alt="Directory" />
+                                       <img src="<%=resource%>/cbi/folder.gif" alt="<%:Directory%>" />
                                        <a href="<%=baseurl%>/<%=e%>?field=<%=field%>"><%=e%>/</a>
                                </li>
                        <% end end -%>
                                        <a href="<%=baseurl%>/<%=e%>?field=<%=field%>"><%=e%>/</a>
                                </li>
                        <% end end -%>
@@ -113,7 +113,7 @@ $Id$
                                if stat and stat.type ~= 'dir' then
                        -%>
                                <li class="file">
                                if stat and stat.type ~= 'dir' then
                        -%>
                                <li class="file">
-                                       <img src="/luci-static/resources/cbi/file.png" alt="File" />
+                                       <img src="<%=resource%>/cbi/file.gif" alt="<%:File%>" />
                                        <a href="#" onclick="callback('<%=filepath..e%>')"><%=e%></a>
                                </li>
                        <% end end -%>
                                        <a href="#" onclick="callback('<%=filepath..e%>')"><%=e%></a>
                                </li>
                        <% end end -%>