Skip to content

Commit

Permalink
Merge branch 'dev' for release 2.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainbx committed Nov 30, 2016
2 parents 920270e + 3fad06c commit b23ebfd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .fabmanager-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.5
2.4.6
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog Fab Manager

## v2.4.6 2016 Novembre 30

- Change display of message about coupon application status
- Fix a bug: compute price API return error 500 if reservable_id is not provided

## v2.4.5 2016 November 29

- Ability to create coupons with cash amounts (previously only percentages were allowed)
Expand Down
18 changes: 14 additions & 4 deletions app/assets/javascripts/directives/coupon.coffee.erb
Original file line number Diff line number Diff line change
@@ -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'
scope:
Expand All @@ -19,6 +19,9 @@ Application.Directives.directive 'coupon', [ '$rootScope', 'Coupon', 'growl', '_
# Binding for the code inputed (see the attached template)
$scope.couponCode = null

# Code validation messages
$scope.messages = []

# Re-compute if the code can be applied when the total of the cart changes
$scope.$watch 'total', (newValue, oldValue) ->
if newValue and newValue != oldValue and $scope.couponCode
Expand All @@ -28,6 +31,7 @@ Application.Directives.directive 'coupon', [ '$rootScope', 'Coupon', 'growl', '_
# Callback to validate the code
##
$scope.validateCode = ->
$scope.messages = []
if $scope.couponCode == ''
$scope.status = 'pending'
$scope.coupon = null
Expand All @@ -36,13 +40,19 @@ Application.Directives.directive 'coupon', [ '$rootScope', 'Coupon', 'growl', '_
$scope.status = 'valid'
$scope.coupon = res
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
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) ->
$scope.status = 'invalid'
$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);
}
]

Expand Down
4 changes: 3 additions & 1 deletion app/assets/templates/shared/_coupon.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<div ng-show="code.input">
<label for="coupon_code" translate>{{ 'code_' }}</label>
<div class="input-group">
<div class="input-group m-b">
<input type="text"
class="form-control"
name="coupon_code"
Expand All @@ -17,5 +17,7 @@
<i class="fa fa-check" ng-show="status == 'valid'"></i>
</span>
</div>

<uib-alert ng-repeat="msg in messages" type="{{msg.type}}" close="closeMessage($index)">{{msg.message}}</uib-alert>
</div>
</div>
2 changes: 1 addition & 1 deletion app/controllers/api/prices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def compute
_user = User.find(_price_params[:user_id])
# reservable
if _price_params[:reservable_id].nil?
@amount = {elements: nil, total: 0}
@amount = {elements: nil, total: 0, before_coupon: 0}
else
_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])
Expand Down

0 comments on commit b23ebfd

Please sign in to comment.