Merge pull request #1767 from SvenRoederer/patch-2
authorHannu Nyman <hannu.nyman@iki.fi>
Sat, 28 Apr 2018 05:48:09 +0000 (08:48 +0300)
committerGitHub <noreply@github.com>
Sat, 28 Apr 2018 05:48:09 +0000 (08:48 +0300)
luci-mod-freifunk: align spacing

modules/luci-base/htdocs/luci-static/resources/xhr.js
modules/luci-base/luasrc/dispatcher.lua
modules/luci-base/luasrc/http.lua
themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/header.htm
themes/luci-theme-freifunk-generic/luasrc/view/themes/freifunk-generic/header.htm
themes/luci-theme-material/luasrc/view/themes/material/header.htm
themes/luci-theme-openwrt/luasrc/view/themes/openwrt.org/header.htm

index 3385f8f..91dcf3f 100644 (file)
@@ -39,7 +39,7 @@ XHR = function()
                        this._xmlHttp.abort();
        }
 
-       this.get = function(url,data,callback)
+       this.get = function(url,data,callback,timeout)
        {
                this.reinit();
 
@@ -54,6 +54,9 @@ XHR = function()
                        else
                                url += '?' + code;
 
+               if (!isNaN(timeout))
+                       xhr.timeout = timeout;
+
                xhr.open('GET', url, true);
 
                xhr.onreadystatechange = function()
@@ -76,7 +79,7 @@ XHR = function()
                xhr.send(null);
        }
 
-       this.post = function(url,data,callback)
+       this.post = function(url,data,callback,timeout)
        {
                this.reinit();
 
@@ -89,6 +92,9 @@ XHR = function()
                                callback(xhr);
                }
 
+               if (!isNaN(timeout))
+                       xhr.timeout = timeout;
+
                xhr.open('POST', url, true);
                xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                xhr.send(code);
@@ -168,7 +174,7 @@ XHR.get = function(url, data, callback)
        (new XHR()).get(url, data, callback);
 }
 
-XHR.poll = function(interval, url, data, callback)
+XHR.poll = function(interval, url, data, callback, post)
 {
        if (isNaN(interval) || interval < 1)
                interval = 5;
@@ -181,22 +187,38 @@ XHR.poll = function(interval, url, data, callback)
                        for (var i = 0, e = XHR._q[0]; i < XHR._q.length; e = XHR._q[++i])
                        {
                                if (!(XHR._t % e.interval) && !e.xhr.busy())
-                                       e.xhr.get(e.url, e.data, e.callback);
+                                       e.xhr[post ? 'post' : 'get'](e.url, e.data, e.callback, e.interval * 1000 - 5);
                        }
 
                        XHR._t++;
                };
        }
 
-       XHR._q.push({
+       var e = {
                interval: interval,
                callback: callback,
                url:      url,
                data:     data,
                xhr:      new XHR()
-       });
+       };
 
+       XHR._q.push(e);
        XHR.run();
+
+       return e;
+}
+
+XHR.stop = function(e)
+{
+       for (var i = 0; XHR._q && XHR._q[i]; i++) {
+               if (XHR._q[i] === e) {
+                       e.xhr.cancel();
+                       XHR._q.splice(i, 1);
+                       return true;
+               }
+       }
+
+       return false;
 }
 
 XHR.halt = function()
index 5fc2b80..1984fc4 100644 (file)
@@ -442,6 +442,13 @@ function dispatch(request)
                ctx.authuser = sdat.username
        end
 
+       if track.cors and http.getenv("REQUEST_METHOD") == "OPTIONS" then
+               luci.http.status(200, "OK")
+               luci.http.header("Access-Control-Allow-Origin", http.getenv("HTTP_ORIGIN") or "*")
+               luci.http.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
+               return
+       end
+
        if c and require_post_security(c.target) then
                if not test_post_security(c) then
                        return
index be5577e..16fb04c 100644 (file)
@@ -486,26 +486,22 @@ end
 -- handled then the whole message body will be stored unaltered as "content"
 -- property within the given message object.
 function parse_message_body(src, msg, filecb)
