From dd6fc02012f1733bcb34f30350b6c54849564004 Mon Sep 17 00:00:00 2001 From: Robert Watt Date: Tue, 10 Jan 2017 11:11:59 -0600 Subject: [PATCH] Add an onUpdate callback for lineItems using oc-quantity-input You can now pass in a function from the parent controller to perform additional validation after line item quantities are updated in the API. Also made a change so that the scope.item and scope.lineitem are updated to reflect changes made in the API. --- src/app/common/directives/oc-quantity-input.js | 11 +++++++---- src/app/common/templates/quantityInput.tpl.html | 3 +-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/app/common/directives/oc-quantity-input.js b/src/app/common/directives/oc-quantity-input.js index 29d425f5..56945795 100644 --- a/src/app/common/directives/oc-quantity-input.js +++ b/src/app/common/directives/oc-quantity-input.js @@ -9,7 +9,8 @@ function OCQuantityInput(toastr, OrderCloud, $rootScope) { product: '=', lineitem: '=', label: '@', - order: '=' + order: '=', + onUpdate: '&' }, templateUrl: 'common/templates/quantityInput.tpl.html', replace: true, @@ -22,13 +23,15 @@ function OCQuantityInput(toastr, OrderCloud, $rootScope) { scope.item = scope.lineitem; scope.content = "lineitem"; scope.updateQuantity = function() { - console.log('hit'); if (scope.item.Quantity > 0) { OrderCloud.LineItems.Patch(scope.order.ID, scope.item.ID, {Quantity: scope.item.Quantity}) - .then(function () { + .then(function (data) { + data.Product = scope.lineitem.Product; + scope.item = data; + scope.lineitem = data; + if (typeof scope.onUpdate === "function") scope.onUpdate(scope.lineitem); toastr.success('Quantity Updated'); $rootScope.$broadcast('OC:UpdateOrder', scope.order.ID, 'Calculating Order Total'); - }); } } diff --git a/src/app/common/templates/quantityInput.tpl.html b/src/app/common/templates/quantityInput.tpl.html index ee6d1228..e6cefd8d 100644 --- a/src/app/common/templates/quantityInput.tpl.html +++ b/src/app/common/templates/quantityInput.tpl.html @@ -33,7 +33,7 @@ ng-min="{{item.Product.StandardPriceSchedule.MinQuantity}}" ng-max="{{item.Product.StandardPriceSchedule.MaxQuantity}}" ng-model="item.Quantity" - ng-model-options="{ debounce: 1500 }" + ng-model-options="{ debounce: 1000 }" ng-change="updateQuantity()" placeholder="Quantity">