diff options
author | lizconlan <liz@mysociety.org> | 2014-08-04 18:48:04 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2014-09-22 12:39:03 +0100 |
commit | 7df6456d69d71e6dba34fbc0d7b3d262d2dc0d38 (patch) | |
tree | 96b34f9e7fbcd7be5fcf0ef0042b10b1b58e222f /app/controllers | |
parent | 31c1f47a6bca88b2be9fb463721fb26698e79f82 (diff) |
Add display order to public body categories and headings
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/admin_public_body_category_controller.rb | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/app/controllers/admin_public_body_category_controller.rb b/app/controllers/admin_public_body_category_controller.rb index 221d8e4ad..f814763ad 100644 --- a/app/controllers/admin_public_body_category_controller.rb +++ b/app/controllers/admin_public_body_category_controller.rb @@ -26,10 +26,27 @@ class AdminPublicBodyCategoryController < AdminController else if params[:headings] heading_ids = params[:headings].values + removed_headings = @category.public_body_heading_ids - heading_ids + added_headings = heading_ids - @category.public_body_heading_ids + + unless removed_headings.empty? + # remove the link objects + deleted_links = PublicBodyCategoryLink.where( + :public_body_category_id => @category.id, + :public_body_heading_id => [removed_headings] + ) + deleted_links.delete_all + + #fix the category object + @category.public_body_heading_ids = heading_ids + end + + added_headings.each do |heading_id| + @category.add_to_heading(PublicBodyHeading.find(heading_id)) + end end if @category.update_attributes(params[:public_body_category]) - @category.public_body_heading_ids = heading_ids flash[:notice] = 'Category was successfully updated.' end end |