/*
   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 feedvalue_widgetlist()
{
  var widgets = {
    "feedvalue":
    {
      "offsetx":-40,"offsety":-30,"width":80,"height":60,
      "menu":"Widgets",
      "options":["feedname","units","decimals"],
      "optionstype":["feed","value","decimals"],
      "optionsname":[_Tr("Feed"),_Tr("Units"),_Tr("Decimals")],
      "optionshint":[_Tr("Feed value"),_Tr("Units to show"),_Tr("Decimals to show (leave blank for automatic)")]
    }
  }
  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=='') 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()
{

}



@@ -437,16 +437,316 @@
 um%0A */%0A%0A
+function addOption(widget, optionKey, optionType, optionName, optionHint, optionData)%0A%7B%0A  widget%5B%22options%22    %5D.push(optionKey);%0A  widget%5B%22optionstype%22%5D.push(optionType);%0A  widget%5B%22optionsname%22%5D.push(optionName);%0A  widget%5B%22optionshint%22%5D.push(optionHint);%0A  widget%5B%22optionsdata%22%5D.push(optionData);%0A%7D%0A%0A
 function
@@ -786,16 +786,18 @@
 idgets =
+%0A 
  %7B%0A    %22
@@ -916,86 +916,346 @@
 ns%22:
-%5B%22feedname%22,%22units%22,%22decimals%22%5D,%0A      %22optionstype%22:%5B%22feed%22,%22value%22,%22decimals
+    %5B%5D,%0A      %22optionstype%22:%5B%5D,%0A      %22optionsname%22:%5B%5D,%0A      %22optionshint%22:%5B%5D,%0A      %22optionsdata%22:%5B%5D%0A    %7D%0A  %7D;%0A%0A  var decimalsDropBoxOptions = %5B        // Options for the type combobox. Each item is %5BtypeID, %22description%22%5D%0A         %5B-1,   %22Automatic%22%5D,%0A%09      %5B0,    %220%22%5D,%0A         %5B1,    %221%22%5D,%0A         %5B2,    %222%22%5D,%0A         %5B3,    %223
 %22%5D,%0A
@@ -1264,188 +1264,575 @@
     
+   
-%22optionsname%22:%5B_Tr(%22Feed%22),_Tr(%22Units%22),_Tr(%22Decimals%22)%5D,%0A      %22optionshint%22:%5B_Tr(%22Feed value%22),_Tr(%22Units to show%22),_Tr(%22Decimals to show (leave blank for automatic)%22)%5D%0A    %7D%0A  %7D
+%5B4,    %224%22%5D,%0A         %5B5,    %225%22%5D,%0A         %5B6,    %226%22%5D%0A       %5D;%0A%0A  addOption(widgets%5B%22feedvalue%22%5D, %22feedname%22,   %22feed%22,    _Tr(%22Feed%22),     _Tr(%22Feed value%22),                                                            %5B%5D);%0A  addOption(widgets%5B%22feedvalue%22%5D, %22units%22,      %22value%22,   _Tr(%22Units%22),    _Tr(%22Units to show%22),                                                     %5B%5D);%0A  addOption(widgets%5B%22feedvalue%22%5D, %22decimals%22,   %22dropbox%22, _Tr(%22Decimals%22), _Tr(%22Decimals to show%22),                                                          decimalsDropBoxOptions);%0A
 %0A  r
@@ -2302,18 +2302,25 @@
 cimals==
-''
+undefined
 ) decima

Update feedvalue_render.js