1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-19 08:52:25 +01:00

coupon edition: display internationalized errors

This commit is contained in:
Sylvain 2016-12-13 12:46:00 +01:00
parent 85ee73f0e0
commit ecbe8a58a2
7 changed files with 24 additions and 10 deletions

View File

@ -3,6 +3,7 @@
## next release
- Improved automated testing
- 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 create or edit a coupon of type 'percentage'

View File

@ -73,6 +73,9 @@ Application.Controllers.controller "EditCouponController", ["$scope", "$state",
## Options for the validity per user
$scope.validities = userValidities
## Mapping for validation errors
$scope.errors = {}
## Default parameters for AngularUI-Bootstrap datepicker (used for coupon validity limit selection)
$scope.datePicker =
format: Fablab.uibDateFormat
@ -98,11 +101,12 @@ Application.Controllers.controller "EditCouponController", ["$scope", "$state",
# Callback to save the coupon's changes to the API
##
$scope.updateCoupon = ->
$scope.errors = {}
Coupon.update {id: $scope.coupon.id}, coupon: $scope.coupon, (coupon) ->
$state.go('app.admin.pricing')
, (err)->
growl.error(_t('unable_to_update_the_coupon_an_error_occurred'))
console.error(err)
$scope.errors = err.data

View File

@ -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>
</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>
<div class="input-group">
<input type="text" id="coupon[valid_until]"
@ -97,10 +97,11 @@
<button type="button" class="btn btn-default" ng-click="toggleDatePicker($event)" ng-disabled="mode == 'EDIT'"><i class="fa fa-calendar"></i></button>
</span>
</div>
<span class="help-block error" ng-show="errors['valid_until']">{{ errors['valid_until'].join(' ; ') }}</span>
<span class="help-block text-info text-xs">
<i class="fa fa-lightbulb-o"></i> {{ 'leave_empty_for_no_limit' | translate }}
</span>
<span class="text-info text-xs">
<i class="fa fa-lightbulb-o"></i> {{ 'leave_empty_for_no_limit' | translate }}
</span>
</div>
<div class="form-group" ng-class="{'has-error': couponForm['coupon[max_usages]'].$dirty && couponForm['coupon[max_usages]'].$invalid}">
@ -113,7 +114,7 @@
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 text-info text-xs">
<span class="text-info text-xs">
<i class="fa fa-lightbulb-o"></i> {{ 'leave_empty_for_no_limit' | translate }}
</span>
</div>

View File

@ -2,14 +2,14 @@ class CouponDiscountValidator < ActiveModel::Validator
def validate(record)
if !record.percent_off.nil?
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
elsif !record.amount_off.nil?
unless record.amount_off > 0
record.errors[:amount_off] << I18n.t('errors.messages.greater_than_or_equal_to', count: 0)
end
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

View File

@ -8,11 +8,11 @@ class CouponExpirationValidator < ActiveModel::Validator
unless current.blank?
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
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

View File

@ -32,6 +32,10 @@ en:
size_too_small: "is too small (should be at least %{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."
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:
errors:

View File

@ -32,6 +32,10 @@ fr:
size_too_small: "est trop petite (au moins %{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."
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:
errors: