-
Notifications
You must be signed in to change notification settings - Fork 0
/
isCheckout.js
executable file
·79 lines (59 loc) · 2.59 KB
/
isCheckout.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
var app = angular.module('isCheckout', ['ngAutocomplete', 'http-auth-interceptor'])
.config(['$httpProvider',function($httpProvider) {
//This will intercept all http calls and broadcast the event
$httpProvider.interceptors.push(function($rootScope, $timeout, $q) {
return {
request: function(request) {
$rootScope.$broadcast('loading:show');
return request;
},
response: function(response) {
$rootScope.$broadcast('loading:hide')
return response;
},
responseError: function(rejection) {
$rootScope.$broadcast('call:error',rejection);
return $q.reject(rejection);
}
}
})
}])
.run(['$rootScope', 'cartFactory', 'pubSubFactory', 'isCartConstants',
function($rootScope, cartFactory, pubSubFactory, isCartConstants) {
$rootScope.$on('loading:show', function(e) {
$rootScope.cartloader = true;
});
$rootScope.$on('loading:hide', function(e) {
$rootScope.cartloader = false;
});
/*-----------------------------------------------------------
// Load the page data and broadcast the page data
// this event has to be subscribed by all controllers
-----------------------------------------------------------*/
cartFactory.communicator(isCartConstants.formName, isCartConstants.Get, isCartConstants.GetJsonURL, isCartConstants.contentType).then(function(response) {
pubSubFactory.publish(isCartConstants.PageLoad, response.data);
});
}])
.controller('mainForm', function($scope, cartFactory, pubSubFactory,isCartConstants) {
$scope.name = "Parent Form";
$scope.cartType = 1; //Cart Type Wizard or single page
$scope.child = {};
$scope.request = "";
//Submit button interaction
$scope.SubmitForm = function(formName) {
var isvalid = true;
$scope.request = angular.toJson($scope.child);
var request = $scope.child;
//if the form is valid call service
if (isvalid) {
//MOCK submit service
cartFactory.communicator(request, isCartConstants.Get, isCartConstants.GetJsonURL, isCartConstants.contentType).then(function(response) {
//publish updated data.
pubSubFactory.publish(isCartConstants.PageUpdate, response.data);
//set server side errors
$scope.formError = "Billing Address Invalid";
});
}
return false; //failed
};
});