mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-29 10:24:20 +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'
|
||||
, ($scope, $state, Coupon, growl, _t) ->
|
||||
|
||||
|
||||
|
||||
### PUBLIC SCOPE ###
|
||||
|
||||
## Values for the coupon currently created
|
||||
$scope.coupon =
|
||||
active: true
|
||||
@ -17,17 +13,22 @@ Application.Controllers.controller "NewCouponController", ["$scope", "$state",'C
|
||||
$scope.datePicker =
|
||||
format: Fablab.uibDateFormat
|
||||
opened: false # default: datePicker is not shown
|
||||
minDate: moment().toDate()
|
||||
options:
|
||||
startingDay: Fablab.weekStartingDay
|
||||
|
||||
|
||||
|
||||
##
|
||||
# Shows the validity limit datepicker
|
||||
# Shows/hides the validity limit datepicker
|
||||
# @param $event {Object} jQuery event object
|
||||
##
|
||||
$scope.openDatePicker = ($event) ->
|
||||
$scope.toggleDatePicker = ($event) ->
|
||||
$event.preventDefault()
|
||||
$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
|
||||
@ -41,14 +42,67 @@ Application.Controllers.controller "NewCouponController", ["$scope", "$state",'C
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
##
|
||||
# Controller used in the coupon edition page
|
||||
##
|
||||
Application.Controllers.controller "EditCouponController", ["$scope", 'Coupon', '_t'
|
||||
, ($scope, Coupon, _t) ->
|
||||
|
||||
|
||||
Application.Controllers.controller "EditCouponController", ["$scope", "$state", 'Coupon', 'couponPromise', '_t'
|
||||
, ($scope, $state, Coupon, couponPromise, _t) ->
|
||||
|
||||
### 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" %>'
|
||||
controller: 'EditCouponController'
|
||||
resolve:
|
||||
couponPromise: ['Coupon', '$stateParams', (Coupon, $stateParams) ->
|
||||
Coupon.get({id: $stateParams.id}).$promise
|
||||
]
|
||||
translations: [ 'Translations', (Translations) ->
|
||||
Translations.query(['app.admin.coupons_edit', 'app.shared.coupon']).$promise
|
||||
]
|
||||
|
@ -38,14 +38,20 @@
|
||||
|
||||
<div class="form-group">
|
||||
<label for="coupon[valid_until]" translate>{{ 'valid_until' }}</label>
|
||||
<input type="text" id="coupon[valid_until]"
|
||||
name="coupon[valid_until]"
|
||||
class="form-control"
|
||||
ng-model="coupon.valid_until"
|
||||
uib-datepicker-popup="{{datePicker.format}}"
|
||||
datepicker-options="datePicker.options"
|
||||
is-open="datePicker.opened"
|
||||
ng-click="openDatePicker($event)"/>
|
||||
<div class="input-group">
|
||||
<input type="text" id="coupon[valid_until]"
|
||||
name="coupon[valid_until]"
|
||||
class="form-control"
|
||||
ng-model="coupon.valid_until"
|
||||
uib-datepicker-popup="{{datePicker.format}}"
|
||||
datepicker-options="datePicker.options"
|
||||
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 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>
|
||||
|
||||
<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>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -162,6 +162,10 @@ fr:
|
||||
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."
|
||||
|
||||
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:
|
||||
new:
|
||||
# ajouter une formule d'abonnement sur la plate-forme
|
||||
|
Loading…
Reference in New Issue
Block a user