diff --git a/lam/lib/html.inc b/lam/lib/html.inc
index a7b3075c3..925f0598c 100644
--- a/lam/lib/html.inc
+++ b/lam/lib/html.inc
@@ -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
@@ -3636,6 +3636,7 @@ class htmlAccordion extends htmlElement {
private $elements;
private $openInitial;
private $saveState;
+ private bool $allowResorting = false;
/**
* Constructor.
@@ -3686,6 +3687,23 @@ class htmlAccordion extends htmlElement {
$hiddenIndexId = $this->id . "_index";
echo '';
echo '';
+ 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;
}
@@ -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;
+ }
+
}
/**
diff --git a/lam/templates/lib/500_lam.js b/lam/templates/lib/500_lam.js
index 14416fe35..de8261357 100644
--- a/lam/templates/lib/500_lam.js
+++ b/lam/templates/lib/500_lam.js
@@ -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 || {};
/**