diff --git a/src/app/addPromotion/addPromotion.js b/src/app/addPromotion/addPromotion.js index 0f751e38..1afffa8c 100644 --- a/src/app/addPromotion/addPromotion.js +++ b/src/app/addPromotion/addPromotion.js @@ -12,6 +12,7 @@ function AddPromotionComponentCtrl($exceptionHandler, $rootScope, OrderCloud, to OrderCloud.Orders.AddPromotion(orderID, promoCode) .then(function(promo) { $rootScope.$broadcast('OC:UpdatePromotions', orderID); + $rootScope.$broadcast('OC:UpdateOrder', orderID); toastr.success('Promo code '+ promo.Code + ' added!', 'Success'); }) .catch(function(err) { diff --git a/src/app/app.controller.js b/src/app/app.controller.js index 33b50842..d53155a6 100644 --- a/src/app/app.controller.js +++ b/src/app/app.controller.js @@ -28,10 +28,7 @@ function AppController($q, $rootScope, $state, $ocMedia, toastr, LoginService, a $rootScope.$on('$stateChangeStart', function(e, toState) { cleanLoadingIndicators(); var defer = $q.defer(); - //defer.delay = 200; - defer.wrapperClass = 'indicator-container'; - (toState.data && toState.data.loadingMessage) ? defer.message = toState.data.loadingMessage : defer.message = null; - defer.templateUrl = 'common/templates/view.loading.tpl.html'; + if (toState.data) defer.message = toState.data.loadingMessage; vm.stateLoading = defer; }); diff --git a/src/app/base/base.js b/src/app/base/base.js index 8142c2b8..5e752877 100644 --- a/src/app/base/base.js +++ b/src/app/base/base.js @@ -62,8 +62,11 @@ function BaseController($rootScope, $state, ProductSearch, CurrentUser, CurrentO }); }; - $rootScope.$on('OC:UpdateOrder', function(event, OrderID) { - OrderCloud.Orders.Get(OrderID) + $rootScope.$on('OC:UpdateOrder', function(event, OrderID, message) { + vm.orderLoading = { + message: message + }; + vm.orderLoading.promise = OrderCloud.Orders.Get(OrderID) .then(function(data) { vm.currentOrder = data; }); diff --git a/src/app/cart/cart.js b/src/app/cart/cart.js index 2fc4313b..3d87cb49 100644 --- a/src/app/cart/cart.js +++ b/src/app/cart/cart.js @@ -42,22 +42,25 @@ function CartConfig($stateProvider) { }); } -function CartController($rootScope, $state, OrderCloud, ocLineItems, LineItemsList, CurrentPromotions, ocConfirm) { +function CartController($rootScope, $state, toastr, OrderCloud, LineItemsList, CurrentPromotions, ocConfirm) { var vm = this; vm.lineItems = LineItemsList; vm.promotions = CurrentPromotions.Meta ? CurrentPromotions.Items : CurrentPromotions; - - vm.updateQuantity = function(order, lineItem) { - ocLineItems.UpdateQuantity(order, lineItem); - }; - - vm.removeItem = function(order, lineItem) { - ocLineItems.RemoveItem(order, lineItem); + vm.removeItem = function(order, scope) { + vm.lineLoading = []; + vm.lineLoading[scope.$index] = OrderCloud.LineItems.Delete(order.ID, scope.lineItem.ID) + .then(function () { + $rootScope.$broadcast('OC:UpdateOrder', order.ID); + vm.lineItems.Items.splice(scope.$index, 1); + toastr.success('Line Item Removed'); + }); }; + //TODO: missing unit tests vm.removePromotion = function(order, scope) { OrderCloud.Orders.RemovePromotion(order.ID, scope.promotion.Code) .then(function() { + $rootScope.$broadcast('OC:UpdateOrder', order.ID); vm.promotions.splice(scope.$index, 1); }); }; @@ -72,16 +75,7 @@ function CartController($rootScope, $state, OrderCloud, ocLineItems, LineItemsLi }); }; - $rootScope.$on('OC:UpdateLineItem', function(event,Order) { - OrderCloud.LineItems.List(Order.ID) - .then(function(data) { - ocLineItems.GetProductInfo(data.Items) - .then(function() { - vm.lineItems = data; - }); - }); - }); - + //TODO: missing unit tests $rootScope.$on('OC:UpdatePromotions', function(event, orderid) { OrderCloud.Orders.ListPromotions(orderid) .then(function(data) { @@ -90,7 +84,6 @@ function CartController($rootScope, $state, OrderCloud, ocLineItems, LineItemsLi } else { vm.promotions = data; } - $rootScope.$broadcast('OC:UpdateOrder', orderid); }); }); } diff --git a/src/app/cart/templates/cart.tpl.html b/src/app/cart/templates/cart.tpl.html index 9b6ae66e..f35a10b4 100644 --- a/src/app/cart/templates/cart.tpl.html +++ b/src/app/cart/templates/cart.tpl.html @@ -11,7 +11,7 @@

You do not have any items in your cart.

- +
@@ -94,7 +94,7 @@

{{lineItem.LineTotal | currency}}

- +
diff --git a/src/app/cart/test/cart.spec.js b/src/app/cart/test/cart.spec.js index ba53fcb3..cd29583f 100644 --- a/src/app/cart/test/cart.spec.js +++ b/src/app/cart/test/cart.spec.js @@ -3,9 +3,9 @@ describe('Component: Cart', function() { q, oc, currentOrder, - currentPromotions, - lineItemHelpers, + rootScope, lineItemsList, + _ocLineItems, fakeOrder, user ; @@ -14,12 +14,13 @@ describe('Component: Cart', function() { beforeEach(module(function($provide) { $provide.value('CurrentOrder', {ID: "MockOrderID3456"}); })); - beforeEach(inject(function($rootScope, $q, OrderCloud, CurrentOrder, ocLineItems) { + beforeEach(inject(function($rootScope, $q, OrderCloud, ocLineItems, CurrentOrder) { scope = $rootScope.$new(); q = $q; oc = OrderCloud; + _ocLineItems = ocLineItems; currentOrder = CurrentOrder; - lineItemHelpers = ocLineItems; + rootScope = $rootScope; fakeOrder = { ID: "TestOrder123456789", Type: "Standard", @@ -33,15 +34,15 @@ describe('Component: Cart', function() { ShippingCost: null, TaxCost: null }; - lineItemsList = { - "Items" : [{}, {}], + lineItemsList = { + "Items" : [{ID:"LI1"}, {ID:"LI2"}], "Meta" : { "Page": 1, "PageSize": 20, "TotalCount":29, "TotalPages": 3, "ItemRange" : [1,2] - } + } }; user = { ID: "TestUser132456789", @@ -54,14 +55,14 @@ describe('Component: Cart', function() { }; })); - describe('Configuration: CartConfig', function() { + describe('State: Cart', function() { var state; beforeEach(inject(function($state) { state = $state.get('cart'); var defer = q.defer(); defer.resolve(lineItemsList); spyOn(oc.LineItems,'List').and.returnValue(defer.promise); - spyOn(lineItemHelpers,'GetProductInfo').and.returnValue(defer.promise); + spyOn(_ocLineItems,'GetProductInfo').and.returnValue(defer.promise); })); it('should call LineItems.List',inject(function($injector){ @@ -71,7 +72,7 @@ describe('Component: Cart', function() { it('should call LineItemHelper', inject(function($injector){ $injector.invoke(state.resolve.LineItemsList); scope.$digest(); - expect(lineItemHelpers.GetProductInfo).toHaveBeenCalled(); + expect(_ocLineItems.GetProductInfo).toHaveBeenCalled(); })); }); @@ -82,47 +83,45 @@ describe('Component: Cart', function() { cartController = $controller('CartCtrl', { $scope: scope, CurrentPromotions: [], - LineItemsList: lineItemsList, - ocLineItems: lineItemHelpers + LineItemsList: lineItemsList }); confirm = ocConfirm; var defer = q.defer(); defer.resolve(lineItemsList); - spyOn(lineItemHelpers,'UpdateQuantity').and.returnValue(defer.promise); - spyOn(confirm,'Confirm').and.returnValue(defer.promise); - spyOn(oc.Orders, 'Delete').and.returnValue(defer.promise); - spyOn(oc.Orders,'Get').and.returnValue(defer.promise); - spyOn(oc.LineItems, 'List').and.returnValue(defer.promise); - spyOn(lineItemHelpers,'GetProductInfo').and.returnValue(defer.promise); + spyOn(rootScope, '$broadcast'); })); - describe('updateQuantity',function(){ - it('should call ocLineItems UpdateQuantity Method', function(){ - cartController.updateQuantity(currentOrder,lineItemsList.Items[0]); - expect(lineItemHelpers.UpdateQuantity).toHaveBeenCalledWith(currentOrder,lineItemsList.Items[0]); - }) ; - }); - describe('CancelOrder',function() { - it('should call OrderCloud Confirm modal prompt', function() { - cartController.cancelOrder(); - expect(confirm.Confirm).toHaveBeenCalled(); - }); - it('should call OC Orders Delete Method', function(){ - cartController.cancelOrder(fakeOrder); - scope.$digest(); - expect(oc.Orders.Delete).toHaveBeenCalledWith(fakeOrder.ID); - }); + describe('removeItem()', function() { + beforeEach(function() { + var df = q.defer(); + df.resolve(); + spyOn(oc.LineItems, 'Delete').and.returnValue(df.promise); + }); + it ('should delete the line item', function() { + cartController.removeItem(fakeOrder, {$index:0, lineItem: lineItemsList.Items[0]}); + expect(oc.LineItems.Delete).toHaveBeenCalledWith(fakeOrder.ID, lineItemsList.Items[0].ID); + scope.$digest(); + expect(rootScope.$broadcast).toHaveBeenCalledWith('OC:UpdateOrder', fakeOrder.ID); + expect(cartController.lineItems.Items).toEqual([{ID:"LI2"}]); + }) }); - describe('OC:UpdateLineItem',function() { - it('should call LineItems List Method', inject(function($rootScope) { - $rootScope.$broadcast('OC:UpdateLineItem' ,fakeOrder); - expect(oc.LineItems.List).toHaveBeenCalledWith(fakeOrder.ID); - })); - it('should call ocLineItems GetProductInfo Method', inject(function($rootScope) { - $rootScope.$broadcast('OC:UpdateLineItem' ,fakeOrder); + + describe('CancelOrder',function() { + beforeEach(function() { + var df = q.defer(); + df.resolve(); + spyOn(confirm,'Confirm').and.returnValue(df.promise); + spyOn(oc.Orders, 'Delete').and.returnValue(df.promise); + }); + it('should call OrderCloud Confirm modal prompt', function() { + cartController.cancelOrder(); + expect(confirm.Confirm).toHaveBeenCalled(); + }); + it('should call OC Orders Delete Method', function(){ + cartController.cancelOrder(fakeOrder); scope.$digest(); - expect(oc.LineItems.List).toHaveBeenCalledWith(fakeOrder.ID); - })) + expect(oc.Orders.Delete).toHaveBeenCalledWith(fakeOrder.ID); + }); }); }); }); \ No newline at end of file diff --git a/src/app/checkout/payment/directives/payment.directives.js b/src/app/checkout/payment/directives/payment.directives.js index 9a7ce719..aac75bcf 100644 --- a/src/app/checkout/payment/directives/payment.directives.js +++ b/src/app/checkout/payment/directives/payment.directives.js @@ -134,12 +134,7 @@ function PaymentSpendingAccountController($scope, $rootScope, toastr, OrderCloud $scope.updatePayment = function(scope) { var oldSelection = angular.copy($scope.payment.SpendingAccountID); $scope.payment.SpendingAccountID = scope.spendingAccount.ID; - - $scope.updatingSpendingAccountPayment = { - templateUrl: 'common/templates/view.loading.tpl.html', - message:null - }; - $scope.updatingSpendingAccountPayment.promise = OrderCloud.Payments.Update($scope.order.ID, $scope.payment.ID, $scope.payment) + $scope.updatingSpendingAccountPayment = OrderCloud.Payments.Update($scope.order.ID, $scope.payment.ID, $scope.payment) .then(function() { $scope.showPaymentOptions = false; toastr.success('Using ' + scope.spendingAccount.Name,'Spending Account Payment'); @@ -225,11 +220,7 @@ function PaymentCreditCardController($scope, $rootScope, toastr, $filter, OrderC $scope.updatePayment = function(scope) { var oldSelection = angular.copy($scope.payment.CreditCardID); $scope.payment.CreditCardID = scope.creditCard.ID; - $scope.updatingCreditCardPayment = { - templateUrl: 'common/templates/view.loading.tpl.html', - message:null - }; - $scope.updatingCreditCardPayment.promise = OrderCloud.Payments.Update($scope.order.ID, $scope.payment.ID, $scope.payment) + $scope.updatingCreditCardPayment = OrderCloud.Payments.Update($scope.order.ID, $scope.payment.ID, $scope.payment) .then(function() { $scope.showPaymentOptions = false; toastr.success('Using ' + $filter('humanize')(scope.creditCard.CardType) + ' ending in ' + scope.creditCard.PartialAccountNumber,'Credit Card Payment'); diff --git a/src/app/checkout/shipping/templates/checkout.shipping.tpl.html b/src/app/checkout/shipping/templates/checkout.shipping.tpl.html index 2a324b78..d79915a5 100644 --- a/src/app/checkout/shipping/templates/checkout.shipping.tpl.html +++ b/src/app/checkout/shipping/templates/checkout.shipping.tpl.html @@ -1,7 +1,7 @@
-
+
New Address

Delivery Address

diff --git a/src/app/common/config/angular-busy.config.js b/src/app/common/config/angular-busy.config.js new file mode 100644 index 00000000..a26a380c --- /dev/null +++ b/src/app/common/config/angular-busy.config.js @@ -0,0 +1,9 @@ +angular.module('orderCloud') + .config(function(angularBusyDefaults) { + angular.extend(angularBusyDefaults, { + templateUrl:'common/templates/view.loading.tpl.html', + message:null, + wrapperClass: 'indicator-container' + }) + }) +; \ No newline at end of file diff --git a/src/app/productDetail/quantityInput/quantityInput.js b/src/app/common/directives/oc-quantity-input.js similarity index 50% rename from src/app/productDetail/quantityInput/quantityInput.js rename to src/app/common/directives/oc-quantity-input.js index 53e79e92..29d425f5 100644 --- a/src/app/productDetail/quantityInput/quantityInput.js +++ b/src/app/common/directives/oc-quantity-input.js @@ -3,16 +3,15 @@ angular.module('orderCloud') ; -function OCQuantityInput(toastr) { +function OCQuantityInput(toastr, OrderCloud, $rootScope) { return { scope: { product: '=', lineitem: '=', label: '@', - order: '=', - updateFn: '=' + order: '=' }, - templateUrl: 'productDetail/quantityInput/templates/quantityInput.tpl.html', + templateUrl: 'common/templates/quantityInput.tpl.html', replace: true, link: function (scope) { if (scope.product){ @@ -21,7 +20,18 @@ function OCQuantityInput(toastr) { } else if(scope.lineitem){ scope.item = scope.lineitem; - scope.content = "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 () { + toastr.success('Quantity Updated'); + $rootScope.$broadcast('OC:UpdateOrder', scope.order.ID, 'Calculating Order Total'); + + }); + } + } } else{ toastr.error('Please input either a product or lineitem attribute in the directive','Error'); diff --git a/src/app/common/services/oc-lineitems.js b/src/app/common/services/oc-lineitems.js index 73a32b5e..a4ea15f3 100644 --- a/src/app/common/services/oc-lineitems.js +++ b/src/app/common/services/oc-lineitems.js @@ -6,8 +6,6 @@ function LineItemFactory($rootScope, $q, $uibModal, OrderCloud) { return { SpecConvert: _specConvert, AddItem: _addItem, - RemoveItem: _removeItem, - UpdateQuantity: _updateQuantity, GetProductInfo: _getProductInfo, CustomShipping: _customShipping, UpdateShipping: _updateShipping, @@ -36,6 +34,7 @@ function LineItemFactory($rootScope, $q, $uibModal, OrderCloud) { }); return results; } + function _addItem(order, product){ var deferred = $q.defer(); @@ -65,24 +64,6 @@ function LineItemFactory($rootScope, $q, $uibModal, OrderCloud) { return deferred.promise; } - function _removeItem(Order, LineItem) { - OrderCloud.LineItems.Delete(Order.ID, LineItem.ID) - .then(function () { - $rootScope.$broadcast('OC:UpdateOrder', Order.ID); - $rootScope.$broadcast('OC:UpdateLineItem',Order); - }); - } - - function _updateQuantity(Order, LineItem) { - if (LineItem.Quantity > 0) { - OrderCloud.LineItems.Patch(Order.ID, LineItem.ID, {Quantity: LineItem.Quantity}) - .then(function () { - $rootScope.$broadcast('OC:UpdateOrder', Order.ID); - $rootScope.$broadcast('OC:UpdateLineItem',Order); - }); - } - } - function _getProductInfo(LineItems) { var li = LineItems.Items || LineItems; var productIDs = _.uniq(_.pluck(li, 'ProductID')); diff --git a/src/app/productDetail/quantityInput/templates/quantityInput.tpl.html b/src/app/common/templates/quantityInput.tpl.html similarity index 95% rename from src/app/productDetail/quantityInput/templates/quantityInput.tpl.html rename to src/app/common/templates/quantityInput.tpl.html index 49dab0d7..63883d4e 100644 --- a/src/app/productDetail/quantityInput/templates/quantityInput.tpl.html +++ b/src/app/common/templates/quantityInput.tpl.html @@ -32,7 +32,7 @@ ng-max="{{item.Product.StandardPriceSchedule.MaxQuantity}}" ng-model="item.Quantity" ng-model-options="{ debounce: 1500 }" - ng-change="updateFn(order, item)" + ng-change="updateQuantity()" placeholder="Quantity">
diff --git a/src/app/login/login.js b/src/app/login/login.js index 475549f7..30f62bd3 100644 --- a/src/app/login/login.js +++ b/src/app/login/login.js @@ -125,11 +125,7 @@ function LoginController($state, $stateParams, $exceptionHandler, OrderCloud, Lo $('#Password').blur(); $('#Remember').blur(); $('#submit_login').blur(); - vm.loading = { - templateUrl: 'common/templates/view.loading.tpl.html', - message: null - }; - vm.loading.promise = OrderCloud.Auth.GetToken(vm.credentials) + vm.loading = OrderCloud.Auth.GetToken(vm.credentials) .then(function(data) { vm.rememberStatus ? OrderCloud.Refresh.SetToken(data['refresh_token']) : angular.noop(); OrderCloud.BuyerID.Set(buyerid); diff --git a/src/app/myAddresses/myAddresses.js b/src/app/myAddresses/myAddresses.js index db46e7a9..4a1b6dbb 100644 --- a/src/app/myAddresses/myAddresses.js +++ b/src/app/myAddresses/myAddresses.js @@ -45,11 +45,7 @@ function MyAddressesController(toastr, OrderCloud, ocConfirm, MyAddressesModal, vm.loading = []; ocConfirm.Confirm("Are you sure you want to delete this address?") .then(function() { - vm.loading[scope.$index] = { - templateUrl:'common/templates/view.loading.tpl.html', - message:null - }; - vm.loading[scope.$index].promise = OrderCloud.Me.DeleteAddress(scope.address.ID) + vm.loading[scope.$index] = OrderCloud.Me.DeleteAddress(scope.address.ID) .then(function() { toastr.success('Address Deleted', 'Success'); vm.list.Items.splice(scope.$index, 1); diff --git a/src/app/myAddresses/myAddresses.modalFactory.js b/src/app/myAddresses/myAddresses.modalFactory.js index 642a3a39..d782f032 100644 --- a/src/app/myAddresses/myAddresses.modalFactory.js +++ b/src/app/myAddresses/myAddresses.modalFactory.js @@ -53,7 +53,6 @@ function CreateAddressModalController($q, $exceptionHandler, $uibModalInstance, vm.submit = function() { vm.loading = { - templateUrl:'common/templates/view.loading.tpl.html', message:'Creating Address' }; vm.loading.promise = OrderCloud.Me.CreateAddress(vm.address) @@ -83,7 +82,6 @@ function EditAddressModalController($exceptionHandler, $uibModalInstance, OrderC vm.submit = function() { vm.loading = { - templateUrl:'common/templates/view.loading.tpl.html', message:'Saving Address' }; vm.loading.promise = OrderCloud.Me.UpdateAddress(vm.addressID, vm.address) diff --git a/src/app/myPayments/myPaymentCreditCard.modalFactory.js b/src/app/myPayments/myPaymentCreditCard.modalFactory.js index 0ed99a62..de77d5d9 100644 --- a/src/app/myPayments/myPaymentCreditCard.modalFactory.js +++ b/src/app/myPayments/myPaymentCreditCard.modalFactory.js @@ -45,14 +45,11 @@ function CreateCreditCardModalController($q, $exceptionHandler, $uibModalInstanc }; vm.submit = function() { - //loading indicator promise - var df = $q.defer(); - df.templateUrl = 'common/templates/view.loading.tpl.html'; - df.message = 'Creating Credit Card'; - vm.loading = df; - ocAuthNet.CreateCreditCard(vm.creditCard) + vm.loading = { + message: 'Creating Credit Card' + }; + vm.loading.promise = ocAuthNet.CreateCreditCard(vm.creditCard) .then(function(data){ - df.resolve(); $uibModalInstance.close(data.ResponseBody); }) .catch(function(error){ @@ -75,14 +72,11 @@ function EditCreditCardModalController($q, $exceptionHandler, $uibModalInstance, vm.submit = function() { //loading indicator promise - var df = $q.defer(); - df.templateUrl = 'common/templates/view.loading.tpl.html'; - df.message = 'Editing Credit Card'; - vm.loading = df; - - ocAuthNet.UpdateCreditCard(vm.creditCard) + vm.loading = { + message: 'Editing Credit Card' + }; + vm.loading.promise = ocAuthNet.UpdateCreditCard(vm.creditCard) .then(function(data){ - df.resolve(); $uibModalInstance.close(data.ResponseBody); }) .catch(function(error){ diff --git a/src/app/myPayments/myPayments.js b/src/app/myPayments/myPayments.js index bb68098e..4a7568ae 100644 --- a/src/app/myPayments/myPayments.js +++ b/src/app/myPayments/myPayments.js @@ -54,11 +54,7 @@ function MyPaymentsController($q, $state, toastr, $exceptionHandler, ocConfirm, vm.loading = []; ocConfirm.Confirm("Are you sure you want to delete this Credit Card?") .then(function(){ - vm.loading[scope.$index] = { - templateUrl: 'common/templates/view.loading.tpl.html', - message: 'Deleting Credit Card' - }; - vm.loading[scope.$index].promise = ocAuthNet.DeleteCreditCard(scope.creditCard) + vm.loading[scope.$index] = ocAuthNet.DeleteCreditCard(scope.creditCard) .then(function(){ toastr.success('Credit Card Deleted', 'Success'); vm.personalCreditCards.Items.splice(scope.$index, 1); diff --git a/src/app/styles/components/_loading-indicators.less b/src/app/styles/components/_loading-indicators.less index 1ee003d6..859ab66d 100644 --- a/src/app/styles/components/_loading-indicators.less +++ b/src/app/styles/components/_loading-indicators.less @@ -6,6 +6,7 @@ position:absolute; left:0; right:0; top:0; bottom:0; z-index:1001; + transform:none !important; &.ng-hide-add, &.ng-hide-remove { transition:all .3s ease;