mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 21:48:16 -06:00
Add color support
This commit is contained in:
parent
5ca798429e
commit
93ad822b77
BIN
netbox/project-static/dist/netbox.js
vendored
BIN
netbox/project-static/dist/netbox.js
vendored
Binary file not shown.
BIN
netbox/project-static/dist/netbox.js.map
vendored
BIN
netbox/project-static/dist/netbox.js.map
vendored
Binary file not shown.
@ -2,7 +2,7 @@ import { initForms } from './forms';
|
|||||||
import { initBootstrap } from './bs';
|
import { initBootstrap } from './bs';
|
||||||
import { initQuickSearch } from './search';
|
import { initQuickSearch } from './search';
|
||||||
// import { initSelect } from './select';
|
// import { initSelect } from './select';
|
||||||
import { initTomSelect } from './tomSelect';
|
import { initSelects } from './tomSelect';
|
||||||
import { initButtons } from './buttons';
|
import { initButtons } from './buttons';
|
||||||
import { initColorMode } from './colorMode';
|
import { initColorMode } from './colorMode';
|
||||||
import { initMessages } from './messages';
|
import { initMessages } from './messages';
|
||||||
@ -24,7 +24,7 @@ function initDocument(): void {
|
|||||||
initForms,
|
initForms,
|
||||||
initQuickSearch,
|
initQuickSearch,
|
||||||
// initSelect,
|
// initSelect,
|
||||||
initTomSelect,
|
initSelects,
|
||||||
initDateSelector,
|
initDateSelector,
|
||||||
initButtons,
|
initButtons,
|
||||||
initClipboard,
|
initClipboard,
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
import { getElements } from './util';
|
import { getElements } from './util';
|
||||||
|
import { TomOption } from 'tom-select/src/types';
|
||||||
import TomSelect from 'tom-select';
|
import TomSelect from 'tom-select';
|
||||||
|
|
||||||
export function initTomSelect(): void {
|
function initStaticSelects(): void {
|
||||||
|
|
||||||
// Static selects
|
for (const select of getElements<HTMLSelectElement>('select:not(.api-select):not(.color-select)')) {
|
||||||
for (const select of getElements<HTMLSelectElement>('select:not(.api-select)')) {
|
|
||||||
new TomSelect(select, {});
|
new TomSelect(select, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
// API selects
|
}
|
||||||
for (const select of getElements<HTMLSelectElement>('.api-select')) {
|
|
||||||
|
function initDynamicSelects(): void {
|
||||||
|
|
||||||
|
for (const select of getElements<HTMLSelectElement>('select.api-select')) {
|
||||||
const api_url = select.getAttribute('data-url') as string;
|
const api_url = select.getAttribute('data-url') as string;
|
||||||
new TomSelect(select, {
|
new TomSelect(select, {
|
||||||
valueField: 'id',
|
valueField: 'id',
|
||||||
@ -19,9 +22,8 @@ export function initTomSelect(): void {
|
|||||||
dropdownParent: 'body',
|
dropdownParent: 'body',
|
||||||
controlInput: '<input>',
|
controlInput: '<input>',
|
||||||
preload: 'focus',
|
preload: 'focus',
|
||||||
load: function(query, callback) {
|
load: function(query: string, callback: Function) {
|
||||||
var url = api_url + '?brief=True&q=' + encodeURIComponent(query);
|
let url = api_url + '?brief=True&q=' + encodeURIComponent(query);
|
||||||
console.log(url);
|
|
||||||
fetch(url)
|
fetch(url)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
@ -34,3 +36,23 @@ export function initTomSelect(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initColorSelects(): void {
|
||||||
|
|
||||||
|
for (const select of getElements<HTMLSelectElement>('select.color-select')) {
|
||||||
|
new TomSelect(select, {
|
||||||
|
render: {
|
||||||
|
option: function(item: TomOption, escape: Function) {
|
||||||
|
return `<div style="background-color: #${escape(item.value)}">${escape(item.text)}</div>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initSelects(): void {
|
||||||
|
initStaticSelects();
|
||||||
|
initDynamicSelects();
|
||||||
|
initColorSelects();
|
||||||
|
}
|
||||||
|
@ -36,7 +36,7 @@ class ColorSelect(forms.Select):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
kwargs['choices'] = add_blank_choice(ColorChoices)
|
kwargs['choices'] = add_blank_choice(ColorChoices)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.attrs['class'] = 'netbox-color-select'
|
self.attrs['class'] = 'color-select'
|
||||||
|
|
||||||
|
|
||||||
class HTMXSelect(forms.Select):
|
class HTMXSelect(forms.Select):
|
||||||
|
Loading…
Reference in New Issue
Block a user