feat(subtools) Changing toolBarSection to accept custom template subtools. I.e. coder could pass his own template as part of subtools for specific tool button (#211)

This commit is contained in:
ladeirarodolfo 2018-06-25 07:08:38 -03:00 committed by Erik Ziegler
parent 9f73ae0153
commit e55e2ad05a
2 changed files with 22 additions and 9 deletions

View File

@ -3,7 +3,7 @@
{{>UI.dynamic template=this.buttonTemplateName data=this}} {{>UI.dynamic template=this.buttonTemplateName data=this}}
{{else}} {{else}}
<div id="{{this.id}}" tabindex="1" <div id="{{this.id}}" tabindex="1"
class="toolbarSectionButton rp-x-1 {{this.classes}} {{activeClass}} {{#if or this.disabled (disableButton)}}disabled{{/if}} {{#if this.subTools}}expandable{{/if}}" class="toolbarSectionButton rp-x-1 {{this.classes}} {{activeClass}} {{#if or this.disabled (disableButton)}}disabled{{/if}} {{#if hasSubTools}}expandable{{/if}}"
title="{{this.tooltipTitle}}"> title="{{this.tooltipTitle}}">
<div class="svgContainer"> <div class="svgContainer">
{{#let svg=svgLink icon=iconClasses}} {{#let svg=svgLink icon=iconClasses}}
@ -18,18 +18,24 @@
</div> </div>
<div class="buttonLabel"> <div class="buttonLabel">
<span>{{this.title}}</span> <span>{{this.title}}</span>
{{#if this.subTools}} {{#if hasSubTools}}
<i class="fa fa-caret-down expanded-status" aria-hidden="true"></i> <i class="fa fa-caret-down expanded-status" aria-hidden="true"></i>
{{/if}} {{/if}}
</div> </div>
{{#if this.subTools}} {{#if hasSubTools}}
<div class="toolbarSectionDrawerContainer"> <div class="toolbarSectionDrawerContainer">
<div class="toolbarSectionDrawer"> <div class="toolbarSectionDrawer">
{{#each subTool in this.subTools}} {{#if this.subToolsTemplateName}}
{{>toolbarSectionButton subTool}} {{>UI.dynamic template=this.subToolsTemplateName data=this}}
{{/each}} {{else}}
{{#if this.subTools}}
{{#each subTool in this.subTools}}
{{>toolbarSectionButton subTool}}
{{/each}}
{{/if}}
{{/if}}
</div> </div>
</div> </div>
{{/if}} {{/if}}
</div> </div>
{{/if}} {{/if}}

View File

@ -106,6 +106,10 @@ Template.toolbarSectionButton.helpers({
const isCommandDisabled = OHIF.commands.isDisabled(instance.data.id); const isCommandDisabled = OHIF.commands.isDisabled(instance.data.id);
const isFunctionDisabled = instance.data.disableFunction && instance.data.disableFunction(); const isFunctionDisabled = instance.data.disableFunction && instance.data.disableFunction();
return isCommandDisabled || isFunctionDisabled; return isCommandDisabled || isFunctionDisabled;
},
hasSubTools() {
return this.subTools || this.subToolsTemplateName;
} }
}); });
@ -113,9 +117,12 @@ Template.toolbarSectionButton.events({
'click .toolbarSectionButton:not(.expandable)'(event, instance) { 'click .toolbarSectionButton:not(.expandable)'(event, instance) {
// Prevent the event from bubbling to parent tools // Prevent the event from bubbling to parent tools
event.stopPropagation(); event.stopPropagation();
const $currentTarget = $(event.currentTarget);
// Stop here if the button is disabled // Stop here if the button is disabled or customAction
if ($(event.currentTarget).hasClass('disabled')) return; if ($currentTarget.hasClass('disabled') || $currentTarget.hasClass('customAction')) {
return;
}
// Run the command attached to the button // Run the command attached to the button
OHIF.commands.run(instance.data.id); OHIF.commands.run(instance.data.id);