Skip to content

Commit

Permalink
Merge pull request #1238 from cfchase/valid-sub-attach
Browse files Browse the repository at this point in the history
1372002 - Set attached subscriptions to 0 if input is not valid.
  • Loading branch information
Joseph Magen committed Sep 27, 2016
2 parents 1ea2f3f + 9f0d4c6 commit eff6120
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions fusor-ember-cli/app/components/tr-subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ export default Ember.Component.extend({
}),

isQtyValid: Ember.computed('subscription.qtyAvailable', 'subscription.qtyToAttach', function() {
if ((this.get('subscription.qtyToAttach') >= 0) && (this.get('subscription.qtyAvailable') > 0)) {
return (this.get('subscription.qtyToAttach') <= this.get('subscription.qtyAvailable'));
let qtyAvailable = this.get('subscription.qtyAvailable');
let qtyToAttach = this.get('subscription.qtyToAttach');
return Ember.isPresent(qtyToAttach) && qtyToAttach >= 0 && qtyToAttach <= qtyAvailable;
}),

qtyToAttachClass: Ember.computed('isQtyValid', function() {
if (this.get('isQtyValid')) {
return 'center';
} else {
return 'center invalid-input';
}
}),
isQtyInValid: Ember.computed.not('isQtyValid'),

disableQty: Ember.computed('subscription.qtyAvailable', function() {
return (this.get('subscription.qtyAvailable') === 0);
Expand Down Expand Up @@ -76,8 +83,8 @@ export default Ember.Component.extend({

actions: {
setValidQty() {
if (this.get('isQtyInValid')) {
this.set('subscription.qtyToAttach', this.get('subscription.qtyAvailable') );
if (!this.get('isQtyValid')) {
this.set('subscription.qtyToAttach', 0 );
}
var pool = this.get('subscription');
this.sendAction('saveSubscription', pool, this.get('subscription.qtyToAttach'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
value=subscription.qtyToAttach
size=5
maxlength=5
class="center {{if isQtyInValid 'invalid-input'}}"
class=qtyToAttachClass
data-qci=attachCssId
disabled=disableQty
focus-out="setValidQty"
Expand Down

0 comments on commit eff6120

Please sign in to comment.