-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathngCart.directives.js
120 lines (107 loc) · 3.87 KB
/
ngCart.directives.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
120
'use strict';
angular.module('ngCart.directives', ['ngCart.fulfilment'])
.controller('CartController',['$scope', 'ngCart', function($scope, ngCart) {
$scope.ngCart = ngCart;
}])
.directive('ngcartAddtocart', ['ngCart', function(ngCart){
return {
restrict : 'E',
controller : 'CartController',
scope: {
id:'@',
name:'@',
quantity:'@',
quantityMax:'@',
price:'@',
data:'='
},
transclude: true,
templateUrl: function(element, attrs) {
if ( typeof attrs.templateUrl == 'undefined' ) {
return 'template/ngCart/addtocart.html';
} else {
return attrs.templateUrl;
}
},
link:function(scope, element, attrs){
scope.attrs = attrs;
scope.inCart = function(){
return ngCart.getItemById(attrs.id);
};
if (scope.inCart()){
scope.q = ngCart.getItemById(attrs.id).getQuantity();
} else {
scope.q = parseInt(scope.quantity);
}
scope.qtyOpt = [];
for (var i = 1; i <= scope.quantityMax; i++) {
scope.qtyOpt.push(i);
}
}
};
}])
.directive('ngcartCart', [function(){
return {
restrict : 'E',
controller : 'CartController',
scope: {},
templateUrl: function(element, attrs) {
if ( typeof attrs.templateUrl == 'undefined' ) {
return 'template/ngCart/cart.html';
} else {
return attrs.templateUrl;
}
},
link:function(scope, element, attrs){
}
};
}])
.directive('ngcartSummary', [function(){
return {
restrict : 'E',
controller : 'CartController',
scope: {},
transclude: true,
templateUrl: function(element, attrs) {
if ( typeof attrs.templateUrl == 'undefined' ) {
return 'template/ngCart/summary.html';
} else {
return attrs.templateUrl;
}
}
};
}])
.directive('ngcartCheckout', [function(){
return {
restrict : 'E',
controller : ('CartController', ['$rootScope', '$scope', 'ngCart', 'fulfilmentProvider', function($rootScope, $scope, ngCart, fulfilmentProvider) {
$scope.ngCart = ngCart;
$scope.checkout = function () {
fulfilmentProvider.setService($scope.service);
fulfilmentProvider.setSettings($scope.settings);
fulfilmentProvider.checkout()
.success(function (data, status, headers, config) {
$rootScope.$broadcast('ngCart:checkout_succeeded', data);
})
.error(function (data, status, headers, config) {
$rootScope.$broadcast('ngCart:checkout_failed', {
statusCode: status,
error: data
});
});
}
}]),
scope: {
service:'@',
settings:'='
},
transclude: true,
templateUrl: function(element, attrs) {
if ( typeof attrs.templateUrl == 'undefined' ) {
return 'template/ngCart/checkout.html';
} else {
return attrs.templateUrl;
}
}
};
}]);