diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/admin_public_body_categories_controller.rb | 44 | ||||
-rw-r--r-- | app/controllers/admin_public_body_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/admin_public_body_headings_controller.rb | 63 |
3 files changed, 63 insertions, 56 deletions
diff --git a/app/controllers/admin_public_body_categories_controller.rb b/app/controllers/admin_public_body_categories_controller.rb index 5e305dde3..a86171c76 100644 --- a/app/controllers/admin_public_body_categories_controller.rb +++ b/app/controllers/admin_public_body_categories_controller.rb @@ -7,17 +7,39 @@ class AdminPublicBodyCategoriesController < AdminController def new @category = PublicBodyCategory.new - render :formats => [:html] + @category.build_all_translations + end + + def create + I18n.with_locale(I18n.default_locale) do + @category = PublicBodyCategory.new(params[:public_body_category]) + if @category.save + # FIXME: This can't handle failure (e.g. if a PublicBodyHeading + # doesn't exist) + if params[:headings] + params[:headings].values.each do |heading_id| + PublicBodyHeading.find(heading_id).add_category(@category) + end + end + flash[:notice] = 'Category was successfully created.' + redirect_to admin_categories_path + else + @category.build_all_translations + render :action => 'new' + end + end end def edit @category = PublicBodyCategory.find(params[:id]) + @category.build_all_translations @tagged_public_bodies = PublicBody.find_by_tag(@category.category_tag) end def update @category = PublicBodyCategory.find(params[:id]) @tagged_public_bodies = PublicBody.find_by_tag(@category.category_tag) + heading_ids = [] I18n.with_locale(I18n.default_locale) do @@ -43,6 +65,8 @@ class AdminPublicBodyCategoriesController < AdminController end added_headings.each do |heading_id| + # FIXME: This can't handle failure (e.g. if a + # PublicBodyHeading doesn't exist) PublicBodyHeading.find(heading_id).add_category(@category) end end @@ -51,29 +75,13 @@ class AdminPublicBodyCategoriesController < AdminController flash[:notice] = 'Category was successfully updated.' redirect_to edit_admin_category_path(@category) else + @category.build_all_translations render :action => 'edit' end end end end - def create - I18n.with_locale(I18n.default_locale) do - @category = PublicBodyCategory.new(params[:public_body_category]) - if @category.save - if params[:headings] - params[:headings].values.each do |heading_id| - PublicBodyHeading.find(heading_id).add_category(@category) - end - end - flash[:notice] = 'Category was successfully created.' - redirect_to admin_categories_path - else - render :action => 'new' - end - end - end - def destroy @locale = self.locale_from_params I18n.with_locale(@locale) do diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb index d188f109d..7de27121a 100644 --- a/app/controllers/admin_public_body_controller.rb +++ b/app/controllers/admin_public_body_controller.rb @@ -23,10 +23,7 @@ class AdminPublicBodyController < AdminController def new @public_body = PublicBody.new - - I18n.available_locales.each do |locale| - @public_body.translations.build(:locale => locale) - end + @public_body.build_all_translations if params[:change_request_id] @change_request = PublicBodyChangeRequest.find(params[:change_request_id]) @@ -58,6 +55,7 @@ class AdminPublicBodyController < AdminController flash[:notice] = 'PublicBody was successfully created.' redirect_to admin_body_url(@public_body) else + @public_body.build_all_translations render :action => 'new' end end @@ -65,10 +63,7 @@ class AdminPublicBodyController < AdminController def edit @public_body = PublicBody.find(params[:id]) - - I18n.available_locales.each do |locale| - @public_body.translations.find_or_initialize_by_locale(locale) - end + @public_body.build_all_translations if params[:change_request_id] @change_request = PublicBodyChangeRequest.find(params[:change_request_id]) @@ -99,6 +94,7 @@ class AdminPublicBodyController < AdminController flash[:notice] = 'PublicBody was successfully updated.' redirect_to admin_body_url(@public_body) else + @public_body.build_all_translations render :action => 'edit' end end diff --git a/app/controllers/admin_public_body_headings_controller.rb b/app/controllers/admin_public_body_headings_controller.rb index e893e760d..a7fe27390 100644 --- a/app/controllers/admin_public_body_headings_controller.rb +++ b/app/controllers/admin_public_body_headings_controller.rb @@ -1,22 +1,52 @@ class AdminPublicBodyHeadingsController < AdminController + def new + @heading = PublicBodyHeading.new + @heading.build_all_translations + end + + def create + I18n.with_locale(I18n.default_locale) do + @heading = PublicBodyHeading.new(params[:public_body_heading]) + if @heading.save + flash[:notice] = 'Heading was successfully created.' + redirect_to admin_categories_url + else + @heading.build_all_translations + render :action => 'new' + end + end + end + def edit @heading = PublicBodyHeading.find(params[:id]) - render :formats => [:html] + @heading.build_all_translations end def update + @heading = PublicBodyHeading.find(params[:id]) + I18n.with_locale(I18n.default_locale) do - @heading = PublicBodyHeading.find(params[:id]) if @heading.update_attributes(params[:public_body_heading]) - flash[:notice] = 'Category heading was successfully updated.' + flash[:notice] = 'Heading was successfully updated.' redirect_to edit_admin_heading_path(@heading) else + @heading.build_all_translations render :action => 'edit' end end end + def destroy + @locale = self.locale_from_params + I18n.with_locale(@locale) do + heading = PublicBodyHeading.find(params[:id]) + heading.destroy + flash[:notice] = "Heading was successfully destroyed." + redirect_to admin_categories_url + end + end + def reorder transaction = reorder_headings(params[:headings]) if transaction[:success] @@ -35,33 +65,6 @@ class AdminPublicBodyHeadingsController < AdminController end end - def new - @heading = PublicBodyHeading.new - render :formats => [:html] - end - - def create - I18n.with_locale(I18n.default_locale) do - @heading = PublicBodyHeading.new(params[:public_body_heading]) - if @heading.save - flash[:notice] = 'Category heading was successfully created.' - redirect_to admin_categories_url - else - render :action => 'new' - end - end - end - - def destroy - @locale = self.locale_from_params() - I18n.with_locale(@locale) do - heading = PublicBodyHeading.find(params[:id]) - heading.destroy - flash[:notice] = "Category heading was successfully destroyed." - redirect_to admin_categories_url - end - end - protected def reorder_headings(headings) |