finished ajax device settings packaging

Thu, 18 Dec 2014 13:04:07 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Thu, 18 Dec 2014 13:04:07 +0100
branch
packaging
changeset 63
93988ac017d0
parent 62
780112d29fd2
child 64
da8bba34e7e1

finished ajax device settings

victrond/http/ajax-ui.html 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/http/maintenance.tmpl file | annotate | diff | comparison | revisions
victrond/victrond.py file | annotate | diff | comparison | revisions
--- a/victrond/http/ajax-ui.html	Thu Dec 18 07:42:52 2014 +0100
+++ b/victrond/http/ajax-ui.html	Thu Dec 18 13:04:07 2014 +0100
@@ -217,80 +217,102 @@
                 <div class="fixedbox">
                         <table>
                             <tr>
-                                <td colspan="3">Device settings</td>
-                            </tr>
-                            <tr>
-                                <td>NoLoad Shutdown</td>        <td><span id="set_SNoLoad_en2"></span></td>
-                                <td>
-                                    <select id="SNoLoad_en">
-                                        <option value="#">Don't change</option>
-                                        <option value="4">Enable</option>
-                                        <option value="0">Disable</option>
-                                    </select>
-                                </td>
+                                <th colspan="3">Device settings</th>
                             </tr>
                             <tr>
-                                <td>Bypass enabled</td>         <td><span id="set_SByPass_en2"></span></td>
+                                <td>NoLoad Shutdown</td>
                                 <td>
-                                    <select id="SByPass_en">
-                                        <option value="#">Don't change</option>
-                                        <option value="2">Enable</option>
-                                        <option value="0">Disable</option>
-                                    </select>
+                                    <div id="radio_SNoLoad_en">
+                                        <input type="radio" name="SNoLoad_en" id="opt_SNoLoad_en_1" value="false" /> <label for="opt_SNoLoad_en_1">Disabled</label>
+                                        <input type="radio" name="SNoLoad_en" id="opt_SNoLoad_en_2" value="true" /> <label for="opt_SNoLoad_en_2">Enabled</label>
+                                    </div>
                                 </td>
-                            </tr>
-                            <tr>
-                                <td>Alarm buzzer</td>           <td><span id="set_SBuzzerTxt2"></span></td>
-                                <td>
-                                    <select id="SBuzzer">
-                                        <option value="#">Don't change</option>
-                                        <option value="1">Disable</option>
-                                        <option value="2">Enable</option>
-                                        <option value="3">Mute</option>
-                                    </select>
+                                <td class="info">
+                                The UPS will power-off if no load connected (approx &lt; 5W)
                                 </td>
                             </tr>
                             <tr>
-                                <td>Output Voltage</td>         <td><span id="set_SOVolt2"></span> V</td>
+                                <td>Bypass enabled</td>
                                 <td>
-                                    <select id="SOVolt">
-                                        <option value="#">Don't change</option>
-                                        <option value="220">220 V</option>
-                                        <option value="230">230 V</option>
-                                        <option value="240">240 V</option>
-                                    </select>
+                                    <div id="radio_SByPass_en">
+                                        <input type="radio" name="SByPass_en" id="opt_SByPass_en_1" value="false" /> <label for="opt_SByPass_en_1">Disabled</label>
+                                        <input type="radio" name="SByPass_en" id="opt_SByPass_en_2" value="true" /> <label for="opt_SByPass_en_2">Enabled</label>
+                                    </div>
+                                </td>
+                                <td class="info">
+                                Enable the bypass circuit if input voltage not in "good" range. If disabled, the UPS will switch to battery immediately.
                                 </td>
                             </tr>
                             <tr>
-                                <td>Output Frequency</td>       <td><span id="set_SOFreq2"></span> Hz</td>
+                                <td>Alarm buzzer</td>
                                 <td>
