responsive delete page

This commit is contained in:
Roland Gruber 2018-11-20 19:18:23 +01:00
parent fe913bd5bf
commit 691ccbc477
6 changed files with 87 additions and 59 deletions

BIN
lam/graphics/cancel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 730 B

View File

@ -1203,7 +1203,7 @@ abstract class baseModule {
* @see htmlElement * @see htmlElement
*/ */
public function display_html_delete() { public function display_html_delete() {
return 0; return null;
} }
/** /**

View File

@ -3000,13 +3000,40 @@ class htmlStatusMessage extends htmlElement {
* @param String $text message (optional) * @param String $text message (optional)
* @param array $params additional message parameters * @param array $params additional message parameters
*/ */
function __construct($type, $title, $text = null, $params = null) { public function __construct($type, $title, $text = null, $params = null) {
$this->type = $type; $this->type = $type;
$this->title = $title; $this->title = $title;
$this->text = $text; $this->text = $text;
$this->params = $params; $this->params = $params;
} }
/**
* Constructor with parameter array.
*
* @param array $params parameters in same order as normal constructor
* @return htmlStatusMessage
*/
public static function fromParamArray($params) {
if (sizeof($params) < 2) {
throw new BadMethodCallException("Invalid parameter count");
}
$count = count($params);
switch ($count) {
case 2:
return new htmlStatusMessage($params[0], $params[1]);
break;
case 3:
return new htmlStatusMessage($params[0], $params[1], $params[2]);
break;
case 4:
return new htmlStatusMessage($params[0], $params[1], $params[2], $params[3]);
break;
default:
throw new BadMethodCallException("Invalid parameter count");
}
}
/** /**
* Prints the HTML code for this element. * Prints the HTML code for this element.
* *
@ -3018,7 +3045,7 @@ class htmlStatusMessage extends htmlElement {
* @param string $scope Account type * @param string $scope Account type
* @return array List of input field names and their type (name => type) * @return array List of input field names and their type (name => type)
*/ */
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) { public function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
StatusMessage($this->type, $this->title, $this->text, $this->params); StatusMessage($this->type, $this->title, $this->text, $this->params);
return array(); return array();
} }

View File

@ -1752,18 +1752,14 @@ class posixAccount extends baseModule implements passwordService {
* @return htmlElement meta HTML code * @return htmlElement meta HTML code
*/ */
function display_html_delete() { function display_html_delete() {
$return = null; $return = new htmlResponsiveRow();
if ($this->get_scope() == 'user' && ($_SESSION['config']->get_scriptPath() != null)) { if ($this->get_scope() == 'user' && ($_SESSION['config']->get_scriptPath() != null)) {
$return = new htmlTable(); $return->add(new htmlResponsiveInputCheckbox('deletehomedir', true, _('Delete home directory'), 'deletehomedir'), 12);
$return->addElement(new htmlTableExtendedInputCheckbox('deletehomedir', true, _('Delete home directory'), 'deletehomedir'), true);
} }
$typeManager = new TypeManager(); $typeManager = new TypeManager();
$sudoTypes = $typeManager->getConfiguredTypesForScope('sudo'); $sudoTypes = $typeManager->getConfiguredTypesForScope('sudo');
if (($this->get_scope() == 'user') && !empty($sudoTypes)) { if (($this->get_scope() == 'user') && !empty($sudoTypes)) {
if ($return == null) { $return->add(new htmlResponsiveInputCheckbox('deleteSudoers', true, _('Delete sudo rights'), 'deleteSudoers'), 12);
$return = new htmlTable();
}
$return->addElement(new htmlTableExtendedInputCheckbox('deleteSudoers', true, _('Delete sudo rights'), 'deleteSudoers'), true);
} }
return $return; return $return;
} }

View File

@ -272,7 +272,7 @@ table.collapse {
} }
.cancelButton { .cancelButton {
background-image: url(../graphics/del.png) !important; background-image: url(../graphics/cancel.png) !important;
background-position: 0px 0px !important; background-position: 0px 0px !important;
} }

View File

