luci-app-commands: prevent page reload on invoking command actions
authorJo-Philipp Wich <jo@mein.io>
Fri, 9 Apr 2021 12:36:19 +0000 (14:36 +0200)
committerJo-Philipp Wich <jo@mein.io>
Fri, 9 Apr 2021 12:37:03 +0000 (14:37 +0200)
Fixes: f117b7f ("luci-app-commands: use <button> elements")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 36959dc0d10bd012f35c51bf8a6b88ce6c5853a2)

applications/luci-app-commands/luasrc/view/commands.htm

index ff82eac47a3d2b6bb7fab9fbb5842a41838f5226..634090e7d749808ecd30538516840a3832e84643 100644 (file)
@@ -37,7 +37,7 @@
 <script type="text/javascript">//<![CDATA[
        var stxhr = new XHR();
 
-       function command_run(id)
+       function command_run(ev, id)
        {
                var args;
                var field = document.getElementById(id);
                                }
                        );
                }
+
+               ev.preventDefault();
        }
 
-       function command_download(id)
+       function command_download(ev, id)
        {
                var args;
                var field = document.getElementById(id);
                        args = encodeURIComponent(field.value);
 
                location.href = '<%=url('admin/system/commands/download')%>/' + id + (args ? '/' + args : '');
+
+               ev.preventDefault();
        }
 
-       function command_link(id)
+       function command_link(ev, id)
        {
                var legend = document.getElementById('command-rc-legend');
                var output = document.getElementById('command-rc-output');
 
                        location.hash = '#output';
                }
+
+               ev.preventDefault();
        }
 
 //]]></script>
                                                <p><%:Arguments:%> <input type="text" id="<%=command['.name']%>" /></p>
                                        <% end %>
                                        <div>
-                                               <button class="cbi-button cbi-button-apply" onclick="command_run('<%=command['.name']%>')"><%:Run%></button>
-                                               <button class="cbi-button cbi-button-download" onclick="command_download('<%=command['.name']%>')"><%:Download%></button>
+                                               <button class="cbi-button cbi-button-apply" onclick="command_run(event, '<%=command['.name']%>')"><%:Run%></button>
+                                               <button class="cbi-button cbi-button-download" onclick="command_download(event, '<%=command['.name']%>')"><%:Download%></button>
                                                <% if command.public == "1" then %>
-                                                       <button class="cbi-button cbi-button-link" onclick="command_link('<%=command['.name']%>')"><%:Link%></button>
+                                                       <button class="cbi-button cbi-button-link" onclick="command_link(event, '<%=command['.name']%>')"><%:Link%></button>
                                                <% end %>
                                        </div>
                                </div>