-                                    <select id="SOFreq">
-                                        <option value="#">Don't change</option>
-                                        <option value="500">50 Hz</option>
-                                        <option value="600">60 Hz</option>
-                                    </select>
+                                    <div id="radio_SBuzzer">
+                                        <input type="radio" name="SBuzzer" id="opt_SBuzzer_1" value="1" /> <label for="opt_SBuzzer_1">Disabled</label>
+                                        <input type="radio" name="SBuzzer" id="opt_SBuzzer_3" value="3" /> <label for="opt_SBuzzer_3">Muted</label>
+                                        <input type="radio" name="SBuzzer" id="opt_SBuzzer_2" value="2" /> <label for="opt_SBuzzer_2">Enabled</label>
+                                    </div>
+                                </td>
+                                <td class="info">
                                 </td>
                             </tr>
                             <tr>
-                                <td>Battery Capacity</td>       <td><span id="set_SBCapa2"></span> Ah</td>
+                                <td>Output Voltage</td>
                                 <td>
-                                    <input id="set_val_SBCapa" SIZE="5" VALUE="">
+                                    <div id="radio_SOVolt">
+                                        <input type="radio" name="SOVolt" id="opt_SOVolt_1" value="220" /> <label for="opt_SOVolt_1">220 V</label>
+                                        <input type="radio" name="SOVolt" id="opt_SOVolt_2" value="230" /> <label for="opt_SOVolt_2">230 V</label>
+                                        <input type="radio" name="SOVolt" id="opt_SOVolt_3" value="240" /> <label for="opt_SOVolt_3">240 V</label>
+                                    </div>
+                                </td>
+                                <td class="info">
+                                Change this at your own risk, while load is connected!
                                 </td>
                             </tr>
                             <tr>
-                                <td>Auto-Restart</td>           <td><span id="set_SAutorestart_en2"></span></td>
+                                <td>Output Frequency</td>
                                 <td>
-                                    <select id="SAutorestart_en">
-                                        <option value="#">Don't change</option>
-                                        <option value="1">Enable</option>
-                                        <option value="2">Disable</option>
-                                    </select>
+                                    <div id="radio_SOFreq">
+                                        <input type="radio" name="SOFreq" id="opt_SOFreq_1" value="50" /> <label for="opt_SOFreq_1">50 Hz</label>
+                                        <input type="radio" name="SOFreq" id="opt_SOFreq_2" value="60" /> <label for="opt_SOFreq_2">60 Hz</label>
+                                    </div>
+                                </td>
+                                <td>
+                                Change this at your own risk, while load is connected!
                                 </td>
                             </tr>
+                            <tr>
+                                <td>Battery Capacity</td>
+                                <td>
+                                    <input id="set_val_SBCapa" size="4" value=""> Ah
+                                </td>
+                                <td class="info">
+                                Define the capacity of a single battery connected in series. You can do two battery strings in parallel, then define the double capacity. But be sure not to overload the charging circuit!
+                                </td>
+                            </tr>
+                            <tr>
+                                <td>Auto-Restart</td>
+                                <td>
+                                    <div id="radio_SAutorestart_en">
+                                        <input type="radio" name="SAutorestart_en" id="opt_SAutorestart_en_1" value="false" /> <label for="opt_SAutorestart_en_1">Disabled</label>
+                                        <input type="radio" name="SAutorestart_en" id="opt_SAutorestart_en_2" value="true" /> <label for="opt_SAutorestart_en_2">Enabled</label>
+                                    </div>
+                                </td>
+                                <td class="info">
+                                If enabled, the UPS will auto power on when mains are back after a system shutdown
+                                </td>
+                            </tr>
+
+                            <tr>
+                                <td width="10%"></td>
+                                <td width="40%">
+                                    <button id="submit_settings">Save &amp; Activate settings</button>
+                                </td>
+                                <td width="50%">
+                                </td>
+                            </tr>
+
                         </table>
 
-                        <button id="submit_settings">Save &amp; Activate settings</button>
-
                     <p />
                     <b> Perform self-tests: </b>
 
@@ -334,7 +356,9 @@
 
         </div>
 
-        <div id="lock_overlay" style="display: none"></div>
+        <div id="lock_overlay" style="display: none">
+            Please wait, victrond is working...
+        </div>
 
     </body>
 </html>
