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 @@
+ + +