From e930b134d704d69b6eaf29d4c1f5317aec6924b6 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 23 Oct 2013 18:05:29 +0000 Subject: [PATCH] confirm profile loading for existing accounts --- lam/lib/html.inc | 21 ++++++++++++++++++--- lam/lib/modules.inc | 4 ++++ lam/templates/lib/500_lam.js | 20 ++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/lam/lib/html.inc b/lam/lib/html.inc index 4001e0b3..222c75db 100644 --- a/lam/lib/html.inc +++ b/lam/lib/html.inc @@ -831,6 +831,8 @@ class htmlButton extends htmlElement { private $iconClass = null; /** onclick event */ private $onClick = null; + /** button type (default: "submit" if no onClick and "button" with onClick) */ + private $type = null; /** * Constructor. @@ -889,10 +891,17 @@ class htmlButton extends htmlElement { if (!$this->isEnabled) { $disabled = ' disabled'; } - $type = ' type="submit"'; + if ($this->type == null) { + $type = ' type="submit"'; + } + else { + $type = ' type="' . $this->type . '"'; + } $onClick = ''; if ($this->onClick != null) { - $type = ' type="button"'; + if ($this->type == null) { + $type = ' type="button"'; + } $onClick = ' onclick="' . $this->onClick . '"'; } $id = ' id="btn_' . preg_replace('/[^a-zA-Z0-9_-]/', '', $this->name) . '"'; @@ -951,7 +960,13 @@ class htmlButton extends htmlElement { $this->onClick = $onClick; } - + /** + * Allows to override the default button type ("submit" if no onClick and "button" with onClick). + */ + public function setType($type) { + $this->type = $type; + } + } /** diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index add5dca1..1d6f63d3 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -1212,6 +1212,10 @@ class accountContainer { $rightGroup->addElement(new htmlSelect('accountContainerSelectLoadProfile', $profilelist, array($this->lastLoadedProfile))); $profileButton = new htmlButton('accountContainerLoadProfile', _('Load profile')); $profileButton->setIconClass('loadProfileButton'); + if (!$this->isNewAccount) { + $profileButton->setType('submit'); + $profileButton->setOnClick('confirmOrStopProcessing(\'' . _('This may overwrite existing values with profile data. Continue?') . '\', event);'); + } $rightGroup->addElement($profileButton); $rightGroup->addElement(new htmlSpacer('1px', null)); $rightGroup->addElement(new htmlHelpLink('401')); diff --git a/lam/templates/lib/500_lam.js b/lam/templates/lib/500_lam.js index b3a27cc0..2a70289b 100644 --- a/lam/templates/lib/500_lam.js +++ b/lam/templates/lib/500_lam.js @@ -322,6 +322,26 @@ function showConfirmationDialog(title, okText, cancelText, dialogDiv, formName, }); } +/** + * Shows a simple confirmation dialog. + * If the user presses Cancel then the current action is stopped (event.preventDefault()). + * + * @param text dialog text + * @param e event + */ +function confirmOrStopProcessing(text, e) { + if (!confirm(text)) { + if (e.preventDefault) { + e.preventDefault(); + } + if (e.returnValue) { + e.returnValue = false; + } + return false; + } + return true; +} + /** * Alines the elements with the given IDs to the same width. *