1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

associate custom price categories to an event

This commit is contained in:
Sylvain 2016-08-25 13:16:47 +02:00
parent bca77559ed
commit 7dc359e4ee
6 changed files with 62 additions and 9 deletions

View File

@ -371,8 +371,8 @@ Application.Controllers.controller "ShowEventReservationsController", ["$scope",
##
# Controller used in the event creation page
##
Application.Controllers.controller "NewEventController", ["$scope", "$state", "$locale", 'CSRF', 'categoriesPromise', 'themesPromise', 'ageRangesPromise', '_t'
, ($scope, $state, $locale, CSRF, categoriesPromise, themesPromise, ageRangesPromise, _t) ->
Application.Controllers.controller "NewEventController", ["$scope", "$state", "$locale", 'CSRF', 'categoriesPromise', 'themesPromise', 'ageRangesPromise', 'priceCategoriesPromise', '_t'
, ($scope, $state, $locale, CSRF, categoriesPromise, themesPromise, ageRangesPromise, priceCategoriesPromise, _t) ->
CSRF.setMetaTags()
## API URL where the form will be posted
@ -390,6 +390,12 @@ Application.Controllers.controller "NewEventController", ["$scope", "$state", "$
## List of age ranges
$scope.ageRanges = ageRangesPromise
## List of availables price's categories
$scope.priceCategories = priceCategoriesPromise
## List of additional prices for the event
$scope.prices = []
## Default event parameters
$scope.event =
event_files_attributes: []
@ -413,6 +419,18 @@ Application.Controllers.controller "NewEventController", ["$scope", "$state", "$
## currency symbol for the current locale (cf. angular-i18n)
$scope.currencySymbol = $locale.NUMBER_FORMATS.CURRENCY_SYM;
##
# Initialize a new price item in the additional prices list
##
$scope.addPrice = ->
$scope.prices.push({
category: null,
amount: null,
})
## Using the EventsController
new EventsController($scope, $state)
]

View File

@ -675,6 +675,9 @@ angular.module('application.router', ['ui.router']).
ageRangesPromise: ['AgeRange', (AgeRange) ->
AgeRange.query().$promise
]
priceCategoriesPromise: ['PriceCategory', (PriceCategory) ->
PriceCategory.query().$promise
]
translations: [ 'Translations', (Translations) ->
Translations.query(['app.admin.events_new', 'app.shared.event']).$promise
]

View File

@ -569,3 +569,13 @@ padding: 10px;
}
}
.link-icon {
color: #1c94c4;
i { margin: 0 5px 0 10px; }
span {
border-bottom: 1px dashed #00b3ee;
text-decoration: none;
cursor: pointer;
}
}

View File

@ -237,15 +237,30 @@
<span class="help-block" translate>{{ '0_=_free' }}</span>
</div>
</div>
<div class="form-group">
<label for="event_reduced_amount" class="col-sm-5 control-label" translate>{{ 'reduced_rate' }}</label>
<div class="form-group" ng-repeat="price in prices">
<div class="col-sm-5">
<select class="form-control"
ng-model="price.category"
name="event[event_price_categories_attributes][][price_category_id]"
ng-options="cat as cat.name for cat in priceCategories track by cat.id">
</select>
</div>
<div class="col-sm-5">
<div class="input-group">
<input ng-model="event.reduced_amount" type="number" name="event[reduced_amount]" class="form-control" id="event_reduced_amount">
<input ng-model="price.amount"
type="number"
name="event[event_price_categories_attributes][][amount]"
class="form-control"
id="event_reduced_amount">
<div class="input-group-addon">{{currencySymbol}}</div>
</div>
</div>
</div>
<div class="link-icon m-b" ng-hide="prices.length == priceCategories.length">
<div class="col-sm-offset-5">
<i class="fa fa-plus"></i> <span ng-click="addPrice()">Ajouter un tarif</span>
</div>
</div>
<div class="form-group">
<label for="event_nb_total_places" class="col-sm-5 control-label" translate>{{ 'tickets_available' }}</label>
<div class="col-sm-6">

View File

@ -63,10 +63,13 @@ class API::EventsController < API::ApiController
# Never trust parameters from the scary internet, only allow the white list through.
def event_params
event_preparams = params.required(:event).permit(:title, :description, :start_date, :start_time, :end_date, :end_time,
:amount, :reduced_amount, :nb_total_places, :availability_id,
:amount, :nb_total_places, :availability_id,
:all_day, :recurrence, :recurrence_end_at, :category_id, :event_theme_ids,
:age_range_id, event_theme_ids: [],
event_image_attributes: [:attachment], event_files_attributes: [:id, :attachment, :_destroy])
event_image_attributes: [:attachment],
event_files_attributes: [:id, :attachment, :_destroy],
event_price_categories_attributes: [:id, :price_category_id, :amount]
)
start_date = Time.zone.parse(event_preparams[:start_date])
end_date = Time.zone.parse(event_preparams[:end_date])
start_time = Time.parse(event_preparams[:start_time]) if event_preparams[:start_time]
@ -80,8 +83,11 @@ class API::EventsController < API::ApiController
end
event_preparams.merge!(availability_attributes: {id: event_preparams[:availability_id], start_at: start_at, end_at: end_at, available_type: 'event'})
.except!(:start_date, :end_date, :start_time, :end_time, :all_day)
event_preparams.merge!(amount: (event_preparams[:amount].to_i * 100 if event_preparams[:amount].present?),
reduced_amount: (event_preparams[:reduced_amount].to_i * 100 if event_preparams[:reduced_amount].present?))
event_preparams.merge!(amount: (event_preparams[:amount].to_i * 100 if event_preparams[:amount].present?))
event_preparams[:event_price_categories_attributes].each do |price_cat|
price_cat[:amount] = price_cat[:amount].to_i * 100
end
event_preparams
end

View File

@ -12,6 +12,7 @@ class Event < ActiveRecord::Base
has_many :event_price_categories
has_many :price_categories, through: :event_price_categories
accepts_nested_attributes_for :event_price_categories, allow_destroy: true
belongs_to :age_range