mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
i18n coupon directive
This commit is contained in:
parent
5ce0097aa3
commit
d1c1a614a9
@ -4,37 +4,33 @@ Application.Directives.directive 'coupon', [ 'Coupon', 'growl', '_t', (Coupon, g
|
||||
scope:
|
||||
show: '='
|
||||
templateUrl: '<%= asset_path "shared/_coupon.html" %>'
|
||||
link: (scope, element, attributes) ->
|
||||
link: ($scope, element, attributes) ->
|
||||
|
||||
# default: do not enable code input
|
||||
scope.input = false
|
||||
# Whether code input is shown or not (ie. the link 'I have a coupon' is shown)
|
||||
$scope.code =
|
||||
input: false
|
||||
|
||||
# default: coupon code is not valid
|
||||
scope.valid = false
|
||||
# Available status are: 'pending', 'valid', 'invalid'
|
||||
$scope.status = 'pending'
|
||||
|
||||
# for dirty checking and request response waiting
|
||||
scope.pending = true
|
||||
|
||||
# binding for the code inputed
|
||||
scope.couponCode = null
|
||||
# Binding for the code inputed
|
||||
$scope.couponCode = null
|
||||
|
||||
|
||||
scope.closeAlert = (index) ->
|
||||
scope.alerts.splice(index, 1);
|
||||
|
||||
##
|
||||
# Callback to validate the code
|
||||
##
|
||||
scope.validateCode = ->
|
||||
unless scope.couponCode == ''
|
||||
Coupon.validate {code: scope.couponCode}, (res) ->
|
||||
scope.valid = true
|
||||
growl.success(res.percent_off+' % de réduction')
|
||||
console.info(res)
|
||||
$scope.validateCode = ->
|
||||
if $scope.couponCode == ''
|
||||
$scope.status = 'pending'
|
||||
else
|
||||
Coupon.validate {code: $scope.couponCode}, (res) ->
|
||||
$scope.status = 'valid'
|
||||
growl.success(_t('the_coupon_has_been_applied_you_get_PERCENT_discount', {PERCENT: res.percent_off}))
|
||||
, (err) ->
|
||||
scope.valid = false
|
||||
growl.error(_t(err.data.status))
|
||||
console.error(err)
|
||||
$scope.status = 'invalid'
|
||||
growl.error(_t('unable_to_apply_the_coupon_because_'+err.data.status))
|
||||
}
|
||||
]
|
||||
|
||||
|
@ -363,7 +363,8 @@ angular.module('application.router', ['ui.router']).
|
||||
]
|
||||
translations: [ 'Translations', (Translations) ->
|
||||
Translations.query(['app.logged.machines_reserve', 'app.shared.plan_subscribe', 'app.shared.member_select',
|
||||
'app.shared.stripe', 'app.shared.valid_reservation_modal', 'app.shared.confirm_modify_slot_modal', 'app.shared.wallet']).$promise
|
||||
'app.shared.stripe', 'app.shared.valid_reservation_modal', 'app.shared.confirm_modify_slot_modal',
|
||||
'app.shared.wallet', 'app.shared.coupon_input']).$promise
|
||||
]
|
||||
.state 'app.admin.machines_edit',
|
||||
url: '/machines/:id/edit'
|
||||
|
@ -1,8 +1,8 @@
|
||||
<div class="form-group m-b-lg" ng-show="show">
|
||||
<a ng-click="input = true" ng-hide="input" class="b-b">J'ai un code promo !</a>
|
||||
<a ng-click="code. input = true" ng-hide="code.input" class="b-b" translate>{{ ' i_have_a_coupon' }}</a>
|
||||
|
||||
<div ng-show="input">
|
||||
<label for="coupon_code">Code : </label>
|
||||
<div ng-show="code.input">
|
||||
<label for="coupon_code" translate>{{ 'code_' }}</label>
|
||||
<div class="input-group">
|
||||
<input type="text"
|
||||
class="form-control"
|
||||
@ -11,9 +11,10 @@
|
||||
id="coupon_code"
|
||||
ng-model-options='{ debounce: 1000 }'
|
||||
ng-change='validateCode()'/>
|
||||
<span class="input-group-addon" ng-class="{'label-success': valid, 'label-danger text-white': !valid}">
|
||||
<i class="fa fa-times" ng-hide="valid"></i>
|
||||
<i class="fa fa-check" ng-show="valid"></i>
|
||||
<span class="input-group-addon" ng-class="{'label-success': status == 'valid', 'label-danger text-white': status == 'invalid'}">
|
||||
<i class="fa fa-spinner fa-pulse fa-fw" ng-show="status == 'pending'"></i>
|
||||
<i class="fa fa-times" ng-show="status == 'invalid'"></i>
|
||||
<i class="fa fa-check" ng-show="status == 'valid'"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -11,6 +11,7 @@ class Coupon < ActiveRecord::Base
|
||||
validates :percent_off, presence: true
|
||||
validates :percent_off, :inclusion => 0..100
|
||||
validates :validity_per_user, presence: true
|
||||
validates :validity_per_user, inclusion: { in: %w(once forever) }
|
||||
|
||||
def safe_destroy
|
||||
if self.invoices.size == 0
|
||||
|
@ -348,4 +348,14 @@ en:
|
||||
valid_until: "Valid until (included)"
|
||||
max_usages: "Maximum usages allowed"
|
||||
max_usages_must_be_equal_or_greater_than_0: "The maximum usages allowed must be greater than 0."
|
||||
enabled: "Active"
|
||||
enabled: "Active"
|
||||
|
||||
coupon_input:
|
||||
# coupon (input zone for users)
|
||||
i_have_a_coupon: "I have a coupon!"
|
||||
code_: "Code:"
|
||||
the_coupon_has_been_applied_you_get_PERCENT_discount: "The coupon has been applied. You get {{PERCENT}}% discount." # angular interpolation
|
||||
unable_to_apply_the_coupon_because_disabled: "Unable to apply the coupon: this code was disabled."
|
||||
unable_to_apply_the_coupon_because_expired: "Unable to apply the coupon: this code has expired."
|
||||
unable_to_apply_the_coupon_because_sold_out: "Unable to apply the coupon: this code reached its quota."
|
||||
unable_to_apply_the_coupon_because_rejected: "This code does not exists."
|
@ -348,4 +348,14 @@ fr:
|
||||
valid_until: "Valable jusqu'au (inclus)"
|
||||
max_usages: "Nombre maximum d'utilisations autorisées"
|
||||
max_usages_must_be_equal_or_greater_than_0: "Le nombre d'utilisations maximum doit être supérieur ou égal à 0."
|
||||
enabled: "Activé"
|
||||
enabled: "Activé"
|
||||
|
||||
coupon_input:
|
||||
# code promotionnel (zone de saisie pour les utilisateurs)
|
||||
i_have_a_coupon: "J'ai un code promo !"
|
||||
code_: "Code :"
|
||||
the_coupon_has_been_applied_you_get_PERCENT_discount: "Le code promo a bien été appliqué. Vous bénéficiez d'une remise de {{PERCENT}} %." # angular interpolation
|
||||
unable_to_apply_the_coupon_because_disabled: "Impossible d'appliquer la réduction : ce code promo a été désactivé."
|
||||
unable_to_apply_the_coupon_because_expired: "Impossible d'appliquer la réduction : ce code promo a expiré."
|
||||
unable_to_apply_the_coupon_because_sold_out: "Impossible d'appliquer la réduction : ce code promo a atteint son quota."
|
||||
unable_to_apply_the_coupon_because_rejected: "Ce code promo n'existe pas."
|
Loading…
Reference in New Issue
Block a user