From 85663b1beea5caf54064fc06f111a3d6f7c23629 Mon Sep 17 00:00:00 2001 From: Ivan Efimov Date: Sun, 17 Apr 2022 00:37:30 -0500 Subject: [PATCH] Presets fix: proper escape button handling for preset dialogs --- .../MotorOutputReorderingComponent.js | 7 +---- src/tabs/presets/CliEngine.js | 2 +- .../DetailedDialog/PresetsDetailedDialog.js | 16 +++++++---- .../presets/SourcesDialog/SourcesDialog.js | 6 ++++- src/tabs/presets/presets.js | 27 +++++++++++++------ 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/components/MotorOutputReordering/MotorOutputReorderingComponent.js b/src/components/MotorOutputReordering/MotorOutputReorderingComponent.js index fe7b147f..1e4d7c34 100644 --- a/src/components/MotorOutputReordering/MotorOutputReorderingComponent.js +++ b/src/components/MotorOutputReordering/MotorOutputReorderingComponent.js @@ -92,12 +92,7 @@ class MotorOutputReorderComponent function reboot() { GUI.log(i18n.getMessage('configurationEepromSaved')); - - GUI.tab_switch_cleanup(function() - { - MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false); - reinitialiseConnection(self); - }); + GUI.tab_switch_cleanup(() => MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(TABS.motors))); } FC.MOTOR_OUTPUT_ORDER = Array.from(this._newMotorOutputReorder); diff --git a/src/tabs/presets/CliEngine.js b/src/tabs/presets/CliEngine.js index 166b63f8..896a06cd 100644 --- a/src/tabs/presets/CliEngine.js +++ b/src/tabs/presets/CliEngine.js @@ -208,7 +208,7 @@ class CliEngine CONFIGURATOR.cliEngineActive = false; CONFIGURATOR.cliEngineValid = false; GUI.log(i18n.getMessage('cliReboot')); - reinitialiseConnection(this._currentTab); + reinitializeConnection(this._currentTab); } } diff --git a/src/tabs/presets/DetailedDialog/PresetsDetailedDialog.js b/src/tabs/presets/DetailedDialog/PresetsDetailedDialog.js index c6602ca6..9f110bf1 100644 --- a/src/tabs/presets/DetailedDialog/PresetsDetailedDialog.js +++ b/src/tabs/presets/DetailedDialog/PresetsDetailedDialog.js @@ -25,6 +25,7 @@ class PresetsDetailedDialog { this._setLoadingState(true); this._domDialog[0].showModal(); this._optionsShowedAtLeastOnce = false; + this._isPresetPickedOnClose = false; this._presetsRepo.loadPreset(this._preset) .then(() => { @@ -231,9 +232,10 @@ class PresetsDetailedDialog { this._readDom(); this._domButtonApply.on("click", () => this._onApplyButtonClicked()); - this._domButtonCancel.on("click", () => this._onCancelButtonClicked(false)); + this._domButtonCancel.on("click", () => this._onCancelButtonClicked()); this._domButtonCliShow.on("click", () => this._showCliText(true)); this._domButtonCliHide.on("click", () => this._showCliText(false)); + this._domDialog.on("close", () => this._onClose()); } _onApplyButtonClicked() { @@ -256,7 +258,8 @@ class PresetsDetailedDialog { const pickedPreset = new PickedPreset(this._preset, cliStrings); this._pickedPresetList.push(pickedPreset); this._onPresetPickedCallback?.(); - this._onCancelButtonClicked(true); + this._isPresetPickedOnClose = true; + this._onCancelButtonClicked(); } _pickPresetFwVersionCheck() { @@ -284,9 +287,12 @@ class PresetsDetailedDialog { } } - _onCancelButtonClicked(isPresetPicked) { - this._destroyOptionsSelect(); + _onCancelButtonClicked() { this._domDialog[0].close(); - this._openPromiseResolve?.(isPresetPicked); + } + + _onClose() { + this._destroyOptionsSelect(); + this._openPromiseResolve?.(this._isPresetPickedOnClose); } } diff --git a/src/tabs/presets/SourcesDialog/SourcesDialog.js b/src/tabs/presets/SourcesDialog/SourcesDialog.js index 8963bf67..abde48be 100644 --- a/src/tabs/presets/SourcesDialog/SourcesDialog.js +++ b/src/tabs/presets/SourcesDialog/SourcesDialog.js @@ -124,13 +124,17 @@ class PresetsSourcesDialog { _setupEvents() { this._domButtonClose.on("click", () => this._onCloseButtonClick()); + this._domDialog.on("close", () => this._onClose()); } _onCloseButtonClick() { - this._sourceSelectedPromiseResolve?.(); this._domDialog[0].close(); } + _onClose() { + this._sourceSelectedPromiseResolve?.(); + } + _readPanels() { this._sources = []; this._activeSourceIndex = 0; diff --git a/src/tabs/presets/presets.js b/src/tabs/presets/presets.js index 740ed174..7a0b5578 100644 --- a/src/tabs/presets/presets.js +++ b/src/tabs/presets/presets.js @@ -42,8 +42,8 @@ TABS.presets.readDom = function() { this._domProgressDialog = $("#presets_apply_progress_dialog")[0]; this._domProgressDialogProgressBar = $(".presets_apply_progress_dialog_progress_bar"); this._domButtonaSaveAnyway = $("#presets_cli_errors_save_anyway_button"); - this._domButtonaCliExit = $("#presets_cli_errors_exit_no_save_button"); - this._domDialogCliErrors = $("#presets_cli_errors_dialog")[0]; + this._domButtonCliExit = $("#presets_cli_errors_exit_no_save_button"); + this._domDialogCliErrors = $("#presets_cli_errors_dialog"); this._domButtonSaveBackup = $(".presets_save_config"); this._domButtonLoadBackup = $(".presets_load_config"); this._domButtonPresetSources = $(".presets_sources_show"); @@ -87,7 +87,8 @@ TABS.presets.onSaveClick = function() { if (newCliErrorsCount !== currentCliErrorsCount) { this._domProgressDialog.close(); - this._domDialogCliErrors.showModal(); + this._domDialogCliErrors[0].showModal(); + this._domDialogCliErrorsSavePressed = false; } else { this._domProgressDialog.close(); this.cliEngine.sendLine(CliEngine.s_commandSave); @@ -117,13 +118,14 @@ TABS.presets.setupMenuButtons = function() { this.enableSaveCancelButtons(false); }); - this._domButtonaCliExit.on("click", () =>{ - this._domDialogCliErrors.close(); - this.cliEngine.sendLine(CliEngine.s_commandExit); - this.disconnectCliMakeSure(); + this._domButtonCliExit.on("click", () =>{ + this._domDialogCliErrorsSavePressed = false; + this._domDialogCliErrors[0].close(); }); + this._domButtonaSaveAnyway.on("click", () => { - this._domDialogCliErrors.close(); + this._domDialogCliErrorsSavePressed = true; + this._domDialogCliErrors[0].close(); this.cliEngine.sendLine(CliEngine.s_commandSave, null, () => { // In case of batch CLI commands errors Firmware requeires extra "save" comand for CLI safety. // No need for this safety in presets as preset tab already detected errors and showed them to the user. @@ -132,6 +134,15 @@ TABS.presets.setupMenuButtons = function() { }); this.disconnectCliMakeSure(); }); + + this._domDialogCliErrors.on("close", () => { + if(!this._domDialogCliErrorsSavePressed) { + this._domDialogCliErrorsSavePressed = true; + this.cliEngine.sendLine(CliEngine.s_commandExit); + this.disconnectCliMakeSure(); + } + }); + this._domButtonSaveBackup.on("click", () => this.onSaveConfigClick()); this._domButtonLoadBackup.on("click", () => this.onLoadConfigClick()); this._domButtonPresetSources.on("click", () => this.onPresetSourcesShowClick());