Explorar el Código

added service handlers

Avetisyan Karen hace 8 años
padre
commit
4ecbf295b9

+ 18 - 0
web_interface/src/wui/bat_test.cgi

@@ -0,0 +1,18 @@
+#!C:\Python27\python.exe
+# -*- coding: utf-8 -*-
+import cgi
+import sys, json
+data = json.load(sys.stdin)
+# form = cgi.FieldStorage()
+print "Content-Type: application/json"
+print ""
+
+if data["func"] == "stop":
+  print "Тест остановлен"
+elif data["func"] == "time" and data["time"]:
+  print "Тест зпущен на " + str(data["time"]) + " секунд"
+elif data["func"] == "discharge":
+  print "Тест зпущен до разряда"
+# elif data["func"] == "run" and !data["time"]:
+#   print "Тест зпущен до разрядки АКБ"
+

+ 203 - 528
web_interface/src/wui/main.js

@@ -277,31 +277,32 @@ function submitForms() {
   }
 }
 
-var pwdIsCorrect;
-function loadXMLDoc(url, method, callback) {
-  var xmlhttp;
-  if (window.XMLHttpRequest) {
-    xmlhttp = new XMLHttpRequest();
-  } else {
-    xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
-  }
-  xmlhttp.open(method, url, true);
-  var status;
-  xmlhttp.onreadystatechange = function () {
-    if (xmlhttp.readyState == 4) {
-      status = xmlhttp.status;
-      if (status == 200) {
-        pwdIsCorrect = xmlhttp.responseText;
-        if (typeof callback == 'function') {
-          callback.apply(xmlhttp);
-        }
-      } else {
-        console.log('Error');
-      }
-    }
-  };
-  xmlhttp.send();
-}
+// var loadXMLDoc = function(){};
+// var pwdIsCorrect;
+// function loadXMLDoc(url, method, callback) {
+//   var xmlhttp;
+//   if (window.XMLHttpRequest) {
+//     xmlhttp = new XMLHttpRequest();
+//   } else {
+//     xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
+//   }
+//   xmlhttp.open(method, url, true);
+//   var status;
+//   xmlhttp.onreadystatechange = function () {
+//     if (xmlhttp.readyState == 4) {
+//       status = xmlhttp.status;
+//       if (status == 200) {
+//         pwdIsCorrect = xmlhttp.responseText;
+//         if (typeof callback == 'function') {
+//           callback.apply(xmlhttp);
+//         }
+//       } else {
+//         console.log('Error');
+//       }
+//     }
+//   };
+//   xmlhttp.send();
+// }
 // function checkPWD(){
 //   var pass = $('pwd').value;
 //   var letter = /^[0-9a-zA-Z]+$/;
@@ -808,6 +809,21 @@ function settingsGET(){
   });
 }
 
