Bug fixes for confirmDelete and lesion management

This commit is contained in:
Erik Ziegler 2015-12-21 09:29:19 -05:00
parent 5eb8a717cb
commit 4ae0183a9c
6 changed files with 43 additions and 14 deletions

View File

@ -44,7 +44,7 @@ Template.viewer.onCreated(function() {
}, },
nonTarget: function() { nonTarget: function() {
toolManager.setActiveTool("nonTarget"); toolManager.setActiveTool("nonTarget");
}, }
}; };
// The hotkey can also be an array (e.g. ["NUMPAD0", "0"]) // The hotkey can also be an array (e.g. ["NUMPAD0", "0"])

View File

@ -37,7 +37,7 @@ var LesionManager = (function() {
// Find the specific lesion to be updated // Find the specific lesion to be updated
var existingMeasurement; var existingMeasurement;
if (lesionData.id) { if (lesionData.id && lesionData.id !== 'notready') {
existingMeasurement = Measurements.findOne(lesionData.id); existingMeasurement = Measurements.findOne(lesionData.id);
} else { } else {
existingMeasurement = Measurements.findOne({ existingMeasurement = Measurements.findOne({

View File

@ -22,6 +22,7 @@
}); });
} }
// TODO = Check if we have the same function already in Cornerstone Tools
function getNearbyToolData(element, coords, toolTypes) { function getNearbyToolData(element, coords, toolTypes) {
var allTools = toolManager.getTools(); var allTools = toolManager.getTools();
var pointNearTool = false; var pointNearTool = false;
@ -77,11 +78,17 @@
var toolTypes = ["lesion", "nonTarget"]; var toolTypes = ["lesion", "nonTarget"];
var nearbyToolData = getNearbyToolData(eventData.element, eventData.currentPoints.canvas, toolTypes); var nearbyToolData = getNearbyToolData(eventData.element, eventData.currentPoints.canvas, toolTypes);
if (nearbyToolData) { if (!nearbyToolData) {
removeMeasurementTimepoint(nearbyToolData.nearbyTool, return;
nearbyToolData.nearbyToolIndex,
nearbyToolData.nearbyToolType);
} }
// TODO= Refactor this so the confirmation dialog is an
// optional settable callback in the tool's configuration
showConfirmDialog(function() {
removeMeasurementTimepoint(nearbyToolData.nearbyTool,
nearbyToolData.nearbyToolIndex,
nearbyToolData.nearbyToolType);
});
} }
} }

View File

@ -2,7 +2,7 @@
<div id="confirmDeleteDialog"> <div id="confirmDeleteDialog">
<h5>Remove Measurement?</h5> <h5>Remove Measurement?</h5>
<p>Are you sure you would like to remove this measurement?</p> <p>Are you sure you would like to remove this measurement?</p>
<button id="cancel" class="btn btn-link">Cancel</button> <button id="cancel" class="btn btn-link" tabindex="1">Cancel</button>
<button id="confirm" class="btn btn-primary">OK</button> <button id="confirm" class="btn btn-primary" tabindex="0">OK</button>
</div> </div>
</template> </template>

View File

@ -9,9 +9,10 @@ function closeHandler() {
delete Template.confirmDeleteDialog.doneCallback; delete Template.confirmDeleteDialog.doneCallback;
} }
showConfirmDialog = function(doneCallback) { showConfirmDialog = function(doneCallback, options) {
// Show the backdrop // Show the backdrop
UI.render(Template.removableBackdrop, document.body); options = options || {};
UI.renderWithData(Template.removableBackdrop, options, document.body);
// Make sure the context menu is closed when the user clicks away // Make sure the context menu is closed when the user clicks away
$(".removableBackdrop").one('mousedown touchstart', function() { $(".removableBackdrop").one('mousedown touchstart', function() {
@ -25,13 +26,17 @@ showConfirmDialog = function(doneCallback) {
} }
}; };
var keys = {
ESC: 27,
ENTER: 13
};
Template.confirmDeleteDialog.events({ Template.confirmDeleteDialog.events({
'click #cancel, click #close': function() { 'click #cancel, click #close': function() {
closeHandler(); closeHandler();
}, },
'click #confirm': function() { 'click #confirm': function() {
var doneCallback = Template.confirmDeleteDialog.doneCallback; var doneCallback = Template.confirmDeleteDialog.doneCallback;
if (doneCallback && typeof doneCallback === 'function') { if (doneCallback && typeof doneCallback === 'function') {
doneCallback(); doneCallback();
} }
@ -39,12 +44,22 @@ Template.confirmDeleteDialog.events({
closeHandler(); closeHandler();
}, },
'keypress #confirmDeleteDialog': function(e) { 'keypress #confirmDeleteDialog': function(e) {
if (e.which === keys.ESC) {
closeHandler();
}
if (this.keyPressAllowed === false) { if (this.keyPressAllowed === false) {
return; return;
} }
var doneCallback = Template.confirmDeleteDialog.doneCallback;
// If Enter is pressed, close the dialog // If Enter is pressed, close the dialog
if (e.which === 13) { if (e.which === keys.ENTER) {
if (doneCallback && typeof doneCallback === 'function') {
doneCallback();
}
closeHandler(); closeHandler();
} }
} }

View File

@ -34,15 +34,22 @@ Template.lesionTableRow.events({
}, },
'keydown .location': function(e) { 'keydown .location': function(e) {
var keyCode = e.which; var keyCode = e.which;
if (keyCode === keys.DELETE || if (keyCode === keys.DELETE ||
(keyCode === keys.D && e.ctrlKey === true)) { (keyCode === keys.D && e.ctrlKey === true)) {
var currentMeasurement = this; var currentMeasurement = this;
var options = {
keyPressAllowed: false
};
showConfirmDialog(function() { showConfirmDialog(function() {
Meteor.call("removeMeasurement", currentMeasurement._id, function(error, response) { Meteor.call("removeMeasurement", currentMeasurement._id, function(error, response) {
console.log('Removed!'); if (error) {
log.warn(error);
}
log.info(response);
}); });
}); }, options);
} }
} }
}); });