Skip to content

Commit

Permalink
allow to move accordion elements
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberroland committed Jan 4, 2024
1 parent 597f095 commit cf3f3e7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lam/lib/html.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2010 - 2023 Roland Gruber
Copyright (C) 2010 - 2024 Roland Gruber
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
Expand Down Expand Up @@ -3636,6 +3636,7 @@ class htmlAccordion extends htmlElement {
private $elements;
private $openInitial;
private $saveState;
private bool $allowResorting = false;

/**
* Constructor.
Expand Down Expand Up @@ -3686,6 +3687,23 @@ class htmlAccordion extends htmlElement {
$hiddenIndexId = $this->id . "_index";
echo '<input type="hidden" name="' . $hiddenIndexId . '" id="' . $hiddenIndexId . '" value="false">';
echo '</div>';
if ($this->allowResorting) {
$onResorting = 'onUpdate: function() {
window.lam.html.updateAccordionSorting("' . $this->id . '");
}';
$scriptContent = '
Sortable.create(
document.getElementById("' . $this->id . '"),
{
' . $onResorting . '
}
);';
$resortingGroup = new htmlGroup();
$script = new htmlJavaScript($scriptContent);
$resortingGroup->addElement($script);
$resortingGroup->addElement(new htmlHiddenInput($this->id . '_sorting', ''));
$resortingGroup->generateHTML($module, $input, $values, $restricted, $scope);
}
return $result;
}

Expand All @@ -3698,6 +3716,13 @@ class htmlAccordion extends htmlElement {
$this->saveState = $saveState;
}

/**
* Allows the user to resort the accordion elements.
*/
public function allowResorting(): void {
$this->allowResorting = true;
}

}

/**
Expand Down
15 changes: 15 additions & 0 deletions lam/templates/lib/500_lam.js
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,21 @@ window.lam.html.initCropping = function() {
});
}

/**
* Updates the field to store the sorting of an accordion.
*
* @param accordionId ID of accordion container
*/
window.lam.html.updateAccordionSorting = function (accordionId) {
const positionsField = document.getElementById(accordionId + '_sorting');
let positions = [];
document.getElementById(accordionId).querySelectorAll('.lam-accordion-button').forEach(function (item) {
const index = item.dataset.index;
positions.push(index);
});
positionsField.value = positions.join(',');
}

window.lam.selfservice = window.lam.selfservice || {};

/**
Expand Down

0 comments on commit cf3f3e7

Please sign in to comment.