+function batTest(options) {
+  this.options = (options ? options : {});
+  var url = 'bat_test.cgi';
+  loadXMLDoc(url, 'POST', function(){
+    this.responseText ? alert(this.responseText) : null;
+  }, JSON.stringify(options));
+}
+function UPSPowerOff(options) {
+  this.options = (options ? options : {});
+  var url = 'ups_power.cgi';
+  loadXMLDoc(url, 'POST', function(){
+    this.responseText ? alert(this.responseText) : null;
+  }, JSON.stringify(options));
+}
+
 // ################################################################################
 
 function infoGet() {
@@ -833,347 +849,6 @@ function infoGet() {
 
 // ################################################################################
 
-/*
-
-SpinBox.js
-
-Implements a spin box interface for a text field
-
-Created by Stephen Morley - http://code.stephenmorley.org/ - and released under
-the terms of the CC0 1.0 Universal legal code:
-
-http://creativecommons.org/publicdomain/zero/1.0/legalcode
-
-*/
-
-/* Creates a spin box. The parameter is:
- *
- * container - either the DOM node to contain the spin box or the ID of the node
- * options   - an object containing various parameters; this optional parameter
- *             defaults to the empty object
- *
- * The options object may contain the following keys:
- *
- * className - a class name to apply to the container; the class name with the
- *             suffixes 'Up' and 'Down' will be applied to the up and down
- *             buttons. The default value is 'spinBox'.
- * value     - the initial value for the spin box. The default is 0 (subject to
- *             restrictions on the minimum and maximum value) if the input
- *             element did not already exist, or the existing value if the input
- *             element did already exist.
- * step      - the value by which to increment or decrement the value. The
- *             default value is 1.
- * minimum   - the minimum allowed value. The default is not to have a minimum
- *             value.
- * maximum   - the maximum allowed value. The default is not to have a maximum
- *             value.
- * decimals  - the number of decimal places allowed. The default is 0.
- * name      - input name attribute.
- *
- * Note that the minimum, maximum, and decimal places restrictions are enforced
- * for values set by the spin box, but a value outside of these restrictions may
- * be typed by the user.
- */
-function SpinBox(container, options) {
-
-  // fetch the DOM node if a string was supplied
-  if (typeof container == 'string') {
-    container = document.getElementById(container);
-  }
-
-  // store the options and set the default values
-  this.options = (options ? options : {});
-  if (!('className' in this.options)) this.options.className = 'spinBox';
-  if (!('step'      in this.options)) this.options.step      = 1;
-  if (!('decimals'  in this.options)) this.options.decimals  = 0;
-
-  // check whether the input field should be created
-  var inputs = container.getElementsByTagName('input');
-  if (inputs.length === 0) {
-
-    // create the input node
-    this.input = document.createElement('input');
-    this.setValue('value' in this.options ? this.options.value : 0);
-    this.setName('name'   in this.options ? this.options.name : '');
-    container.appendChild(this.input);
-
-  } else {
-
-    // store a reference to the input node
-    this.input = inputs[0];
-    this.setValue(this.options.value ? this.options.value : this.input.value);
-
-  }
-
-  // create the up button
-  var upButton = document.createElement('span');
-  upButton.appendChild(document.createElement('span'));
-  upButton.innerHTML = '+';
-  container.appendChild(upButton);
-
-  // create the down button
-  var downButton = document.createElement('span');
-  downButton.appendChild(document.createElement('span'));
-  downButton.innerHTML = '-';
-  container.appendChild(downButton);
-
-  // apply the classes
-  container.className += ' ' + this.options.className;
-  upButton.className = this.options.className + 'Up';
-  downButton.className = this.options.className + 'Down';
-
-  // add the listeners
-  this.addEventListener(this.input, 'mousewheel',     this.handleMouseWheel, [], true);
-  this.addEventListener(this.input, 'DOMMouseScroll', this.handleMouseWheel, [], true);
-  this.addEventListener(this.input, 'keydown',        this.handleKeyDown, [], true);
-  this.addEventListener(this.input, 'keypress',       this.handleKeyPress, [], true);
-  this.addEventListener(this.input, 'keyup',          this.stop);
-  this.addEventListener(upButton,   'mousedown',      this.start, [true]);
-  this.addEventListener(upButton,   'mouseup',        this.stop);
-  this.addEventListener(upButton,   'mouseout',       this.stop);
-  this.addEventListener(downButton, 'mousedown',      this.start, [false]);
-  this.addEventListener(downButton, 'mouseup',        this.stop);
-  this.addEventListener(downButton, 'mouseout',       this.stop);
-
-}
-
-/* Returns the current value. This will be a number, or the value NaN if the
- * current contents of the input field do not start with a valid number.
- */
-SpinBox.prototype.getValue = function () {
-
-  // parse and return the value
-  return parseFloat(this.input.value);
-
-};
-
-SpinBox.prototype.setName = function (name) {
-
-  // asign input name
-  this.input.name = name;
-};
-/* Sets the value. Restrictions on the minimum and maximum value are enforced.
- * The parameter is:
- *
- * value - the value
- */
-SpinBox.prototype.setValue = function (value) {
-
-  // ensure the value is within the permitted range
-  if ('minimum' in this.options) value = Math.max(this.options.minimum, value);
-  if ('maximum' in this.options) value = Math.min(this.options.maximum, value);
-
-  // store the sign
-  var sign = (value < 0 ? '-' : '');
-  value = Math.abs(value);
-
-  // determine the multiplier for rounding
-  var multiplier = Math.pow(10, this.options.decimals);
-
-  // split the value in to integer and fractional parts
-  value = Math.round(value * multiplier);
-  var integer = (value - value % multiplier) / multiplier;
-  var fractional = '' + value % multiplier;
-
-  // add leading zeros to the fractional part
-  while (fractional.length < this.options.decimals) {
-    fractional = '0' + fractional;
-  }
-
-  // set the value
-  this.input.value =
-      sign + integer + (this.options.decimals > 0 ? '.' + fractional : '');
-
-  // check whether the browser can dispatch events
-  if ('dispatchEvent' in this.input){
-
-    // create the event
-    var event;
-    try{
-      event = new Event('change', {bubbles : true, cancelable : true});
-    }catch (e){
-      event = document.createEvent('Event');
-      event.initEvent('change', true, true);
-    }
-
-    // dispatch the event
-    this.input.dispatchEvent(event);
-
-  }
-
-};
-
-/* Adds an event listener to a node. The event listener is bound to the current
- * value of 'this'. The parameters are:
- *
- * node         - the node
- * event        - the event name
- * listener     - the listener functions
- * parameters   - an array of additional parameters to pass to the listener;
- *                these are placed after the event parameter
- * allowDefault - true if the default action should not be prevented
- */
-SpinBox.prototype.addEventListener = function (
-node, event, listener, parameters, allowDefault) {
-
-  // store a reference to the 'this' object
-  var thisObject = this;
-
-  // create the bound listener
-  function boundListener(e) {
-
-    // get the event if it is not supplied
-    if (!e) e = window.event;
-
-    // call the listener
-    listener.apply(thisObject, [e].concat(parameters));
-
-    // prevent the default action if necessary
-    if (!allowDefault) {
-      if (e.preventDefault) {
-        e.preventDefault();
-      } else {
-        e.returnValue = false;
-      }
-    }
-
-  }
-
-  // add the event listener
-  if (node.addEventListener) {
-    node.addEventListener(event, boundListener, false);
-  } else {
-    node.attachEvent('on' + event, boundListener);
-  }
-
-};
-
-/* Handles a mouse wheel event by updating the value if the field is active. The
- * parameter is:
- *
- * e - the event object
- */
-SpinBox.prototype.handleMouseWheel = function (e) {
-
-  // check whether the field is active
-  if (document.activeElement == this.input) {
-
-    // update the value
-    if (e.wheelDelta) {
-      this.start(e, e.wheelDelta > 1);
-    } else if (e.detail) {
-      this.start(e, e.detail < 1);
-    }
-    this.stop();
-
-    // prevent the default action
-    if (e.preventDefault) {
-      e.preventDefault();
-    } else {
-      e.returnValue = false;
-    }
-
-  }
-
-};
-
-/* Handles a key down event by starting updating if appropriate. The parameter
- * is:
- *
- * e - the event object
- */
-SpinBox.prototype.handleKeyDown = function (e) {
-
-  // if the up or down keys were pressed, start updating
-  if (e.keyCode == 38) this.start(e, true);
-  if (e.keyCode == 40) this.start(e, false);
-
-};
-
-/* Handles a key press event by filtering out invalid characters. The parameter
- * is:
- *
- * e - the event object
- */
-SpinBox.prototype.handleKeyPress = function (e) {
-
-  // determine the character code
-  var charCode = ('charCode' in e ? e.charCode : e.keyCode);
-
-  // allow special key presses
-  if (charCode === 0 || e.altKey || e.ctrlKey || e.metaKey) return;
-
-  // allow a minus sign if the value can be negative
-  if (charCode == 45 && (!('minimum' in this.options) || this.options.minimum < 0)) {
-    return;
-  }
-
-  // allow a decimal point if the value may contain decimals
-  if (charCode == 46 && this.options.decimals > 0) return;
-
-  // allow digits
-  if (charCode >= 48 && charCode <= 57) return;
-
-  // prevent the default action
-  if (e.preventDefault) {
-    e.preventDefault();
-  } else {
-    e.returnValue = false;
-  }
-
-};
-
-/* Starts updating the value. The parameters are:
- *
- * e  - the event object
- * up - true to increment the value, false to decrement the value
- */
-SpinBox.prototype.start = function (e, up) {
-
-  // if the field is disabled or we are already updating, return immediately
-  if (this.input.disabled || 'timeout' in this) return;
-
-  // set the update step
-  this.updateStep = (up ? this.options.step : -this.options.step);
-
-  // initialise the timeout delay
-  this.timeoutDelay = 500;
-
-  // update the value
-  this.update();
-
-};
-
-// Stops update the value.
-SpinBox.prototype.stop = function () {
-
-  // clear the timeout if it exists
-  if ('timeout' in this) {
-    window.clearTimeout(this.timeout);
-    delete this.timeout;
-  }
-
-};
-
-// Updates the value.
-SpinBox.prototype.update = function () {
-
-  // determine the current value
-  var value = parseFloat(this.input.value);
-  if (isNaN(value)) value = 0;
-
-  // update the value
-  this.setValue(value + this.updateStep);
-
-  // reduce the delay
-  this.timeoutDelay = Math.max(20, Math.floor(this.timeoutDelay * 0.9));
-
-  // call this function again
-  var thisObject = this;
-  this.timeout = window.setTimeout(function () { thisObject.update(); }, this.timeoutDelay);
-
-};
-
 
 /*
   This code is from Dynamic Web Coding at dyn-web.com
@@ -1592,35 +1267,35 @@ DYN_WEB.Tabs = (function () {
  * @param  {String} type - request | cancel | native.
  * @return {Function} Timing function.
  */
-function requestFrame(type) {
-  // The only vendor prefixes required.
-  var vendors = ['moz', 'webkit'],
+  function requestFrame(type) {
+    // The only vendor prefixes required.
+    var vendors = ['moz', 'webkit'],
 
-    // Disassembled timing function abbreviations.
-    aF = 'AnimationFrame',
-    rqAF = 'Request' + aF,
+      // Disassembled timing function abbreviations.
+      aF = 'AnimationFrame',
+      rqAF = 'Request' + aF,
 
-    // Final assigned functions.
-    assignedRequestAnimationFrame,
-    assignedCancelAnimationFrame,
+      // Final assigned functions.
+      assignedRequestAnimationFrame,
+      assignedCancelAnimationFrame,
 
-    // Initial time of the timing lapse.
-    previousTime = 0,
+      // Initial time of the timing lapse.
+      previousTime = 0,
 
-    mozRAF = window.mozRequestAnimationFrame,
-    mozCAF = window.mozCancelAnimationFrame,
+      mozRAF = window.mozRequestAnimationFrame,
+      mozCAF = window.mozCancelAnimationFrame,
 
-    // Checks for firefox 4 - 10 function pair mismatch.
-    hasMozMismatch = mozRAF && !mozCAF,
+      // Checks for firefox 4 - 10 function pair mismatch.
+      hasMozMismatch = mozRAF && !mozCAF,
 
-    func;
+      func;
 
-  // Date.now polyfill, mainly for legacy IE versions.
-  if (!Date.now) {
-    Date.now = function() {
-      return new Date().getTime();
-    };
-  }
+    // Date.now polyfill, mainly for legacy IE versions.
+    if (!Date.now) {
+      Date.now = function() {
+        return new Date().getTime();
+      };
+    }
 
   /**
    * hasIOS6RequestAnimationFrameBug.
@@ -1629,112 +1304,112 @@ function requestFrame(type) {
    * @Copyright 2015 - Julien Etienne.
    * @License: MIT.
    */
-  function hasIOS6RequestAnimationFrameBug() {
-    var webkitRAF = window.webkitRequestAnimationFrame,
-      rAF = window.requestAnimationFrame,
+    function hasIOS6RequestAnimationFrameBug() {
+      var webkitRAF = window.webkitRequestAnimationFrame,
+        rAF = window.requestAnimationFrame,
 
-      // CSS/ Device with max for iOS6 Devices.
-      hasMobileDeviceWidth = screen.width <= 768 ? true : false,
+        // CSS/ Device with max for iOS6 Devices.
+        hasMobileDeviceWidth = screen.width <= 768 ? true : false,
 
-      // Only supports webkit prefixed requestAnimtionFrane.
-      requiresWebkitprefix = !(webkitRAF && rAF),
+        // Only supports webkit prefixed requestAnimtionFrane.
+        requiresWebkitprefix = !(webkitRAF && rAF),
 
-      // iOS6 webkit browsers don't support performance now.
-      hasNoNavigationTiming = window.performance ? false : true,
+        // iOS6 webkit browsers don't support performance now.
+        hasNoNavigationTiming = window.performance ? false : true,
 
-      iOS6Notice = 'setTimeout is being used as a substitiue for' +
-      'requestAnimationFrame due to a bug within iOS 6 builds',
+        iOS6Notice = 'setTimeout is being used as a substitiue for' +
+        'requestAnimationFrame due to a bug within iOS 6 builds',
 
-      hasIOS6Bug = requiresWebkitprefix && hasMobileDeviceWidth &&
-      hasNoNavigationTiming;
+        hasIOS6Bug = requiresWebkitprefix && hasMobileDeviceWidth &&
+        hasNoNavigationTiming;
 
-    function bugCheckresults(timingFnA, timingFnB, notice) {
-      if (timingFnA || timingFnB) {
-        console.warn(notice);
-        return true;
-      } else {
-        return false;
+      function bugCheckresults(timingFnA, timingFnB, notice) {
+        if (timingFnA || timingFnB) {
+          console.warn(notice);
+          return true;
+        } else {
+          return false;
+        }
       }
-    }
 
-    function displayResults() {
-      if (hasIOS6Bug) {
-        return bugCheckresults(webkitRAF, rAF, iOS6Notice);
-      } else {
-        return false;
+      function displayResults() {
+        if (hasIOS6Bug) {
+          return bugCheckresults(webkitRAF, rAF, iOS6Notice);
+        } else {
+          return false;
+        }
       }
-    }
-
-    return displayResults();
-  }
 
-  /**
-   * Native clearTimeout function.
-   * @return {Function}
-   */
-  function clearTimeoutWithId(id) {
-    clearTimeout(id);
-  }
-
-  /**
-   * Based on a polyfill by Erik, introduced by Paul Irish &
-   * further improved by Darius Bacon.
-   * @see  {@link http://www.paulirish.com/2011/
-   * requestanimationframe-for-smart-animating}
-   * @see  {@link https://github.com/darius/requestAnimationFrame/blob/
-   * master/requestAnimationFrame.js}
-   * @callback {Number} Timestamp.
-   * @return {Function} setTimeout Function.
-   */
-  function setTimeoutWithTimestamp(callback) {
-    var immediateTime = Date.now(),
-      lapsedTime = Math.max(previousTime + 16, immediateTime);
-    return setTimeout(function() {
-      callback(previousTime = lapsedTime);
-    },
-        lapsedTime - immediateTime);
-  }
+      return displayResults();
+    }
 
     /**
-     * Queries the native function, prefixed function
-     * or use the setTimeoutWithTimestamp function.
+     * Native clearTimeout function.
      * @return {Function}
      */
-  function queryRequestAnimationFrame() {
-    if (Array.prototype.filter) {
-      assignedRequestAnimationFrame = window['request' + aF] ||
-        window[vendors.filter(function(vendor) {
-          if (window[vendor + rqAF] !== undefined)
-            return vendor;
-        }) + rqAF] || setTimeoutWithTimestamp;
-    } else {
-      return setTimeoutWithTimestamp;
+    function clearTimeoutWithId(id) {
+      clearTimeout(id);
     }
-    if (!hasIOS6RequestAnimationFrameBug()) {
-      return assignedRequestAnimationFrame;
-    } else {
-      return setTimeoutWithTimestamp;
+
+    /**
+     * Based on a polyfill by Erik, introduced by Paul Irish &
+     * further improved by Darius Bacon.
+     * @see  {@link http://www.paulirish.com/2011/
+     * requestanimationframe-for-smart-animating}
+     * @see  {@link https://github.com/darius/requestAnimationFrame/blob/
+     * master/requestAnimationFrame.js}
+     * @callback {Number} Timestamp.
+     * @return {Function} setTimeout Function.
+     */
+    function setTimeoutWithTimestamp(callback) {
+      var immediateTime = Date.now(),
+        lapsedTime = Math.max(previousTime + 16, immediateTime);
+      return setTimeout(function() {
+        callback(previousTime = lapsedTime);
+      },
+          lapsedTime - immediateTime);
+    }
+
+      /**
+       * Queries the native function, prefixed function
+       * or use the setTimeoutWithTimestamp function.
+       * @return {Function}
+       */
+    function queryRequestAnimationFrame() {
+      if (Array.prototype.filter) {
+        assignedRequestAnimationFrame = window['request' + aF] ||
+          window[vendors.filter(function(vendor) {
+            if (window[vendor + rqAF] !== undefined)
+              return vendor;
+          }) + rqAF] || setTimeoutWithTimestamp;
+      } else {
+        return setTimeoutWithTimestamp;
+      }
+      if (!hasIOS6RequestAnimationFrameBug()) {
+        return assignedRequestAnimationFrame;
+      } else {
+        return setTimeoutWithTimestamp;
+      }
     }
-  }
 
     /**
      * Queries the native function, prefixed function
      * or use the clearTimeoutWithId function.
      * @return {Function}
      */
-  function queryCancelAnimationFrame() {
-    var cancellationNames = [];
-    if (Array.prototype.map) {
-      vendors.map(function(vendor) {
-        return ['Cancel', 'CancelRequest'].map(
-          function(cancellationNamePrefix) {
-            cancellationNames.push(vendor +
-                cancellationNamePrefix + aF);
-          });
-      });
-    } else {
-      return clearTimeoutWithId;
-    }
+    function queryCancelAnimationFrame() {
+      var cancellationNames = [];
+      if (Array.prototype.map) {
+        vendors.map(function(vendor) {
+          return ['Cancel', 'CancelRequest'].map(
+            function(cancellationNamePrefix) {
+              cancellationNames.push(vendor +
+                  cancellationNamePrefix + aF);
+            });
+        });
+      } else {
+        return clearTimeoutWithId;
+      }
 
       /**
        * Checks for the prefixed cancelAnimationFrame implementation.
@@ -1742,75 +1417,75 @@ function requestFrame(type) {
        * @param  {Number} i - Iteration start point.
        * @return {Function} prefixed cancelAnimationFrame function.
        */
-    function prefixedCancelAnimationFrame(prefixedNames, i) {
-      var cancellationFunction;
-      for (; i < prefixedNames.length; i++) {
-        if (window[prefixedNames[i]]) {
-          cancellationFunction = window[prefixedNames[i]];
-          break;
+      function prefixedCancelAnimationFrame(prefixedNames, i) {
+        var cancellationFunction;
+        for (; i < prefixedNames.length; i++) {
+          if (window[prefixedNames[i]]) {
+            cancellationFunction = window[prefixedNames[i]];
+            break;
+          }
         }
+        return cancellationFunction;
       }
-      return cancellationFunction;
-    }
 
-    // Use truthly function
-    assignedCancelAnimationFrame = window['cancel' + aF] ||
-        prefixedCancelAnimationFrame(cancellationNames, 0) ||
-        clearTimeoutWithId;
+      // Use truthly function
+      assignedCancelAnimationFrame = window['cancel' + aF] ||
+          prefixedCancelAnimationFrame(cancellationNames, 0) ||
+          clearTimeoutWithId;
 
-    // Check for iOS 6 bug
-    if (!hasIOS6RequestAnimationFrameBug()) {
-      return assignedCancelAnimationFrame;
-    } else {
-      return clearTimeoutWithId;
+      // Check for iOS 6 bug
+      if (!hasIOS6RequestAnimationFrameBug()) {
+        return assignedCancelAnimationFrame;
+      } else {
+        return clearTimeoutWithId;
+      }
     }
-  }
 
-  function getRequestFn() {
-    if (hasMozMismatch) {
-      return setTimeoutWithTimestamp;
-    } else {
-      return queryRequestAnimationFrame();
+    function getRequestFn() {
+      if (hasMozMismatch) {
+        return setTimeoutWithTimestamp;
+      } else {
+        return queryRequestAnimationFrame();
+      }
     }
-  }
-
-  function getCancelFn() {
-    return queryCancelAnimationFrame();
-  }
 
-  function setNativeFn() {
-    if (hasMozMismatch) {
-      window.requestAnimationFrame = setTimeoutWithTimestamp;
-      window.cancelAnimationFrame = clearTimeoutWithId;
-    } else {
-      window.requestAnimationFrame = queryRequestAnimationFrame();
-      window.cancelAnimationFrame = queryCancelAnimationFrame();
+    function getCancelFn() {
+      return queryCancelAnimationFrame();
     }
-  }
-
-    /**
-     * The type value "request" singles out firefox 4 - 10 and
-     * assigns the setTimeout function if plausible.
-     */
 
-  switch (type) {
-  case 'request':
-  case '':
-    func = getRequestFn();
-    break;
+    function setNativeFn() {
+      if (hasMozMismatch) {
+        window.requestAnimationFrame = setTimeoutWithTimestamp;
+        window.cancelAnimationFrame = clearTimeoutWithId;
+      } else {
+        window.requestAnimationFrame = queryRequestAnimationFrame();
+        window.cancelAnimationFrame = queryCancelAnimationFrame();
+      }
+    }
 
-  case 'cancel':
-    func = getCancelFn();
-    break;
+      /**
+       * The type value "request" singles out firefox 4 - 10 and
+       * assigns the setTimeout function if plausible.
+       */
 
-  case 'native':
-    setNativeFn();
-    break;
-  default:
-    throw new Error('RequestFrame parameter is not a type.');
+    switch (type) {
+    case 'request':
+    case '':
+      func = getRequestFn();
+      break;
+
+    case 'cancel':
+      func = getCancelFn();
+      break;
+
+    case 'native':
+      setNativeFn();
+      break;
+    default:
+      throw new Error('RequestFrame parameter is not a type.');
+    }
+    return func;
   }
-  return func;
-}
   // Default to window as global
   if (typeof window === 'object') {
     window.requestFrame = requestFrame;

+ 3 - 2
web_interface/src/wui/role.js

@@ -80,7 +80,7 @@ function logOut() {
   return false;
 }
 
-function loadXMLDoc(url, method, callback) {
+function loadXMLDoc(url, method, callback, body) {
   var xmlhttp;
   if (window.XMLHttpRequest) {
     xmlhttp = new XMLHttpRequest();
@@ -88,6 +88,7 @@ function loadXMLDoc(url, method, callback) {
     xmlhttp = new window.ActiveXObject('Microsoft.XMLHTTP');
   }
   xmlhttp.open(method, url, true);
+  xmlhttp.setRequestHeader('Content-Type', 'application/json');
   var status;
   xmlhttp.onreadystatechange = function () {
     if (xmlhttp.readyState == 4) {
@@ -102,7 +103,7 @@ function loadXMLDoc(url, method, callback) {
       }
     }
   };
-  xmlhttp.send();
+  xmlhttp.send(body);
 }
 
 function addSort(page){

+ 17 - 15
web_interface/src/wui/settings.html

@@ -118,7 +118,6 @@
         <thead>
           <tr>
             <th>Контакт</th>
-            <!-- <th>Тип</th> -->
             <th>Источник</th>
           </tr>
         </thead>
@@ -177,25 +176,25 @@
   <div class="panel-body section group">
     <div class="col span_1_of_3">
       <h4 class="col span_2_of_2">Аккумуляторные батареи</h4>
-      <button type="button" class="btn btn-default" id="">Остановка теста</button>
-      <button type="button" class="btn btn-default" id="">Запуск теста до разряда</button>
-      <button type="button" class="btn btn-default" id="">Запуск теста</button>
+      <button type="button" class="btn btn-default" onclick="batTest({ 'func': 'stop' });">Остановка теста</button>
+      <button type="button" class="btn btn-default" onclick="batTest({ 'func': 'discharge' });">Запуск теста до разряда</button>
+      <button type="button" class="btn btn-default" onclick="batTest({ 'func': 'time', 'time': $('test_time').value });">Запуск теста</button>
       <label for="" class="col span_1_of_2">Время теста (сек)</label>
       <div class="col span_1_of_2">
-        <input type="text" class="form-control">
+        <input type="text" class="form-control" value="10" maxlength="6" id="test_time">
       </div>
     </div>
     <div class="col span_1_of_3">
       <h4 class="col span_2_of_2">ИБП</h4>
-      <button type="button" class="btn btn-default" id="">Отмена выключения</button>
-      <button type="button" class="btn btn-default" id="">Выключить</button>
+      <button type="button" class="btn btn-default" onclick="UPSPowerOff({'func': 'cancel'})">Отмена выключения</button>
+      <button type="button" class="btn btn-default" onclick="UPSPowerOff({'func': 'off', 'after': $('upspo_after').value, 'to': $('upspo_to').value})">Выключить</button>
       <label for="" class="col span_1_of_2">Выключить на (сек)</label>
       <div class="col span_1_of_2">
-        <input type="text" class="form-control">
+        <input type="text" class="form-control" value="10" maxlength="6" id="upspo_to">
       </div>
       <label for="" class="col span_1_of_2">Включить через (сек)</label>
       <div class="col span_1_of_2">
-        <input type="text" class="form-control">
+        <input type="text" class="form-control" value="10" maxlength="6" id="upspo_after">
       </div>
     </div>
     <div class="col span_1_of_3">
@@ -334,26 +333,29 @@ settingsGET();
 // };
 $('dev-update').onclick = function(){
   if( confirm('Перевести контроллер в режим обновления ПО?') ){
-    checkPWD()
+    checkPWD();
   };
 };
+
 $('close-pass').onclick = function(){
   $('count-wrap').style.display = 'none';
   $('checkUpdatePass').style.display = 'none';
-}
+};
+
 $('dev-reset').onclick = function(){
+  function foo(){window.location.href = '/settings.html';}
   if (getCGI('reset.cgi') == true) {
-    function foo(){window.location.href = '/settings.html';}
     setTimeout(foo, 1000);
-  };
+  }
 };
+
 $('dev-reboot').onclick = function(){
-  a = 'reboot.cgi';
+  var a = 'reboot.cgi';
   if (getCGI(a) == true) {
     $('count-wrap').style.display = 'block';
     $('countdown').style.display = 'block';
     countdown(true);
-  };
+  }
 };
 </script>
 </html>

+ 16 - 0
web_interface/src/wui/ups_power.cgi

@@ -0,0 +1,16 @@
+#!C:\Python27\python.exe
+# -*- coding: utf-8 -*-
+import cgi
+import sys, json
+data = json.load(sys.stdin)
+# form = cgi.FieldStorage()
+print "Content-Type: application/json"
+print ""
+
+if data["func"] == "cancel":
+  print "Выключенеие астановлено"
+elif data["func"] == "off":
+  print "ИБП выключится через " + str(data["after"]) + " секунд на " + str(data["to"]) + " секунд"
+# elif data["func"] == "run" and !data["time"]:
+#   print "Тест зпущен до разрядки АКБ"
+