allow to change order of account modules

This commit is contained in:
Roland Gruber 2014-10-26 16:24:44 +00:00
parent e19ed3bfa4
commit 85cd14436d
5 changed files with 103 additions and 43 deletions

View File

@ -1,5 +1,8 @@
December 2014 4.8 December 2014 4.8
- FreeRadius: support dialupAccess and radiusProfileDn - FreeRadius: support dialupAccess and radiusProfileDn
- Usability improvements
- LAM Pro:
-> Self service: added option if referrals should be followed
07.10.2014 4.7.1 07.10.2014 4.7.1

View File

@ -3072,7 +3072,7 @@ class htmlSortableList extends htmlElement {
/** /**
* Constructor. * Constructor.
* *
* @param array $elements list of element IDs (HTML special chars must be escaped already) * @param array $elements list of elements as text (HTML special chars must be escaped already) or htmlElement
* @param String HTML ID * @param String HTML ID
* @param String $elementWidth width of elements (default 250px) * @param String $elementWidth width of elements (default 250px)
*/ */
@ -3101,7 +3101,12 @@ class htmlSortableList extends htmlElement {
echo '<ul style="width:' . $this->elementWidth . ';" class="sortableList" id="' . $this->id . '">'; echo '<ul style="width:' . $this->elementWidth . ';" class="sortableList" id="' . $this->id . '">';
foreach ($this->elements as $element) { foreach ($this->elements as $element) {
echo '<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>'; echo '<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>';
echo $element; if ($element instanceof htmlElement) {
parseHtml($module, $element, $values, $restricted, $tabindex, $scope);
}
else {
echo $element;
}
echo '</li>'; echo '</li>';
} }
echo '</ul>'; echo '</ul>';

View File

@ -443,6 +443,11 @@ img.photo {
max-height: 400px; max-height: 400px;
} }
div.confModList {
max-height: 300px;
overflow-y: auto;
}
/* schema browser */ /* schema browser */

View File

@ -3,7 +3,7 @@
$Id$ $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) 2004 - 2013 Roland Gruber Copyright (C) 2004 - 2014 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
@ -297,41 +297,54 @@ function config_showAccountModules($scope, $title, &$container) {
// add account module selection // add account module selection
$container->addElement(new htmlSubTitle($title, '../../graphics/' . $scope . '.png'), true); $container->addElement(new htmlSubTitle($title, '../../graphics/' . $scope . '.png'), true);
$container->addElement(new htmlOutputText(_("Selected modules"))); $container->addElement(new htmlOutputText(_("Selected modules")));
// add/remove buttons $container->addElement(new htmlOutputText(''));
$buttonContainer = new htmlTable();
$buttonContainer->rowspan = 2;
if (sizeof($availOptions) > 0) {
$addButton = new htmlButton($scope . "_add", 'back.gif', true);
$addButton->setTitle(_('Add'));
$buttonContainer->addElement($addButton, true);
}
if (sizeof($selOptions) > 0) {
$remButton = new htmlButton($scope . "_remove", 'forward.gif', true);
$remButton->setTitle(_('Remove'));
$buttonContainer->addElement($remButton, true);
}
$container->addElement($buttonContainer);
$container->addElement(new htmlOutputText(_("Available modules")), true); $container->addElement(new htmlOutputText(_("Available modules")), true);
$container->addVerticalSpace('10px');
$container->addNewLine();
// selected modules // selected modules
if (sizeof($selOptions) > 0) { if (sizeof($selOptions) > 0) {
$selSelect = new htmlSelect($scope . '_selected', $selOptions, array(), 5); $listElements = array();
$selSelect->setTransformSingleSelect(false); foreach ($selOptions as $key => $value) {
$selSelect->setMultiSelect(true); $el = new htmlTable('100%');
$selSelect->setHasDescriptiveElements(true); $mod = new $value($scope);
$selSelect->setSortElements(false); $el->addElement(new htmlImage('../../graphics/' . $mod->getIcon(), '16px', '16px'));
$container->addElement($selSelect); $el->addElement(new htmlOutputText($key));
$delButton = new htmlButton('del_' . $scope . '_' . $value, 'del.png', true);
$delButton->alignment = htmlElement::ALIGN_RIGHT;
$el->addElement($delButton);
$listElements[] = $el;
}
$selSortable = new htmlSortableList($listElements, $scope . '_selected', '350px');
$selSortable->alignment = htmlElement::ALIGN_TOP;
$selSortable->setOnUpdate('updateModulePositions(\'positions_' . $scope . '\', ui.item.data(\'posOrig\'), ui.item.index());');
$container->addElement($selSortable);
} }
else { else {
$container->addElement(new htmlOutputText('')); $container->addElement(new htmlOutputText(''));
} }
// space
$container->addSpace('20px');
// available modules // available modules
if (sizeof($availOptions) > 0) { if (sizeof($availOptions) > 0) {
$availSelect = new htmlSelect($scope . "_available", $availOptions, array(), 5); $availTable = new htmlTable();
$availSelect->setTransformSingleSelect(false); foreach ($availOptions as $text => $key) {
$availSelect->setHasDescriptiveElements(true); $mod = new $key($scope);
$availSelect->setMultiSelect(true); $availTable->addElement(new htmlImage('../../graphics/' . $mod->getIcon(), '16px', '16px'));
$container->addElement($availSelect, true); $availTable->addElement(new htmlOutputText($text));
$addButton = new htmlButton('add_' . $scope . '_' . $key, 'add.png', true);
$addButton->alignment = htmlElement::ALIGN_RIGHT;
$availTable->addElement($addButton, true);
}
$availDiv = new htmlDiv(null, $availTable);
$availDiv->alignment = htmlElement::ALIGN_TOP;
$availDiv->setCSSClasses(array('confModList'));
$container->addElement($availDiv, true);
} }
$positions = '';
for ($i = 0; $i < sizeof($selOptions); $i++) {
$positions[] = $i;
}
$container->addElement(new htmlHiddenInput('positions_' . $scope, implode(',', $positions)), true);
// spacer to next account type // spacer to next account type
$container->addElement(new htmlSpacer(null, '30px'), true); $container->addElement(new htmlSpacer(null, '30px'), true);
} }
@ -361,23 +374,32 @@ function checkInput() {
$selected[] = $selected_temp[$i]; $selected[] = $selected_temp[$i];
} }
} }
// remove modules from selection // reorder based on sortable list
if (isset($_POST[$scope . '_selected']) && isset($_POST[$scope . '_remove'])) { $sorting = $_POST['positions_' . $scope];
$new_selected = array(); if (!empty($sorting)) {
for ($i = 0; $i < sizeof($selected); $i++) { $sorting = explode(',', $sorting);
if (! in_array($selected[$i], $_POST[$scope . '_selected'])) $new_selected[] = $selected[$i]; $sortTmp = array();
foreach ($sorting as $pos) {
$sortTmp[] = $selected[$pos];
} }
$selected = $new_selected; $selected = $sortTmp;
$typeSettings['modules_' . $scope] = implode(',', $selected);
} }
// add modules to selection // remove modules from selection
elseif (isset($_POST[$scope . '_available']) && isset($_POST[$scope . '_add'])) { $new_selected = array();
$new_selected = $selected; for ($i = 0; $i < sizeof($selected); $i++) {
for ($i = 0; $i < sizeof($_POST[$scope . '_available']); $i++) { if (!isset($_POST['del_' . $scope . '_' . $selected[$i]])) {
if (! in_array($_POST[$scope . '_available'][$i], $selected)) $new_selected[] = $_POST[$scope . '_available'][$i]; $new_selected[] = $selected[$i];
}
}
$selected = $new_selected;
$typeSettings['modules_' . $scope] = implode(',', $selected);
// add modules to selection
foreach ($available as $modName) {
if (isset($_POST['add_' . $scope . '_' . $modName])) {
$selected[] = $modName;
$typeSettings['modules_' . $scope] = implode(',', $selected);
break;
} }
$selected = $new_selected;
$typeSettings['modules_' . $scope] = implode(',', $selected);
} }
// check dependencies // check dependencies
$depends = check_module_depends($selected, getModulesDependencies($scope)); $depends = check_module_depends($selected, getModulesDependencies($scope));

View File

@ -571,4 +571,29 @@ function checkPasswordStrengthHandleReply(data, fieldID) {
} }
} }
/**
* Updates the positions of a htmlSortable list in a hidden input field.
* The positions must be separated by comma (e.g. "0,1,2,3").
*
* @param id HTML ID of hidden input field
* @param oldPos old position
* @param newPos new position
*/
function updateModulePositions(id, oldPos, newPos) {
var positions = jQuery('#' + id).val().split(',');
if (newPos > oldPos) {
var save = positions[oldPos];
for (var i = oldPos; i < newPos; i++) {
positions[i] = positions[i + 1];
}
positions[newPos] = save;
}
if (newPos < oldPos) {
var save = positions[oldPos];
for (var i = oldPos; i > newPos; i--) {
positions[i] = positions[i - 1];
}
positions[newPos] = save;
}
jQuery('#' + id).val(positions.join(','));
}