ajaxified device settings packaging

Thu, 18 Dec 2014 07:42:52 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Thu, 18 Dec 2014 07:42:52 +0100
branch
packaging
changeset 62
780112d29fd2
parent 61
0cf3cb807a81
child 63
93988ac017d0

ajaxified device settings

victrond/http/ajax-ui.html file | annotate | diff | comparison | revisions
victrond/http/css/ajax_loader_blue_128.gif file | annotate | diff | comparison | revisions
victrond/http/css/victrond.css file | annotate | diff | comparison | revisions
victrond/http/js/victrond.js file | annotate | diff | comparison | revisions
victrond/victrond.py file | annotate | diff | comparison | revisions
--- a/victrond/http/ajax-ui.html	Thu Dec 18 06:25:07 2014 +0100
+++ b/victrond/http/ajax-ui.html	Thu Dec 18 07:42:52 2014 +0100
@@ -215,7 +215,6 @@
 <!-- START: MAINTENANCE -->
             <div id="tab-maintenance">
                 <div class="fixedbox">
-                    <form action="setSettings.py" name="settings" method="post">
                         <table>
                             <tr>
                                 <td colspan="3">Device settings</td>
@@ -223,7 +222,7 @@
                             <tr>
                                 <td>NoLoad Shutdown</td>        <td><span id="set_SNoLoad_en2"></span></td>
                                 <td>
-                                    <select name="SNoLoad_en">
+                                    <select id="SNoLoad_en">
                                         <option value="#">Don't change</option>
                                         <option value="4">Enable</option>
                                         <option value="0">Disable</option>
@@ -233,7 +232,7 @@
                             <tr>
                                 <td>Bypass enabled</td>         <td><span id="set_SByPass_en2"></span></td>
                                 <td>
-                                    <select name="SByPass_en">
+                                    <select id="SByPass_en">
                                         <option value="#">Don't change</option>
                                         <option value="2">Enable</option>
                                         <option value="0">Disable</option>
@@ -243,7 +242,7 @@
                             <tr>
                                 <td>Alarm buzzer</td>           <td><span id="set_SBuzzerTxt2"></span></td>
                                 <td>
-                                    <select name="SBuzzer">
+                                    <select id="SBuzzer">
                                         <option value="#">Don't change</option>
                                         <option value="1">Disable</option>
                                         <option value="2">Enable</option>
@@ -254,7 +253,7 @@
                             <tr>
                                 <td>Output Voltage</td>         <td><span id="set_SOVolt2"></span> V</td>
                                 <td>
-                                    <select name="SOVolt">
+                                    <select id="SOVolt">
                                         <option value="#">Don't change</option>
                                         <option value="220">220 V</option>
                                         <option value="230">230 V</option>
@@ -265,7 +264,7 @@
                             <tr>
                                 <td>Output Frequency</td>       <td><span id="set_SOFreq2"></span> Hz</td>
                                 <td>
-                                    <select name="SOFreq">
+                                    <select id="SOFreq">
                                         <option value="#">Don't change</option>
                                         <option value="500">50 Hz</option>
                                         <option value="600">60 Hz</option>
@@ -275,13 +274,13 @@
                             <tr>
                                 <td>Battery Capacity</td>       <td><span id="set_SBCapa2"></span> Ah</td>
                                 <td>
-                                    <input name="SBCapa" id="set_val_SBCapa" SIZE="5" VALUE="">
+                                    <input id="set_val_SBCapa" SIZE="5" VALUE="">
                                 </td>
                             </tr>
                             <tr>
                                 <td>Auto-Restart</td>           <td><span id="set_SAutorestart_en2"></span></td>
                                 <td>
-                                    <select name="SAutorestart_en">
+                                    <select id="SAutorestart_en">
                                         <option value="#">Don't change</option>
                                         <option value="1">Enable</option>
                                         <option value="2">Disable</option>
@@ -290,8 +289,7 @@
                             </tr>
                         </table>
 
-                        <input type="button" value="Save &amp; Activate settings" onClick="javascript:submit_yesno('settings','Some settings may be vulnerable to attached hardware. Activate settings now?')">
-                    </form>
+                        <button id="submit_settings">Save &amp; Activate settings</button>
 
                     <p />
                     <b> Perform self-tests: </b>
