mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 11:59:23 +00:00
Remove ajax_select from counters
This commit is contained in:
30
club/static/webpack/club/components/ajax-select-index.ts
Normal file
30
club/static/webpack/club/components/ajax-select-index.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { AjaxSelect } from "#core:core/components/ajax-select-base";
|
||||
import { registerComponent } from "#core:utils/web-components";
|
||||
import type { TomOption } from "tom-select/dist/types/types";
|
||||
import type { escape_html } from "tom-select/dist/types/utils";
|
||||
import { type ClubSchema, clubSearchClub } from "#openapi";
|
||||
|
||||
@registerComponent("club-ajax-select")
|
||||
export class ClubAjaxSelect extends AjaxSelect {
|
||||
protected valueField = "id";
|
||||
protected labelField = "name";
|
||||
protected searchField = ["code", "name"];
|
||||
|
||||
protected async search(query: string): Promise<TomOption[]> {
|
||||
const resp = await clubSearchClub({ query: { search: query } });
|
||||
if (resp.data) {
|
||||
return resp.data.results;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
protected renderOption(item: ClubSchema, sanitize: typeof escape_html) {
|
||||
return `<div class="select-item">
|
||||
<span class="select-item-text">${sanitize(item.name)}</span>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
protected renderItem(item: ClubSchema, sanitize: typeof escape_html) {
|
||||
return `<span>${sanitize(item.name)}</span>`;
|
||||
}
|
||||
}
|
25
club/widgets/select.py
Normal file
25
club/widgets/select.py
Normal file
@ -0,0 +1,25 @@
|
||||
from django.forms import Select, SelectMultiple
|
||||
|
||||
from club.models import Club
|
||||
from club.schemas import ClubSchema
|
||||
from core.views.widgets.select import AutoCompleteSelectMixin
|
||||
|
||||
|
||||
class AutoCompleteSelectClub(AutoCompleteSelectMixin, Select):
|
||||
component_name = "club-ajax-select"
|
||||
model = Club
|
||||
schema = ClubSchema
|
||||
|
||||
js = [
|
||||
"webpack/club/components/ajax-select-index.ts",
|
||||
]
|
||||
|
||||
|
||||
class AutoCompleteSelectMultipleClub(AutoCompleteSelectMixin, SelectMultiple):
|
||||
component_name = "club-ajax-select"
|
||||
model = Club
|
||||
schema = ClubSchema
|
||||
|
||||
js = [
|
||||
"webpack/club/components/ajax-select-index.ts",
|
||||
]
|
Reference in New Issue
Block a user