mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
display coupon application result in inline message instead of growl notification
This commit is contained in:
parent
16ed469c72
commit
4c8b661750
@ -1,4 +1,4 @@
|
|||||||
Application.Directives.directive 'coupon', [ '$rootScope', 'Coupon', 'growl', '_t', ($rootScope, Coupon, growl, _t) ->
|
Application.Directives.directive 'coupon', [ '$rootScope', 'Coupon', '_t', ($rootScope, Coupon, _t) ->
|
||||||
{
|
{
|
||||||
restrict: 'E'
|
restrict: 'E'
|
||||||
scope:
|
scope:
|
||||||
@ -19,6 +19,9 @@ Application.Directives.directive 'coupon', [ '$rootScope', 'Coupon', 'growl', '_
|
|||||||
# Binding for the code inputed (see the attached template)
|
# Binding for the code inputed (see the attached template)
|
||||||
$scope.couponCode = null
|
$scope.couponCode = null
|
||||||
|
|
||||||
|
# Code validation messages
|
||||||
|
$scope.messages = []
|
||||||
|
|
||||||
# Re-compute if the code can be applied when the total of the cart changes
|
# Re-compute if the code can be applied when the total of the cart changes
|
||||||
$scope.$watch 'total', (newValue, oldValue) ->
|
$scope.$watch 'total', (newValue, oldValue) ->
|
||||||
if newValue and newValue != oldValue and $scope.couponCode
|
if newValue and newValue != oldValue and $scope.couponCode
|
||||||
@ -28,6 +31,7 @@ Application.Directives.directive 'coupon', [ '$rootScope', 'Coupon', 'growl', '_
|
|||||||
# Callback to validate the code
|
# Callback to validate the code
|
||||||
##
|
##
|
||||||
$scope.validateCode = ->
|
$scope.validateCode = ->
|
||||||
|
$scope.messages = []
|
||||||
if $scope.couponCode == ''
|
if $scope.couponCode == ''
|
||||||
$scope.status = 'pending'
|
$scope.status = 'pending'
|
||||||
$scope.coupon = null
|
$scope.coupon = null
|
||||||
@ -36,13 +40,19 @@ Application.Directives.directive 'coupon', [ '$rootScope', 'Coupon', 'growl', '_
|
|||||||
$scope.status = 'valid'
|
$scope.status = 'valid'
|
||||||
$scope.coupon = res
|
$scope.coupon = res
|
||||||
if res.type == 'percent_off'
|
if res.type == 'percent_off'
|
||||||
growl.success(_t('the_coupon_has_been_applied_you_get_PERCENT_discount', {PERCENT: res.percent_off}))
|
$scope.messages.push(type: 'success', message: _t('the_coupon_has_been_applied_you_get_PERCENT_discount', {PERCENT: res.percent_off}))
|
||||||
else
|
else
|
||||||
growl.success(_t('the_coupon_has_been_applied_you_get_AMOUNT_CURRENCY', {AMOUNT: res.amount_off, CURRENCY: $rootScope.currencySymbol}))
|
$scope.messages.push(type: 'success', message: _t('the_coupon_has_been_applied_you_get_AMOUNT_CURRENCY', {AMOUNT: res.amount_off, CURRENCY: $rootScope.currencySymbol}))
|
||||||
, (err) ->
|
, (err) ->
|
||||||
$scope.status = 'invalid'
|
$scope.status = 'invalid'
|
||||||
$scope.coupon = null
|
$scope.coupon = null
|
||||||
growl.error(_t('unable_to_apply_the_coupon_because_'+err.data.status))
|
$scope.messages.push(type: 'danger', message: _t('unable_to_apply_the_coupon_because_'+err.data.status))
|
||||||
|
|
||||||
|
##
|
||||||
|
# Callback to remove the message at provided index from the displayed list
|
||||||
|
##
|
||||||
|
$scope.closeMessage = (index) ->
|
||||||
|
$scope.messages.splice(index, 1);
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<div ng-show="code.input">
|
<div ng-show="code.input">
|
||||||
<label for="coupon_code" translate>{{ 'code_' }}</label>
|
<label for="coupon_code" translate>{{ 'code_' }}</label>
|
||||||
<div class="input-group">
|
<div class="input-group m-b">
|
||||||
<input type="text"
|
<input type="text"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
name="coupon_code"
|
name="coupon_code"
|
||||||
@ -17,5 +17,7 @@
|
|||||||
<i class="fa fa-check" ng-show="status == 'valid'"></i>
|
<i class="fa fa-check" ng-show="status == 'valid'"></i>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<uib-alert ng-repeat="msg in messages" type="{{msg.type}}" close="closeMessage($index)">{{msg.message}}</uib-alert>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -41,7 +41,7 @@ class API::PricesController < API::ApiController
|
|||||||
_user = User.find(_price_params[:user_id])
|
_user = User.find(_price_params[:user_id])
|
||||||
# reservable
|
# reservable
|
||||||
if _price_params[:reservable_id].nil?
|
if _price_params[:reservable_id].nil?
|
||||||
@amount = {elements: nil, total: 0}
|
@amount = {elements: nil, total: 0, before_coupon: 0}
|
||||||
else
|
else
|
||||||
_reservable = _price_params[:reservable_type].constantize.find(_price_params[:reservable_id])
|
_reservable = _price_params[:reservable_type].constantize.find(_price_params[:reservable_id])
|
||||||
@amount = Price.compute(current_user.is_admin?, _user, _reservable, _price_params[:slots_attributes], _price_params[:plan_id], _price_params[:nb_reserve_places], _price_params[:tickets_attributes], coupon_params[:coupon_code])
|
@amount = Price.compute(current_user.is_admin?, _user, _reservable, _price_params[:slots_attributes], _price_params[:plan_id], _price_params[:nb_reserve_places], _price_params[:tickets_attributes], coupon_params[:coupon_code])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user