mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-26 20:54:21 +01:00
ability to edit coupons
This commit is contained in:
parent
01b77b3179
commit
23320104c5
@ -5,10 +5,6 @@
|
|||||||
Application.Controllers.controller "NewCouponController", ["$scope", "$state",'Coupon', 'growl', '_t'
|
Application.Controllers.controller "NewCouponController", ["$scope", "$state",'Coupon', 'growl', '_t'
|
||||||
, ($scope, $state, Coupon, growl, _t) ->
|
, ($scope, $state, Coupon, growl, _t) ->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### PUBLIC SCOPE ###
|
|
||||||
|
|
||||||
## Values for the coupon currently created
|
## Values for the coupon currently created
|
||||||
$scope.coupon =
|
$scope.coupon =
|
||||||
active: true
|
active: true
|
||||||
@ -17,17 +13,22 @@ Application.Controllers.controller "NewCouponController", ["$scope", "$state",'C
|
|||||||
$scope.datePicker =
|
$scope.datePicker =
|
||||||
format: Fablab.uibDateFormat
|
format: Fablab.uibDateFormat
|
||||||
opened: false # default: datePicker is not shown
|
opened: false # default: datePicker is not shown
|
||||||
|
minDate: moment().toDate()
|
||||||
options:
|
options:
|
||||||
startingDay: Fablab.weekStartingDay
|
startingDay: Fablab.weekStartingDay
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Shows the validity limit datepicker
|
# Shows/hides the validity limit datepicker
|
||||||
# @param $event {Object} jQuery event object
|
# @param $event {Object} jQuery event object
|
||||||
##
|
##
|
||||||
$scope.openDatePicker = ($event) ->
|
$scope.toggleDatePicker = ($event) ->
|
||||||
$event.preventDefault()
|
$event.preventDefault()
|
||||||
$event.stopPropagation()
|
$event.stopPropagation()
|
||||||
$scope.datePicker.opened = true
|
$scope.datePicker.opened = !$scope.datePicker.opened
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Callback to save the new coupon in $scope.coupon and redirect the user to the listing page
|
# Callback to save the new coupon in $scope.coupon and redirect the user to the listing page
|
||||||
@ -41,14 +42,67 @@ Application.Controllers.controller "NewCouponController", ["$scope", "$state",'C
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Controller used in the coupon edition page
|
# Controller used in the coupon edition page
|
||||||
##
|
##
|
||||||
Application.Controllers.controller "EditCouponController", ["$scope", 'Coupon', '_t'
|
Application.Controllers.controller "EditCouponController", ["$scope", "$state", 'Coupon', 'couponPromise', '_t'
|
||||||
, ($scope, Coupon, _t) ->
|
, ($scope, $state, Coupon, couponPromise, _t) ->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### PUBLIC SCOPE ###
|
### PUBLIC SCOPE ###
|
||||||
$scope.test = 'edit'
|
|
||||||
|
|
||||||
|
|
||||||
|
## Coupon to edit
|
||||||
|
$scope.coupon = couponPromise
|
||||||
|
|
||||||
|
## Default parameters for AngularUI-Bootstrap datepicker (used for coupon validity limit selection)
|
||||||
|
$scope.datePicker =
|
||||||
|
format: Fablab.uibDateFormat
|
||||||
|
opened: false # default: datePicker is not shown
|
||||||
|
minDate: moment().toDate()
|
||||||
|
options:
|
||||||
|
startingDay: Fablab.weekStartingDay
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# Shows/hides the validity limit datepicker
|
||||||
|
# @param $event {Object} jQuery event object
|
||||||
|
##
|
||||||
|
$scope.toggleDatePicker = ($event) ->
|
||||||
|
$event.preventDefault()
|
||||||
|
$event.stopPropagation()
|
||||||
|
$scope.datePicker.opened = !$scope.datePicker.opened
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# Callback to save the coupon's changes to the API
|
||||||
|
##
|
||||||
|
$scope.updateCoupon = ->
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### PRIVATE SCOPE ###
|
||||||
|
|
||||||
|
##
|
||||||
|
# Kind of constructor: these actions will be realized first when the controller is loaded
|
||||||
|
##
|
||||||
|
initialize = ->
|
||||||
|
# parse the date if any
|
||||||
|
if (couponPromise.valid_until)
|
||||||
|
$scope.coupon.valid_until = moment(couponPromise.valid_until).toDate()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## !!! MUST BE CALLED AT THE END of the controller
|
||||||
|
initialize()
|
||||||
]
|
]
|
@ -807,6 +807,9 @@ angular.module('application.router', ['ui.router']).
|
|||||||
templateUrl: '<%= asset_path "admin/coupons/edit.html" %>'
|
templateUrl: '<%= asset_path "admin/coupons/edit.html" %>'
|
||||||
controller: 'EditCouponController'
|
controller: 'EditCouponController'
|
||||||
resolve:
|
resolve:
|
||||||
|
couponPromise: ['Coupon', '$stateParams', (Coupon, $stateParams) ->
|
||||||
|
Coupon.get({id: $stateParams.id}).$promise
|
||||||
|
]
|
||||||
translations: [ 'Translations', (Translations) ->
|
translations: [ 'Translations', (Translations) ->
|
||||||
Translations.query(['app.admin.coupons_edit', 'app.shared.coupon']).$promise
|
Translations.query(['app.admin.coupons_edit', 'app.shared.coupon']).$promise
|
||||||
]
|
]
|
||||||
|
@ -38,14 +38,20 @@
|
|||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="coupon[valid_until]" translate>{{ 'valid_until' }}</label>
|
<label for="coupon[valid_until]" translate>{{ 'valid_until' }}</label>
|
||||||
<input type="text" id="coupon[valid_until]"
|
<div class="input-group">
|
||||||
name="coupon[valid_until]"
|
<input type="text" id="coupon[valid_until]"
|
||||||
class="form-control"
|
name="coupon[valid_until]"
|
||||||
ng-model="coupon.valid_until"
|
class="form-control"
|
||||||
uib-datepicker-popup="{{datePicker.format}}"
|
ng-model="coupon.valid_until"
|
||||||
datepicker-options="datePicker.options"
|
uib-datepicker-popup="{{datePicker.format}}"
|
||||||
is-open="datePicker.opened"
|
datepicker-options="datePicker.options"
|
||||||
ng-click="openDatePicker($event)"/>
|
is-open="datePicker.opened"
|
||||||
|
min-date="datePicker.minDate"
|
||||||
|
ng-click="toggleDatePicker($event)"/>
|
||||||
|
<span class="input-group-btn">
|
||||||
|
<button type="button" class="btn btn-default" ng-click="toggleDatePicker($event)"><i class="fa fa-calendar"></i></button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group" ng-class="{'has-error': couponForm['coupon[max_usages]'].$dirty && couponForm['coupon[max_usages]'].$invalid}">
|
<div class="form-group" ng-class="{'has-error': couponForm['coupon[max_usages]'].$dirty && couponForm['coupon[max_usages]'].$invalid}">
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
<ng-include src="'<%= asset_path 'admin/coupons/_form.html' %>'"></ng-include>
|
<ng-include src="'<%= asset_path 'admin/coupons/_form.html' %>'"></ng-include>
|
||||||
|
|
||||||
<div class="panel-footer no-padder">
|
<div class="panel-footer no-padder">
|
||||||
<input type="submit" value="{{ 'confirm_changes' | translate }}" class="r-b btn-valid btn btn-warning btn-block p-lg btn-lg text-u-c" ng-disabled="couponForm.$invalid"/>
|
<input type="button" value="{{ 'confirm_changes' | translate }}" class="r-b btn-valid btn btn-warning btn-block p-lg btn-lg text-u-c" ng-disabled="couponForm.$invalid" ng-click="updateCoupon()"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -162,6 +162,10 @@ fr:
|
|||||||
add_a_coupon: "Ajouter un code promotionnel"
|
add_a_coupon: "Ajouter un code promotionnel"
|
||||||
unable_to_create_the_coupon_an_error_occurred: "Impossible de créer le code promotionnel : une erreur est survenue."
|
unable_to_create_the_coupon_an_error_occurred: "Impossible de créer le code promotionnel : une erreur est survenue."
|
||||||
|
|
||||||
|
coupons_edit:
|
||||||
|
# mettre à jour un code promotionnel
|
||||||
|
unable_to_update_the_coupon_an_error_occurred: "Impossible de mettre à jour le code promotionnel : une erreur est survenue."
|
||||||
|
|
||||||
plans:
|
plans:
|
||||||
new:
|
new:
|
||||||
# ajouter une formule d'abonnement sur la plate-forme
|
# ajouter une formule d'abonnement sur la plate-forme
|
||||||
|
Loading…
x
Reference in New Issue
Block a user