@ -1,11 +1,17 @@
<?php <?php
namespace LAM\DELETE; namespace LAM\DELETE;
use \htmlGroup;
use \htmlResponsiveRow;
use \htmlButton;
use \htmlSpacer;
use \htmlHiddenInput;
use \htmlOutputText;
use \htmlStatusMessage;
/* /*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz Copyright (C) 2003 - 2006 Tilo Lutz
Copyright (C) 2007 - 2017 Roland Gruber Copyright (C) 2007 - 2018 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -96,55 +102,56 @@ if (isset($_GET['type']) && isset($_SESSION['delete_dn'])) {
//load account //load account
$_SESSION['account'] = new \accountContainer($type, 'account'); $_SESSION['account'] = new \accountContainer($type, 'account');
// Show HTML Page // Show HTML Page
include 'main_header.php'; include '../lib/adminHeader.inc';
echo "<div class=\"" . $type->getScope() . "-bright smallPaddingContent\">"; echo "<div class=\"" . $type->getScope() . "-bright smallPaddingContent\">";
echo "<br>\n"; echo "<br>\n";
echo "<form action=\"delete.php\" method=\"post\">\n"; echo "<form action=\"delete.php\" method=\"post\">\n";
echo '<input type="hidden" name="' . getSecurityTokenName() . '" value="' . getSecurityTokenValue() . '">'; $tabindex = 1;
echo "<input name=\"type\" type=\"hidden\" value=\"" . $type->getId() . "\">\n"; $container = new htmlResponsiveRow();
echo "<b>" . _("Do you really want to remove the following accounts?") . "</b>"; $container->add(new htmlOutputText(_("Do you really want to remove the following accounts?")), 12);
echo "<br><br>\n"; $container->addVerticalSpacer('2rem');
echo "<table border=0>\n";
$userCount = sizeof($users); $userCount = sizeof($users);
for ($i = 0; $i < $userCount; $i++) { for ($i = 0; $i < $userCount; $i++) {
echo "<tr>\n"; $container->addLabel(new htmlOutputText(_("Account name:")));
echo "<td><b>" . _("Account name:") . "</b> " . htmlspecialchars($users[$i]) . "</td>\n"; $container->addField(new htmlOutputText($users[$i]));
echo "<td>&nbsp;&nbsp;<b>" . _('DN') . ":</b> " . htmlspecialchars($_SESSION['delete_dn'][$i]) . "</td>\n"; $container->addLabel(new htmlOutputText(_('DN') . ':'));
$container->addField(new htmlOutputText($_SESSION['delete_dn'][$i]));
$_SESSION['account']->load_account($_SESSION['delete_dn'][$i]); $_SESSION['account']->load_account($_SESSION['delete_dn'][$i]);
if (!$_SESSION['account']->hasOnlyVirtualChildren()) { if (!$_SESSION['account']->hasOnlyVirtualChildren()) {
$childCount = getChildCount($_SESSION['delete_dn'][$i]); $childCount = getChildCount($_SESSION['delete_dn'][$i]);
if ($childCount > 0) { if ($childCount > 0) {
echo "<td>&nbsp;&nbsp;<b>" . _('Number of child entries') . ":</b> " . $childCount . "</td>\n"; $container->addLabel(new htmlOutputText(_('Number of child entries') . ':'));
$container->addField(new htmlOutputText($childCount));
} }
} }
echo "</tr>\n";
} }
echo "</table>\n"; addSecurityTokenToMetaHTML($container);
echo "<br>\n"; $container->add(new htmlHiddenInput('type', $type->getId()), 12);
$container->addVerticalSpacer('1rem');
parseHtml(null, $container, array(), false, $tabindex, $type->getScope());
// Print delete rows from modules // Print delete rows from modules
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
$modules = $_SESSION['config']->get_AccountModules($type->getId()); $modules = $_SESSION['config']->get_AccountModules($type->getId());
$values = array(); $values = array();
$tabindex = 100;
foreach ($modules as $module) { foreach ($modules as $module) {
$module = \moduleCache::getModule($module, $type->getScope()); $module = \moduleCache::getModule($module, $type->getScope());
parseHtml(get_class($module), $module->display_html_delete(), $values, true, $tabindex, $type->getScope()); parseHtml(get_class($module), $module->display_html_delete(), $values, true, $tabindex, $type->getScope());
} }
echo "</table>\n"; $buttonContainer = new htmlResponsiveRow();
echo "<br>\n"; $buttonContainer->addVerticalSpacer('1rem');
echo "<button class=\"smallPadding\" name=\"delete\" id=\"submitButton\">" . _('Delete') . "</button>&nbsp;\n"; $buttonGroup = new htmlGroup();
echo "<button class=\"smallPadding\" name=\"cancel\" id=\"cancelButton\">" . _('Cancel') . "</button>\n"; $delButton = new htmlButton('delete', _('Delete'));
$delButton->setIconClass('deleteButton');
$buttonGroup->addElement($delButton);
$buttonGroup->addElement(new htmlSpacer('0.5rem', null));
$cancelButton = new htmlButton('cancel', _('Cancel'));
$cancelButton->setIconClass('cancelButton');
$buttonGroup->addElement($cancelButton);
$buttonContainer->add($buttonGroup, 12);
$buttonContainer->addVerticalSpacer('1rem');
parseHtml(null, $buttonContainer, array(), false, $tabindex, $type->getScope());
echo "</form>\n"; echo "</form>\n";
echo "</div>\n"; echo "</div>\n";
?> include '../lib/adminFooter.inc';
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#submitButton').button();
jQuery('#cancelButton').button();
});
</script>
<?php
include 'main_footer.php';
} }
if (isset($_POST['cancel'])) { if (isset($_POST['cancel'])) {
@ -153,7 +160,7 @@ if (isset($_POST['cancel'])) {
} }
elseif (isset($_POST['cancelAllOk'])) { elseif (isset($_POST['cancelAllOk'])) {
if (isset($_SESSION['delete_dn'])) unset($_SESSION['delete_dn']); if (isset($_SESSION['delete_dn'])) unset($_SESSION['delete_dn']);
metaRefresh("lists/list.php?type=" . $_POST['type'] . '&amp;deleteAllOk=1'); metaRefresh("lists/list.php?type=" . $_POST['type'] . '&deleteAllOk=1');
} }
if (isset($_POST['delete'])) { if (isset($_POST['delete'])) {
@ -164,12 +171,12 @@ if (isset($_POST['delete'])) {
die(); die();
} }
// Show HTML Page // Show HTML Page
include 'main_header.php'; include '../lib/adminHeader.inc';
echo "<form action=\"delete.php\" method=\"post\">\n"; echo "<form action=\"delete.php\" method=\"post\">\n";
echo '<input type="hidden" name="' . getSecurityTokenName() . '" value="' . getSecurityTokenValue() . '">';
echo "<input name=\"type\" type=\"hidden\" value=\"" . $type->getId() . "\">\n";
echo "<div class=\"" . $type->getScope() . "-bright smallPaddingContent\"><br>\n"; echo "<div class=\"" . $type->getScope() . "-bright smallPaddingContent\"><br>\n";
echo "<br>\n"; $container = new htmlResponsiveRow();
addSecurityTokenToMetaHTML($container);
$container->add(new htmlHiddenInput('type', $type->getId()), 12);
// Delete dns // Delete dns
$allOk = true; $allOk = true;
@ -289,41 +296,39 @@ if (isset($_POST['delete'])) {
} }
} }
if (!$stopprocessing) { if (!$stopprocessing) {
echo sprintf(_('Deleted DN: %s'), $deleteDN) . "<br>\n"; $container->add(new htmlOutputText(sprintf(_('Deleted DN: %s'), $deleteDN)), 12);
foreach ($errors as $error) { foreach ($errors as $error) {
call_user_func_array('StatusMessage', $error); $container->add(htmlStatusMessage::fromParamArray($error), 12);
} }
echo "<br>\n";
flush();
} }
else { else {
echo sprintf(_('Error while deleting DN: %s'), $deleteDN) . "<br>\n"; $container->add(new htmlOutputText(sprintf(_('Error while deleting DN: %s'), $deleteDN)), 12);
foreach ($errors as $error) { foreach ($errors as $error) {
call_user_func_array('StatusMessage', $error); $container->add(htmlStatusMessage::fromParamArray($error), 12);
} }
echo "<br>\n";
} }
$allErrors = array_merge($allErrors, $errors); $allErrors = array_merge($allErrors, $errors);
} }
echo "<br>\n"; $container->addVerticalSpacer('2rem');
echo "<br><button class=\"smallPadding\" name=\"cancel\" id=\"backButton\">" . _('Back to list') . "</button>\n"; $buttonName = $allOk ? 'cancelAllOk' : 'cancel';
echo "<br><button class=\"hidden\" name=\"cancelAllOk\" id=\"backButtonAllOk\"> </button>\n"; $container->add(new htmlButton($buttonName, _('Back to list')), 12);
$container->addVerticalSpacer('1rem');
parseHtml(null, $container, array(), false, $tabindex, $type->getScope());
echo "</div>\n"; echo "</div>\n";
echo "</form>\n"; echo "</form>\n";
?> ?>
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function() { jQuery(document).ready(function() {
jQuery('#backButton').button();
<?php <?php
if ($allOk) { if ($allOk) {
$_SESSION['listRedirectMessages'] = $allErrors; $_SESSION['listRedirectMessages'] = $allErrors;
echo "jQuery('#backButtonAllOk').click();"; echo "jQuery('#btn_cancelAllOk').click();";
} }
?> ?>
}); });
</script> </script>
<?php <?php
include 'main_footer.php'; include '../lib/adminFooter.inc';
} }