confirm profile loading for existing accounts

This commit is contained in:
Roland Gruber 2013-10-23 18:05:29 +00:00
parent b32c965786
commit e930b134d7
3 changed files with 42 additions and 3 deletions

View File

@ -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';
}
if ($this->type == null) {
$type = ' type="submit"';
}
else {
$type = ' type="' . $this->type . '"';
}
$onClick = '';
if ($this->onClick != null) {
if ($this->type == null) {
$type = ' type="button"';
}
$onClick = ' onclick="' . $this->onClick . '"';
}
$id = ' id="btn_' . preg_replace('/[^a-zA-Z0-9_-]/', '', $this->name) . '"';
@ -951,6 +960,12 @@ 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;
}
}

View File

@ -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'));

View File

@ -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.
*