FW_version["fhemweb_iconRadio.js"] = "$Id$"; FW_widgets['iconRadio'] = { createFn:FW_iconRadioCreate, }; /********* iconRadio *********/ function FW_iconRadioCreate(elName, devName, vArr, currVal, set, params, cmd) { if( 0 ) { console.log( "elName: "+elName ); console.log( "devName: "+devName ); console.log( "vArr: "+vArr ); console.log( "currVal: "+currVal ); console.log( "set: "+set ); console.log( "params: "+params ); console.log( "cmd: "+cmd ); } if(!vArr.length || vArr[0] != "iconRadio") return undefined; var ipar = 2; if( vArr[1].match(/^[A-F0-9]{6}$/)) vArr[1] = "#"+vArr[1]; var newEl = $("
").get(0); $(newEl).addClass(vArr[0]); var hidden; if(elName) hidden = $(''); $(newEl).append(hidden); var clicked = function(arg) { var new_val=newEl.getValueFn(arg); newEl.setValueFn( new_val ); if( cmd ) cmd(new_val); }; var buttons = []; for( var i = 2; i < (vArr.length); i+=ipar ) { vArr[i] = vArr[i].replace(/#/g," "); var button = $('').uniqueId(); var label = $(''); buttons.push(button); $(newEl).append(button); $(newEl).append(label); $(button).change(clicked); if( currVal ) button.prop("checked", currVal == vArr[i] ); } $(newEl).buttonset(); $(newEl).find("label").css({"margin":"0","border":"0","border-radius":"4px","background":"inherit"}); $(newEl).find("span").css({"padding":"0.0em 0.3em"}); $(newEl).find("label").each(function(ind,val){ $(val).addClass("iconRadio_widget") var ico = vArr[ind*ipar+3]; FW_cmd(FW_root+"?cmd={FW_makeImage('"+ico+"')}&XHR=1",function(data){ data = data.replace(/\n$/,''); $(newEl).find("label").each(function(ind,val){ var re = new RegExp("\"\s?"+$(val).attr("name")+"(\s?|\")","i"); if (!(data.match(re) === null) && ($(val).find("span").html().match(re) === null)) { $(val).find("span").addClass("iconRadio_widget").html(data); return false; } }); }); }); if( !currVal ) currVal = ","; newEl.getValueFn = function(arg) { var new_val=""; for( var i = 0; i < buttons.length; ++i ) { var button = buttons[i]; if( $(button).prop("checked") ) { button.next().css({"background-color":vArr[1]}); if( new_val ) new_val += ','; new_val += $(button).button( "option", "label") } } if( !new_val ) return ','; return new_val; }; newEl.setValueFn = function(arg){ if( !arg ) arg = ','; if( hidden ) hidden.attr("value", arg); for( var i = 0; i < buttons.length; ++i ) { var button = buttons[i]; button.prop("checked", (arg == vArr[i*ipar+2]) ); if (button.prop("checked")==true){ button.next().css({"background-color":vArr[1]}); } else { button.next().css({"background-color":"inherit"}); } button.button("refresh"); } }; newEl.setValueFn( currVal ); return newEl; } /* =pod =begin html
To the icon.* widgets listed below applies:
<color> is specified by a color name or a color number without leading # e.g. FFA500 or orange. Depending on the context @ has to be escaped \@.
<icon> is the icon name.
Examples for import with raw definition, will be found in FHEMWEB-Widgets
  • iconRadio,<select color>,<value>,<icon>[@<color>][,<value>,<icon>[@<color>]]... - displays Icons as radio button and returns value if pushed. <value> return value.
    <select color> the background color of the selected icon.
    The widget contains a CSS-class "iconRadio_widget".
  • iconButtons,<select color>,<value>,<icon>[@<color>][,<value>,<icon>[@<color>]]... - displays Icons as button bar and returns comma separated values of pushed buttons. <value> return value.
    <select color> the background color of the selected icon.
    The widget contains a CSS-class "iconButtons_widget".
  • iconLabel[,<reference value>,[<icon>][@<color>]][,<reference value>,[<icon>][@<color>]]... - displays states by colorized values, labels and icons, if the current value fits to the reference value. A state is described by a parameter peer. The number of peers is arbitrarily. A peer consists of a <reference value> and an optional display value with an optional color value <reference value> is a number or a regular expression.
    If <icon> is no icon name, the text will be displayed, otherwise the icon. If nothing is specified, the current value will be displayed.
  • iconSwitch,<reference value>,[<icon>][@<color>][,<reference value>,[<icon>][@<color>]]... - switches cyclic after actuation to the diplayed state and the actual value is set to the reference Value. A state is described by a parameter peer. The number of peers is arbitrarily. A peer consists of a <reference value> and an optional display value with an optional color value [<icon>][@<color>].
    <reference value> is a number or a string.
    If <icon> is no icon name, the text will be displayed, otherwise the icon. If nothing is specified, the reference value will be displayed.

  • =end html =begin html_DE
    Für die folgenden icon.* Widgets gilt:
    <color> kann ein Farbname oder eine Farbnummer ohne führende # sein, z.B. orange oder FFA500. Abhängig vom Kontext ist @ zu escapen \@.
    <icon> ist der Iconname.
    Beispiele zum Import über Raw definition findet man im FHEM-Wiki unter FHEMWEB-Widgets
  • iconRadio,<select color>,<value>,<icon>[@<color>][,<value>,<icon>[@<color>]]... - zeigt Icons als Radiobutton an und gibt Value bei Betätigung zurück.
    <value> ist der Rückgabewert.
    <select color> die Hintergrundfarbe des gewählten Icons.
    Das Widget enthält eine CSS-Klasse "iconRadio_widget".
  • iconButtons,<select color>,<value>,<icon>[@<color>][,<value>,<icon>[@<color>]]... - zeigt Icons als Tastenleiste an und gibt durch Komma getrennte Werte der betätigten Tasten zurück.
    <value> ist der Rückgabewert.
    <select color> die Hintergrundfarbe des gewählten Icons.
    Das Widget enthält eine CSS-Klasse "iconButton_widget".
  • iconLabel[,<reference value>,[<icon>][@<color>]][,<reference value>,[<icon>][@<color>]]... - zeigt Zustände durch colorierte Werte, Beschriftungen und Icons an, wenn der aktuelle Wert zum Vergleichswert passt. Ein Zustand wird durch ein Parameterpaar beschrieben. Es können beliebig viele Paare angegeben werden. Ein Paar besteht aus einem Vergleichswert <reference value> und einem optionalen Anzeigewert mit optionaler mit Farbangabe [,<reference value>,[<icon>][@<color>]].
    <reference value> kann eine Zahl oder ein regulärer Ausdruck sein.
    Wenn <icon> keinem Iconnamen entspricht, wird der Text angezeigt, sonst das Icon. Wird <icon> nicht angegeben, wird der aktuelle Wert angezeigt.
  • iconSwitch,<reference value>,[<icon>][@<color>][,<reference value>,[<icon>][@<color>]]... - schaltet zyklisch nach jeder Betätigung in den angezeigten Zustand, dabei wird der aktuelle Wert auf den Vergleichswert gesetzt. Ein Zustand wird durch ein Parameterpaar beschrieben. Es können beliebig viele Paare angegeben werden. Ein Paar besteht aus einem Vergleichswert <reference value> und einem optionalen Anzeigewert mit optionaler mit Farbangabe [,<reference value>,[<icon>][@<color>]].
    <reference value> kann eine Zahl oder eine Zeichenkette sein.
    Wenn <icon> keinem Iconnamen entspricht, wird der Text angezeigt, sonst das Icon. Wird <icon> nicht angegeben, wird der Vergleichwert angezeigt.

  • =end html_DE =cut */