--- a/victrond/http/css/victrond.css	Thu Dec 18 07:42:52 2014 +0100
+++ b/victrond/http/css/victrond.css	Thu Dec 18 13:04:07 2014 +0100
@@ -6,8 +6,10 @@
     padding: 0;
     font-size: 10pt;
 }
+.ui-widget{font-size:10pt !important;}
+
 table { width:100% }
-td    { border: thin solid grey; color: #cccccc; }
+td    { color: #cccccc; }
 th    { font-weight:bold; color: #cccccc; background-color: #0273a6; }
 .clearer { clear:both; }
 .infobox { width: 400px; border:1px solid black; padding:5px;}
@@ -17,7 +19,15 @@
 .btn_switch { width:98px; }
 .graphs { width: auto; }
 .graphs img { float: left; }
-.fixedbox { width: 840px }
+
+.fixedbox { width: 1000px }
+.fixedbox tr td {
+    border-bottom: 1px solid #444444;
+}
+
+.fixedbox tr:last-child td{
+    border: none;
+}
 
 #jspanel {
     width: 195px;
@@ -94,5 +104,9 @@
     left: 0;
     width: 100%;
     height: 100%;
+    text-align: center;
+    color: #cccccc;
+    font-size: 18pt;
+    padding-top: 30px;
     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 07:42:52 2014 +0100
+++ b/victrond/http/js/victrond.js	Thu Dec 18 13:04:07 2014 +0100
@@ -1,7 +1,15 @@
 var cur_load = 0;
 
-$(function() {
+$(document).ready(function() {
     $("#tabs").tabs();
+    $("[id^=radio_]").buttonset();
+    $("#set_val_SBCapa").spinner({
+        step: 0.1,
+        culture: 'en',
+        max: 300,
+        min: 6,
+        numberFormat: 'n'
+    });
 
     $.ajax({
         type: 'GET',
@@ -31,13 +39,13 @@
                     async: false,
                     data: {
                         json: true,
-                        SNoLoad_en: $("#SNoLoad_en").val(),
-                        SByPass_en: $("#SByPass_en").val(),
-                        SBuzzer: $("#SBuzzer").val(),
-                        SOVolt: $("#SOVolt").val(),
-                        SOFreq: $("#SOFreq").val(),
+                        SNoLoad_en: getRadio('SNoLoad_en'),
+                        SByPass_en: getRadio('SByPass_en'),
+                        SBuzzer: getRadio('SBuzzer'),
+                        SOVolt: getRadio('SOVolt'),
+                        SOFreq: getRadio('SOFreq'),
                         SBCapa: $("#set_val_SBCapa").val(),
-                        SAutorestart_en: $("#SAutorestart_en").val()
+                        SAutorestart_en: getRadio('SAutorestart_en')
                     },
                     success: display_func_result,
                     error: display_error,
@@ -67,7 +75,6 @@
         success: function(data) {
             for (var k in data.values) $("#"+k).html(data.values[k]);
             for (var k in data.settings) $("[id^=set_"+k+"]").html(data.settings[k]);
-            $("#set_val_SBCapa").val(data.settings.SBCapa);
             set_load(data.values.OLoad);
             for (var k in data.values.leds) {
                 if (data.values.leds[k] == 0)
@@ -75,10 +82,33 @@
                 else
                     $("#led"+k).removeClass('off');
             }
+            // set the values on settings tab!
+            $("#set_val_SBCapa").val(data.settings.SBCapa);
+            setRadio('SNoLoad_en', data.settings.SNoLoad_en);
+            setRadio('SByPass_en', data.settings.SByPass_en);
+            setRadio('SAutorestart_en', data.settings.SAutorestart_en);
+            setRadio('SOVolt', data.settings.SOVolt);
+            setRadio('SOFreq', data.settings.SOFreq);
+            setRadio('SBuzzer', data.settings.SBuzzer);
         }
     });
 }
 
+function setRadio(name, value) {
+    if (value === true) value = 'true';
+    if (value === false) value = 'false';
+console.log(value);
+    var $radios = $('input:radio[name="'+name+'"]');
+    $radios.attr('checked', false);
+    $radios.filter('[value="'+value+'"]')
+        .attr('checked', true)
+        .trigger('click');
+}
+
+function getRadio(name) {
+    return $('input[name="'+name+'"]:checked').val();
+}
+
 function set_load(pct) {
     var px = pct/100*116;
     //var px = pct+16;
--- a/victrond/http/maintenance.tmpl	Thu Dec 18 07:42:52 2014 +0100
+++ b/victrond/http/maintenance.tmpl	Thu Dec 18 13:04:07 2014 +0100
@@ -10,8 +10,8 @@
 			<td>
 			    <select name="SNoLoad_en">
 				<option value="#">Don't change</option>
-				<option value="4">Enable</option>
-				<option value="0">Disable</option>
+				<option value="true">Enable</option>
+				<option value="false">Disable</option>
 			    </select>
 			</td>    	
 		    </tr>
@@ -20,8 +20,8 @@
 			<td>
 			    <select name="SByPass_en">
 				<option value="#">Don't change</option>
-				<option value="2">Enable</option>
-				<option value="0">Disable</option>
+				<option value="true">Enable</option>
+				<option value="false">Disable</option>
 			    </select>
 			</td>    	
 		    </tr>
@@ -53,8 +53,8 @@
 			<td>
 			    <select name="SOFreq">
 				<option value="#">Don't change</option>
-				<option value="500">50 Hz</option>
-				<option value="600">60 Hz</option>
+				<option value="50">50 Hz</option>
+				<option value="60">60 Hz</option>
 			    </select>
 			</td>
 		    </tr>
@@ -69,8 +69,8 @@
 			<td>
 			    <select name="SAutorestart_en">
 				<option value="#">Don't change</option>
-				<option value="1">Enable</option>
-				<option value="2">Disable</option>
+				<option value="true">Enable</option>
+				<option value="false">Disable</option>
 			    </select>
 			</td>    	
 		    </tr>
--- a/victrond/victrond.py	Thu Dec 18 07:42:52 2014 +0100
+++ b/victrond/victrond.py	Thu Dec 18 13:04:07 2014 +0100
@@ -169,6 +169,8 @@
         self.settings = {
             "SNoLoad_en": ((vz2c & 4) == 4),
             "SByPass_en": ((vz2c & 2) == 2),
+            "SReceptacle_en": self.query("vC0f") == "1",
+            "SAutorestart_en": self.query("vCe") == "1",
             "SModemNumber": self.query("vZ0d"),
             "SBuzzer": buzzer,
             "SBuzzerTxt": BUZZERTEXTS.get(buzzer, "Unknown: " + str(buzzer)),
@@ -176,8 +178,6 @@
             "SOFreq": float(self.query("vFd")) / 10,  # 500, 600
             "SBCapa": float(self.query("vFk")) / 10,  # 40-3000
             "SReceptacle_count": int(self.query("vCn")),
-            "SReceptacle_en": self.query("vC0f") == "1",
-            "SAutorestart_en": self.query("vCe") == "1",
             "Shutdown_type": vca,
             "Shutdown_typeTxt": SHUTDOWNTYPETEXTS.get(vca,
                                                       "Unknown: " + str(vca))
@@ -429,16 +429,34 @@
             "SAutorestart_en": "vCe"
         }
 
-        ret = ""
+        if not ('json' in form.keys()):
+            ret = ""
+        else:
+            ret = []
+
         for field in form.keys():
             cmd = setcmd.get(field, "")
             if (cmd != "") & (form[field].value != "#"):
                 val = form[field].value
 
+                if cmd == "vFh":
+                    if int(val) == self.settings["SBuzzer"]:
+                        val = "#"
+
+                if cmd == "vFc":
+                    if int(val) == self.settings["SOVolt"]:
+                        val = "#"
+
+                if cmd == "vFd":
+                    if (float(val)) == self.settings["SOFreq"]:
+                        val = "#"
+                    else:
+                        val = str(int(float(val)*10)) # ja, ich weiss, float/int, aber das passt schon so!
+
                 if cmd == "vFk":
                     val = float(val)
-                    if val < 4:
-                        val = 4
+                    if val < 6:
+                        val = 6
                     if val > 300:
                         val = 300
                     if self.settings["SBCapa"] != val:
@@ -446,10 +464,23 @@
                     else:
                         val = "#"
 
+                if cmd == "vCe":
+                    if (val == 'true') == self.settings["SAutorestart_en"]:
+                        val = "#"
+                    else:
+                        if val == 'true':
+                            val = '1'
+                        else:
+                            val = '2'
+
                 if val != "#":
                     cmd = cmd + val
-                    ret += field + ": cmd='" + cmd + "' <br />\n"
-                    self.query(cmd, 1)
+                    if not ('json' in form.keys()):
+                        ret += field + ": cmd='" + cmd + "' <br />\n"
+                        self.query(cmd, 1)
+                    else:
+                        ret.append("%s: cmd=%s" % (field, cmd));
+                        self.query(cmd, 1)
 
         # get vZ2c setting bits
         self.query("vCC5424107", 1)
@@ -457,16 +488,12 @@
         vz2c_old = vz2c
         if vz2c > 0:
             vz2c &= 249  # clear bots bits first
-            noload = form["SNoLoad_en"].value
-            bypass = form["SByPass_en"].value
-            if noload == "#":
+            noload = (form["SNoLoad_en"].value == 'true')
+            bypass = (form["SByPass_en"].value == 'true')
+            if (noload == "#") or (self.settings['SNoLoad_en'] == noload):
                 noload = ((vz2c_old & 4) == 4)
-            else:
-                noload = (int(noload) != 0)
-            if bypass == "#":
+            if (bypass == "#") or (self.settings['SByPass_en'] == bypass):
                 bypass = ((vz2c_old & 2) == 2)
-            else:
-                bypass = (int(bypass) != 0)
 
             if noload is True:
                 vz2c = (vz2c | 4)
@@ -474,26 +501,34 @@
                 vz2c = (vz2c | 2)
 
             if vz2c_old != vz2c:
-                ret += """\n<br />Setting general bitmask (NoLoad/Bypass)
- -> bitmask old/new: %s / %s""" % (vz2c_old, vz2c)
-                self.query("vZ2c" + str(vz2c), 1)
+                if not ('json' in form.keys()):
+                    ret += "\n<br />Setting general bitmask (NoLoad/Bypass) -> bitmask old/new: %s / %s" % (vz2c_old, vz2c)
+                    self.query("vZ2c" + str(vz2c), 1)
+                else:
+                    ret.append("Setting general bitmask (NoLoad/Bypass) -> bitmask old/new: %s / %s" % (vz2c_old, vz2c))
+                    self.query("vZ2c" + str(vz2c), 1)
 
         self.comm_free = True
 
         self.get_settings()
 
-        if ret == "":
-            ret = "Nothing changed!"
-        else:
-            mail_deliver(NOTICE_EMAIL, "Device settings changed", ret)
-
-        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>"""
+            if ret == "":
+                ret = "Nothing changed!"
+            else:
+                mail_deliver(NOTICE_EMAIL, "Device settings changed", ret)
+            ret = "Activating modified settings in UPS hardware:<br/>" + ret
+            ret += "<hr />--&gt;&gt; <a href='maintenance.tmpl'> back to maintenance page</a>"
             return ret
         else:
-            return json.dumps({"message": ret})
+            if len(ret) == 0:
+                ret.append("Nothing changed!")
+            else:
+                mail_deliver(NOTICE_EMAIL, "Device settings changed", "\n".join(ret))
+            return json.dumps({
+                "message": "Executed commands:\n%s" % ("\n".join(ret)),
+                "values": ret
+                })
 
     def _get_event_status(self):
         """

mercurial