go back in DN selection

This commit is contained in:
Roland Gruber 2018-10-13 19:05:50 +02:00
parent d0388973e5
commit f0cbe217eb
2 changed files with 108 additions and 25 deletions

View File

@ -1043,24 +1043,21 @@ window.lam.html.showDnSelection = function(fieldId, title, okText, cancelText, t
}) })
.done(function(jsonData) { .done(function(jsonData) {
jQuery('#dlg_' + fieldId).html(jsonData.dialogData); jQuery('#dlg_' + fieldId).html(jsonData.dialogData);
}) var buttonList = {};
.fail(function() { buttonList[cancelText] = function() { jQuery(this).dialog("close"); };
jQuery(this).dialog("close"); jQuery('#dlg_' + fieldId).dialog({
}); modal: true,
var buttonList = {}; title: title,
buttonList[cancelText] = function() { jQuery(this).dialog("close"); }; dialogClass: 'defaultBackground',
jQuery('#dlg_' + fieldId).dialog({ buttons: buttonList,
modal: true, width: 'auto'
title: title, });
dialogClass: 'defaultBackground',
buttons: buttonList,
width: 'auto'
}); });
}; };
/** /**
* Selects the DN from dialog. * Selects the DN from dialog.
* *
* @param el ok button in dialog * @param el ok button in dialog
* @param fieldId field id of input field * @param fieldId field id of input field
* @returns false * @returns false
@ -1073,6 +1070,39 @@ window.lam.html.selectDn = function(el, fieldId) {
return false; return false;
} }
/**
* Updates the DN selection.
*
* @param el element
* @param fieldId field id of dialog
* @param tokenName CSRF token name
* @param tokenValue CSRF token value
*/
window.lam.html.updateDnSelection = function(el, fieldId, tokenName, tokenValue) {
var fieldDiv = jQuery('#dlg_' + fieldId);
var dn = jQuery(el).parents('.row').data('dn');
var data = {
jsonInput: ''
};
data[tokenName] = tokenValue;
data['fieldId'] = fieldId;
data['dn'] = dn;
jQuery.ajax({
url: '../misc/ajax.php?function=dnselection',
method: 'POST',
data: data
})
.done(function(jsonData) {
jQuery('#dlg_' + fieldId).html(jsonData.dialogData);
jQuery(fieldDiv).dialog({
position: {my: 'center', at: 'center', of: window}
});
})
.fail(function() {
jQuery(fieldDiv).dialog("close");
});
}
jQuery(document).ready(function() { jQuery(document).ready(function() {
window.lam.gui.equalHeight(); window.lam.gui.equalHeight();
window.lam.form.autoTrim(); window.lam.form.autoTrim();

View File

@ -4,8 +4,7 @@ use \LAM\TOOLS\IMPORT_EXPORT\Importer;
use \LAM\TOOLS\IMPORT_EXPORT\Exporter; use \LAM\TOOLS\IMPORT_EXPORT\Exporter;
use \LAM\TYPES\TypeManager; use \LAM\TYPES\TypeManager;
use \htmlResponsiveRow; use \htmlResponsiveRow;
use \htmlDiv; use \htmlLink;
use \htmlGroup;
use \htmlOutputText; use \htmlOutputText;
use \htmlButton; use \htmlButton;
/* /*
@ -171,25 +170,28 @@ class Ajax {
$result = checkPasswordStrength($password, null, null); $result = checkPasswordStrength($password, null, null);
echo json_encode(array("result" => $result)); echo json_encode(array("result" => $result));
} }
/** /**
* Handles DN selection fields. * Handles DN selection fields.
* *
* @return string JSON output * @return string JSON output
*/ */
private function dnSelection() { private function dnSelection() {
$dn = trim($_POST['dn']); $dn = trim($_POST['dn']);
if (empty($dn) || !get_preg($dn, 'dn')) { if (empty($dn) || !get_preg($dn, 'dn')) {
$dnList = $this->getDefaultDns(); $dnList = $this->getDefaultDns();
$dn = null;
} }
$dnList = $this->getDefaultDns(); // TODO remove else {
$html = $this->buildDnSelectionHtml($dnList); $dnList = $this->getSubDns($dn);
}
$html = $this->buildDnSelectionHtml($dnList, $dn);
return json_encode(array('dialogData' => $html)); return json_encode(array('dialogData' => $html));
} }
/** /**
* Returns a list of default DNs from account types + tree suffix. * Returns a list of default DNs from account types + tree suffix.
* *
* @return string[] default DNs * @return string[] default DNs
*/ */
private function getDefaultDns() { private function getDefaultDns() {
@ -206,22 +208,57 @@ class Ajax {
$baseDnList[] = $suffix; $baseDnList[] = $suffix;
} }
$baseDnList = array_unique($baseDnList); $baseDnList = array_unique($baseDnList);
sort($baseDnList); usort($baseDnList, 'compareDN');
return $baseDnList; return $baseDnList;
} }
/** /**
* Returns the HTML to build the DN selection list. * Returns the HTML to build the DN selection list.
* *
* @param string[] $dnList DN list * @param string[] $dnList DN list
* @param string $currentDn current DN
*/ */
private function buildDnSelectionHtml($dnList) { private function buildDnSelectionHtml($dnList, $currentDn) {
$fieldId = trim($_POST['fieldId']); $fieldId = trim($_POST['fieldId']);
$mainRow = new htmlResponsiveRow(); $mainRow = new htmlResponsiveRow();
if (!empty($currentDn)) {
$row = new htmlResponsiveRow();
$row->addDataAttribute('dn', $currentDn);
$text = new htmlOutputText($currentDn);
$text->setIsBold(true);
$row->add($text, 12, 9);
$row->setCSSClasses(array('text-right'));
$buttonId = base64_encode($currentDn);
$buttonId = str_replace('=', '', $buttonId);
$button = new htmlButton($buttonId, _('Ok'));
$button->setIconClass('okButton');
$button->setOnClick('window.lam.html.selectDn(this, \'' . htmlspecialchars($fieldId) . '\')');
$row->add($button, 12, 3);
$mainRow->add($row, 12);
// back up
$onclickUp = 'window.lam.html.updateDnSelection(this, \''
. htmlspecialchars($fieldId) . '\', \'' . getSecurityTokenName() . '\', \''
. getSecurityTokenValue() . '\')';
$row = new htmlResponsiveRow();
$row->addDataAttribute('dn', extractDNSuffix($currentDn));
$text = new htmlLink('..', '#');
$text->setCSSClasses(array('bold'));
$text->setOnClick($onclickUp);
$row->add($text, 12, 9);
$row->setCSSClasses(array('text-right'));
$buttonId = base64_encode('..');
$buttonId = str_replace('=', '', $buttonId);
$button = new htmlButton($buttonId, _('Up'));
$button->setIconClass('upButton');
$button->setOnClick($onclickUp);
$row->add($button, 12, 3);
$mainRow->add($row, 12);
}
foreach ($dnList as $dn) { foreach ($dnList as $dn) {
$row = new htmlResponsiveRow(); $row = new htmlResponsiveRow();
$row->addDataAttribute('dn', $dn); $row->addDataAttribute('dn', $dn);
$row->add(new htmlOutputText($dn), 12, 9); $row->add(new htmlOutputText($dn), 12, 9);
$row->setCSSClasses(array('text-right'));
$buttonId = base64_encode($dn); $buttonId = base64_encode($dn);
$buttonId = str_replace('=', '', $buttonId); $buttonId = str_replace('=', '', $buttonId);
$button = new htmlButton($buttonId, _('Ok')); $button = new htmlButton($buttonId, _('Ok'));
@ -238,6 +275,22 @@ class Ajax {
return $out; return $out;
} }
/**
* Returns the sub DNs of given DN.
*
* @param string $dn DN
* @return string[] sub DNs
*/
private function getSubDns($dn) {
$dnEntries = ldapListDN($dn);
$dnList = array();
foreach ($dnEntries as $entry) {
$dnList[] = $entry['dn'];
}
usort($dnList, 'compareDN');
return $dnList;
}
} }