From 1511936bd5f58833bd691d50e259dc97ae9dc127 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Mon, 8 Aug 2016 16:31:21 +0000 Subject: [PATCH] 01_FHEMWEB.pm/fhemweb.js: confirmDelete Attribute (Forum #55905) git-svn-id: https://svn.fhem.de/fhem/trunk@11924 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/01_FHEMWEB.pm | 34 +++++++++++++++++++++++------- fhem/www/pgm2/fhemweb.js | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm index 0838aed55..0ebf512da 100755 --- a/fhem/FHEM/01_FHEMWEB.pm +++ b/fhem/FHEM/01_FHEMWEB.pm @@ -145,6 +145,7 @@ FHEMWEB_Initialize($) basicAuthMsg closeConn:1,0 column + confirmDelete defaultRoom deviceOverview:always,iconOnly,onClick,never editConfig:1,0 @@ -1171,7 +1172,9 @@ FW_doDetail($) my $h = $defs{$d}; my $t = $h->{TYPE}; $t = "MISSING" if(!defined($t)); - FW_pO "
"; + my $cd = AttrVal($FW_wname, "confirmDelete", 1); + FW_pO "
"; if($FW_ss) { # FS20MS2 special: on and off, is not the same as toggle my $webCmd = AttrVal($d, "webCmd", undef); @@ -3077,6 +3080,21 @@ FW_widgetOverride($$) Space in the room and group name has to be written as %20 for this attribute. +
+ + +
  • confirmDelete
    + confirm delete actions with a dialog. Default is 1, set it to 0 to + disable the feature. +
  • +
    + + +
  • CORS
    + If set to 1, FHEMWEB will supply a "Cross origin resource sharing" + header, see the wikipedia for details. +
  • +
  • csrfToken
    @@ -3107,13 +3125,6 @@ FW_widgetOverride($$)

  • - -
  • CORS
    - If set to 1, FHEMWEB will supply a "Cross origin resource sharing" - header, see the wikipedia for details. -
  • -
    -
  • defaultRoom
    show the specified room if no room selected, e.g. on execution of some @@ -3782,6 +3793,13 @@ FW_widgetOverride($$) %20 zu schreiben.

  • + +
  • confirmDelete
    + Löschaktionen weden mit einem Dialog bestätigt. + Falls dieses Attribut auf 0 gesetzt ist, entfällt das. +
  • +
    +
  • CORS
    Wenn auf 1 gestellt, wird FHEMWEB einen "Cross origin resource sharing" diff --git a/fhem/www/pgm2/fhemweb.js b/fhem/www/pgm2/fhemweb.js index 342f9e66d..ce0421014 100644 --- a/fhem/www/pgm2/fhemweb.js +++ b/fhem/www/pgm2/fhemweb.js @@ -88,6 +88,7 @@ FW_jqueryReadyFn() FW_root = r; FW_replaceWidgets($("html")); + FW_confirmDelete(); // Fix the td count by setting colspan on the last column $("table.block.wide").each(function(){ // table @@ -214,6 +215,50 @@ FW_jqueryReadyFn() FW_inlineModify(); } +function +FW_confirmDelete() +{ + var d = $("div#content"); + var cd = $(d).attr("data-confirmDelete"); + if(!cd || cd == 0) + return; + var wn = $(d).attr("data-webName"); + $(d).find("a").each(function(){ + var href = $(this).attr("href"); + if(!href) + return; + var ma = $(this).attr("href").match(/.*cmd[^=]*=(delete[^&]*)&.*$/); + if(!ma || ma.length != 2) + return; + $(this).attr("href", "#"); + $(this).unbind("click"); + $(this).click(function(e){ + e.preventDefault(); + + var div = $("
    "); + $(div).html("Do you really want to "+ma[1]+"?

    "+ + " Skip this dialog in the future"); + $("body").append(div); + + function + doClose() + { + if($(div).find("input:checked").length) + FW_cmd(FW_root+"?cmd=attr "+wn+" confirmDelete 0&XHR=1"); + $(this).dialog("close"); $(div).remove(); + } + + $(div).dialog({ + dialogClass:"no-close", modal:true, width:"auto", closeOnEscape:true, + maxWidth:$(window).width()*0.9, maxHeight:$(window).height()*0.9, + buttons: [ + {text:"Yes", click:function(){ location.href = ma[0]; doClose(); }}, + {text:"No", click:function(){ doClose(); }}] + }); + }); + }); +} + // Show the webCmd list in a dialog if: smallScreen & hiddenroom=detail & room function FW_smallScreenCommands()