1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00

update event recurrent

This commit is contained in:
Du Peng 2020-01-29 17:20:19 +01:00
parent de02bb1c72
commit 35d9bec8a5
8 changed files with 118 additions and 52 deletions

View File

@ -56,14 +56,7 @@ class EventsController {
* @param content {Object} JSON - The upload's result
*/
$scope.submited = function (content) {
if ((content.id == null)) {
$scope.alerts = [];
angular.forEach(content, function (v, k) {
angular.forEach(v, function (err) { $scope.alerts.push({ msg: k + ': ' + err, type: 'danger' }); });
});
} else {
$state.go('app.public.events_list');
}
$scope.onSubmited(content);
};
/**
@ -490,6 +483,17 @@ Application.Controllers.controller('NewEventController', ['$scope', '$state', 'C
{ label: _t('app.admin.events_new.every_year'), value: 'year' }
];
$scope.onSubmited = function(content) {
if ((content.id == null)) {
$scope.alerts = [];
angular.forEach(content, function (v, k) {
angular.forEach(v, function (err) { $scope.alerts.push({ msg: k + ': ' + err, type: 'danger' }); });
});
} else {
$state.go('app.public.events_list');
}
};
// Using the EventsController
return new EventsController($scope, $state);
}
@ -498,8 +502,8 @@ Application.Controllers.controller('NewEventController', ['$scope', '$state', 'C
/**
* Controller used in the events edition page
*/
Application.Controllers.controller('EditEventController', ['$scope', '$state', '$stateParams', 'CSRF', 'eventPromise', 'categoriesPromise', 'themesPromise', 'ageRangesPromise', 'priceCategoriesPromise', '$uibModal',
function ($scope, $state, $stateParams, CSRF, eventPromise, categoriesPromise, themesPromise, ageRangesPromise, priceCategoriesPromise, $uibModal) {
Application.Controllers.controller('EditEventController', ['$scope', '$state', '$stateParams', 'CSRF', 'eventPromise', 'categoriesPromise', 'themesPromise', 'ageRangesPromise', 'priceCategoriesPromise', '$uibModal', 'growl', '_t',
function ($scope, $state, $stateParams, CSRF, eventPromise, categoriesPromise, themesPromise, ageRangesPromise, priceCategoriesPromise, $uibModal, growl, _t) {
/* PUBLIC SCOPE */
// API URL where the form will be posted
@ -529,7 +533,7 @@ Application.Controllers.controller('EditEventController', ['$scope', '$state', '
// show edit mode modal if event is recurrence
$scope.isShowEditModeModal = $scope.event.recurrence_events.length > 0;
$scope.editRecurrent = async function (e) {
$scope.editRecurrent = function (e) {
if ($scope.isShowEditModeModal && $scope.event.recurrence_events.length > 0) {
e.preventDefault();
@ -552,6 +556,51 @@ Application.Controllers.controller('EditEventController', ['$scope', '$state', '
}
};
$scope.onSubmited = function(data) {
if (data.total === data.updated) {
if (data.updated > 1) {
growl.success(_t(
'app.admin.events_edit.events_updated',
{COUNT: data.updated - 1}
));
} else {
growl.success(_t(
'app.admin.events_edit.event_successfully_updated'
));
}
} else {
if (data.total > 1) {
growl.warning(_t(
'app.admin.events_edit.events_not_updated',
{TOTAL: data.total, COUNT: data.total - data.updated}
));
if (_.find(data.details, { error: 'EventPriceCategory' })) {
growl.error(_t(
'app.admin.events_edit.error_deleting_reserved_price'
));
} else {
growl.error(_t(
'app.admin.events_edit.other_error'
));
}
} else {
growl.error(_t(
'app.admin.events_edit.unable_to_update_the_event'
));
if (data.details[0].error === 'EventPriceCategory') {
growl.error(_t(
'app.admin.events_edit.error_deleting_reserved_price'
));
} else {
growl.error(_t(
'app.admin.events_edit.other_error'
));
}
}
}
$state.go('app.public.events_list');
};
/* PRIVATE SCOPE */
/**

View File

@ -1,21 +1,21 @@
<div class="modal-header">
<img ng-src="{{logoBlack.custom_asset_file_attributes.attachment_url}}" alt="{{logo.custom_asset_file_attributes.attachment}}" class="modal-logo"/>
<h1 translate>{{ 'app.admin.events.confirmation_required' }}</h1>
<h1 translate>{{ 'app.admin.events_edit.confirmation_required' }}</h1>
</div>
<div class="modal-body">
<p translate>{{ 'app.admin.events.edit_recurring_event' }}</p>
<p translate>{{ 'app.admin.events_edit.edit_recurring_event' }}</p>
<div class="form-group">
<label class="checkbox">
<input type="radio" name="edit_mode" ng-model="editMode" value="single" required/>
<span translate>{{ 'app.admin.events.edit_this_event' }}</span>
<span translate>{{ 'app.admin.events_edit.edit_this_event' }}</span>
</label>
<label class="checkbox">
<input type="radio" name="edit_mode" ng-model="editMode" value="next" required/>
<span translate>{{ 'app.admin.events.edit_this_and_next' }}</span>
<span translate>{{ 'app.admin.events_edit.edit_this_and_next' }}</span>
</label>
<label class="checkbox">
<input type="radio" name="edit_mode" ng-model="editMode" value="all" required/>
<span translate>{{ 'app.admin.events.edit_all' }}</span>
<span translate>{{ 'app.admin.events_edit.edit_all' }}</span>
</label>
</div>
</div>

View File

@ -55,22 +55,8 @@ class API::EventsController < API::ApiController
def update
authorize Event
begin
res = EventService.update(@event, event_params.permit!, params[:edit_mode])
if res.all? { |r| r[:status] }
render :show, status: :ok, location: @event
else
render json: { total: res.length, updated: res.select { |r| r[:status] }.length, details: res }, 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
res = EventService.update(@event, event_params.permit!, params[:edit_mode])
render json: { action: 'update', total: res.length, updated: res.select { |r| r[:status] }.length, details: res }, status: :ok, location: @event
end
def destroy

View File

@ -123,6 +123,13 @@ class EventService
amount: epca['amount'],
_destroy: epca['_destroy']
)
else
event_price = event.event_price_categories.find(epca['id'])
epc_attributes.push(
price_category_id: epca['price_category_id'],
amount: event_price.amount,
_destroy: ''
)
end
end
end

View File

@ -217,11 +217,6 @@ en:
do_you_really_want_to_delete_this_price_category: "Do you really want to delete this price category?"
price_category_successfully_deleted: "Price category successfully deleted."
price_category_deletion_failed: "Price category deletion failed."
confirmation_required: "Confirmation required"
edit_recurring_event: "What do you want to update this periodic event ?"
edit_this_event: "Only this event"
edit_this_and_next: "This event and the following"
edit_all: "All events"
events_new:
# add a new event
@ -235,6 +230,17 @@ en:
events_edit:
# edit an existing event
edit_the_event: "Edit the event"
confirmation_required: "Confirmation required"
edit_recurring_event: "What do you want to update this periodic event ?"
edit_this_event: "Only this event"
edit_this_and_next: "This event and the following"
edit_all: "All events"
event_successfully_updated: "Event successfully updated"
events_updated: "The event, and {COUNT, plural, =1{one other} other{{COUNT} others}}, have been updated"
unable_to_update_the_event: "Unable to update the event"
events_not_updated: "On {TOTAL} events, {COUNT, plural, =1{one was not updated} other{{COUNT} were not deleted}}."
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"
event_reservations:
# event reservations list

View File

@ -217,11 +217,6 @@ es:
do_you_really_want_to_delete_this_price_category: "¿Desea realmente eliminar esta categoría de precios?"
price_category_successfully_deleted: "Categoría de precio eliminada correctamente."
price_category_deletion_failed: "Error al eliminar la categoría de precio."
confirmation_required: "Confirmation required"
edit_recurring_event: "What do you want to update this periodic event ?"
edit_this_event: "Only this event"
edit_this_and_next: "This event and the following"
edit_all: "All events"
events_new:
# add a new event
@ -235,6 +230,17 @@ es:
events_edit:
# edit an existing event
edit_the_event: "Editar el evento"
confirmation_required: "Confirmation required"
edit_recurring_event: "What do you want to update this periodic event ?"
edit_this_event: "Only this event"
edit_this_and_next: "This event and the following"
edit_all: "All events"
event_successfully_updated: "Event successfully updated"
events_updated: "The event, and {COUNT, plural, =1{one other} other{{COUNT} others}}, have been updated"
unable_to_update_the_event: "Unable to update the event"
events_not_updated: "On {TOTAL} events, {COUNT, plural, =1{one was not updated} other{{COUNT} were not deleted}}."
error_deleting_reserved_price: "No se puede eliminar el precio solicitado porque está asociado con algunas reservas."
other_error: "Se ha producido un error inesperado al actualizar el evento."
event_reservations:
# event reservations list

View File

@ -217,11 +217,6 @@ fr:
do_you_really_want_to_delete_this_price_category: "Êtes vous sur de vouloir supprimer cette catégorie tarifaire ?"
price_category_successfully_deleted: "Catégorie tarifaire supprimée avec succès."
price_category_deletion_failed: "Échec de la suppression de la catégorie tarifaire."
confirmation_required: "Confirmation requise"
edit_recurring_event: "Que voulez-vous modifier cet évènement périodique ?"
edit_this_event: "Uniquement cet évènement"
edit_this_and_next: "Cet évènement et tous les suivants"
edit_all: "Tous les évènements"
events_new:
# ajouter un nouvel évènement
@ -235,6 +230,17 @@ fr:
events_edit:
# modifier un évènement existant
edit_the_event: "Éditer l'évènement"
confirmation_required: "Confirmation requise"
edit_recurring_event: "Que voulez-vous modifier cet évènement périodique ?"
edit_this_event: "Uniquement cet évènement"
edit_this_and_next: "Cet évènement et tous les suivants"
edit_all: "Tous les évènements"
event_successfully_updated: "L'évènement a bien été modifié."
events_updated: "L'évènement, ainsi {COUNT, plural, =1{qu'un autre} other{que {COUNT} autres}}, ont été modifiés"
unable_to_update_the_event: "L'évènement n'a pu être modifié"
events_not_updated: "Sur {TOTAL} évènements, {COUNT, plural, =1{un n'a pas pu être modifié} other{{COUNT} n'ont pas pu être modifiés}}."
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"
event_reservations:
# liste des réservations sur un évènement

View File

@ -217,11 +217,6 @@ pt:
do_you_really_want_to_delete_this_price_category: "Você realmente quer deletar este preço de categoria?"
price_category_successfully_deleted: "Preço de categoria deletado com sucesso."
price_category_deletion_failed: "Falha ao deletar preço de categoria."
confirmation_required: "Confirmation required"
edit_recurring_event: "What do you want to update this periodic event ?"
edit_this_event: "Only this event"
edit_this_and_next: "This event and the following"
edit_all: "All events"
events_new:
# add a new event
@ -235,6 +230,17 @@ pt:
events_edit:
# edit an existing event
edit_the_event: "Editar evento"
confirmation_required: "Confirmation required"
edit_recurring_event: "What do you want to update this periodic event ?"
edit_this_event: "Only this event"
edit_this_and_next: "This event and the following"
edit_all: "All events"
event_successfully_updated: "Event successfully updated"
events_updated: "The event, and {COUNT, plural, =1{one other} other{{COUNT} others}}, have been updated"
unable_to_update_the_event: "Unable to update the event"
events_not_updated: "On {TOTAL} events, {COUNT, plural, =1{one was not updated} other{{COUNT} were not deleted}}."
error_deleting_reserved_price: "Não permitido deletar o preço requisitado, pois está associado a algumas reservas"
other_error: "Um erro inesperado ocorreu enquanto o evento era atualizado"
event_reservations:
# event reservations list