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

View File

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