added first level of DN selection

This commit is contained in:
Roland Gruber 2018-10-11 16:52:38 +02:00
parent 89df814e77
commit d0388973e5
5 changed files with 104 additions and 5 deletions

View File

@ -3960,7 +3960,7 @@ class htmlResponsiveRow extends htmlElement {
if ($this->id !== null) { if ($this->id !== null) {
$idParam = ' id="' . $this->id . '"'; $idParam = ' id="' . $this->id . '"';
} }
echo '<div class="row ' . $cssClasses . '"' . $idParam . '>'; echo '<div class="row ' . $cssClasses . '"' . $this->getDataAttributesAsString() . $idParam . '>';
foreach ($this->cells as $cell) { foreach ($this->cells as $cell) {
$return = array_merge($return, $cell->generateHTML($module, $input, $values, $restricted, $tabindex, $scope)); $return = array_merge($return, $cell->generateHTML($module, $input, $values, $restricted, $tabindex, $scope));
} }

View File

@ -380,6 +380,12 @@ table.collapse {
background-position: 0px 0px !important; background-position: 0px 0px !important;
} }
.okButton {
background-image: url(../graphics/pass.png) !important;
background-size: 16px 16px;
background-position: 0px 0px !important;
}
.smallPadding span { .smallPadding span {
padding: 0.1em 0.4em !important; padding: 0.1em 0.4em !important;
} }

View File

@ -1034,18 +1034,20 @@ window.lam.html.showDnSelection = function(fieldId, title, okText, cancelText, t
jsonInput: '' jsonInput: ''
}; };
data[tokenName] = tokenValue; data[tokenName] = tokenValue;
data['fieldId'] = fieldId;
data['dn'] = dnValue; data['dn'] = dnValue;
jQuery.ajax({ jQuery.ajax({
url: '../misc/ajax.php?function=dnselection', url: '../misc/ajax.php?function=dnselection',
method: 'POST', method: 'POST',
data: data data: data
}) })
.done(function(jsonData){ .done(function(jsonData) {
jQuery('#dlg_' + fieldId).html(jsonData.dialogData);
}) })
.fail(function() { .fail(function() {
jQuery(this).dialog("close");
}); });
var buttonList = {}; var buttonList = {};
buttonList[okText] = function() { alert('OK'); };
buttonList[cancelText] = function() { jQuery(this).dialog("close"); }; buttonList[cancelText] = function() { jQuery(this).dialog("close"); };
jQuery('#dlg_' + fieldId).dialog({ jQuery('#dlg_' + fieldId).dialog({
modal: true, modal: true,
@ -1056,6 +1058,21 @@ window.lam.html.showDnSelection = function(fieldId, title, okText, cancelText, t
}); });
}; };
/**
* Selects the DN from dialog.
*
* @param el ok button in dialog
* @param fieldId field id of input field
* @returns false
*/
window.lam.html.selectDn = function(el, fieldId) {
var field = jQuery('#' + fieldId);
var dn = jQuery(el).parents('.row').data('dn');
field.val(dn);
jQuery('#dlg_' + fieldId).dialog("close");
return false;
}
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

@ -2,6 +2,12 @@
namespace LAM\AJAX; namespace LAM\AJAX;
use \LAM\TOOLS\IMPORT_EXPORT\Importer; use \LAM\TOOLS\IMPORT_EXPORT\Importer;
use \LAM\TOOLS\IMPORT_EXPORT\Exporter; use \LAM\TOOLS\IMPORT_EXPORT\Exporter;
use \LAM\TYPES\TypeManager;
use \htmlResponsiveRow;
use \htmlDiv;
use \htmlGroup;
use \htmlOutputText;
use \htmlButton;
/* /*
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/)
@ -128,6 +134,12 @@ class Ajax {
ob_end_clean(); ob_end_clean();
echo $jsonOut; echo $jsonOut;
} }
elseif ($function === 'dnselection') {
ob_start();
$jsonOut = $this->dnSelection();
ob_end_clean();
echo $jsonOut;
}
} }
/** /**
@ -160,6 +172,72 @@ class Ajax {
echo json_encode(array("result" => $result)); echo json_encode(array("result" => $result));
} }
/**
* Handles DN selection fields.
*
* @return string JSON output
*/
private function dnSelection() {
$dn = trim($_POST['dn']);
if (empty($dn) || !get_preg($dn, 'dn')) {
$dnList = $this->getDefaultDns();
}
$dnList = $this->getDefaultDns(); // TODO remove
$html = $this->buildDnSelectionHtml($dnList);
return json_encode(array('dialogData' => $html));
}
/**
* Returns a list of default DNs from account types + tree suffix.
*
* @return string[] default DNs
*/
private function getDefaultDns() {
$typeManager = new TypeManager();
$baseDnList = array();
foreach ($typeManager->getConfiguredTypes() as $type) {
$suffix = $type->getSuffix();
if (!empty($suffix)) {
$baseDnList[] = $suffix;
}
}
$treeSuffix = $_SESSION['config']->get_Suffix('tree');
if (!empty($treeSuffix)) {
$baseDnList[] = $suffix;
}
$baseDnList = array_unique($baseDnList);
sort($baseDnList);
return $baseDnList;
}
/**
* Returns the HTML to build the DN selection list.
*
* @param string[] $dnList DN list
*/
private function buildDnSelectionHtml($dnList) {
$fieldId = trim($_POST['fieldId']);
$mainRow = new htmlResponsiveRow();
foreach ($dnList as $dn) {
$row = new htmlResponsiveRow();
$row->addDataAttribute('dn', $dn);
$row->add(new htmlOutputText($dn), 12, 9);
$buttonId = base64_encode($dn);
$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);
}
$tabindex = 1000;
ob_start();
parseHtml(null, $mainRow, array(), false, $tabindex, 'user');
$out = ob_get_contents();
ob_end_clean();
return $out;
}
} }

View File

@ -15,8 +15,6 @@ use \htmlLink;
use \htmlResponsiveInputCheckbox; use \htmlResponsiveInputCheckbox;
use \htmlResponsiveSelect; use \htmlResponsiveSelect;
use \htmlResponsiveInputField; use \htmlResponsiveInputField;
use \htmlGroup;
use \htmlInputField;
use \htmlHiddenInput; use \htmlHiddenInput;
use LAM\TYPES\TypeManager; use LAM\TYPES\TypeManager;