diff --git a/app/assets/javascripts/controllers/admin/events.coffee b/app/assets/javascripts/controllers/admin/events.coffee index f9ff1a531..31364fb2a 100644 --- a/app/assets/javascripts/controllers/admin/events.coffee +++ b/app/assets/javascripts/controllers/admin/events.coffee @@ -7,7 +7,6 @@ # in the various events' admin controllers. # # Provides : -# - $scope.categories = [{Category}] # - $scope.datePicker = {} # - $scope.submited(content) # - $scope.cancel() @@ -23,13 +22,7 @@ # - $state (Ui-Router) [ 'app.public.events_list' ] ## class EventsController - constructor: ($scope, $state, Event, Category) -> - - ## Retrieve the list of categories from the server (course, workshop, ...) - Category.query().$promise.then (data)-> - $scope.categories = data.map (d) -> - id: d.id - name: d.name + constructor: ($scope, $state) -> ## default parameters for AngularUI-Bootstrap datepicker $scope.datePicker = @@ -286,8 +279,8 @@ Application.Controllers.controller "ShowEventReservationsController", ["$scope", ## # Controller used in the event creation page ## -Application.Controllers.controller "NewEventController", ["$scope", "$state", "$locale", 'Event', 'Category', 'CSRF', '_t' -, ($scope, $state, $locale, Event, Category, CSRF, _t) -> +Application.Controllers.controller "NewEventController", ["$scope", "$state", "$locale", 'CSRF', 'categoriesPromise', 'themesPromise', 'ageRangesPromise', '_t' +, ($scope, $state, $locale, CSRF, categoriesPromise, themesPromise, ageRangesPromise, _t) -> CSRF.setMetaTags() ## API URL where the form will be posted @@ -296,6 +289,15 @@ Application.Controllers.controller "NewEventController", ["$scope", "$state", "$ ## Form action on the above URL $scope.method = 'post' + ## List of categories for the events + $scope.categories = categoriesPromise + + ## List of events themes + $scope.themes = themesPromise + + ## List of age ranges + $scope.ageRanges = ageRangesPromise + ## Default event parameters $scope.event = event_files_attributes: [] @@ -320,7 +322,7 @@ Application.Controllers.controller "NewEventController", ["$scope", "$state", "$ $scope.currencySymbol = $locale.NUMBER_FORMATS.CURRENCY_SYM; ## Using the EventsController - new EventsController($scope, $state, Event, Category) + new EventsController($scope, $state) ] @@ -328,8 +330,8 @@ Application.Controllers.controller "NewEventController", ["$scope", "$state", "$ ## # Controller used in the events edition page ## -Application.Controllers.controller "EditEventController", ["$scope", "$state", "$stateParams", "$locale", 'Event', 'Category', 'CSRF', 'eventPromise' -, ($scope, $state, $stateParams, $locale, Event, Category, CSRF, eventPromise) -> +Application.Controllers.controller "EditEventController", ["$scope", "$state", "$stateParams", "$locale", 'CSRF', 'eventPromise', 'categoriesPromise', 'themesPromise', 'ageRangesPromise' +, ($scope, $state, $stateParams, $locale, CSRF, eventPromise, categoriesPromise, themesPromise, ageRangesPromise) -> ### PUBLIC SCOPE ### @@ -347,6 +349,15 @@ Application.Controllers.controller "EditEventController", ["$scope", "$state", " ## currency symbol for the current locale (cf. angular-i18n) $scope.currencySymbol = $locale.NUMBER_FORMATS.CURRENCY_SYM; + ## List of categories for the events + $scope.categories = categoriesPromise + + ## List of events themes + $scope.themes = themesPromise + + ## List of age ranges + $scope.ageRanges = ageRangesPromise + ### PRIVATE SCOPE ### @@ -364,7 +375,7 @@ Application.Controllers.controller "EditEventController", ["$scope", "$state", " $scope.event.end_date = moment($scope.event.end_date).toDate() ## Using the EventsController - new EventsController($scope, $state, Event, Category) + new EventsController($scope, $state) diff --git a/app/assets/javascripts/router.coffee.erb b/app/assets/javascripts/router.coffee.erb index 6b3f32cde..7138a3204 100644 --- a/app/assets/javascripts/router.coffee.erb +++ b/app/assets/javascripts/router.coffee.erb @@ -562,6 +562,15 @@ angular.module('application.router', ['ui.router']). templateUrl: '<%= asset_path "events/new.html" %>' controller: 'NewEventController' resolve: + categoriesPromise: ['Category', (Category) -> + Category.query().$promise + ] + themesPromise: ['EventTheme', (EventTheme) -> + EventTheme.query().$promise + ] + ageRangesPromise: ['AgeRange', (AgeRange) -> + AgeRange.query().$promise + ] translations: [ 'Translations', (Translations) -> Translations.query(['app.admin.events_new', 'app.shared.event']).$promise ] @@ -575,6 +584,15 @@ angular.module('application.router', ['ui.router']). eventPromise: ['Event', '$stateParams', (Event, $stateParams)-> Event.get(id: $stateParams.id).$promise ] + categoriesPromise: ['Category', (Category) -> + Category.query().$promise + ] + themesPromise: ['EventTheme', (EventTheme) -> + EventTheme.query().$promise + ] + ageRangesPromise: ['AgeRange', (AgeRange) -> + AgeRange.query().$promise + ] translations: [ 'Translations', (Translations) -> Translations.query(['app.admin.events_edit', 'app.shared.event']).$promise ] diff --git a/app/assets/templates/events/_form.html.erb b/app/assets/templates/events/_form.html.erb index 685ea8172..a00c014c0 100644 --- a/app/assets/templates/events/_form.html.erb +++ b/app/assets/templates/events/_form.html.erb @@ -80,7 +80,7 @@
-

