-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use tomselect instead of jquery autoselect for counter clicks
- Loading branch information
Showing
4 changed files
with
126 additions
and
72 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
counter/static/bundled/counter/components/counter-product-select-index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { AutoCompleteSelectBase } from "#core:core/components/ajax-select-base"; | ||
import { registerComponent } from "#core:utils/web-components"; | ||
import type { RecursivePartial, TomSettings } from "tom-select/dist/types/types"; | ||
|
||
const productParsingRegex = /^(\d+x)?(.*)/i; | ||
|
||
function parseProduct(query: string): [number, string] { | ||
const parsed = productParsingRegex.exec(query); | ||
return [Number.parseInt(parsed[1] || "1"), parsed[2]]; | ||
} | ||
|
||
@registerComponent("counter-product-select") | ||
export class CounterProductSelect extends AutoCompleteSelectBase { | ||
public getOperationCodes(): string[] { | ||
return ["FIN", "ANN"]; | ||
} | ||
|
||
protected attachBehaviors(): void { | ||
this.allowMultipleProducts(); | ||
} | ||
|
||
private allowMultipleProducts(): void { | ||
const search = this.widget.search; | ||
const onOptionSelect = this.widget.onOptionSelect; | ||
this.widget.hook("instead", "search", (query: string) => { | ||
return search.call(this.widget, parseProduct(query)[1]); | ||
}); | ||
this.widget.hook( | ||
"instead", | ||
"onOptionSelect", | ||
(evt: MouseEvent | KeyboardEvent, option: HTMLElement) => { | ||
const [quantity, _] = parseProduct(this.widget.inputValue()); | ||
const originalValue = option.getAttribute("data-value") ?? option.innerText; | ||
|
||
if (quantity === 1 || this.getOperationCodes().includes(originalValue)) { | ||
return onOptionSelect.call(this.widget, evt, option); | ||
} | ||
|
||
const value = `${quantity}x${originalValue}`; | ||
const label = `${quantity}x${option.innerText}`; | ||
this.widget.addOption({ value: value, text: label }, true); | ||
return onOptionSelect.call( | ||
this.widget, | ||
evt, | ||
this.widget.getOption(value, true), | ||
); | ||
}, | ||
); | ||
|
||
this.widget.hook("after", "onOptionSelect", () => { | ||
/* Focus the next element if it's an input */ | ||
if (this.nextElementSibling.nodeName === "INPUT") { | ||
(this.nextElementSibling as HTMLInputElement).focus(); | ||
} | ||
}); | ||
} | ||
protected tomSelectSettings(): RecursivePartial<TomSettings> { | ||
/* We disable the dropdown on focus because we're going to always autofocus the widget */ | ||
return { ...super.tomSelectSettings(), openOnFocus: false }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
msgid "" | ||
msgstr "" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-12-19 10:43+0100\n" | ||
"POT-Creation-Date: 2024-12-19 14:40+0100\n" | ||
"PO-Revision-Date: 2016-07-18\n" | ||
"Last-Translator: Maréchal <[email protected]\n" | ||
"Language-Team: AE info <[email protected]>\n" | ||
|
@@ -586,7 +586,7 @@ msgstr "Classeur : " | |
#: accounting/templates/accounting/journal_statement_accounting.jinja:30 | ||
#: core/templates/core/user_account.jinja:39 | ||
#: core/templates/core/user_account_detail.jinja:9 | ||
#: counter/templates/counter/counter_click.jinja:31 | ||
#: counter/templates/counter/counter_click.jinja:37 | ||
msgid "Amount: " | ||
msgstr "Montant : " | ||
|
||
|
@@ -1216,7 +1216,7 @@ msgid "Barman" | |
msgstr "Barman" | ||
|
||
#: club/templates/club/club_sellings.jinja:51 | ||
#: counter/templates/counter/counter_click.jinja:28 | ||
#: counter/templates/counter/counter_click.jinja:34 | ||
#: counter/templates/counter/last_ops.jinja:22 | ||
#: counter/templates/counter/last_ops.jinja:47 | ||
#: counter/templates/counter/refilling_list.jinja:12 | ||
|
@@ -2037,8 +2037,8 @@ msgid "" | |
"The groups this user belongs to. A user will get all permissions granted to " | ||
"each of their groups." | ||
msgstr "" | ||
"Les groupes auxquels cet utilisateur appartient. Un utilisateur aura toutes les " | ||
"permissions de chacun de ses groupes." | ||
"Les groupes auxquels cet utilisateur appartient. Un utilisateur aura toutes " | ||
"les permissions de chacun de ses groupes." | ||
|
||
#: core/models.py:277 | ||
msgid "profile" | ||
|
@@ -2561,7 +2561,7 @@ msgstr "Confirmation" | |
|
||
#: core/templates/core/delete_confirm.jinja:20 | ||
#: core/templates/core/file_delete_confirm.jinja:46 | ||
#: counter/templates/counter/counter_click.jinja:100 | ||
#: counter/templates/counter/counter_click.jinja:121 | ||
#: counter/templates/counter/fragments/delete_student_card.jinja:12 | ||
#: sas/templates/sas/ask_picture_removal.jinja:20 | ||
msgid "Cancel" | ||
|
@@ -3275,7 +3275,7 @@ msgid "Go to my Trombi tools" | |
msgstr "Allez à mes outils de Trombi" | ||
|
||
#: core/templates/core/user_preferences.jinja:39 | ||
#: counter/templates/counter/counter_click.jinja:123 | ||
#: counter/templates/counter/counter_click.jinja:144 | ||
msgid "Student card" | ||
msgstr "Carte étudiante" | ||
|
||
|
@@ -3916,12 +3916,28 @@ msgstr "oui" | |
msgid "There is no cash register summary in this website." | ||
msgstr "Il n'y a pas de relevé de caisse dans ce site web." | ||
|
||
#: counter/templates/counter/counter_click.jinja:35 | ||
#: counter/templates/counter/counter_click.jinja:41 | ||
#: launderette/templates/launderette/launderette_admin.jinja:8 | ||
msgid "Selling" | ||
msgstr "Vente" | ||
|
||
#: counter/templates/counter/counter_click.jinja:46 | ||
#: counter/templates/counter/counter_click.jinja:52 | ||
msgid "Select a product..." | ||
msgstr "Sélectionnez un produit…" | ||
|
||
#: counter/templates/counter/counter_click.jinja:54 | ||
msgid "Operations" | ||
msgstr "Opérations" | ||
|
||
#: counter/templates/counter/counter_click.jinja:55 | ||
msgid "Confirm (FIN)" | ||
msgstr "Confirmer (FIN)" | ||
|
||
#: counter/templates/counter/counter_click.jinja:56 | ||
msgid "Cancel (ANN)" | ||
msgstr "Annuler (ANN)" | ||
|
||
#: counter/templates/counter/counter_click.jinja:67 | ||
#: counter/templates/counter/fragments/create_refill.jinja:8 | ||
#: counter/templates/counter/fragments/create_student_card.jinja:10 | ||
#: counter/templates/counter/invoices_call.jinja:16 | ||
|
@@ -3932,21 +3948,21 @@ msgstr "Vente" | |
msgid "Go" | ||
msgstr "Valider" | ||
|
||
#: counter/templates/counter/counter_click.jinja:53 | ||
#: counter/templates/counter/counter_click.jinja:74 | ||
#: eboutic/templates/eboutic/eboutic_makecommand.jinja:19 | ||
msgid "Basket: " | ||
msgstr "Panier : " | ||
|
||
#: counter/templates/counter/counter_click.jinja:94 | ||
#: counter/templates/counter/counter_click.jinja:115 | ||
msgid "Finish" | ||
msgstr "Terminer" | ||
|
||
#: counter/templates/counter/counter_click.jinja:104 | ||
#: counter/templates/counter/counter_click.jinja:125 | ||
#: counter/templates/counter/refilling_list.jinja:9 | ||
msgid "Refilling" | ||
msgstr "Rechargement" | ||
|
||
#: counter/templates/counter/counter_click.jinja:114 | ||
#: counter/templates/counter/counter_click.jinja:135 | ||
msgid "" | ||
"As a barman, you are not able to refill any account on your own. An admin " | ||
"should be connected on this counter for that. The customer can refill by " | ||
|