added first level of DN selection
This commit is contained in:
		
							parent
							
								
									89df814e77
								
							
						
					
					
						commit
						d0388973e5
					
				| 
						 | 
				
			
			@ -3960,7 +3960,7 @@ class htmlResponsiveRow extends htmlElement {
 | 
			
		|||
		if ($this->id !== null) {
 | 
			
		||||
			$idParam = ' id="' . $this->id . '"';
 | 
			
		||||
		}
 | 
			
		||||
		echo '<div class="row ' . $cssClasses . '"' . $idParam . '>';
 | 
			
		||||
		echo '<div class="row ' . $cssClasses . '"' .  $this->getDataAttributesAsString() . $idParam . '>';
 | 
			
		||||
		foreach ($this->cells as $cell) {
 | 
			
		||||
			$return = array_merge($return, $cell->generateHTML($module, $input, $values, $restricted, $tabindex, $scope));
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -380,6 +380,12 @@ table.collapse {
 | 
			
		|||
	background-position: 0px 0px !important;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.okButton {
 | 
			
		||||
	background-image: url(../graphics/pass.png) !important;
 | 
			
		||||
	background-size: 16px 16px;
 | 
			
		||||
	background-position: 0px 0px !important;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.smallPadding span {
 | 
			
		||||
	padding: 0.1em 0.4em !important;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1034,18 +1034,20 @@ window.lam.html.showDnSelection = function(fieldId, title, okText, cancelText, t
 | 
			
		|||
		jsonInput: ''
 | 
			
		||||
	};
 | 
			
		||||
	data[tokenName] = tokenValue;
 | 
			
		||||
	data['fieldId'] = fieldId;
 | 
			
		||||
	data['dn'] = dnValue;
 | 
			
		||||
	jQuery.ajax({
 | 
			
		||||
		url: '../misc/ajax.php?function=dnselection',
 | 
			
		||||
		method: 'POST',
 | 
			
		||||
		data: data
 | 
			
		||||
	})
 | 
			
		||||
	.done(function(jsonData){
 | 
			
		||||
	.done(function(jsonData) {
 | 
			
		||||
		jQuery('#dlg_' + fieldId).html(jsonData.dialogData);
 | 
			
		||||
	})
 | 
			
		||||
	.fail(function() {
 | 
			
		||||
		jQuery(this).dialog("close");
 | 
			
		||||
	});
 | 
			
		||||
	var buttonList = {};
 | 
			
		||||
	buttonList[okText] = function() { alert('OK'); };
 | 
			
		||||
	buttonList[cancelText] = function() { jQuery(this).dialog("close"); };
 | 
			
		||||
	jQuery('#dlg_' + fieldId).dialog({
 | 
			
		||||
		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() {
 | 
			
		||||
	window.lam.gui.equalHeight();
 | 
			
		||||
	window.lam.form.autoTrim();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,12 @@
 | 
			
		|||
namespace LAM\AJAX;
 | 
			
		||||
use \LAM\TOOLS\IMPORT_EXPORT\Importer;
 | 
			
		||||
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/)
 | 
			
		||||
| 
						 | 
				
			
			@ -128,6 +134,12 @@ class Ajax {
 | 
			
		|||
			ob_end_clean();
 | 
			
		||||
			echo $jsonOut;
 | 
			
		||||
		}
 | 
			
		||||
		elseif ($function === 'dnselection') {
 | 
			
		||||
			ob_start();
 | 
			
		||||
			$jsonOut = $this->dnSelection();
 | 
			
		||||
			ob_end_clean();
 | 
			
		||||
			echo $jsonOut;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
| 
						 | 
				
			
			@ -159,6 +171,72 @@ class Ajax {
 | 
			
		|||
		$result = checkPasswordStrength($password, null, null);
 | 
			
		||||
		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;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,8 +15,6 @@ use \htmlLink;
 | 
			
		|||
use \htmlResponsiveInputCheckbox;
 | 
			
		||||
use \htmlResponsiveSelect;
 | 
			
		||||
use \htmlResponsiveInputField;
 | 
			
		||||
use \htmlGroup;
 | 
			
		||||
use \htmlInputField;
 | 
			
		||||
use \htmlHiddenInput;
 | 
			
		||||
use LAM\TYPES\TypeManager;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue