1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-29 18:52:22 +01:00

ability to remove an unused custom price for an event (#61)

This commit is contained in:
Sylvain 2017-03-02 18:34:55 +01:00
parent 0f6358011f
commit 796f0a87ae
8 changed files with 56 additions and 8 deletions

View File

@ -1,6 +1,7 @@
# Changelog Fab Manager
## next release (v2.5.0)
- Ability to remove an unused custom price for an event (#61)
- Prevent polling notifications when the application is in background
- Ability to export the availabilities and their reservation rate from the admin calendar
- Ability to create, manage and reserve spaces

View File

@ -16,6 +16,8 @@
# - $scope.toggleStartDatePicker($event)
# - $scope.toggleEndDatePicker($event)
# - $scope.toggleRecurrenceEnd(e)
# - $scope.addPrice()
# - $scope.removePrice(price, $event)
#
# Requires :
# - $scope.event.event_files_attributes = []
@ -137,6 +139,21 @@ class EventsController
##
# Remove the price or mark it as 'to delete'
##
$scope.removePrice = (price, event) ->
event.preventDefault()
event.stopPropagation()
if price.id
price._destroy = true
else
index = $scope.event.prices.indexOf(price)
$scope.event.prices.splice(index, 1)
##
# Controller used in the events listing page (admin view)
##

View File

@ -246,7 +246,7 @@
<span class="help-block" translate>{{ '0_=_free' }}</span>
</div>
</div>
<div class="form-group" ng-repeat="price in event.prices">
<div class="form-group" ng-repeat="price in event.prices" ng-show="!price._destroy">
<div class="col-sm-5">
<input type="hidden" name="event[event_price_categories_attributes][][id]" ng-value="price.id">
<select class="form-control"
@ -264,6 +264,10 @@
<div class="input-group-addon">{{currencySymbol}}</div>
</div>
</div>
<div class="col-sm-1">
<input type="hidden" name="event[event_price_categories_attributes][][_destroy]" ng-value="price._destroy">
<a class="btn" ng-click="removePrice(price, $event)" href="#"><i class="fa fa-times text-danger"></i></a>
</div>
</div>
<div class="link-icon m-b" ng-hide="event.prices.length == priceCategories.length">
<div class="col-sm-offset-5">

View File

@ -12,7 +12,6 @@ class API::EventsController < API::ApiController
# paginate
@events = @events.page(@page).per(12)
end
# GET /events/upcoming/:limit
@ -38,11 +37,20 @@ class API::EventsController < API::ApiController
def update
authorize Event
if @event.update(event_params.permit!)
render :show, status: :ok, location: @event
else
render json: @event.errors, status: :unprocessable_entity
begin
if @event.update(event_params.permit!)
render :show, status: :ok, location: @event
else
render json: @event.errors, status: :unprocessable_entity
end
rescue ActiveRecord::RecordNotDestroyed => e
if e.record.class.name == 'EventPriceCategory'
render json: {error: ["#{e.record.price_category.name}: #{t('events.error_deleting_reserved_price')}"]}, status: :unprocessable_entity
else
render json: {error: [t('events.other_error')]}, status: :unprocessable_entity
end
end
end
def destroy
@ -69,7 +77,7 @@ class API::EventsController < API::ApiController
:age_range_id, event_theme_ids: [],
event_image_attributes: [:attachment],
event_files_attributes: [:id, :attachment, :_destroy],
event_price_categories_attributes: [:id, :price_category_id, :amount]
event_price_categories_attributes: [:id, :price_category_id, :amount, :_destroy]
)
# handle dates & times (whole-day events or not, maybe during many days)
start_date = Time.zone.parse(event_preparams[:start_date])

View File

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

View File

@ -6,4 +6,12 @@ class EventPriceCategory < ActiveRecord::Base
validates :price_category_id, presence: true
validates :amount, presence: true
before_destroy :verify_no_associated_tickets
protected
def verify_no_associated_tickets
tickets.count == 0
end
end

View File

@ -124,6 +124,11 @@ en:
i_ve_reserved: "I've reserved"
completed: "Full"
events:
# error messages when updating an event
error_deleting_reserved_price: "Unable to delete the requested price because it is associated with some reservations"
other_error: "An unexpected error occurred while updating the event"
export_members:
# members list export to EXCEL format
members: "Members"

View File

@ -124,6 +124,11 @@ fr:
i_ve_reserved: "J'ai réservé"
completed: "Complet"
events:
# messages d'erreur lors de la mise à jour d'un évènement
error_deleting_reserved_price: "Impossible de supprimer le tarif demandé car il est associé à des réservations"
other_error: "Une erreur inattendue est survenue lors de la mise à jour de l'évènement"
export_members:
# export de la liste des members au format EXCEL
members: "Membres"