-       local ctype = lhttp.header_attribute(msg.env.CONTENT_TYPE, nil)
+       if msg.env.CONTENT_LENGTH or msg.env.REQUEST_METHOD == "POST" then
+               local ctype = lhttp.header_attribute(msg.env.CONTENT_TYPE, nil)
 
-       -- Is it multipart/mime ?
-       if msg.env.REQUEST_METHOD == "POST" and
-          ctype == "multipart/form-data"
-       then
-               return mimedecode_message_body(src, msg, filecb)
+               -- Is it multipart/mime ?
+               if ctype == "multipart/form-data" then
+                       return mimedecode_message_body(src, msg, filecb)
 
-       -- Is it application/x-www-form-urlencoded ?
-       elseif msg.env.REQUEST_METHOD == "POST" and
-              ctype == "application/x-www-form-urlencoded"
-       then
-               return urldecode_message_body(src, msg)
+               -- Is it application/x-www-form-urlencoded ?
+               elseif ctype == "application/x-www-form-urlencoded" then
+                       return urldecode_message_body(src, msg)
 
+               end
 
-       -- Unhandled encoding
-       -- If a file callback is given then feed it chunk by chunk, else
-       -- store whole buffer in message.content
-       else
-
+               -- Unhandled encoding
+               -- If a file callback is given then feed it chunk by chunk, else
+               -- store whole buffer in message.content
                local sink
 
                -- If we have a file callback then feed it
@@ -553,4 +549,6 @@ function parse_message_body(src, msg, filecb)
 
                return true
        end
+
+       return false
 end
index 0441c95..4881535 100644 (file)
                        end
 
                        if ucichanges > 0 then
-                               write('<a class="label notice" href="%s?redir=%s">%s: %d</a>' %{
+                               write('<a class="uci_change_indicator label notice" href="%s?redir=%s">%s: %d</a>' %{
                                        url(category, 'uci/changes'),
                                        http.urlencode(http.formvalue('redir') or table.concat(disp.context.request, "/")),
                                        translate('Unsaved Changes'),
index 8185655..16ffc99 100644 (file)
@@ -205,7 +205,7 @@ if tree.nodes[category] and tree.nodes[category].ucidata then
 -%>
        <div id="savemenu">
                <% if ucic > 0 then %>
-                       <a class="warning" href="<%=controller%>/<%=category%>/uci/changes/?redir=<%=http.urlencode(http.formvalue('redir') or table.concat(disp.context.request, "/"))%>"><%:Unsaved Changes%>: <%=ucic%></a>
+                       <a class="uci_change_indicator warning" href="<%=controller%>/<%=category%>/uci/changes/?redir=<%=http.urlencode(http.formvalue('redir') or table.concat(disp.context.request, "/"))%>"><%:Unsaved Changes%>: <%=ucic%></a>
                <% end -%>
        </div>
 <% end %>
index be7b9ff..0aca882 100644 (file)
                        end
 
                        if ucichanges > 0 then
-                               write('<a class="label notice" href="%s?redir=%s">%s: %d</a>' %{
+                               write('<a class="uci_change_indicator label notice" href="%s?redir=%s">%s: %d</a>' %{
                                        url(category, 'uci/changes'),
                                        http.urlencode(http.formvalue('redir') or table.concat(disp.context.request, "/")),
                                        translate('Unsaved Changes'),
index d6db8e8..a560014 100644 (file)
                                end
                        end
 
-                       write('<div id="savemenu">')
-
                        if ucic > 0 then
-                               write('<a class="warning" href="%s?redir=%s">%s: %d</a>' %{
+                               write('<div id="savemenu" class="uci_change_indicator"><a class="warning" href="%s?redir=%s">%s: %d</a></div>' %{
                                        url(category, 'uci/changes'),
                                        http.urlencode(http.formvalue('redir') or table.concat(disp.context.request, "/")),
                                        translate('Unsaved Changes'),
                                        ucic
                                })
-                       else
-                               write('<a href="#">%s: 0</a>' %{
-                                       translate('Unsaved Changes')
-                               })
                        end
-
-                       write('</div>')
                end
        end
 -%>