mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-20 09:52:19 +01:00
coupon edition: display internationalized errors
This commit is contained in:
parent
85ee73f0e0
commit
ecbe8a58a2
@ -3,6 +3,7 @@
|
|||||||
## next release
|
## next release
|
||||||
- Improved automated testing
|
- Improved automated testing
|
||||||
- Added an information notice about the processing time of deleting an administrator
|
- Added an information notice about the processing time of deleting an administrator
|
||||||
|
- Ability to change the expiration date of a coupon after its creation
|
||||||
- Fix a bug: unable to run rake db:migrate on first install
|
- Fix a bug: unable to run rake db:migrate on first install
|
||||||
- Fix a bug: unable to create or edit a coupon of type 'percentage'
|
- Fix a bug: unable to create or edit a coupon of type 'percentage'
|
||||||
|
|
||||||
|
@ -73,6 +73,9 @@ Application.Controllers.controller "EditCouponController", ["$scope", "$state",
|
|||||||
## Options for the validity per user
|
## Options for the validity per user
|
||||||
$scope.validities = userValidities
|
$scope.validities = userValidities
|
||||||
|
|
||||||
|
## Mapping for validation errors
|
||||||
|
$scope.errors = {}
|
||||||
|
|
||||||
## Default parameters for AngularUI-Bootstrap datepicker (used for coupon validity limit selection)
|
## Default parameters for AngularUI-Bootstrap datepicker (used for coupon validity limit selection)
|
||||||
$scope.datePicker =
|
$scope.datePicker =
|
||||||
format: Fablab.uibDateFormat
|
format: Fablab.uibDateFormat
|
||||||
@ -98,11 +101,12 @@ Application.Controllers.controller "EditCouponController", ["$scope", "$state",
|
|||||||
# Callback to save the coupon's changes to the API
|
# Callback to save the coupon's changes to the API
|
||||||
##
|
##
|
||||||
$scope.updateCoupon = ->
|
$scope.updateCoupon = ->
|
||||||
|
$scope.errors = {}
|
||||||
Coupon.update {id: $scope.coupon.id}, coupon: $scope.coupon, (coupon) ->
|
Coupon.update {id: $scope.coupon.id}, coupon: $scope.coupon, (coupon) ->
|
||||||
$state.go('app.admin.pricing')
|
$state.go('app.admin.pricing')
|
||||||
, (err)->
|
, (err)->
|
||||||
growl.error(_t('unable_to_update_the_coupon_an_error_occurred'))
|
growl.error(_t('unable_to_update_the_coupon_an_error_occurred'))
|
||||||
console.error(err)
|
$scope.errors = err.data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@
|
|||||||
<span class="help-block error" ng-show="couponForm['coupon[validity_per_user]'].$dirty && couponForm['coupon[validity_per_user]'].$error.required" translate>{{ 'validity_per_user_is_required' }}</span>
|
<span class="help-block error" ng-show="couponForm['coupon[validity_per_user]'].$dirty && couponForm['coupon[validity_per_user]'].$error.required" translate>{{ 'validity_per_user_is_required' }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group" ng-class="{'has-error': errors['valid_until']}">
|
||||||
<label for="coupon[valid_until]" translate>{{ 'valid_until' }}</label>
|
<label for="coupon[valid_until]" translate>{{ 'valid_until' }}</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input type="text" id="coupon[valid_until]"
|
<input type="text" id="coupon[valid_until]"
|
||||||
@ -97,8 +97,9 @@
|
|||||||
<button type="button" class="btn btn-default" ng-click="toggleDatePicker($event)" ng-disabled="mode == 'EDIT'"><i class="fa fa-calendar"></i></button>
|
<button type="button" class="btn btn-default" ng-click="toggleDatePicker($event)" ng-disabled="mode == 'EDIT'"><i class="fa fa-calendar"></i></button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
<span class="help-block error" ng-show="errors['valid_until']">{{ errors['valid_until'].join(' ; ') }}</span>
|
||||||
|
|
||||||
<span class="help-block text-info text-xs">
|
<span class="text-info text-xs">
|
||||||
<i class="fa fa-lightbulb-o"></i> {{ 'leave_empty_for_no_limit' | translate }}
|
<i class="fa fa-lightbulb-o"></i> {{ 'leave_empty_for_no_limit' | translate }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@ -113,7 +114,7 @@
|
|||||||
min="0"/>
|
min="0"/>
|
||||||
<span class="help-block error" ng-show="couponForm['coupon[max_usages]'].$dirty && couponForm['coupon[max_usages]'].$error.min" translate>{{ 'max_usages_must_be_equal_or_greater_than_0' }}</span>
|
<span class="help-block error" ng-show="couponForm['coupon[max_usages]'].$dirty && couponForm['coupon[max_usages]'].$error.min" translate>{{ 'max_usages_must_be_equal_or_greater_than_0' }}</span>
|
||||||
|
|
||||||
<span class="help-block text-info text-xs">
|
<span class="text-info text-xs">
|
||||||
<i class="fa fa-lightbulb-o"></i> {{ 'leave_empty_for_no_limit' | translate }}
|
<i class="fa fa-lightbulb-o"></i> {{ 'leave_empty_for_no_limit' | translate }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,14 +2,14 @@ class CouponDiscountValidator < ActiveModel::Validator
|
|||||||
def validate(record)
|
def validate(record)
|
||||||
if !record.percent_off.nil?
|
if !record.percent_off.nil?
|
||||||
unless (0..100).include? record.percent_off
|
unless (0..100).include? record.percent_off
|
||||||
record.errors[:percent_off] << 'Percentage must be included between 0 and 100'
|
record.errors[:percent_off] << I18n.t('errors.messages.percentage_out_of_range')
|
||||||
end
|
end
|
||||||
elsif !record.amount_off.nil?
|
elsif !record.amount_off.nil?
|
||||||
unless record.amount_off > 0
|
unless record.amount_off > 0
|
||||||
record.errors[:amount_off] << I18n.t('errors.messages.greater_than_or_equal_to', count: 0)
|
record.errors[:amount_off] << I18n.t('errors.messages.greater_than_or_equal_to', count: 0)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
record.errors[:percent_off] << 'cannot be blank when amount_off is blank too'
|
record.errors[:percent_off] << I18n.t('errors.messages.cannot_be_blank_at_same_time', field: 'amount_off')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -8,11 +8,11 @@ class CouponExpirationValidator < ActiveModel::Validator
|
|||||||
|
|
||||||
unless current.blank?
|
unless current.blank?
|
||||||
if current.end_of_day < Time.now
|
if current.end_of_day < Time.now
|
||||||
record.errors[:valid_until] << 'New expiration date cannot be in the past'
|
record.errors[:valid_until] << I18n.t('errors.messages.cannot_be_in_the_past')
|
||||||
end
|
end
|
||||||
|
|
||||||
if !previous.blank? and current.end_of_day < previous.end_of_day
|
if !previous.blank? and current.end_of_day < previous.end_of_day
|
||||||
record.errors[:valid_until] << 'New expiration date cannot be before the previous one'
|
record.errors[:valid_until] << I18n.t('errors.messages.cannot_be_before_previous_value')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -32,6 +32,10 @@ en:
|
|||||||
size_too_small: "is too small (should be at least %{file_size})"
|
size_too_small: "is too small (should be at least %{file_size})"
|
||||||
size_too_big: "is too big (should be at most %{file_size})"
|
size_too_big: "is too big (should be at most %{file_size})"
|
||||||
export_not_found: "Requested export was not found. It was probably deleted, please generate a new export."
|
export_not_found: "Requested export was not found. It was probably deleted, please generate a new export."
|
||||||
|
percentage_out_of_range: "Percentage must be included between 0 and 100"
|
||||||
|
cannot_be_blank_at_same_time: "cannot be blank when %{field} is blank too"
|
||||||
|
cannot_be_in_the_past: "cannot be in the past"
|
||||||
|
cannot_be_before_previous_value: "cannot be before the previous value"
|
||||||
|
|
||||||
activemodel:
|
activemodel:
|
||||||
errors:
|
errors:
|
||||||
|
@ -32,6 +32,10 @@ fr:
|
|||||||
size_too_small: "est trop petite (au moins %{file_size})"
|
size_too_small: "est trop petite (au moins %{file_size})"
|
||||||
size_too_big: "est trop grande (pas plus de %{file_size})"
|
size_too_big: "est trop grande (pas plus de %{file_size})"
|
||||||
export_not_found: "L'export demandé n'a pas été trouvé. Il a probablement été supprimé, veuillez lancer la génération d'un nouvel export."
|
export_not_found: "L'export demandé n'a pas été trouvé. Il a probablement été supprimé, veuillez lancer la génération d'un nouvel export."
|
||||||
|
percentage_out_of_range: "Le pourcentage doit être inclus entre 0 et 100"
|
||||||
|
cannot_be_blank_at_same_time: "ou %{field} doit être rempli(e)"
|
||||||
|
cannot_be_in_the_past: "ne peut pas être dans le passé"
|
||||||
|
cannot_be_before_previous_value: "ne peut pas être antérieur(e) à la valeur précédente"
|
||||||
|
|
||||||
activemodel:
|
activemodel:
|
||||||
errors:
|
errors:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user