Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Fixed inventory location pickers for medication fulfillment/dispense
Browse files Browse the repository at this point in the history
  • Loading branch information
jkleinsc committed Oct 28, 2015
1 parent 0162a3a commit e837a3b
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions app/components/inventory-location-picker.js
Original file line number Diff line number Diff line change
@@ -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 = [];
Expand All @@ -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());
Expand All @@ -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) {
Expand All @@ -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')
});

0 comments on commit e837a3b

Please sign in to comment.