1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

Merge branch 'dev' for release 2.4.6

This commit is contained in:
Sylvain 2016-11-30 17:29:06 +01:00
commit b23ebfdcaa
5 changed files with 24 additions and 7 deletions

View File

@ -1 +1 @@
2.4.5
2.4.6

View File

@ -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)

View File

@ -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:
@ -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
@ -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
@ -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);
}
]

View File

@ -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"
@ -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>

View File

@ -41,7 +41,7 @@ class API::PricesController < API::ApiController
_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])