Skip to content

Commit

Permalink
#11 - Same As Shipping Checkbox - when billing address is defaulted i…
Browse files Browse the repository at this point in the history
…n changing the ship address clears billing
  • Loading branch information
jrasmussen451 committed Jan 23, 2016
1 parent 466b54b commit db61aad
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions Same As Shipping Checkbox/sameAsShippingCheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,44 @@ function SameAsShippingCheckboxCtrl($scope, $rootScope) {
$scope.copyShipAddress = false;

$scope.setBilling = function() {
if ($scope.copyShipAddress == true) {
$scope.BillAddress = $scope.orderShipAddress;
$scope.BillAddressID = $scope.currentOrder.ShipAddressID;
$scope.currentOrder.BillAddressID = $scope.currentOrder.ShipAddressID;
$scope.BillAddress.IsBilling = true;
$scope.billaddresses.push($scope.BillAddress);
}
if ($scope.copyShipAddress == false) {
$scope.BillAddress = '';
$scope.BillAddressID = '';
$scope.currentOrder.BillAddressID = '';
if ($scope.copyShipAddress === true) {
if ($scope.currentOrder && ($scope.currentOrder.BillAddressID != $scope.currentOrder.ShipAddressID)) {
$scope.currentOrder.BillAddressID = $scope.currentOrder.ShipAddressID;
$scope.BillAddress = $scope.orderShipAddress;
$scope.BillAddressID = $scope.currentOrder.BillAddressID;
$scope.BillAddress.IsBilling = true;

var addressChecker = [];
angular.forEach($scope.billaddresses, function(address) {
addressChecker.push(address.ID);
});

if(addressChecker.indexOf($scope.orderShipAddress.ID) == -1){
$scope.billaddresses.push($scope.orderShipAddress);
}
}
}
};

$scope.$watch('currentOrder.ShipAddressID', function(newValue) {
if (newValue || newValue == null) {
$scope.$watch('currentOrder.ShipAddressID', function(newValue) {
if (newValue || newValue === null) {
//broadcast that the ship address changed
$rootScope.$broadcast('shipChange');
}
});

$scope.$watch('currentOrder.BillAddressID', function(newValue) {
if ($scope.currentOrder && newValue != $scope.currentOrder.ShipAddressID) {
$scope.copyShipAddress = false;
$scope.$on('shipChange', function() {
if ($scope.currentOrder && ($scope.currentOrder.BillAddressID != $scope.currentOrder.ShipAddressID) && ($scope.copyShipAddress === true)) {
$scope.copyShipAddress = false;
$scope.currentOrder.BillAddressID = '';
$scope.BillAddress = null;
$scope.BillAddressID = '';
}
});

$scope.$on('shipChange', function() {
$scope.copyShipAddress = false;
$scope.BillAddress = null;
$scope.BillAddressID = '';
if ($scope.currentOrder) $scope.currentOrder.BillAddressID = '';
$scope.$watch('currentOrder.BillAddressID', function(newValue) {
if ($scope.currentOrder && (newValue != $scope.currentOrder.ShipAddressID) && ($scope.copyShipAddress === true)) {
$scope.copyShipAddress = false;
}
});
}

0 comments on commit db61aad

Please sign in to comment.