{{ 'event_type' }}

+

{{ 'event_type' }} *

@@ -96,6 +96,40 @@
+
+
+

{{ 'event_theme' }}

+
+
+ + + + + + + + + + +
+
+ +
+
+

{{ 'age_range' }}

+
+
+ + + + + + + + + +
+

{{ 'dates_and_opening_hours' }}

diff --git a/app/controllers/api/events_controller.rb b/app/controllers/api/events_controller.rb index 8661801d1..b00f2abaa 100644 --- a/app/controllers/api/events_controller.rb +++ b/app/controllers/api/events_controller.rb @@ -64,7 +64,8 @@ class API::EventsController < API::ApiController 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, - :all_day, :recurrence, :recurrence_end_at, :category_ids, category_ids: [], + :all_day, :recurrence, :recurrence_end_at, :category_ids, :event_theme_ids, + :age_range_id, event_theme_ids: [], category_ids: [], event_image_attributes: [:attachment], event_files_attributes: [:id, :attachment, :_destroy]) start_date = Time.zone.parse(event_preparams[:start_date]) end_date = Time.zone.parse(event_preparams[:end_date]) diff --git a/app/views/api/events/_event.json.jbuilder b/app/views/api/events/_event.json.jbuilder index e630941b6..04ce57fc4 100644 --- a/app/views/api/events/_event.json.jbuilder +++ b/app/views/api/events/_event.json.jbuilder @@ -1,4 +1,4 @@ -json.extract! event, :id, :title, :description +json.extract! event, :id, :title, :description, :age_range_id json.event_image event.event_image.attachment_url if event.event_image json.event_files_attributes event.event_files do |f| json.id f.id @@ -10,6 +10,14 @@ json.categories event.categories do |c| json.id c.id json.name c.name end +json.event_theme_ids event.event_theme_ids +json.event_themes event.event_themes do |e| + json.name e.name +end +json.age_range_id event.age_range_id +json.age_range do + json.name event.age_range.name +end if event.age_range json.start_date event.availability.start_at json.start_time event.availability.start_at json.end_date event.availability.end_at @@ -28,3 +36,4 @@ json.amount (event.amount / 100.0) if event.amount json.reduced_amount (event.reduced_amount / 100.0) if event.reduced_amount json.nb_total_places event.nb_total_places json.nb_free_places event.nb_free_places || event.nb_total_places + diff --git a/config/locales/app.shared.en.yml b/config/locales/app.shared.en.yml index b30ae8140..21180f4cd 100644 --- a/config/locales/app.shared.en.yml +++ b/config/locales/app.shared.en.yml @@ -184,6 +184,8 @@ en: standard_rate: "Standard rate" 0_=_free: "0 = free" tickets_available: "Tickets available" + event_theme: "Event theme" + age_range: "Age range" plan: # subscription plan edition form diff --git a/config/locales/app.shared.fr.yml b/config/locales/app.shared.fr.yml index a4716f1d9..93df97090 100644 --- a/config/locales/app.shared.fr.yml +++ b/config/locales/app.shared.fr.yml @@ -184,6 +184,8 @@ fr: standard_rate: "Tarif standard" 0_=_free: "0 = gratuit" tickets_available: "Places disponibles" + event_theme: "Thème de l'évènement" + age_range: "Tranche d'âge" plan: # formulaire d'édition d'une formule d'abonnement