diff --git a/CHANGELOG.md b/CHANGELOG.md index bb3db7540..86325760f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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' diff --git a/app/assets/javascripts/controllers/admin/coupons.coffee b/app/assets/javascripts/controllers/admin/coupons.coffee index 5433d4248..c62693e80 100644 --- a/app/assets/javascripts/controllers/admin/coupons.coffee +++ b/app/assets/javascripts/controllers/admin/coupons.coffee @@ -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 diff --git a/app/assets/templates/admin/coupons/_form.html.erb b/app/assets/templates/admin/coupons/_form.html.erb index 87ce08937..9a54b7995 100644 --- a/app/assets/templates/admin/coupons/_form.html.erb +++ b/app/assets/templates/admin/coupons/_form.html.erb @@ -81,7 +81,7 @@ {{ 'validity_per_user_is_required' }} -
+
+ {{ errors['valid_until'].join(' ; ') }} - - {{ 'leave_empty_for_no_limit' | translate }} - + + {{ 'leave_empty_for_no_limit' | translate }} +
@@ -113,7 +114,7 @@ min="0"/> {{ 'max_usages_must_be_equal_or_greater_than_0' }} - + {{ 'leave_empty_for_no_limit' | translate }}
diff --git a/app/validators/coupon_discount_validator.rb b/app/validators/coupon_discount_validator.rb index 072ae089f..60a674804 100644 --- a/app/validators/coupon_discount_validator.rb +++ b/app/validators/coupon_discount_validator.rb @@ -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 \ No newline at end of file diff --git a/app/validators/coupon_expiration_validator.rb b/app/validators/coupon_expiration_validator.rb index b6ecf3892..d9a80f55e 100644 --- a/app/validators/coupon_expiration_validator.rb +++ b/app/validators/coupon_expiration_validator.rb @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index f30febc5e..11dbd5fd8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 68bb7179c..1cebdb59d 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -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: