diff --git a/Packages/ohif-core/client/components/base/section/section.js b/Packages/ohif-core/client/components/base/section/section.js index 095221994..98b087d8d 100644 --- a/Packages/ohif-core/client/components/base/section/section.js +++ b/Packages/ohif-core/client/components/base/section/section.js @@ -1,8 +1,26 @@ +import { Template } from 'meteor/templating'; +import { Tracker } from 'meteor/tracker'; +import { ReactiveVar } from 'meteor/reactive-var'; import { OHIF } from 'meteor/ohif:core'; +// Get the view that contains the desired section's content and return it +const getSection = (view, sectionName) => { + let currentView = view; + while (!currentView._sectionMap || !currentView._sectionMap.get(sectionName)) { + currentView = OHIF.blaze.getParentTemplateView(currentView); + if (!currentView) return; + } + + return currentView._sectionMap.get(sectionName); +}; + Template.section.onCreated(() => { const instance = Template.instance(); + if (instance.data === 'dialogFooter') { + console.warn('>>>>instance', instance); + } + // Create the render function and section data as reactive objects instance.renderFunction = new ReactiveVar(null); instance.sectionData = new ReactiveVar(null); @@ -18,36 +36,28 @@ Template.section.onCreated(() => { // Get the content block const templateContentBlock = instance.view.templateContentBlock; + // Get the parent template view of this section block + let currentView = OHIF.blaze.getParentTemplateView(instance.view); + // Check if it is defining or printing the section content if (templateContentBlock) { - // Get the parent component of this section - const component = OHIF.blaze.getParentComponent(instance.view, '_wrapperComponent'); - - // Stop here if this section is not inside a component - if (!component) { - return; + // Define a section map for template's view if none was yet set + if (!currentView._sectionMap) { + currentView._sectionMap = new Map(); } // Define the content - component.templateInstance.sections[sectionName] = { - data: component.templateInstance.data, + currentView._sectionMap.set(sectionName, { + data: currentView._templateInstance.data, renderFunction: templateContentBlock.renderFunction - }; + }); } else { // Wait for re-rendering and print the section content Tracker.afterFlush(() => { - // Get the parent component of this section - const component = OHIF.blaze.getParentComponent(instance.view, '_wrapperComponent'); + // Get the defined section's content + const section = getSection(currentView, sectionName); - // Stop here if this section is not inside a component - if (!component) { - return; - } - - // Get the defined section content - const section = component.templateInstance.sections[sectionName]; - - // Stop here if the section content is not defined yet + // Stop here if the section content is not defined if (!section) { return; } diff --git a/Packages/ohif-core/client/components/base/template.js b/Packages/ohif-core/client/components/base/template.js index 1b56db365..20dad4c18 100644 --- a/Packages/ohif-core/client/components/base/template.js +++ b/Packages/ohif-core/client/components/base/template.js @@ -65,7 +65,6 @@ Template.baseComponent.constructView = function(contentFunc, elseFunc) { // Iterate over all wrappers and assign the component to them wrapperInstances.forEach(wrapperInstance => { - wrapperInstance.view._wrapperComponent = instance.component; wrapperInstance.component = instance.component; }); }); diff --git a/Packages/ohif-core/client/lib/blaze.js b/Packages/ohif-core/client/lib/blaze.js index ed4cd99a5..1ccd56775 100644 --- a/Packages/ohif-core/client/lib/blaze.js +++ b/Packages/ohif-core/client/lib/blaze.js @@ -40,3 +40,14 @@ OHIF.blaze.getParentComponent = (view, property='_component') => { } } }; + +// Search for the parent template of the given view +OHIF.blaze.getParentTemplateView = view => { + let currentView = view; + while (currentView) { + currentView = currentView.originalParentView || currentView.parentView; + if (currentView.name.indexOf('Template.') > -1) { + return currentView; + } + } +};