From e837a3b0bdd351e41262bd814327b4db0cb0405e Mon Sep 17 00:00:00 2001 From: John Kleinschmidt Date: Wed, 28 Oct 2015 16:42:12 -0400 Subject: [PATCH] Fixed inventory location pickers for medication fulfillment/dispense --- app/components/inventory-location-picker.js | 48 +++++++++++---------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/app/components/inventory-location-picker.js b/app/components/inventory-location-picker.js index a5b085c9e2..e4ca5e0805 100644 --- a/app/components/inventory-location-picker.js +++ b/app/components/inventory-location-picker.js @@ -1,16 +1,16 @@ import Ember from 'ember'; import SelectValues from 'hospitalrun/utils/select-values'; export default Ember.Component.extend({ + calculatedLocationPickers: null, doingSetup: false, label: null, - locationPickers: null, locationList: null, quantityRequested: null, locationChange: function() { var doingSetup = this.get('doingSetup'), locationList = this.get('locationList'), - locationPickers = this.get('locationPickers'), + locationPickers = this.get('calculatedLocationPickers'), quantityRequested = this.get('quantityRequested'), quantitySatisfiedIdx = -1, selectedLocations = []; @@ -31,7 +31,7 @@ export default Ember.Component.extend({ if (quantitySatisfiedIdx > -1) { if (locationPickers.get('length') > (quantitySatisfiedIdx + 1)) { locationPickers = locationPickers.slice(0, quantitySatisfiedIdx + 1); - this.set('locationPickers', locationPickers); + this.set('calculatedLocationPickers', locationPickers); } } else { locationPickers.addObject(Ember.Object.create()); @@ -46,24 +46,6 @@ export default Ember.Component.extend({ _setup: function() { Ember.Binding.from('selectedLocations').to('componentSelectedLocations').connect(this); - var locationList = this.get('locationList'), - locationPickers = [], - quantityRequested = this.get('quantityRequested'); - if (Ember.isEmpty(locationList) || Ember.isEmpty(quantityRequested)) { - // We need both a locationList and a quantityRequested - return; - } - this.set('doingSetup', true); - locationList.reduce(function(previousValue, location) { - if (previousValue < quantityRequested) { - locationPickers.addObject(Ember.Object.create()); - } - return (previousValue + location.get('quantity')); - }, 0); - this._setupLocationPickers(locationPickers, locationList, true); - this.set('locationPickers', locationPickers); - this.locationChange(); - this.set('doingSetup', false); }.on('init'), _setupLocationPickers: function(locationPickers, locationList, setInitialLocation) { @@ -82,5 +64,27 @@ export default Ember.Component.extend({ if (!Ember.isEmpty(firstPicker)) { firstPicker.set('label', this.get('label')); } - } + this.set('calculatedLocationPickers', locationPickers); + }, + + locationPickers: function() { + var locationList = this.get('locationList'), + locationPickers = [], + quantityRequested = this.get('quantityRequested'); + if (Ember.isEmpty(locationList) || Ember.isEmpty(quantityRequested)) { + // We need both a locationList and a quantityRequested + return; + } + this.set('doingSetup', true); + locationList.reduce(function(previousValue, location) { + if (previousValue < quantityRequested) { + locationPickers.addObject(Ember.Object.create()); + } + return (previousValue + location.get('quantity')); + }, 0); + this._setupLocationPickers(locationPickers, locationList, true); + this.locationChange(); + this.set('doingSetup', false); + return this.get('calculatedLocationPickers'); + }.property('calculatedLocationPickers', 'locationList', 'quantityRequested') });