From df34ffdb62c871885de7a0570c174b5169980943 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Felix=20D=C3=B6rre?= Date: Thu, 18 Aug 2016 19:24:01 +0200 Subject: [PATCH] add: modal javascript-dialogs for confirming dangerous action. Change-Id: I1c10b021325439c71183efb875bcf856eb23931c --- static/static/js/expert.js | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/static/static/js/expert.js b/static/static/js/expert.js index 07d1da49..731dddde 100644 --- a/static/static/js/expert.js +++ b/static/static/js/expert.js @@ -1,4 +1,53 @@ (function() { + var modal = undefined; + + function showModal(content){ + var HTML = ``; + if(modal === undefined) { + modal = $(HTML); + modal.action = function(){}; + modal.appendTo("body"); + $(modal.get(0)).find(".modal-footer .btn-confirm").click(function(){ + modal.action(); + modal.modal("hide"); + }); + } + var m = $(modal.get(0)); + m.find(".modal-body").text($(content).attr("data-confirm")); + var reply = $(content).attr("data-reply").split(","); + m.find(".modal-footer .btn-cancel").text(reply[0]); + m.find(".modal-footer .btn-confirm").text(reply[1]); + modal.action=function(){ + content.confirmed=true; + $(content).click(); + }; + modal.modal("show"); + } + function initConfirm() { + $(".btn-confirm").click(function(){ + if(this.confirmed === true){ + return true; + } + showModal(this); + return false; + }); + } function showExpert(isExpert) { var elements = document.getElementsByClassName("expert"); @@ -43,6 +92,7 @@ panel.find(".panel-heading [type=\"radio\"]").change(refresh); return this.id; }); + initConfirm(); } (function(oldLoad) { if (oldLoad == undefined) { -- 2.39.2