From a2c8d0627e660896a72e741fa92936352f2a31cf Mon Sep 17 00:00:00 2001 From: Bruno Alves de Faria Date: Mon, 15 Aug 2016 16:35:50 -0300 Subject: [PATCH] LT-275: Fixing common section selection for inner levels --- .../components/bootstrap/input/selectTree.js | 23 ++++++++++++++++++- Packages/ohif-core/client/lib/string.js | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Packages/ohif-core/client/components/bootstrap/input/selectTree.js b/Packages/ohif-core/client/components/bootstrap/input/selectTree.js index 70faf99cd..e5364ffb4 100644 --- a/Packages/ohif-core/client/components/bootstrap/input/selectTree.js +++ b/Packages/ohif-core/client/components/bootstrap/input/selectTree.js @@ -140,7 +140,7 @@ Template.selectTree.events({ 'change .select-tree:first>.tree-content>.tree-options>.tree-inputs>label>input'(event, instance) { const component = instance.component; - const $target = $(event.target); + const $target = $(event.currentTarget); const $label = $target.closest('label'); const eventComponent = $target.data('component'); const rootComponent = instance.data.root || component; @@ -229,6 +229,27 @@ Template.selectTree.events({ currentInstance = currentInstance.component.parent.templateInstance; } } + }, + + 'click .select-tree-common label'(event, instance) { + // Get the clicked label + const $target = $(event.currentTarget); + + // Build the input selector based on the label target + const inputSelector = '#' + $target.attr('for'); + + // Check if the input is not rendered + if (!$(inputSelector).length) { + // Change the search terms with the clicked label string + + instance.$('.tree-search input').val($target.text()).trigger('input'); + // Wait for options rerendering + + Tracker.afterFlush(() => { + // Wait for components initialization + Meteor.defer(() => $(inputSelector).click()); + }); + } } }); diff --git a/Packages/ohif-core/client/lib/string.js b/Packages/ohif-core/client/lib/string.js index f6cfcf838..d23734407 100644 --- a/Packages/ohif-core/client/lib/string.js +++ b/Packages/ohif-core/client/lib/string.js @@ -7,7 +7,7 @@ OHIF.string = {}; // Search for some string inside any object or array OHIF.string.search = (object, query, property=null, result=[]) => { // Create the search pattern - const pattern = new RegExp($.trim(query).replace(/\s/gi, '|'), 'i'); + const pattern = new RegExp($.trim(query), 'i'); _.each(object, item => { // Stop here if item is empty