-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckOutViewCtrl.js
119 lines (107 loc) · 3.87 KB
/
checkOutViewCtrl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
four51.app.controller('CheckOutViewCtrl', ['$scope', '$routeParams', '$location', '$filter', '$rootScope', '$451', 'User', 'Order', 'OrderConfig', 'FavoriteOrder', 'AddressList', 'GoogleAnalytics',
function ($scope, $routeParams, $location, $filter, $rootScope, $451, User, Order, OrderConfig, FavoriteOrder, AddressList, GoogleAnalytics) {
$scope.errorSection = 'open';
$scope.isEditforApproval = $routeParams.id != null && $scope.user.Permissions.contains('EditApprovalOrder');
if ($scope.isEditforApproval) {
Order.get($routeParams.id, function(order) {
$scope.currentOrder = order;
});
}
if (!$scope.currentOrder) {
$location.path('catalog');
}
$scope.hasOrderConfig = OrderConfig.hasConfig($scope.currentOrder, $scope.user);
$scope.checkOutSection = $scope.hasOrderConfig ? 'order' : 'shipping';
function submitOrder() {
$scope.displayLoadingIndicator = true;
$scope.submitClicked = true;
$scope.errorMessage = null;
Order.submit($scope.currentOrder,
function(data) {
if ($scope.user.Company.GoogleAnalyticsCode) {
GoogleAnalytics.ecommerce(data, $scope.user);
}
$scope.user.CurrentOrderID = null;
User.save($scope.user, function(data) {
$scope.user = data;
$scope.displayLoadingIndicator = false;
});
$scope.currentOrder = null;
$location.path('/order/' + data.ID);
},
function(ex) {
$scope.submitClicked = false;
$scope.errorMessage = ex.Message;
$scope.displayLoadingIndicator = false;
$scope.shippingUpdatingIndicator = false;
$scope.shippingFetchIndicator = false;
}
);
};
$scope.$watch('currentOrder.CostCenter', function() {
OrderConfig.address($scope.currentOrder, $scope.user);
});
function saveChanges(callback) {
$scope.displayLoadingIndicator = true;
$scope.errorMessage = null;
$scope.actionMessage = null;
var auto = $scope.currentOrder.autoID;
Order.save($scope.currentOrder,
function(data) {
$scope.currentOrder = data;
if (auto) {
$scope.currentOrder.autoID = true;
$scope.currentOrder.ExternalID = 'auto';
}
$scope.displayLoadingIndicator = false;
if (callback) callback($scope.currentOrder);
$scope.actionMessage = "Your changes have been saved";
},
function(ex) {
$scope.currentOrder.ExternalID = null;
$scope.errorMessage = ex.Message;
$scope.displayLoadingIndicator = false;
$scope.shippingUpdatingIndicator = false;
$scope.shippingFetchIndicator = false;
}
);
};
$scope.continueShopping = function() {
if (confirm('Do you want to save changes to your order before continuing?') == true)
saveChanges(function() { $location.path('catalog') });
else
$location.path('catalog');
};
$scope.cancelOrder = function() {
if (confirm('Are you sure you wish to cancel your order?') == true) {
$scope.displayLoadingIndicator = true;
Order.delete($scope.currentOrder,
function() {
$scope.user.CurrentOrderID = null;
$scope.currentOrder = null;
User.save($scope.user, function(data) {
$scope.user = data;
$scope.displayLoadingIndicator = false;
$location.path('catalog');
});
},
function(ex) {
$scope.actionMessage = ex.Message;
$scope.displayLoadingIndicator = false;
}
);
}
};
$scope.saveChanges = function() {
saveChanges();
};
$scope.submitOrder = function() {
submitOrder();
};
$scope.saveFavorite = function() {
FavoriteOrder.save($scope.currentOrder);
};
$scope.cancelEdit = function() {
$location.path('order');
};
}]);