ohif-viewer/Packages/ohif-viewerbase/client/components/viewer/toolbarSectionButton/toolbarSectionButton.js

72 lines
2.5 KiB
JavaScript

import { OHIF } from 'meteor/ohif:core';
import { Template } from 'meteor/templating';
import { Session } from 'meteor/session';
import { _ } from 'meteor/underscore';
Template.toolbarSectionButton.helpers({
activeClass() {
// TODO: Find a way to prevent the 'flash' after a click, but before this helper runs
const instance = Template.instance();
const subTools = instance.data.subTools;
const currentId = instance.data.id;
const activeId = Session.get('ToolManagerActiveTool');
const isCurrentTool = currentId === activeId;
const isSubTool = subTools && _.findWhere(subTools, { id: activeId });
// Check if the current tool or a sub tool is the active one
if (isCurrentTool || isSubTool) {
// Return the active class
return 'active';
}
},
disableButton() {
const instance = Template.instance();
return instance.disableFunction && instance.disableFunction();
}
});
Template.toolbarSectionButton.events({
'click .imageViewerTool'(event, instance) {
// Prevent the event from bubbling to parent tools
event.stopPropagation();
// Stop here if the tool is disabled
if ($(event.currentTarget).hasClass('disabled')) {
return;
}
const tool = event.currentTarget.id;
const elements = instance.$('.imageViewerViewport');
const activeTool = toolManager.getActiveTool();
if (tool === activeTool) {
const defaultTool = toolManager.getDefaultTool();
OHIF.log.info('Setting active tool to: ' + defaultTool);
toolManager.setActiveTool(defaultTool, elements);
} else {
OHIF.log.info('Setting active tool to: ' + tool);
toolManager.setActiveTool(tool, elements);
}
},
'click .imageViewerCommand'(event, instance) {
// Prevent the event from bubbling to parent tools
event.stopPropagation();
// Stop here if the tool is disabled
if ($(event.currentTarget).hasClass('disabled')) {
return;
}
const command = event.currentTarget.id;
if (!OHIF.viewer.functionList || !OHIF.viewer.functionList.hasOwnProperty(command)) {
return;
}
const activeViewport = Session.get('activeViewport');
const element = $('.imageViewerViewport').get(activeViewport);
OHIF.viewer.functionList[command](element);
}
});