aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/assets/stylesheets/main.scss31
-rw-r--r--app/controllers/request_controller.rb11
-rw-r--r--app/views/request/select_authorities.html.erb72
-rw-r--r--spec/controllers/request_controller_spec.rb34
4 files changed, 145 insertions, 3 deletions
diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss
index 625245cce..278106d2a 100644
--- a/app/assets/stylesheets/main.scss
+++ b/app/assets/stylesheets/main.scss
@@ -1777,3 +1777,34 @@ text-decoration:none;
the axes black rather than transparent grey for the moment: */
color: #000 !important;
}
+
+
+#body_selection .body_list {
+ width: 45%;
+}
+
+#body_selection .body_list input[type='submit'] {
+ margin: 10px 0;
+ width: 45%;
+}
+
+#body_selection .body_list #body_deselect_button{
+ float: right;
+}
+
+#body_selection #body_candidates {
+ float: left;
+}
+
+#body_selection #body_selections {
+ float: right;
+}
+
+#body_selection #body_submission input[type='submit'] {
+ margin: 10px 0;
+ width:100%;
+}
+
+#body_selection .body_select {
+ width: 100%;
+}
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 11e85764a..feac94b92 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -58,6 +58,17 @@ class RequestController < ApplicationController
if !@user.can_make_batch_requests?
return render_hidden('request/batch_not_allowed')
end
+ if !params[:public_body_query].nil?
+ @search_bodies = perform_search_typeahead(params[:public_body_query], PublicBody)
+ end
+ if !params[:public_body_ids].nil?
+ if !params[:remove_public_body_ids].nil?
+ body_ids = params[:public_body_ids] - params[:remove_public_body_ids]
+ else
+ body_ids = params[:public_body_ids]
+ end
+ @public_bodies = PublicBody.where({:id => body_ids}).all
+ end
end
def show
diff --git a/app/views/request/select_authorities.html.erb b/app/views/request/select_authorities.html.erb
index 80bf93c8c..616cb3f50 100644
--- a/app/views/request/select_authorities.html.erb
+++ b/app/views/request/select_authorities.html.erb
@@ -1,4 +1,74 @@
<% @title = _("Select the authorities to write to") %>
+<h1><%= _('1. Select authorities') %></h1>
- <h1><%= _('1. Select the authorities') %></h1>
+<p>
+ <%= _("Search for the authorities you'd like information from:") %>
+</p>
+
+<div>
+ <%= form_tag(select_authorities_path, {:method => 'get', :id => 'body_search_form'}) do %>
+ <%= text_field_tag 'public_body_query', params[:public_body_query], { :size => 30, :title => "type your search term here" } %>
+ <% if !@public_bodies.blank? %>
+ <%- @public_bodies.each do |public_body| %>
+ <%= hidden_field_tag "public_body_ids[]", public_body.id, {:id => nil} %>
+ <%- end %>
+ <% end %>
+ <% end %>
+</div>
+
+<div id="body_selection">
+ <div id="body_lists">
+ <div id="body_candidates" class="body_list">
+ <%= form_tag(select_authorities_path, {:id => "body_select_form"}) do %>
+ <%= submit_tag _(' > '), :id => 'body_select_button' %>
+ <%= hidden_field_tag "public_body_query", params[:public_body_query], { :id => 'public_body_select_query' } %>
+ <% if !@public_bodies.blank? %>
+ <% @public_bodies.each do |public_body| %>
+ <%= hidden_field_tag "public_body_ids[]", public_body.id, {:id => nil} %>
+ <% end %>
+ <% end %>
+ <select multiple name="public_body_ids[]" id="select_body_candidates" class="body_select" size="15">
+ <% if @search_bodies %>
+ <% @search_bodies.results.each do |result| %>
+ <% unless (@public_bodies && @public_bodies.include?(result[:model])) %>
+ <option value="<%= result[:model].id %>"><%= result[:model].name %></option>
+ <% end %>
+ <% end %>
+ <% end %>
+ </select>
+ <% end %>
+ </div>
+
+ <div id="body_selections" class="body_list">
+ <%= form_tag(select_authorities_path, {:id => "body_deselect_form"}) do %>
+ <%= submit_tag _(' < '), :id => 'body_deselect_button' %>
+ <%= hidden_field_tag "public_body_query", params[:public_body_query], { :id => 'public_body_deselect_query' } %>
+ <% if @public_bodies %>
+ <% @public_bodies.each do |public_body| %>
+ <%= hidden_field_tag "public_body_ids[]", public_body.id, {:id => nil} %>
+ <% end %>
+ <% end %>
+ <select multiple name="remove_public_body_ids[]" id="select_body_selections" class="body_select" size="15">
+ <% if @public_bodies %>
+ <% @public_bodies.each do |public_body| %>
+ <option value="<%= public_body.id %>"><%= public_body.name %></option>
+ <% end %>
+ <% end %>
+ </select>
+ <% end %>
+
+ <div id="body_submission">
+ <%= form_tag(new_batch_path, {:id => "body_submit_form"}) do %>
+ <% if @public_bodies %>
+ <% @public_bodies.each do |public_body| %>
+ <%= hidden_field_tag "public_body_ids[]", public_body.id , {:id => nil} %>
+ <% end %>
+ <% end %>
+ <%= submit_tag _('Make a request to these authorities'), :id => 'body_submit_button' %>
+ <% end %>
+ </div>
+
+ </div>
+ </div>
+</div>
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 1a95a5ac5..d29552b15 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -897,7 +897,7 @@ describe RequestController, "when handling prominence" do
expect_hidden('request/hidden_correspondence')
end
- it 'should download attachments for an admin user', :focus => true do
+ it 'should download attachments for an admin user' do
session[:user_id] = FactoryGirl.create(:admin_user).id
get :get_attachment, :incoming_message_id => @incoming_message.id,
:id => @info_request.id,
@@ -959,7 +959,7 @@ describe RequestController, "when handling prominence" do
response.should be_success
end
- it 'should download attachments for an admin user', :focus => true do
+ it 'should download attachments for an admin user' do
session[:user_id] = FactoryGirl.create(:admin_user).id
get :get_attachment, :incoming_message_id => @incoming_message.id,
:id => @info_request.id,
@@ -2514,6 +2514,8 @@ describe RequestController, "#select_authorities" do
context "when batch requests is enabled" do
before do
+ get_fixtures_xapian_index
+ load_raw_emails_data
AlaveteliConfiguration.stub!(:allow_batch_requests).and_return(true)
end
@@ -2528,6 +2530,34 @@ describe RequestController, "#select_authorities" do
response.should be_success
end
+ it 'should render the "select_authorities" template' do
+ get :select_authorities, {}, {:user_id => @user.id}
+ response.should render_template('request/select_authorities')
+ end
+
+ it 'should assign a list of search results to the view if passed a query' do
+ get :select_authorities, {:public_body_query => "Quango"}, {:user_id => @user.id}
+ assigns[:search_bodies].results.size.should == 1
+ assigns[:search_bodies].results[0][:model].name.should == public_bodies(:geraldine_public_body).name
+ end
+
+ it 'should assign a list of public bodies to the view if passed a list of ids' do
+ get :select_authorities, {:public_body_ids => [public_bodies(:humpadink_public_body).id]},
+ {:user_id => @user.id}
+ assigns[:public_bodies].size.should == 1
+ assigns[:public_bodies][0].name.should == public_bodies(:humpadink_public_body).name
+ end
+
+ it 'should subtract a list of public bodies to remove from the list of bodies assigned to
+ the view' do
+ get :select_authorities, {:public_body_ids => [public_bodies(:humpadink_public_body).id,
+ public_bodies(:geraldine_public_body).id],
+ :remove_public_body_ids => [public_bodies(:geraldine_public_body).id]},
+ {:user_id => @user.id}
+ assigns[:public_bodies].size.should == 1
+ assigns[:public_bodies][0].name.should == public_bodies(:humpadink_public_body).name
+ end
+
end
context "when the current user can't make batch requests" do