/*
   All emon_widgets code is released under the GNU General Public License v3.
   See COPYRIGHT.txt and LICENSE.txt.

    ---------------------------------------------------------------------
    Part of the OpenEnergyMonitor project:
    http://openenergymonitor.org

    Author: Trystan Lea: trystan.lea@googlemail.com
    If you have any questions please get in touch, try the forums here:
    http://openenergymonitor.org/emon/forum
 */

function addOption(widget, optionKey, optionType, optionName, optionHint, optionData)
{
  widget["options"    ].push(optionKey);
  widget["optionstype"].push(optionType);
  widget["optionsname"].push(optionName);
  widget["optionshint"].push(optionHint);
  widget["optionsdata"].push(optionData);
}

function feedvalue_widgetlist()
{
  var widgets =
  {
    "feedvalue":
    {
      "offsetx":-40,"offsety":-30,"width":80,"height":60,
      "menu":"Widgets",
      "options":    [],
      "optionstype":[],
      "optionsname":[],
      "optionshint":[],
      "optionsdata":[]
    }
  };

  var decimalsDropBoxOptions = [        // Options for the type combobox. Each item is [typeID, "description"]
         [-1,   "Automatic"],
	 [0,    "0"],
         [1,    "1"],
         [2,    "2"],
         [3,    "3"],
         [4,    "4"],
         [5,    "5"],
         [6,    "6"]
       ];

  addOption(widgets["feedvalue"], "feedname",   "feed",    _Tr("Feed"),     _Tr("Feed value"),                                                            []);
  addOption(widgets["feedvalue"], "units",      "value",   _Tr("Units"),    _Tr("Units to show"),                                                     []);
  addOption(widgets["feedvalue"], "decimals",   "dropbox", _Tr("Decimals"), _Tr("Decimals to show"),                                                          decimalsDropBoxOptions);

  return widgets;
}

function feedvalue_init()
{
  feedvalue_draw();
}

function feedvalue_draw()
{
  $('.feedvalue').each(function(index)
  {
    var feed = $(this).attr("feedname");
    if (feed==undefined) feed = $(this).attr("feed");

    var units = $(this).attr("units");
    var val = assoc[feed];
    var decimals = $(this).attr("decimals");

    if (feed==undefined) val = 0;
    if (units==undefined) units = '';
    if (val==undefined) val = 0;
    if (decimals==undefined) decimals = -1;
    
    if (isNaN(val))  val = 0;
    
    if (decimals<0)
    {

      if (val>=100)
          val = (val*1).toFixed(0);
      else if (val>=10)
          val = (val*1).toFixed(1);
      else if (val<=-100)
          val = (val*1).toFixed(0);
      else if (val<=-10)
          val = (val*1).toFixed(1);
      else
          val = (val*1).toFixed(2);
    }
    else 
    {
      val = val.toFixed(decimals);
    }

    $(this).html(val+units);
  });
}

function feedvalue_slowupdate()
{
  feedvalue_draw();
}

function feedvalue_fastupdate()
{

}



@@ -1138,25 +1138,18 @@
 ption%22%5D%0A
-         
+%09%09
 %5B-1,   %22
@@ -1162,17 +1162,17 @@
 tic%22%5D,%0A%09
- 
+%09
 %5B0,    %22
@@ -1176,25 +1176,18 @@
   %220%22%5D,%0A
-         
+%09%09
 %5B1,    %22
@@ -1191,25 +1191,18 @@
   %221%22%5D,%0A
-         
+%09%09
 %5B2,    %22
@@ -1206,25 +1206,18 @@
   %222%22%5D,%0A
-         
+%09%09
 %5B3,    %22
@@ -1221,25 +1221,18 @@
   %223%22%5D,%0A
-         
+%09%09
 %5B4,    %22
@@ -1236,25 +1236,18 @@
   %224%22%5D,%0A
-         
+%09%09
 %5B5,    %22
@@ -1251,25 +1251,18 @@
   %225%22%5D,%0A
-         
+%09%09
 %5B6,    %22
@@ -1265,23 +1265,17 @@
    %226%22%5D%0A
-       
+%09
 %5D;%0A%0A  ad
@@ -1368,68 +1368,10 @@
 e%22),
-                                                            
+%09%09
 %5B%5D);
@@ -1472,61 +1472,9 @@
 w%22),
-                                                     
+%09
 %5B%5D);
@@ -1578,66 +1578,9 @@
 w%22),
-                                                          
+%09
 deci

Update feedvalue_render.js