Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ c9178ef17a0e1070f5a25096d8e13385d404dc92
6cff02078799b7c683a0d39630d49ab4fe532e7c
4286a23df64f6ce3b9b6ed097f4d1aac7d9e0de4
241b8e1aab7fc71018a059467b2ba17bce6556cc
fc0a0ebd4fe573299a5f978e77fa3bca8424f661
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ repos:
rev: 7.3.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v9.39.1
hooks:
- id: eslint
- repo: https://github.com/biomejs/pre-commit
rev: v2.4.12
hooks:
Expand Down
29 changes: 22 additions & 7 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
"docs/_theme/**/*.css",
"!docs/_theme/djangodocs/static/fontawesome/**",
"!docs/_theme/djangodocs/static/reset-fonts-grids.css",
"!**/*.min.css"
"!**/*.min.css",
"django/contrib/admin/static/admin/js/**/*.js",
"!django/contrib/admin/static/admin/js/vendor/**",
"django/contrib/gis/static/gis/js/**/*.js",
"js_tests/**/*.js",
"!**/*.min.js"
]
},
"formatter": {
Expand All @@ -19,17 +24,27 @@
"enabled": true,
"rules": {
"complexity": {
"noImportantStyles": "off"
"noArguments": "off",
"noImportantStyles": "off",
"noUselessLoneBlockStatements": "off",
"useArrowFunction": "off",
"useIndexOf": "off",
"useOptionalChain": "off"
},
"correctness": {
"noUnusedFunctionParameters": "off",
"noUnusedVariables": "off",
"useParseIntRadix": "off"
},
"style": {
"noDescendingSpecificity": "off"
"noDescendingSpecificity": "off",
"useTemplate": "off"
},
"suspicious": {
"noRedundantUseStrict": "off"
}
}
},
"javascript": {
"linter": { "enabled": false },
"formatter": { "enabled": false }
},
"json": {
"linter": { "enabled": false },
"formatter": { "enabled": false }
Expand Down
90 changes: 61 additions & 29 deletions django/contrib/admin/static/admin/js/SelectBox.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,60 @@
'use strict';
"use strict";
{
const getOptionGroupName = (option) => option.parentElement.label;
const SelectBox = {
cache: {},
init: function(id) {
init: function (id) {
const box = document.getElementById(id);
SelectBox.cache[id] = [];
const cache = SelectBox.cache[id];
for (const node of box.options) {
const group = getOptionGroupName(node);
cache.push({group, value: node.value, text: node.text, displayed: 1});
cache.push({
group,
value: node.value,
text: node.text,
displayed: 1,
});
}
// Only sort if there are any groups (to preserve existing behavior for non-grouped selects)
if (cache.some(item => item.group)) {
if (cache.some((item) => item.group)) {
SelectBox.sort(id);
}
},
redisplay: function(id) {
redisplay: function (id) {
// Repopulate HTML select box from cache
const box = document.getElementById(id);
const scroll_value_from_top = box.scrollTop;
box.innerHTML = '';
box.innerHTML = "";
let node = box;
let currentOptgroup = null;
for (const option of SelectBox.cache[id]) {
if (option.displayed) {
// Create a new optgroup when the group changes
if (option.group && option.group !== currentOptgroup) {
currentOptgroup = option.group;
node = document.createElement('optgroup');
node.setAttribute('label', option.group);
node = document.createElement("optgroup");
node.setAttribute("label", option.group);
box.appendChild(node);
} else if (!option.group && currentOptgroup !== null) {
// Back to ungrouped options
currentOptgroup = null;
node = box;
}
const new_option = new Option(option.text, option.value, false, false);
const new_option = new Option(
option.text,
option.value,
false,
false,
);
// Shows a tooltip when hovering over the option
new_option.title = option.text;
node.appendChild(new_option);
}
}
box.scrollTop = scroll_value_from_top;
},
filter: function(id, text) {
filter: function (id, text) {
// Redisplay the HTML select box, displaying only the choices containing ALL
// the words in text. (It's an AND search.)
const tokens = text.toLowerCase().split(/\s+/);
Expand All @@ -62,9 +72,9 @@
},
get_hidden_node_count(id) {
const cache = SelectBox.cache[id] || [];
return cache.filter(node => node.displayed === 0).length;
return cache.filter((node) => node.displayed === 0).length;
},
delete_from_cache: function(id, value) {
delete_from_cache: function (id, value) {
let delete_index = null;
const cache = SelectBox.cache[id];
for (const [i, node] of cache.entries()) {
Expand All @@ -75,10 +85,15 @@
}
cache.splice(delete_index, 1);
},
add_to_cache: function(id, option) {
SelectBox.cache[id].push({group: option.group, value: option.value, text: option.text, displayed: 1});
add_to_cache: function (id, option) {
SelectBox.cache[id].push({
group: option.group,
value: option.value,
text: option.text,
displayed: 1,
});
},
cache_contains: function(id, value) {
cache_contains: function (id, value) {
// Check if an item is contained in the cache
for (const node of SelectBox.cache[id]) {
if (node.value === value) {
Expand All @@ -87,59 +102,76 @@
}
return false;
},
move: function(from, to) {
move: function (from, to) {
const from_box = document.getElementById(from);
for (const option of from_box.options) {
const option_value = option.value;
if (option.selected && SelectBox.cache_contains(from, option_value)) {
if (
option.selected &&
SelectBox.cache_contains(from, option_value)
) {
const group = getOptionGroupName(option);
SelectBox.add_to_cache(to, {group, value: option_value, text: option.text, displayed: 1});
SelectBox.add_to_cache(to, {
group,
value: option_value,
text: option.text,
displayed: 1,
});
SelectBox.delete_from_cache(from, option_value);
}
}
// Only sort if there are any groups (to preserve existing behavior for non-grouped selects)
if (SelectBox.cache[to].some(item => item.group)) {
if (SelectBox.cache[to].some((item) => item.group)) {
SelectBox.sort(to);
}
SelectBox.redisplay(from);
SelectBox.redisplay(to);
},
move_all: function(from, to) {
move_all: function (from, to) {
const from_box = document.getElementById(from);
for (const option of from_box.options) {
const option_value = option.value;
if (SelectBox.cache_contains(from, option_value)) {
const group = getOptionGroupName(option);
SelectBox.add_to_cache(to, {group, value: option_value, text: option.text, displayed: 1});
SelectBox.add_to_cache(to, {
group,
value: option_value,
text: option.text,
displayed: 1,
});
SelectBox.delete_from_cache(from, option_value);
}
}
// Only sort if there are any groups (to preserve existing behavior for non-grouped selects)
if (SelectBox.cache[to].some(item => item.group)) {
if (SelectBox.cache[to].some((item) => item.group)) {
SelectBox.sort(to);
}
SelectBox.redisplay(from);
SelectBox.redisplay(to);
},
sort: function(id) {
SelectBox.cache[id].sort(function(a, b) {
a = (a.group && a.group.toLowerCase() || '') + a.text.toLowerCase();
b = (b.group && b.group.toLowerCase() || '') + b.text.toLowerCase();
sort: function (id) {
SelectBox.cache[id].sort(function (a, b) {
a =
((a.group && a.group.toLowerCase()) || "") +
a.text.toLowerCase();
b =
((b.group && b.group.toLowerCase()) || "") +
b.text.toLowerCase();
if (a > b) {
return 1;
}
if (a < b) {
return -1;
}
return 0;
} );
});
},
select_all: function(id) {
select_all: function (id) {
const box = document.getElementById(id);
for (const option of box.options) {
option.selected = true;
}
}
},
};
window.SelectBox = SelectBox;
}
Loading
Loading