aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin_public_body_category_controller.rb55
-rw-r--r--app/controllers/admin_public_body_heading_controller.rb54
2 files changed, 109 insertions, 0 deletions
diff --git a/app/controllers/admin_public_body_category_controller.rb b/app/controllers/admin_public_body_category_controller.rb
new file mode 100644
index 000000000..635e664ee
--- /dev/null
+++ b/app/controllers/admin_public_body_category_controller.rb
@@ -0,0 +1,55 @@
+class AdminPublicBodyCategoryController < AdminController
+ def index
+ @locale = self.locale_from_params
+ @category_headings = PublicBodyHeading.all
+ end
+
+ def new
+ @category = PublicBodyCategory.new
+ render :formats => [:html]
+ end
+
+ def edit
+ @category = PublicBodyCategory.find(params[:id])
+ @tagged_public_bodies = PublicBody.find_by_tag(@category.category_tag)
+ end
+
+ def update
+ I18n.with_locale(I18n.default_locale) do
+ @category = PublicBodyCategory.find(params[:id])
+ if @category.update_attributes(params[:public_body_category])
+ flash[:notice] = 'Category was successfully updated.'
+ end
+ render :action => 'edit'
+ end
+ end
+
+ def create
+ I18n.with_locale(I18n.default_locale) do
+ @category = PublicBodyCategory.new(params[:public_body_category])
+ if @category.save
+ flash[:notice] = 'Category was successfully created.'
+ redirect_to admin_category_index_url
+ else
+ render :action => 'new'
+ end
+ end
+ end
+
+ def destroy
+ @locale = self.locale_from_params
+ I18n.with_locale(@locale) do
+ category = PublicBodyCategory.find(params[:id])
+
+ if PublicBody.find_by_tag(category.category_tag).count > 0
+ flash[:notice] = "There are authorities associated with this category, so can't destroy it"
+ redirect_to admin_category_edit_url(category)
+ return
+ end
+
+ category.destroy
+ flash[:notice] = "Category was successfully destroyed."
+ redirect_to admin_category_index_url
+ end
+ end
+end
diff --git a/app/controllers/admin_public_body_heading_controller.rb b/app/controllers/admin_public_body_heading_controller.rb
new file mode 100644
index 000000000..43d8e329c
--- /dev/null
+++ b/app/controllers/admin_public_body_heading_controller.rb
@@ -0,0 +1,54 @@
+class AdminPublicBodyHeadingController < AdminController
+ def index
+ redirect_to admin_category_index_url
+ end
+
+ def edit
+ @heading = PublicBodyHeading.find(params[:id])
+ render :formats => [:html]
+ end
+
+ def update
+ 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.'
+ end
+ render :action => 'edit'
+ 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_category_index_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])
+
+ if heading.public_body_categories.count > 0
+ flash[:notice] = "There are categories associated with this heading, so can't destroy it"
+ redirect_to admin_heading_edit_url(heading)
+ return
+ end
+
+ heading.destroy
+ flash[:notice] = "Category heading was successfully destroyed."
+ redirect_to admin_category_index_url
+ end
+ end
+end