diff --git a/Packages/ohif-core/client/components/base/mixins/selectTree.js b/Packages/ohif-core/client/components/base/mixins/selectTree.js index 55011d574..9384c14c1 100644 --- a/Packages/ohif-core/client/components/base/mixins/selectTree.js +++ b/Packages/ohif-core/client/components/base/mixins/selectTree.js @@ -42,6 +42,23 @@ OHIF.mixins.selectTree = new OHIF.Mixin({ // Change the current node instance.data.currentNode.set(node); }; + + // Return plain data for all the leaves inside current node + component.getLeaves = () => { + const recursiveSeek = (items, result=[]) => { + _.each(items, item => { + if (item.items) { + recursiveSeek(item.items, result); + } else { + result.push(item); + } + }); + return result; + }; + + return recursiveSeek(instance.data.items); + }; + } } }); diff --git a/Packages/ohif-core/client/components/bootstrap/index.js b/Packages/ohif-core/client/components/bootstrap/index.js index 48677b019..6bc4a245e 100644 --- a/Packages/ohif-core/client/components/bootstrap/index.js +++ b/Packages/ohif-core/client/components/bootstrap/index.js @@ -7,3 +7,5 @@ import './input/select.html'; import './input/text.html'; import './input/selectTree.html'; import './input/selectTree.js'; +import './input/selectTreeCommon.html'; +import './input/selectTreeCommon.js'; diff --git a/Packages/ohif-core/client/components/bootstrap/input/selectTree.html b/Packages/ohif-core/client/components/bootstrap/input/selectTree.html index d04514164..2789a7c02 100644 --- a/Packages/ohif-core/client/components/bootstrap/input/selectTree.html +++ b/Packages/ohif-core/client/components/bootstrap/input/selectTree.html @@ -24,6 +24,7 @@
{{#each item in (reactive this.items)}} {{>inputRadio + id=(concat this.storageKey '_' (encodeId item.value)) class=this.radioClass name=this.key value=item.value @@ -43,20 +44,12 @@
{{/let}} - {{#unless this.root}} - {{>selectTreeCommon this}} - {{/unless}} + {{#if (and (not this.root) this.storageKey)}} + {{>selectTreeCommon (clone this component=this.component)}} + {{/if}} {{/group}} - - diff --git a/Packages/ohif-core/client/helpers/string.js b/Packages/ohif-core/client/helpers/string.js index 88cf9af74..57476ef20 100644 --- a/Packages/ohif-core/client/helpers/string.js +++ b/Packages/ohif-core/client/helpers/string.js @@ -1,3 +1,4 @@ +import { OHIF } from 'meteor/ohif:core'; import { _ } from 'meteor/underscore'; import { Template } from 'meteor/templating'; @@ -14,3 +15,6 @@ Template.registerHelper('concat', (...args) => { }); return result; }); + +// Encode any string into a safe format for HTML id attribute +Template.registerHelper('encodeId', string => OHIF.string.encodeId(string)); diff --git a/Packages/ohif-core/client/lib/string.js b/Packages/ohif-core/client/lib/string.js index 412216b87..6ffdda68c 100644 --- a/Packages/ohif-core/client/lib/string.js +++ b/Packages/ohif-core/client/lib/string.js @@ -31,3 +31,17 @@ OHIF.string.search = (object, query, property=null, result=[]) => { // Return the found items return result; }; + +// Encode any string into a safe format for HTML id attribute +OHIF.string.encodeId = string => { + // Return an underscore if the given string is empty or if it's not a string + if (string === '' || typeof string !== 'string') { + return '_'; + } + + // Create a converter to replace non accepted chars + const converter = match => '_' + match[0].charCodeAt(0).toString(16) + '_'; + + // Encode the given string and return it + return string.replace(/[^a-zA-Z0-9-]/g, converter); +}; diff --git a/Packages/ohif-core/client/lib/user.js b/Packages/ohif-core/client/lib/user.js index fb0f00e36..bc2cb81d8 100644 --- a/Packages/ohif-core/client/lib/user.js +++ b/Packages/ohif-core/client/lib/user.js @@ -14,8 +14,11 @@ OHIF.user.getData = key => { // Check if there is an user logged in OHIF.user.validate(); + // Get user profile data + const profile = Meteor.user().profile; + // Get the user persistent data - const data = Meteor.user().profile.persistent; + const data = profile && profile.persistent; if (data) { return data[key];