mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
edit event recurrent in progress
This commit is contained in:
parent
22b6560baf
commit
b1419271e6
@ -498,8 +498,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',
|
||||
function ($scope, $state, $stateParams, CSRF, eventPromise, categoriesPromise, themesPromise, ageRangesPromise, priceCategoriesPromise) {
|
||||
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) {
|
||||
/* PUBLIC SCOPE */
|
||||
|
||||
// API URL where the form will be posted
|
||||
@ -523,6 +523,35 @@ Application.Controllers.controller('EditEventController', ['$scope', '$state', '
|
||||
// List of age ranges
|
||||
$scope.ageRanges = ageRangesPromise;
|
||||
|
||||
// Default edit mode for periodic event
|
||||
$scope.editMode = 'single';
|
||||
|
||||
// show edit mode modal if event is recurrence
|
||||
$scope.isShowEditModeModal = $scope.event.recurrence_events.length > 0;
|
||||
|
||||
$scope.editRecurrent = async function (e) {
|
||||
if ($scope.isShowEditModeModal && $scope.event.recurrence_events.length > 0) {
|
||||
e.preventDefault();
|
||||
|
||||
// open a choice edit mode dialog
|
||||
const modalInstance = $uibModal.open({
|
||||
animation: true,
|
||||
templateUrl: '<%= asset_path "events/editRecurrent.html" %>',
|
||||
size: 'md',
|
||||
controller: 'EditRecurrentEventController',
|
||||
resolve: {
|
||||
editMode: function () { return $scope.editMode; }
|
||||
}
|
||||
});
|
||||
// submit form event by edit mode
|
||||
modalInstance.result.then(function(res) {
|
||||
$scope.isShowEditModeModal = false;
|
||||
$scope.editMode = res.editMode;
|
||||
e.target.click();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/* PRIVATE SCOPE */
|
||||
|
||||
/**
|
||||
@ -543,3 +572,29 @@ Application.Controllers.controller('EditEventController', ['$scope', '$state', '
|
||||
return initialize();
|
||||
}
|
||||
]);
|
||||
|
||||
/**
|
||||
* Controller used in the event edit mode modal window
|
||||
*/
|
||||
Application.Controllers.controller('EditRecurrentEventController', ['$scope', '$uibModalInstance', 'editMode', 'growl', '_t',
|
||||
function ($scope, $uibModalInstance, editMode, growl, _t) {
|
||||
// with recurrent slots: how many slots should we update?
|
||||
$scope.editMode = editMode;
|
||||
|
||||
/**
|
||||
* Confirmation callback
|
||||
*/
|
||||
$scope.ok = function () {
|
||||
$uibModalInstance.close({
|
||||
editMode: $scope.editMode,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancellation callback
|
||||
*/
|
||||
$scope.cancel = function () {
|
||||
$uibModalInstance.dismiss('cancel');
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
@ -77,11 +77,13 @@
|
||||
|
||||
|
||||
</div> <!-- ./panel-body -->
|
||||
<input ng-model="editMode" type="hidden" name="edit_mode">
|
||||
<div class="panel-footer no-padder">
|
||||
<input type="submit"
|
||||
ng-value="submitName"
|
||||
class="r-b btn-valid btn btn-warning btn-block p-lg btn-lg text-u-c"
|
||||
ng-disabled="eventForm.$invalid || event.category_id === null"/>
|
||||
ng-value="submitName"
|
||||
class="r-b btn-valid btn btn-warning btn-block p-lg btn-lg text-u-c"
|
||||
ng-disabled="eventForm.$invalid || event.category_id === null"
|
||||
ng-click="editRecurrent($event)"/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
</section>
|
||||
|
||||
|
||||
<form role="form" name="eventForm" class="form-horizontal" novalidate action="{{ actionUrl }}" ng-upload="submited(content)" upload-options-enable-rails-csrf="true">
|
||||
<form role="form" name="eventForm" class="form-horizontal" novalidate action="{{ actionUrl }}" ng-upload="submited(content)" upload-options-enable-rails-csrf="true" upload-options-convert-hidden="true">
|
||||
|
||||
<ng-include src="'<%= asset_path "events/_form.html" %>'"></ng-include>
|
||||
|
||||
|
25
app/assets/templates/events/editRecurrent.html
Normal file
25
app/assets/templates/events/editRecurrent.html
Normal file
@ -0,0 +1,25 @@
|
||||
<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>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p translate>{{ 'app.admin.events.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>
|
||||
</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>
|
||||
</label>
|
||||
<label class="checkbox">
|
||||
<input type="radio" name="edit_mode" ng-model="editMode" value="all" required/>
|
||||
<span translate>{{ 'app.admin.events.edit_all' }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-info" ng-click="ok()" translate>{{ 'app.shared.buttons.apply' }}</button>
|
||||
<button class="btn btn-default" ng-click="cancel()" translate>{{ 'app.shared.buttons.cancel' }}</button>
|
||||
</div>
|
@ -56,10 +56,11 @@ class API::EventsController < API::ApiController
|
||||
def update
|
||||
authorize Event
|
||||
begin
|
||||
if @event.update(event_params.permit!)
|
||||
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: @event.errors, status: :unprocessable_entity
|
||||
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'
|
||||
|
@ -72,4 +72,39 @@ class EventService
|
||||
end
|
||||
results
|
||||
end
|
||||
|
||||
# update one or more events (if periodic)
|
||||
def self.update(event, event_params, mode = 'single')
|
||||
results = []
|
||||
events = case mode
|
||||
when 'single'
|
||||
[event]
|
||||
when 'next'
|
||||
Event.includes(:availability)
|
||||
.where(
|
||||
'availabilities.start_at >= ? AND events.recurrence_id = ?',
|
||||
event.availability.start_at,
|
||||
event.recurrence_id
|
||||
)
|
||||
.references(:availabilities, :events)
|
||||
when 'all'
|
||||
Event.where(
|
||||
'recurrence_id = ?',
|
||||
event.recurrence_id
|
||||
)
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
||||
events.each do |e|
|
||||
if e.id == event.id
|
||||
results.push status: !!e.update(event_params), event: e # rubocop:disable Style/DoubleNegation
|
||||
else
|
||||
puts '------------'
|
||||
puts e.id
|
||||
puts event_params
|
||||
end
|
||||
end
|
||||
results
|
||||
end
|
||||
end
|
||||
|
@ -217,6 +217,11 @@ 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
|
||||
|
@ -217,6 +217,11 @@ 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
|
||||
|
@ -217,6 +217,11 @@ 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
|
||||
|
@ -217,6 +217,11 @@ 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user