Skip to content

Commit

Permalink
Toolbar: ask for confirmation when "Home" is clicked
Browse files Browse the repository at this point in the history
So far confirmation was only asked for when clicking one of the data
view entries directly. It is more consistent and safe to also ask for
confirmation when "Home" is clicked directly, too.
  • Loading branch information
tomka committed Jul 9, 2024
1 parent 0973ddb commit ffe464e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ Miscellaneous:
- The navigate-with-project setting of a stack viewer is now respected in
stored layouts.

- Clicking the Home link in the upper left corner with a project open, will now
also ask for confirmation (like clicking any data view entry in the menu).

## Maintenance updates

- Node distance measurements: computation of straight line distance has been
Expand Down
25 changes: 23 additions & 2 deletions django/applications/catmaid/static/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,12 @@ var project;
document.getElementById( "account" ).onkeydown = login_oninputreturn;
document.getElementById( "password" ).onkeydown = login_oninputreturn;

document.getElementById( "home_button" ).addEventListener('click', event => {
CATMAID.client.confirmLoadHomeView()
.catch(CATMAID.handleError);
return false;
});

CATMAID.DataViews.list().then(dataviews => {
this._knownDataViews = dataviews;
this._updateDataViewMenu();
Expand Down Expand Up @@ -1818,7 +1824,7 @@ var project;
// If a project is active, ask for confirmation before closing it.
if (project) {
if (!confirm('Are you sure you want to close all widgets and views?')) {
return;
return Promise.reject(new CATMAID.Warning('Cancelled by user'));
}
project.destroy();
} else {
Expand Down Expand Up @@ -1887,6 +1893,21 @@ var project;
}
};

/**
* Ask the user whether to close an active project, before loading the home
* view.
*/
Client.prototype.confirmLoadHomeView = function(backgroundDataView = false) {
// If a project is active, ask for confirmation before closing it.
if (project) {
if (!confirm('Are you sure you want to close the active project including all windows?')) {
return Promise.reject(new CATMAID.Warning('Cancelled by user'));
}
project.destroy();
}
return CATMAID.client.loadHomeView(backgroundDataView);
};

/**
* Load a particular data view.
*
Expand Down Expand Up @@ -1925,7 +1946,7 @@ var project;
*/
Client.prototype.load_default_dataview = function(background) {
var self = this;
CATMAID.DataViews.getDefaultConfig()
return CATMAID.DataViews.getDefaultConfig()
.then(function(config) {
// If no data view is defined on the back-end, use a default data view.
if (!config || !config.id || CATMAID.tools.isEmpty(config.config)) {
Expand Down
2 changes: 1 addition & 1 deletion django/applications/catmaid/templates/catmaid/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<div class="menu toolbar_item">
<div id="home_box" class="box">
<div class="menu_item" style="float:left" onpointerover="this.lastChild.style.display = 'block';" onpointerout="this.lastChild.style.display = 'none';">
<p><a onclick="if (project) { project.destroy(); } else { CATMAID.client.loadHomeView(); } return false;">Home</a></p>
<p><a id="home_button">Home</a></p>
<div class="pulldown" id="dataview_menu"></div></div>
</div>
<div id="projectmenu_box" class="box">
Expand Down

0 comments on commit ffe464e

Please sign in to comment.