1
- Application.Directives.directive 'coupon', [ '$rootScope', 'Coupon', 'growl', ' _t', ($rootScope, Coupon, growl , _t) ->
1
+ Application.Directives.directive 'coupon', [ '$rootScope', 'Coupon', '_t', ($rootScope, Coupon, _t) ->
2
2
{
3
3
restrict: 'E'
4
4
scope:
@@ -19,6 +19,9 @@ Application.Directives.directive 'coupon', [ '$rootScope', 'Coupon', 'growl', '_
19
19
# Binding for the code inputed (see the attached template)
20
20
$scope.couponCode = null
21
21
22
+ # Code validation messages
23
+ $scope.messages = []
24
+
22
25
# Re-compute if the code can be applied when the total of the cart changes
23
26
$scope.$watch 'total', (newValue, oldValue) ->
24
27
if newValue and newValue != oldValue and $scope.couponCode
@@ -28,6 +31,7 @@ Application.Directives.directive 'coupon', [ '$rootScope', 'Coupon', 'growl', '_
28
31
# Callback to validate the code
29
32
##
30
33
$scope.validateCode = ->
34
+ $scope.messages = []
31
35
if $scope.couponCode == ''
32
36
$scope.status = 'pending'
33
37
$scope.coupon = null
@@ -36,13 +40,19 @@ Application.Directives.directive 'coupon', [ '$rootScope', 'Coupon', 'growl', '_
36
40
$scope.status = 'valid'
37
41
$scope.coupon = res
38
42
if res.type == 'percent_off'
39
- growl.success( _t('the_coupon_has_been_applied_you_get_PERCENT_discount', {PERCENT: res.percent_off}))
43
+ $scope.messages.push(type: 'success', message: _t('the_coupon_has_been_applied_you_get_PERCENT_discount', {PERCENT: res.percent_off}))
40
44
else
41
- growl.success( _t('the_coupon_has_been_applied_you_get_AMOUNT_CURRENCY', {AMOUNT: res.amount_off, CURRENCY: $rootScope.currencySymbol}))
45
+ $scope.messages.push(type: 'success', message: _t('the_coupon_has_been_applied_you_get_AMOUNT_CURRENCY', {AMOUNT: res.amount_off, CURRENCY: $rootScope.currencySymbol}))
42
46
, (err) ->
43
47
$scope.status = 'invalid'
44
48
$scope.coupon = null
45
- growl.error(_t('unable_to_apply_the_coupon_because_'+err.data.status))
49
+ $scope.messages.push(type: 'danger', message: _t('unable_to_apply_the_coupon_because_'+err.data.status))
50
+
51
+ ##
52
+ # Callback to remove the message at provided index from the displayed list
53
+ ##
54
+ $scope.closeMessage = (index) ->
55
+ $scope.messages.splice(index, 1);
46
56
}
47
57
]
48
58
0 commit comments