@@ -335,5 +333,8 @@
 <!-- END: MAINTENANCE -->
 
         </div>
+
+        <div id="lock_overlay" style="display: none"></div>
+
     </body>
 </html>
Binary file victrond/http/css/ajax_loader_blue_128.gif has changed
--- a/victrond/http/css/victrond.css	Thu Dec 18 06:25:07 2014 +0100
+++ b/victrond/http/css/victrond.css	Thu Dec 18 07:42:52 2014 +0100
@@ -86,3 +86,13 @@
 #jspanel .off div {
     background-position: 0 0 !important;
 }
+
+#lock_overlay {
+    position: absolute;
+    z-index: 100000;
+    top: 0;
+    left: 0;
+    width: 100%;
+    height: 100%;
+    background: url(ajax_loader_blue_128.gif) no-repeat scroll center center rgba(0,0,0,0.7);
+}
--- a/victrond/http/js/victrond.js	Thu Dec 18 06:25:07 2014 +0100
+++ b/victrond/http/js/victrond.js	Thu Dec 18 07:42:52 2014 +0100
@@ -19,8 +19,45 @@
     $("#graph-src").change(function() {
         $("#graph-img").attr('src', $(this).val());
     });
+
+    $("#submit_settings")
+        .button()
+        .click(function() {
+            if (prompt_yesno('Some settings may be vulnerable to attached hardware. Activate settings now?')) {
+                lockui();
+                $.ajax({
+                    type: "POST",
+                    url: "setSettings.py",
+                    async: false,
+                    data: {
+                        json: true,
+                        SNoLoad_en: $("#SNoLoad_en").val(),
+                        SByPass_en: $("#SByPass_en").val(),
+                        SBuzzer: $("#SBuzzer").val(),
+                        SOVolt: $("#SOVolt").val(),
+                        SOFreq: $("#SOFreq").val(),
+                        SBCapa: $("#set_val_SBCapa").val(),
+                        SAutorestart_en: $("#SAutorestart_en").val()
+                    },
+                    success: display_func_result,
+                    error: display_error,
+                    dataType: 'json'
+                });
+                unlockui();
+            }
+        });
 });
 
+function display_func_result(data) {
+    unlockui();
+    refresh_data();
+    alert(data.message);
+}
+
+function display_error(jqXHR, textStatus, errorThrown) {
+    alert(textStatus + ": " + errorThrown);
+}
+
 function refresh_data() {
     $.ajax({
         type: 'GET',
@@ -57,3 +94,16 @@
     document.forms[frm].submit()
   }
 }
+
+function prompt_yesno(msg) {
+    // todo: change this to jqueryui dialog
+    return window.confirm(msg);
+}
+
+function lockui() {
+    $("#lock_overlay").show();
+}
+
+function unlockui() {
+    $("#lock_overlay").hide();
+}
\ No newline at end of file
--- a/victrond/victrond.py	Thu Dec 18 06:25:07 2014 +0100
+++ b/victrond/victrond.py	Thu Dec 18 07:42:52 2014 +0100
@@ -487,11 +487,13 @@
         else:
             mail_deliver(NOTICE_EMAIL, "Device settings changed", ret)
 
-        ret = "Activating modified settings in UPS hardware...<hr />" + ret
-        ret += """<hr />--&gt;&gt; <a href='maintenance.tmpl'>
+        ret = "Activating modified settings in UPS hardware:<br/>" + ret
+        if not ('json' in form.keys()):
+            ret += """<hr />--&gt;&gt; <a href='maintenance.tmpl'>
 back to maintenance page</a>"""
-
-        return ret
+            return ret
+        else:
+            return json.dumps({"message": ret})
 
     def _get_event_status(self):
         """
@@ -873,7 +875,7 @@
                 self.end_headers()
                 # execute given function file
                 # print "DEBUG: py call: "+file_basename
-                self.wfile.write("""Running function - this may take a while.
+                if not ('json' in form.keys()): self.wfile.write("""Running function - this may take a while.
 <br />Please do not cancel!<br /><hr />""")
                 http_result = eval("UPS.func_" + file_basename + "()")
                 self.wfile.write(http_result)

mercurial