FW_version["fhemweb_uzsu.js"] = "$Id$"; FW_widgets['uzsuToggle'] = { createFn:FW_uzsuToggleCreate, }; FW_widgets['uzsuSelect'] = { createFn:FW_uzsuSelectCreate, }; FW_widgets['uzsuSelectRadio'] = { createFn:FW_uzsuSelectRadioCreate, }; FW_widgets['uzsuDropDown'] = { createFn:FW_uzsuDropDownCreate, }; FW_widgets['uzsuTimerEntry'] = { createFn:FW_uzsuTimerEntryCreate, }; FW_widgets['uzsuList'] = { createFn:FW_uzsuListCreate, }; FW_widgets['uzsu'] = { createFn:FW_uzsuCreate, }; function FW_uzsuDropDownCreate(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] != "uzsuDropDown") return undefined; //vArr[0] = 'time'; //return FW_createTime(elName, devName, vArr, currVal, set, params, cmd); var newEl = $("
").get(0); if( vArr[1] === undefined ) vArr = ["select", "00:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00","08:00","09:00", "10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00", "20:00","21:00","22:00","23:00"]; else vArr[0] = 'select'; $(newEl).append( FW_createSelect(elName, devName, vArr, currVal, set, params, cmd) ); var select = $(newEl).find("select"); select.selectmenu(); select.selectmenu( "option", "width", "auto" ); select.selectmenu( "option", "position", {collision: "flipfit"} ); select.selectmenu( { change: function( event, data ) { if( cmd ) cmd(data.item.value); } }); newEl.getValueFn = function(arg){ return select.val(); }; newEl.setValueFn = function(arg){ select.val(arg); select.selectmenu("refresh"); } //newEl.setValueFn(currVal); return newEl; } function FW_uzsuSelectCreate(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] != "uzsuSelect") return undefined; 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 = 1; i < vArr.length; ++i ) { var button = $('').uniqueId(); var label = $(''); buttons.push(button); $(newEl).append(button); $(newEl).append(label); $(button).change(clicked); } $(newEl).buttonset(); 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") ) { 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.match(new RegExp('(^|,)'+vArr[i+1]+'($|,)') ) ); button.button("refresh"); } }; newEl.setValueFn( currVal ); return newEl; } function FW_uzsuSelectRadioCreate(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] != "uzsuSelectRadio") return undefined; 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 = 1; i < vArr.length; ++i ) { 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(); 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") ) { 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+1]) ); button.button("refresh"); } }; newEl.setValueFn( currVal ); return newEl; } function FW_uzsuToggleCreate(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<3 || vArr[0] != "uzsuToggle") return undefined; var newEl = $("
").get(0); $(newEl).addClass(vArr[0]); var hidden; if(elName) hidden = $(''); $(newEl).append(hidden); var button = $('').uniqueId(); var label = $(''); $(newEl).append(button); $(newEl).append(label); button.button(); $(newEl).change(function(arg) { var new_val = newEl.getValueFn(); newEl.setValueFn( new_val ); if( cmd ) cmd(new_val); } ); newEl.getValueFn = function(arg){ return button.prop("checked")?vArr[2]:vArr[1]; }; newEl.setValueFn = function(arg){ if( !arg ) arg = vArr[1]; if( hidden ) hidden.attr("value", arg); button.button( "option", "label", arg); button.prop("checked", arg.match(new RegExp('(^|,)'+vArr[2]+'($|,)') ) ); button.button("refresh"); }; newEl.setValueFn( currVal ); return newEl; } function FW_uzsuTimerEntryCreate(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] != "uzsuTimerEntry") return undefined; if( !currVal ) currVal = ''; currVals = currVal.split('|'); if( !currVals[2] ); currVals[2] = "enabled"; var newEl = $("
").get(0); $(newEl).addClass(vArr[0]); var hidden; if(elName) hidden = $(''); $(newEl).append(hidden); var changed = function(arg) { $(newEl).change(); if(hidden) hidden.attr("value", newEl.getValueFn()); if(cmd && newEl.getValueFn) cmd(newEl.getValueFn())}; var wval; var wchanged = function(arg) { wval = arg; changed() }; var days = FW_uzsuSelectCreate(undefined, devName+"Days", ["uzsuSelect","Mo","Di","Mi","Do","Fr","Sa","So"], currVals[0], undefined, params, changed); $(newEl).append(days); //days.activateFn(); var time = FW_uzsuDropDownCreate(undefined, devName+"Time", ["uzsuDropDown"], currVals[1], undefined, params, changed); $(newEl).append(time); //time.activateFn(); var widget; if( vArr[1] ) { var vArr = vArr; var params = vArr.slice(1).join(',').split(','); var wn = params[0]; FW_callCreateFn(elName+'-'+wn, devName+'-'+wn, params, currVals[3], undefined, undefined, wchanged, function(wn, ne) { widget = ne; if( widget ) { if( widget.activateFn ) widget.activateFn(); wval = currVals[3]; if( typeof wval == 'undefined' ) wval = params[1]; if( widget.setValueFn &&( typeof wval !== 'undefined' ) ) widget.setValueFn(wval); $(widget).css('margin','0 8px 0 4px'); $(newEl).append(widget) } else { var button = $(''); button.button(); button.val(wn); button.css('margin','0 8px 0 4px'); button.css('height','29px'); button.button("disable"); $(newEl).append(button); } }); } var enabled = FW_uzsuToggleCreate(undefined, devName+"Enabled", ["uzsuToggle","disabled","enabled"], currVals[2], undefined, params, changed); $(newEl).append(enabled); //enabled.activateFn(); newEl.getValueFn = function() { var ret = ""; ret += days.getValueFn(); ret += '|'; ret += time.getValueFn(); ret += '|'; ret += enabled.getValueFn(); if( widget && ( typeof wval !== 'undefined' ) ) { ret += '|'; ret += wval; //ret += $(widget).val(); } return ret; } newEl.setValueFn = function(arg){ if( hidden ) hidden.attr("value", arg); var args = arg.split('|'); days.setValueFn(args[0]); time.setValueFn(args[1]) enabled.setValueFn(args[2]) wval = args[3]; if( widget && widget.setValueFn && ( typeof wval !== 'undefined' ) ) { widget.setValueFn(wval); } }; if( currVal ) newEl.setValueFn( currVal ); return newEl; } function FW_uzsuListCreate(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] != "uzsuList") return undefined; var newEl = $("
").get(0); $(newEl).addClass(vArr[0]); var button = $('