select options in extension configuration can retain order (only attributedefinitions)

This commit is contained in:
Uwe Steinmann 2025-02-04 13:39:02 +01:00
parent c815b0069d
commit 4d44774a7f
3 changed files with 33 additions and 1 deletions

View File

@ -762,12 +762,22 @@ if(($kkk = $this->callHook('getFullSearchEngine')) && is_array($kkk))
case "attributedefinitions":
$objtype = empty($conf['objtype']) ? 0 : $conf['objtype'];
$attrtype = empty($conf['attrtype']) ? 0 : $conf['attrtype'];
$order = empty($conf['order']) ? '' : $conf['order'];
$recs = $dms->getAllAttributeDefinitions($objtype, $attrtype);
if($recs) {
echo "<select class=\"chzn-select\"".($allowempty ? " data-allow-clear=\"true\"" : "")." name=\"extensions[".$extname."][".$confkey."][]\"".(!empty($conf['multiple']) ? " multiple" : "").(!empty($conf['size']) ? " size=\"".$conf['size']."\"" : "")." data-placeholder=\"".getMLText("select_attrdef")."\" data-no_results_text=\"".getMLText('unknown_attrdef')."\" style=\"width: 100%;\">";
echo "<select class=\"chzn-select\"".($allowempty ? " data-allow-clear=\"true\"" : "").($order ? " order=\"".$order."\"" : "")." name=\"extensions[".$extname."][".$confkey."][]\"".(!empty($conf['multiple']) ? " multiple" : "").(!empty($conf['size']) ? " size=\"".$conf['size']."\"" : "")." data-placeholder=\"".getMLText("select_attrdef")."\" data-no_results_text=\"".getMLText('unknown_attrdef')."\" style=\"width: 100%;\">";
if($allowempty)
echo "<option value=\"\"></option>";
if($order == 'keep') {
foreach($selections as $selid) {
if($rec = $dms->getAttributeDefinition($selid)) {
echo "<option value=\"".$rec->getID()."\" selected data-subtitle=\"".htmlspecialchars(getAttributeObjectTypeText($rec).", ".getAttributeTypeText($rec))."\">".htmlspecialchars($rec->getName())."</option>";
}
}
}
foreach($recs as $rec) {
if($order == 'keep' && in_array($rec->getID(), $selections))
continue;
echo "<option value=\"".$rec->getID()."\"";
if(in_array($rec->getID(), $selections))
echo " selected";

View File

@ -28,6 +28,12 @@ chzn_template_func = function (state) { /* {{{ */
return $newstate;
}; /* }}} */
function chzn_select_item(target, id) { /* {{{ */
var option = $(target).children('[value=' + id + ']');
option.detach();
$(target).append(option).change();
}; /* }}} */
function escapeHtml(text) { /* {{{ */
var map = {
'&': '&amp;',
@ -99,6 +105,11 @@ function initMost() { /* {{{ */
templateResult: chzn_template_func
}); /* }}} */
/* newly selected items will be appended to the end */
$('.chzn-select[order=keep]').on('select2:select', function (e) { /* {{{ */
chzn_select_item(e.target, e.params.data.id);
}); /* }}} */
$(".chzn-select-folder").select2({ /* {{{ */
theme: "bootstrap4",
width: 'resolve',

View File

@ -28,6 +28,12 @@ chzn_template_func = function (state) { /* {{{ */
return $newstate;
}; /* }}} */
function chzn_select_item(target, id) { /* {{{ */
var option = $(target).children('[value=' + id + ']');
option.detach();
$(target).append(option).change();
}; /* }}} */
function escapeHtml(text) { /* {{{ */
var map = {
'&': '&amp;',
@ -103,6 +109,11 @@ function initMost() { /* {{{ */
templateResult: chzn_template_func
}); /* }}} */
/* newly selected items will be appended to the end */
$('.chzn-select[order=keep]').on('select2:select', function (e) { /* {{{ */
chzn_select_item(e.target, e.params.data.id);
}); /* }}} */
$(".chzn-select-folder").select2({ /* {{{ */
theme: "bootstrap4",
width: 'resolve',