Properly use the _listener variables as expected, and allow Enter key to execute the action

This commit is contained in:
Gregoo 2025-01-27 23:13:42 +01:00
parent cf6d5f43c0
commit f12d608738
2 changed files with 38 additions and 25 deletions

View File

@ -11,15 +11,9 @@ class BrickInstructionsSocket extends BrickSocket {
this.html_files = document.getElementById(`${id}-files`);
if (this.html_button) {
this.download_listener = ((bricksocket) => (e) => {
if (!bricksocket.disabled && bricksocket.socket !== undefined && bricksocket.socket.connected) {
bricksocket.toggle(false);
bricksocket.download_instructions();
}
})(this);
this.html_button.addEventListener("click", this.download_listener);
this.download_listener = this.html_button.addEventListener("click", ((bricksocket) => (e) => {
bricksocket.execute();
})(this));
}
if (this.html_card_dismiss && this.html_card) {
@ -43,6 +37,15 @@ class BrickInstructionsSocket extends BrickSocket {
this.download_instructions(true);
}
// Execute the action
execute() {
if (!this.disabled && this.socket !== undefined && this.socket.connected) {
this.toggle(false);
this.download_instructions();
}
}
// Get the list of checkboxes describing files
get_files(checked=false) {
let files = [];

View File

@ -5,6 +5,7 @@ class BrickSetSocket extends BrickSocket {
// Listeners
this.add_listener = undefined;
this.input_listener = undefined;
this.confirm_listener = undefined;
// Form elements (built based on the initial id)
@ -23,24 +24,15 @@ class BrickSetSocket extends BrickSocket {
this.html_card_dismiss = document.getElementById(`${id}-card-dismiss`);
if (this.html_button) {
this.add_listener = ((bricksocket) => (e) => {
if (!bricksocket.disabled && bricksocket.socket !== undefined && bricksocket.socket.connected) {
bricksocket.toggle(false);
this.add_listener = this.html_button.addEventListener("click", ((bricksocket) => (e) => {
bricksocket.execute();
})(this));
// Split and save the list if bulk
if (bricksocket.bulk) {
bricksocket.read_set_list()
}
if (bricksocket.bulk || (bricksocket.html_no_confim && bricksocket.html_no_confim.checked)) {
bricksocket.import_set(true);
} else {
bricksocket.load_set();
}
this.input_listener = this.html_input.addEventListener("keyup", ((bricksocket) => (e) => {
if (e.key === 'Enter') {
bricksocket.execute();
}
})(this);
this.html_button.addEventListener("click", this.add_listener);
})(this))
}
if (this.html_card_dismiss && this.html_card) {
@ -80,6 +72,24 @@ class BrickSetSocket extends BrickSocket {
}
}
// Execute the action
execute() {
if (!this.disabled && this.socket !== undefined && this.socket.connected) {
this.toggle(false);
// Split and save the list if bulk
if (this.bulk) {
this.read_set_list();
}
if (this.bulk || (this.html_no_confim && this.html_no_confim.checked)) {
this.import_set(true);
} else {
this.load_set();
}
}
}
// Upon receiving a fail message
fail(data) {
super.fail(data);