Skip to content

Commit

Permalink
Disable buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Nov 4, 2023
1 parent f83c460 commit af5b911
Showing 1 changed file with 56 additions and 38 deletions.
94 changes: 56 additions & 38 deletions src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ firmware_flasher.initialize = function (callback) {
self.flashingMessage(`<a class="save_firmware" href="#" title="Save Firmware">${i18n.getMessage('firmwareFlasherFirmwareOnlineLoaded', { filename: fileName, bytes: self.parsed_hex.bytes_total })}</a>`,
self.FLASH_MESSAGE_TYPES.NEUTRAL);
}
self.enableFlashing(true);
self.enableFlashButton(true);
}

function showReleaseNotes(summary) {
Expand Down Expand Up @@ -156,7 +156,7 @@ firmware_flasher.initialize = function (callback) {
showLoadedHex(key);
} else {
self.flashingMessage(i18n.getMessage('firmwareFlasherHexCorrupted'), self.FLASH_MESSAGE_TYPES.INVALID);
self.enableFlashing(false);
self.enableFlashButton(false);
}
});
}
Expand All @@ -165,7 +165,7 @@ firmware_flasher.initialize = function (callback) {
self.localFirmwareLoaded = false;

processHex(data, key);
$("a.load_remote_file").removeClass('disabled');
self.enableLoadRemoteFileButton(true);
$("a.load_remote_file").text(i18n.getMessage('firmwareFlasherButtonLoadOnline'));
}

