aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/admin/category-order.js9
-rw-r--r--app/controllers/admin_public_body_categories_controller.rb (renamed from app/controllers/admin_public_body_category_controller.rb)28
-rw-r--r--app/controllers/admin_public_body_headings_controller.rb (renamed from app/controllers/admin_public_body_heading_controller.rb)30
-rw-r--r--app/views/admin_general/_admin_navbar.html.erb2
-rw-r--r--app/views/admin_public_body_categories/_form.html.erb (renamed from app/views/admin_public_body_category/_form.html.erb)0
-rw-r--r--app/views/admin_public_body_categories/_one.html.erb (renamed from app/views/admin_public_body_category/_one.html.erb)2
-rw-r--r--app/views/admin_public_body_categories/_one_list.html.erb (renamed from app/views/admin_public_body_category/_one_list.html.erb)9
-rw-r--r--app/views/admin_public_body_categories/edit.html.erb (renamed from app/views/admin_public_body_category/edit.html.erb)8
-rw-r--r--app/views/admin_public_body_categories/index.html.erb (renamed from app/views/admin_public_body_category/index.html.erb)6
-rw-r--r--app/views/admin_public_body_categories/new.html.erb (renamed from app/views/admin_public_body_category/new.html.erb)4
-rw-r--r--app/views/admin_public_body_headings/_form.html.erb (renamed from app/views/admin_public_body_heading/_form.html.erb)0
-rw-r--r--app/views/admin_public_body_headings/edit.html.erb (renamed from app/views/admin_public_body_heading/edit.html.erb)8
-rw-r--r--app/views/admin_public_body_headings/new.html.erb (renamed from app/views/admin_public_body_heading/new.html.erb)4
13 files changed, 49 insertions, 61 deletions
diff --git a/app/assets/javascripts/admin/category-order.js b/app/assets/javascripts/admin/category-order.js
index 6e210083c..3be82e46f 100644
--- a/app/assets/javascripts/admin/category-order.js
+++ b/app/assets/javascripts/admin/category-order.js
@@ -1,14 +1,12 @@
$(function() {
- var endpoints = { 'heading' : '/admin/category_heading/reorder',
- 'category' : '/admin/category/reorder' }
$('.save-order').each(function(index){
// identify the elements that will work together
var save_button = $(this);
var save_notice = save_button.next();
var save_panel = save_button.parent();
- var list_type = save_button.data('list-type');
var list_element = $(save_button.data('list-id'));
+ var endpoint = save_button.data('endpoint');
// on the first list change, show that there are unsaved changes
list_element.sortable({
@@ -24,11 +22,6 @@ $(function() {
save_button.click(function(){
if (!save_button.is('.disabled')){
var data = list_element.sortable('serialize', {'attribute': 'data-id'});
- var endpoint = endpoints[list_type];
- if (list_type == 'category'){
- heading_id = save_button.data('heading-id');
- endpoint = endpoint + "/" + heading_id;
- }
var update_call = $.ajax({ data: data, type: 'POST', url: endpoint });
// on success, disable the save button again, and show success notice
diff --git a/app/controllers/admin_public_body_category_controller.rb b/app/controllers/admin_public_body_categories_controller.rb
index 99a4a7f3c..e9ca57434 100644
--- a/app/controllers/admin_public_body_category_controller.rb
+++ b/app/controllers/admin_public_body_categories_controller.rb
@@ -1,4 +1,4 @@
-class AdminPublicBodyCategoryController < AdminController
+class AdminPublicBodyCategoriesController < AdminController
def index
@locale = self.locale_from_params
@category_headings = PublicBodyHeading.all
@@ -55,28 +55,6 @@ class AdminPublicBodyCategoryController < AdminController
end
end
- def reorder
- error = nil
- ActiveRecord::Base.transaction do
- params[:categories].each_with_index do |category_id, index|
- conditions = { :public_body_category_id => category_id,
- :public_body_heading_id => params[:heading_id] }
- link = PublicBodyCategoryLink.where(conditions).first
- unless link
- error = "Couldn't find PublicBodyCategoryLink for category #{category_id}, heading #{params[:heading_id]}"
- raise ActiveRecord::Rollback
- end
- link.category_display_order = index
- unless link.save
- error = link.errors.full_messages.join(",")
- raise ActiveRecord::Rollback
- end
- end
- render :nothing => true, :status => :ok and return
- end
- render :text => error, :status => :unprocessable_entity
- end
-
def create
I18n.with_locale(I18n.default_locale) do
@category = PublicBodyCategory.new(params[:public_body_category])
@@ -87,7 +65,7 @@ class AdminPublicBodyCategoryController < AdminController
end
end
flash[:notice] = 'Category was successfully created.'
- redirect_to admin_category_index_url
+ redirect_to categories_path
else
render :action => 'new'
end
@@ -100,7 +78,7 @@ class AdminPublicBodyCategoryController < AdminController
category = PublicBodyCategory.find(params[:id])
category.destroy
flash[:notice] = "Category was successfully destroyed."
- redirect_to admin_category_index_url
+ redirect_to categories_path
end
end
end
diff --git a/app/controllers/admin_public_body_heading_controller.rb b/app/controllers/admin_public_body_headings_controller.rb
index 0fba350cc..6eec4b65e 100644
--- a/app/controllers/admin_public_body_heading_controller.rb
+++ b/app/controllers/admin_public_body_headings_controller.rb
@@ -1,4 +1,4 @@
-class AdminPublicBodyHeadingController < AdminController
+class AdminPublicBodyHeadingsController < AdminController
def edit
@heading = PublicBodyHeading.find(params[:id])
@@ -36,6 +36,28 @@ class AdminPublicBodyHeadingController < AdminController
render :text => error, :status => :unprocessable_entity
end
+ def reorder_categories
+ error = nil
+ ActiveRecord::Base.transaction do
+ params[:categories].each_with_index do |category_id, index|
+ conditions = { :public_body_category_id => category_id,
+ :public_body_heading_id => params[:id] }
+ link = PublicBodyCategoryLink.where(conditions).first
+ unless link
+ error = "Couldn't find PublicBodyCategoryLink for category #{category_id}, heading #{params[:id]}"
+ raise ActiveRecord::Rollback
+ end
+ link.category_display_order = index
+ unless link.save
+ error = link.errors.full_messages.join(",")
+ raise ActiveRecord::Rollback
+ end
+ end
+ render :nothing => true, :status => :ok and return
+ end
+ render :text => error, :status => :unprocessable_entity
+ end
+
def new
@heading = PublicBodyHeading.new
render :formats => [:html]
@@ -46,7 +68,7 @@ class AdminPublicBodyHeadingController < AdminController
@heading = PublicBodyHeading.new(params[:public_body_heading])
if @heading.save
flash[:notice] = 'Category heading was successfully created.'
- redirect_to admin_category_index_url
+ redirect_to categories_url
else
render :action => 'new'
end
@@ -60,13 +82,13 @@ class AdminPublicBodyHeadingController < AdminController
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)
+ redirect_to edit_heading_url(heading)
return
end
heading.destroy
flash[:notice] = "Category heading was successfully destroyed."
- redirect_to admin_category_index_url
+ redirect_to categories_url
end
end
end
diff --git a/app/views/admin_general/_admin_navbar.html.erb b/app/views/admin_general/_admin_navbar.html.erb
index dcf55dc50..e19a0ac5c 100644
--- a/app/views/admin_general/_admin_navbar.html.erb
+++ b/app/views/admin_general/_admin_navbar.html.erb
@@ -10,7 +10,7 @@
<li><%= link_to 'Stats', admin_stats_path %></li>
<li><%= link_to 'Debug', admin_debug_path %></li>
<li><%= link_to 'Authorities', admin_body_list_path %></li>
- <li><%= link_to 'Categories', admin_category_index_path %></li>
+ <li><%= link_to 'Categories', categories_path %></li>
<li><%= link_to 'Requests', admin_request_list_path %></li>
<li><%= link_to 'Users', admin_user_list_path %></li>
<li><%= link_to 'Tracks', admin_track_list_path %></li>
diff --git a/app/views/admin_public_body_category/_form.html.erb b/app/views/admin_public_body_categories/_form.html.erb
index b0778d371..b0778d371 100644
--- a/app/views/admin_public_body_category/_form.html.erb
+++ b/app/views/admin_public_body_categories/_form.html.erb
diff --git a/app/views/admin_public_body_category/_one.html.erb b/app/views/admin_public_body_categories/_one.html.erb
index 6b881a669..46f4f855c 100644
--- a/app/views/admin_public_body_category/_one.html.erb
+++ b/app/views/admin_public_body_categories/_one.html.erb
@@ -1,5 +1,5 @@
<div class="category-list-item" <% if heading %> data-id="categories_<%= category.id %>"<% end %>>
- <%= link_to(category.title, admin_category_edit_path(category), :title => "view full details") %>
+ <%= link_to(category.title, edit_category_path(category), :title => "view full details") %>
</div>
diff --git a/app/views/admin_public_body_category/_one_list.html.erb b/app/views/admin_public_body_categories/_one_list.html.erb
index 1c7856c10..1849f4b22 100644
--- a/app/views/admin_public_body_category/_one_list.html.erb
+++ b/app/views/admin_public_body_categories/_one_list.html.erb
@@ -1,12 +1,10 @@
-
-
<div class="accordion" id="category_list">
<% for heading in category_headings %>
<div class="accordion-group" data-id="headings_<%=heading.id%>">
<div class="accordion-heading accordion-toggle row">
<span class="item-title span6">
<a href="#heading_<%=heading.id%>_categories" data-toggle="collapse" data-parent="#categories" ><%= chevron_right %></a>
- <strong><%= link_to(heading.name, admin_heading_edit_path(heading), :title => "view full details") %></strong>
+ <strong><%= link_to(heading.name, edit_heading_path(heading), :title => "view full details") %></strong>
</span>
</div>
@@ -19,13 +17,10 @@
</div>
<div class="form-actions save-panel">
- <%= link_to "Save", '#', :class => "btn btn-primary disabled save-order", "data-heading-id" => heading.id, "data-list-id" => "#heading_#{heading.id}_category_list", 'data-list-type' => 'category' %><p class="save-notice" data-unsaved-text="There are unsaved changes to the order of categories." data-success-text="Changes saved." data-error-text="There was an error saving your changes: ">Drag and drop to change the order of categories.</p>
+ <%= link_to "Save", '#', :class => "btn btn-primary disabled save-order", "data-heading-id" => heading.id, "data-list-id" => "#heading_#{heading.id}_category_list", 'data-endpoint' => reorder_categories_heading_path(heading) %><p class="save-notice" data-unsaved-text="There are unsaved changes to the order of categories." data-success-text="Changes saved." data-error-text="There was an error saving your changes: ">Drag and drop to change the order of categories.</p>
</div>
</div>
</div>
-
-
</div>
<% end %>
-
</div>
diff --git a/app/views/admin_public_body_category/edit.html.erb b/app/views/admin_public_body_categories/edit.html.erb
index c1e522cac..206e610fc 100644
--- a/app/views/admin_public_body_category/edit.html.erb
+++ b/app/views/admin_public_body_categories/edit.html.erb
@@ -3,7 +3,7 @@
<div class="row">
<div class="span8">
<div id="public_body_category_form">
- <%= form_for @category, :url => admin_category_update_path(@category), :html => { :class => "form form-horizontal" } do |f| %>
+ <%= form_for @category, :url => category_path(@category), :html => { :class => "form form-horizontal" } do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<div class="form-actions">
<%= f.submit 'Save', :accesskey => 's', :class => "btn btn-success" %></p>
@@ -14,17 +14,17 @@
<div class="row">
<div class="span8 well">
- <%= link_to 'List all', admin_category_index_path, :class => "btn" %>
+ <%= link_to 'List all', categories_path, :class => "btn" %>
</div>
</div>
<% if @tagged_public_bodies.empty? %>
<div class="row">
<div class="span8">
- <%= form_tag(admin_category_destroy_path(@category), :class => "form form-inline") do %>
+ <%= form_tag(category_path(@category), :method => 'delete', :class => "form form-inline") do %>
<%= hidden_field_tag(:public_body_id, { :value => @category.id } ) %>
<%= submit_tag "Destroy #{@category.title}", :title => @category.title, :class => "btn btn-danger" %> (this is permanent!)
<% end %>
</div>
</div>
-<% end %> \ No newline at end of file
+<% end %>
diff --git a/app/views/admin_public_body_category/index.html.erb b/app/views/admin_public_body_categories/index.html.erb
index 85f2282ab..061ad0080 100644
--- a/app/views/admin_public_body_category/index.html.erb
+++ b/app/views/admin_public_body_categories/index.html.erb
@@ -4,10 +4,10 @@
<div class="btn-toolbar">
<div class="btn-group">
- <%= link_to 'New category', admin_category_new_path, :class => "btn btn-primary" %>
+ <%= link_to 'New category', new_category_path, :class => "btn btn-primary" %>
</div>
<div class="btn-group">
- <%= link_to 'New category heading', admin_heading_new_path, :class => "btn" %>
+ <%= link_to 'New category heading', new_heading_path, :class => "btn" %>
</div>
</div>
@@ -24,5 +24,5 @@
<% end %>
<% end %>
<div class="form-actions save-panel">
-<%= link_to "Save", '#', :class => "btn btn-primary disabled save-order", "data-list-id" => '#category_list', 'data-list-type' => 'heading' %><p class="save-notice" data-unsaved-text="There are unsaved changes to the order of category headings." data-success-text="Changes saved." data-error-text="There was an error saving your changes: ">Drag and drop to change the order of category headings.</p>
+<%= link_to "Save", '#', :class => "btn btn-primary disabled save-order", "data-list-id" => '#category_list', 'data-endpoint' => reorder_headings_path %><p class="save-notice" data-unsaved-text="There are unsaved changes to the order of category headings." data-success-text="Changes saved." data-error-text="There was an error saving your changes: ">Drag and drop to change the order of category headings.</p>
</div>
diff --git a/app/views/admin_public_body_category/new.html.erb b/app/views/admin_public_body_categories/new.html.erb
index 0a016182f..f91f5597c 100644
--- a/app/views/admin_public_body_category/new.html.erb
+++ b/app/views/admin_public_body_categories/new.html.erb
@@ -4,7 +4,7 @@
<div class="row">
<div class="span8">
<div id="public_category_form">
- <%= form_for @category, :as => :public_body_category, :url => admin_category_create_path, :html => {:class => "form form-horizontal"} do |f| %>
+ <%= form_for @category, :url => categories_path, :html => {:class => "form form-horizontal"} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<div class="form-actions">
@@ -13,7 +13,7 @@
<% end %>
<div class="row">
<div class="span8 well">
- <%= link_to 'List all', admin_category_index_path, :class => "btn" %>
+ <%= link_to 'List all', categories_path, :class => "btn" %>
</div>
</div>
</div>
diff --git a/app/views/admin_public_body_heading/_form.html.erb b/app/views/admin_public_body_headings/_form.html.erb
index d4e914ca1..d4e914ca1 100644
--- a/app/views/admin_public_body_heading/_form.html.erb
+++ b/app/views/admin_public_body_headings/_form.html.erb
diff --git a/app/views/admin_public_body_heading/edit.html.erb b/app/views/admin_public_body_headings/edit.html.erb
index df5ae7d0e..1c8416df3 100644
--- a/app/views/admin_public_body_heading/edit.html.erb
+++ b/app/views/admin_public_body_headings/edit.html.erb
@@ -3,7 +3,7 @@
<div class="row">
<div class="span8">
<div id="public_body_heading_form">
- <%= form_for @heading, :url => admin_heading_update_path(@heading), :html => { :class => "form form-horizontal" } do |f| %>
+ <%= form_for @heading, :url => heading_path(@heading), :html => { :class => "form form-horizontal" } do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<div class="form-actions">
<%= f.submit 'Save', :accesskey => 's', :class => "btn btn-success" %></p>
@@ -14,17 +14,17 @@
<div class="row">
<div class="span8 well">
- <%= link_to 'List all', admin_category_index_path, :class => "btn" %>
+ <%= link_to 'List all', categories_path, :class => "btn" %>
</div>
</div>
<% if @heading.public_body_categories.empty? %>
<div class="row">
<div class="span8">
- <%= form_tag(admin_heading_destroy_path(@heading), :class => "form form-inline") do %>
+ <%= form_tag(heading_path(@heading), :method => 'delete', :class => "form form-inline") do %>
<%= hidden_field_tag(:public_body_heading_id, { :value => @heading.id } ) %>
<%= submit_tag "Destroy #{@heading.name}", :name => @heading.name, :class => "btn btn-danger" %> (this is permanent!)
<% end %>
</div>
</div>
-<% end %> \ No newline at end of file
+<% end %>
diff --git a/app/views/admin_public_body_heading/new.html.erb b/app/views/admin_public_body_headings/new.html.erb
index 22cb88901..b0066481f 100644
--- a/app/views/admin_public_body_heading/new.html.erb
+++ b/app/views/admin_public_body_headings/new.html.erb
@@ -4,7 +4,7 @@
<div class="row">
<div class="span8">
<div id="public_heading_form">
- <%= form_for @heading, :as => :public_body_heading, :url => admin_heading_create_path, :html => {:class => "form form-horizontal"} do |f| %>
+ <%= form_for @heading, :url => headings_path, :html => {:class => "form form-horizontal"} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<div class="form-actions">
@@ -13,7 +13,7 @@
<% end %>
<div class="row">
<div class="span8 well">
- <%= link_to 'List all', admin_category_index_path, :class => "btn" %>
+ <%= link_to 'List all', categories_path, :class => "btn" %>
</div>
</div>
</div>