2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 18:59:33 +00:00

YAF: Activated modify-dialog for generic widget.

* generic widget: allow modify, allow click actions
* Foundations for widget modify
* Code optimization
* Code formating



git-svn-id: https://svn.fhem.de/fhem/trunk@3699 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
marcproe 2013-08-14 19:28:55 +00:00
parent ebaf5c1b07
commit a829409cd6
8 changed files with 282 additions and 160 deletions

View File

@ -345,6 +345,22 @@ sub YAF_Request ($@) {
YAF_Print("0");
}
}
#-- edit Widget // more or less: set widget attributes
elsif($function eq "editWidget"){
if ($_GET{"view_id"} && $_GET{"widget_id"} && $_GET{"keys"} && $_GET{"vals"}) {
my $viewid = $_GET{"view_id"};
my $widgetid = $_GET{"widget_id"};
my @keys = split(/,/,$_GET{"keys"});
my @vals = split(/,/,$_GET{"vals"});
for my $i (0 .. $#keys) {
YAF_setWidgetAttribute($viewid,$widgetid,$keys[$i],$vals[$i]);
}
YAF_Print("1");
}
else {
YAF_Print("0");
}
}
#-- get RefreshTime
elsif($function eq "getRefreshTime"){
my $refreshTime = YAF_getRefreshTime();

View File

@ -179,7 +179,6 @@ sub YAF_editView{
#save new config
fhem ("attr yaf views $newview");
#fhem("save");
return 1;
}
@ -252,8 +251,6 @@ sub YAF_deleteView{
fhem ("attr global userattr $newuserattr");
}
#fhem("save");
return 1;
}
@ -298,7 +295,6 @@ sub YAF_addView{
fhem ("attr yaf views $newview");
fhem ("attr yaf backgrounds $newbackground");
fhem ("attr global userattr $newuserattr");
#fhem("save");
return 1;
}
@ -354,7 +350,6 @@ sub YAF_addWidget{
$newId = 0;
} else {
fhem("attr $fhemname yaf_$viewId $widgetString");
#fhem("save");
}
return $newId;
@ -383,7 +378,6 @@ sub YAF_deleteWidget{
delete $fhemwidgets{$viewId}{$widgetId};
fhem("deleteattr $widgetname yaf_$viewId");
#fhem("save");
return 1;
}
@ -446,7 +440,6 @@ sub YAF_setWidgetPosition{
}
fhem("attr $widgetname yaf_$viewId $newattr");
#fhem("save");
}
#######################################################################################
@ -494,7 +487,6 @@ sub YAF_getWidgetAttribute{
}
}
}
if(length $retAttr > 0) {
return $retAttr; #return the found config
} else {
@ -517,7 +509,6 @@ sub YAF_getRefreshTime{
} else {
Log 1,"YAF_getRefreshTime: refresh_interval attribute was not found (so it will be created with a default value)";
fhem("attr yaf refresh_interval 60");
fhem("save");
return 60;
}
}
@ -534,7 +525,6 @@ sub YAF_setRefreshTime{
if($newRefreshInterval =~ /^\d+$/) {
fhem("attr yaf refresh_interval $newRefreshInterval");
#fhem("save");
return 1;
} else {
Log 1,"YAF_setRefreshTime: no valid refresh value or refresh attribute was not found";
@ -542,4 +532,29 @@ sub YAF_setRefreshTime{
}
}
sub YAF_setWidgetAttribute{
my $viewId = $_[0];
my $widgetId = $_[1];
my $key = $_[2];
my $val = $_[3];
my $widgetname = $fhemwidgets{$viewId}{$widgetId};
my %attrhash = ();
foreach my $attrs (split (/,/,AttrVal($widgetname, "yaf_".$viewId, undef))) {
my @attr = split(/=/,$attrs);
$attrhash{$attr[0]} = $attr[1];
}
$attrhash{$key} = $val;
my $newattr = "id=" . $widgetId . ",";
foreach my $ckey (keys %attrhash) {
if ($ckey ne "id" and defined $attrhash{$ckey}) {
$newattr .= $ckey."=".$attrhash{$ckey}.",";
}
}
fhem("attr $widgetname yaf_$viewId $newattr");
}
1;

View File

@ -165,6 +165,11 @@ sub fht80_get_addwidget_prepare_attributes() {
return $output;
}
sub fht80_get_editwidget_setup_html() {
my $output = "";
$output .= "TEST!";
return $output;
}
########################################################################################
#
# fht80t_getwidget_html - HTML code for this widget. DO WE NEED THIS ? SEE ABOVE
@ -201,12 +206,12 @@ sub fht80_get_temp() {
}
# get all the needed data
my $temp = fht80_isdef($defs{$fhemname}{READINGS}{temperature}{VAL}, 0);
my $temptimestamp = fht80_isdef($defs{$fhemname}{READINGS}{temperature}{TIME}, "");
my $actuator = fht80_isdef($defs{$fhemname}{READINGS}{actuator}{VAL}, "");
my $mode = fht80_isdef($defs{$fhemname}{READINGS}{mode}{VAL}, "none");
my $desi = fht80_isdef($defs{$fhemname}{READINGS}{"desired-temp"}{VAL}, "");
my $battery = fht80_isdef($defs{$fhemname}{READINGS}{battery}{VAL}, "");
my $temp = ReadingsVal($fhemname, "temperature", 0);
my $temptimestamp = ReadingsTimestamp($fhemname, "temperature", "big-bang");
my $actuator = ReadingsVal($fhemname, "actuator", "");
my $mode = ReadingsVal($fhemname, "mode", "none");
my $desi = ReadingsVal($fhemname, "desired-temp", "");
my $battery = ReadingsVal($fhemname, "battery", "");
my $nomode = YAF_getWidgetAttribute($viewid, $widgetid, "nomode", 0);
my $labeltype = YAF_getWidgetAttribute($viewid, $widgetid, "labeltype", "");
$ret[1] = YAF_getWidgetAttribute($viewid, $widgetid, "size", 1); #we don't process the size, so put it in the return array right away.
@ -238,8 +243,4 @@ sub fht80_get_temp() {
return encode_json(\@ret);
}
sub fht80_isdef() {
return ((defined $_[0]) ? $_[0] : $_[1]);
}
1;

View File

@ -72,8 +72,26 @@ sub generic_get_widgetjs() {
}
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
function generic_on_click(view_id, widget_id) {
$.ajax({
type: "GET",
async: true,
url: "../../ajax/widget/generic/on_click",
data: "view_id="+view_id+"&widget_id="+widget_id,
context: document.body,
success: function(data){
var mydata = jQuery.parseJSON(data);
if(mydata[0] == "redirect") {
window.location.href = mydata[1];
} else {
generic_update_widget(view_id, widget_id);
}
}
});
}
function generic_update_widget(view_id, widget_id) {
$.ajax({
type: "GET",
@ -188,6 +206,25 @@ sub generic_get_addwidget_setup_html() {
# return encode_json(\@ret);
# }
sub generic_get_editwidget_setup_html() {
my $viewId = $_GET{"view_id"};
my $widgetId = $_GET{"widget_id"};
my $output = "";
my $fhemname = YAF_getWidgetAttribute($viewId, $widgetId, "fhemname", "");
my $labeltype = YAF_getWidgetAttribute($viewId, $widgetId, "labeltype","");
my $statetype = YAF_getWidgetAttribute($viewId, $widgetId, "statetype","");
my $showlabel = YAF_getWidgetAttribute($viewId, $widgetId, "showlabel","1");
my $showicon = YAF_getWidgetAttribute($viewId, $widgetId, "showicon","1");
$output .= "<label title='Name des Devices'>Name:</label><input class='input_edit_widget' disabled='disabled' name='fhemname' value='" . $fhemname . "' /><br />";
$output .= "<label title='Welches Attributfeld soll als Label des Widgets gezeigt werden?'>Label (Attribut):</label><input class='input_edit_widget' name='labeltype' value='" . $labeltype . "' /><br />";
$output .= "<label title='Welches Reading soll als Status gezeigt werden?'>Status (Reading):</label><input class='input_edit_widget' name='statetype' value='" . $statetype . "' /><br />";
$output .= "<label title='Soll das Label angezeigt werden?'>Label anzeigen? (1/0):</label><input class='input_edit_widget' name='showlabel' value='" . $showlabel . "' /><br />";
$output .= "<label title='Soll das Icon angezeigt werden?'>Icon anzeigen? (1/0):</label><input class='input_edit_widget' name='showicon' value='" . $showicon . "' /><br />";
return $output;
}
########################################################################################
#
# generic_get_addwidget_prepare_attributes -
@ -231,15 +268,18 @@ sub generic_getwidget_html() {
########################################################################################
sub generic_get_state() {
my $fhemname = YAF_getWidgetAttribute($_GET{"view_id"}, $_GET{"widget_id"}, "fhemname");
my $labeltype = YAF_getWidgetAttribute($_GET{"view_id"}, $_GET{"widget_id"}, "labeltype","");
my $statetype = YAF_getWidgetAttribute($_GET{"view_id"}, $_GET{"widget_id"}, "statetype","");
my $showlabel = YAF_getWidgetAttribute($_GET{"view_id"}, $_GET{"widget_id"}, "showlabel","1");
my $showicon = YAF_getWidgetAttribute($_GET{"view_id"}, $_GET{"widget_id"}, "showicon","1");
my $viewId = $_GET{"view_id"};
my $widgetId = $_GET{"widget_id"};
my $fhemname = YAF_getWidgetAttribute($viewId, $widgetId, "fhemname", "");
my $labeltype = YAF_getWidgetAttribute($viewId, $widgetId, "labeltype","");
my $statetype = YAF_getWidgetAttribute($viewId, $widgetId, "statetype","");
my $showlabel = YAF_getWidgetAttribute($viewId, $widgetId, "showlabel","1");
my $showicon = YAF_getWidgetAttribute($viewId, $widgetId, "showicon","1");
my $d = $defs{$fhemname};
my $state = $d->{STATE};
my $iconpath = "/fhem/images/default/";
my $iconpath = "";
my @ret = ();
if(!defined $state) {
@ -251,8 +291,9 @@ sub generic_get_state() {
if(defined $devStateIcon) {
foreach my $entry (split (/ /,$devStateIcon)) {
my @keyval = split(/:/,$entry);
if($keyval[0] =~ $state) {
$iconpath .= $keyval[1] . ".png";
my $regex = $keyval[0];
if($state =~ m/$regex/) {
$iconpath = "/fhem/images/default/" . $keyval[1] . ".png";
}
}
$ret[1] = $iconpath;
@ -266,7 +307,7 @@ sub generic_get_state() {
$ret[0] =~ s/( )/&nbsp;/g;
if($statetype ne "") {
$ret[2] = generic_isdef($defs{$fhemname}{READINGS}{$statetype}{VAL}, "no-reading");
$ret[2] = ReadingsVal($fhemname, $statetype, "no-reading");
} else {
$ret[2] = $state;
}
@ -289,8 +330,30 @@ sub generic_get_state() {
}
}
sub generic_isdef() {
return ((defined $_[0]) ? $_[0] : $_[1]);
sub generic_on_click() {
my $fhemname = YAF_getWidgetAttribute($_GET{"view_id"}, $_GET{"widget_id"}, "fhemname");
my $d = $defs{$fhemname};
my $clicklink = YAF_getWidgetAttribute($_GET{"view_id"}, $_GET{"widget_id"}, "clicklink", "");
my @ret = ();
if($clicklink ne "") {
if($clicklink eq "_detail") {
$ret[0] = "redirect";
$ret[1] = "/fhem?detail=" . $fhemname;
} else {
$ret[0] = "redirect";
$ret[1] = $clicklink;
}
return encode_json(\@ret);
}
my $setstate = YAF_getWidgetAttribute($_GET{"view_id"}, $_GET{"widget_id"}, "_".$d->{STATE}, "");
if($setstate ne "") {
fhem("set " . $fhemname . " " . $setstate);
return encode_json(\@ret);
}
}
1;

View File

@ -422,15 +422,12 @@ function init_handlers() {
});
$("#button_saveconfig").click(function () {
//window.location.href = "../../../../fhem?cmd=save";
//return false;
$.ajax({
type: "GET",
async: true,
url: "../../ajax/global/saveconfig",
context: document.body,
success: function (jsondata) {
//console.log("Config saved " + jsondata);
$("#button_saveconfig").button({
icons: {
secondary: "ui-icon-check"

View File

@ -265,16 +265,53 @@ function init_dialogs() {
$("#dialog_editwidget").dialog({
autoOpen: false,
resizable: true,
height: 300,
width: 400,
height: 400,
width: 500,
modal: true,
buttons: {
"Speichern": function (ui) {
var keys = new Array();
var vals = new Array();
keys[0] = "id";
vals[0] = current_widget_id;
$('.input_edit_widget').each(function(i, obj) {
keys[i+1] = obj.name;
vals[i+1] = obj.value;
});
$.ajax({
type: "GET",
async: false,
url: "../../ajax/global/editWidget",
data: "view_id="+current_view_id+"&widget_id="+current_widget_id+"&keys="+keys+"&vals="+vals,
context: document.body,
success: function (jsondata) {
}
});
$(this).dialog("close");
},
"Abbrechen": function () {
$(this).dialog("close");
}
},
open: function (event, ui) {
$("#dialog_addwidget_loading").show();
$.ajax({
type: "GET",
async: false,
url: "../../ajax/widget/generic/get_editwidget_setup_html",
data: "view_id="+current_view_id+"&widget_id="+current_widget_id,
context: document.body,
success: function (jsondata) {
//var myform = jQuery.parseJSON(jsondata);
$("#dialog_editwidget_setup_form").html(jsondata);
$("#dialog_addwidget_loading").hide();
}
});
}
});

View File

@ -38,8 +38,6 @@
<script type="text/javascript" src="js/yaf-basics.js"></script>
<script>
// Array mit den Namen und den zugehörigen Id's der Sichten
var views = new Array();
var widgets = new Array();
@ -60,10 +58,6 @@
var edit_view_id = null;
var add_widget_name = null;
// Initialisiert die Oberfläche
function init() {
$.ajaxSetup({ cache: false });
@ -80,7 +74,6 @@
return;
}
###widget_js###
$(document).ready(function() {

View File

@ -17,19 +17,19 @@ DIR FHEM/YAF/www/smoothness/images
DIR FHEM/YAF/www/img
DIR FHEM/YAF/www/js
DIR FHEM/YAF/xml
UPD 2013-08-01_11:10:00 11623 FHEM/01_YAF.pm
UPD 2013-08-14_21:30:00 12046 FHEM/01_YAF.pm
UPD 2013-05-15_20:00:00 6590 FHEM/YAF/widgets/fs20st/fs20st.pm
UPD 2013-07-31_15:30:00 7548 FHEM/YAF/widgets/fht80/fht80.pm
UPD 2013-08-14_21:30:00 7471 FHEM/YAF/widgets/fht80/fht80.pm
UPD 2013-07-31_15:30:00 6534 FHEM/YAF/widgets/fhttk/fhttk.pm
UPD 2013-07-31_15:30:00 8834 FHEM/YAF/widgets/generic/generic.pm
UPD 2013-08-14_21:30:00 11361 FHEM/YAF/widgets/generic/generic.pm
UPD 2013-05-15_20:00:00 6617 FHEM/YAF/widgets/fs20easylamp/fs20easylamp.pm
UPD 2013-05-15_20:00:00 2608 FHEM/YAF/www/img/loading.gif
UPD 2013-05-15_20:00:00 766 FHEM/YAF/www/img/lamp_off.png
UPD 2013-05-15_20:00:00 19226 FHEM/YAF/www/img/background.png
UPD 2013-05-15_20:00:00 831 FHEM/YAF/www/img/lamp_on.png
UPD 2013-08-01_11:10:00 12433 FHEM/YAF/www/js/yaf-basics.js
UPD 2013-07-31_15:30:00 10727 FHEM/YAF/www/js/yaf-dialogs.js
UPD 2013-08-02_22:15:00 7596 FHEM/YAF/www/yaf.htm
UPD 2013-08-14_21:30:00 12312 FHEM/YAF/www/js/yaf-basics.js
UPD 2013-08-14_21:30:00 11737 FHEM/YAF/www/js/yaf-dialogs.js
UPD 2013-08-14_21:30:00 7489 FHEM/YAF/www/yaf.htm
UPD 2013-05-15_20:00:00 3433 FHEM/YAF/www/js/combobox.js
UPD 2013-05-15_20:00:00 4593 FHEM/YAF/www/js/jquery.ui.touch-punch.min.js
UPD 2013-05-15_20:00:00 237176 FHEM/YAF/www/js/jquery-ui-1.9.1.custom.min.js
@ -53,5 +53,5 @@ UPD 2013-05-15_20:00:00 101 FHEM/YAF/www/css/smoothness/images/ui-bg_highlight-s
UPD 2013-05-15_20:00:00 26086 FHEM/YAF/www/css/smoothness/jquery-ui-1.9.1.custom.min.css
UPD 2013-05-15_20:00:00 3641 FHEM/YAF/xml/xmlSchema.xsd
UPD 2013-05-15_20:00:00 1690 FHEM/YAF/xml/yafConfig.xml
UPD 2013-07-28_17:00:00 15329 FHEM/YAF/YAFConfig.pm
UPD 2013-08-14_21:30:00 15797 FHEM/YAF/YAFConfig.pm
UPD 2013-05-15_20:00:00 3439 FHEM/YAF/YAFWidgets.pm