Expand Down Expand Up @@ -299,11 +299,12 @@ firmware_flasher.initialize = function (callback) {

loadSponsor();

buildType_e.change(function() {
buildType_e.on('change', function() {
self.enableLoadRemoteFileButton(false);

tracking.setFirmwareData(tracking.DATA.FIRMWARE_CHANNEL, $('option:selected', this).text());

$("a.load_remote_file").addClass('disabled');
const build_type = $(this).val();
const build_type = buildType_e.val();

$('select[name="board"]').empty()
.append($(`<option value='0'>${i18n.getMessage("firmwareFlasherOptionLoading")}</option>`));
Expand All @@ -327,7 +328,7 @@ firmware_flasher.initialize = function (callback) {
$('div.release_info').slideUp();

if (!self.localFirmwareLoaded) {
self.enableFlashing(false);
self.enableFlashButton(false);
self.flashingMessage(i18n.getMessage('firmwareFlasherLoadFirmwareFile'), self.FLASH_MESSAGE_TYPES.NEUTRAL);
if (self.parsed_hex && self.parsed_hex.bytes_total) {
// Changing the board triggers a version change, so we need only dump it here.
Expand Down Expand Up @@ -369,7 +370,7 @@ firmware_flasher.initialize = function (callback) {
setBoardConfig(response.configuration);
}

$("a.load_remote_file").removeClass('disabled');
self.enableLoadRemoteFileButton(true);
}

self.releaseLoader.loadTarget(target, release, onTargetDetail);
Expand Down Expand Up @@ -452,8 +453,8 @@ firmware_flasher.initialize = function (callback) {
}
});

$('select[name="board"]').change(function() {
$("a.load_remote_file").addClass('disabled');
$('select[name="board"]').on('change', function() {
self.enableLoadRemoteFileButton(false);
let target = $(this).val();

// exception for board flashed with local custom firmware
Expand All @@ -473,7 +474,7 @@ firmware_flasher.initialize = function (callback) {
$('div.build_configuration').slideUp();

if (!self.localFirmwareLoaded) {
self.enableFlashing(false);
self.enableFlashButton(false);
}

const versions_e = $('select[name="firmware_version"]');
Expand Down Expand Up @@ -814,8 +815,8 @@ firmware_flasher.initialize = function (callback) {
$('input.flash_manual_baud_rate').change();

// UI Hooks
$('a.load_file').click(function () {
self.enableFlashing(false);
$('a.load_file').on('click', function () {
self.enableFlashButton(false);
self.developmentFirmwareLoaded = false;

tracking.setFirmwareData(tracking.DATA.FIRMWARE_CHANNEL, undefined);
Expand Down Expand Up @@ -874,7 +875,7 @@ firmware_flasher.initialize = function (callback) {
}

if ((self.isConfigLocal && self.parsed_hex && !self.localFirmwareLoaded) || self.localFirmwareLoaded) {
self.enableFlashing(true);
self.enableFlashButton(true);
self.flashingMessage(i18n.getMessage('firmwareFlasherFirmwareLocalLoaded', self.parsed_hex.bytes_total), self.FLASH_MESSAGE_TYPES.NEUTRAL);
}
}
Expand All @@ -896,8 +897,13 @@ firmware_flasher.initialize = function (callback) {
},
);

$('a.load_remote_file').click(function (evt) {
self.enableFlashing(false);
$('a.load_remote_file').on('click', function (evt) {
if (!self.selectedBoard) {
return;
}

self.enableLoadRemoteFileButton(false);
self.enableFlashButton(false);
self.localFirmwareLoaded = false;
self.developmentFirmwareLoaded = buildTypesToShow[$('select[name="build_type"]').val()].tag === 'firmwareFlasherOptionLabelBuildTypeDevelopment';

Expand All @@ -910,7 +916,7 @@ firmware_flasher.initialize = function (callback) {

function onLoadFailed() {
$('span.progressLabel').attr('i18n','firmwareFlasherFailedToLoadOnlineFirmware').removeClass('i18n-replaced');
$("a.load_remote_file").removeClass('disabled');
self.enableLoadRemoteFileButton(true);
$("a.load_remote_file").text(i18n.getMessage('firmwareFlasherButtonLoadOnline'));
i18n.localizePage();
}
Expand Down Expand Up @@ -1009,7 +1015,7 @@ firmware_flasher.initialize = function (callback) {
}

updateStatus('Processing', response.key, retries * 10, false);
retries = retries + 1;
retries++;
});
}, 5000);
});
Expand All @@ -1018,7 +1024,7 @@ firmware_flasher.initialize = function (callback) {

if (self.targetDetail) { // undefined while list is loading or while running offline
$("a.load_remote_file").text(i18n.getMessage('firmwareFlasherButtonDownloading'));
$("a.load_remote_file").addClass('disabled');
self.enableLoadRemoteFileButton(false);

showReleaseNotes(self.targetDetail);

Expand All @@ -1031,9 +1037,10 @@ firmware_flasher.initialize = function (callback) {

const exitDfuElement = $('a.exit_dfu');

exitDfuElement.click(function () {
exitDfuElement.on('click', function () {
if (!exitDfuElement.hasClass('disabled')) {
exitDfuElement.addClass("disabled");
self.enableDfuExitButton(false);

if (!GUI.connect_lock) { // button disabled while flashing is in progress
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLASHING, 'ExitDfu', null);
try {
Expand All @@ -1050,27 +1057,34 @@ firmware_flasher.initialize = function (callback) {
if (GUI.active_tab === 'firmware_flasher') {
if (!GUI.connect_lock) {
if ($('option:selected', this).data().isDFU) {
exitDfuElement.removeClass('disabled');
self.enableDfuExitButton(true);
} else {
// Porthandler resets board on port detect
if (self.boardNeedsVerification) {
// reset to prevent multiple calls
self.boardNeedsVerification = false;
verifyBoard();
}

$("a.load_remote_file").removeClass('disabled');
$("a.load_file").removeClass('disabled');
exitDfuElement.addClass('disabled');
if (self.selectedBoard) {
self.enableLoadRemoteFileButton(true);
}
self.enableLoadFileButton(true);
self.enableDfuExitButton(false);
}
}
updateDetectBoardButton();
}
}).trigger('change');

$('a.flash_firmware').click(function () {
$('a.flash_firmware').on('click', function () {
const flashButtonElement = $(this);

if (!flashButtonElement.hasClass('disabled')) {
self.enableFlashButton(false);
self.enableDfuExitButton(false);
self.enableLoadRemoteFileButton(false);
self.enableLoadFileButton(false);

if (!$(this).hasClass('disabled')) {
function goFlashing() {
if (self.developmentFirmwareLoaded) {
checkShowAcknowledgementDialog();
Expand Down Expand Up @@ -1153,10 +1167,6 @@ firmware_flasher.initialize = function (callback) {
}

function startFlashing() {
exitDfuElement.addClass('disabled');
$('a.flash_firmware').addClass('disabled');
$("a.load_remote_file").addClass('disabled');
$("a.load_file").addClass('disabled');
if (!GUI.connect_lock) { // button disabled while flashing is in progress
if (self.parsed_hex) {
try {
Expand Down Expand Up @@ -1462,12 +1472,20 @@ firmware_flasher.cleanup = function (callback) {
if (callback) callback();
};

firmware_flasher.enableFlashing = function (enabled) {
if (enabled) {
$('a.flash_firmware').removeClass('disabled');
} else {
$('a.flash_firmware').addClass('disabled');
}
firmware_flasher.enableFlashButton = function (enabled) {
$('a.flash_firmware').toggleClass('disabled', !enabled);
};

firmware_flasher.enableLoadRemoteFileButton = function (enabled) {
$('a.load_remote_file').toggleClass('disabled', !enabled);
};

firmware_flasher.enableLoadFileButton = function (enabled) {
$('a.load_file').toggleClass('disabled', !enabled);
};

firmware_flasher.enableDfuExitButton = function (enabled) {
$('a.exit_dfu').toggleClass('disabled', !enabled);
};

firmware_flasher.refresh = function (callback) {
Expand Down

0 comments on commit af5b911

Please sign in to comment.