aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/general.js2
-rw-r--r--app/assets/stylesheets/admin.scss8
-rw-r--r--app/assets/stylesheets/responsive/_public_body_layout.scss8
-rw-r--r--app/assets/stylesheets/responsive/_public_body_style.scss33
-rw-r--r--app/assets/stylesheets/responsive/_search_layout.scss8
-rw-r--r--app/assets/stylesheets/responsive/_search_style.scss83
-rw-r--r--app/controllers/admin_public_body_categories_controller.rb44
-rw-r--r--app/controllers/admin_public_body_controller.rb12
-rw-r--r--app/controllers/admin_public_body_headings_controller.rb63
-rw-r--r--app/controllers/general_controller.rb5
-rw-r--r--app/helpers/public_body_helper.rb26
-rw-r--r--app/models/public_body.rb74
-rw-r--r--app/models/public_body_category.rb65
-rw-r--r--app/models/public_body_heading.rb43
-rw-r--r--app/views/admin_public_body/_form.html.erb27
-rw-r--r--app/views/admin_public_body_categories/_form.html.erb75
-rw-r--r--app/views/admin_public_body_categories/_locale_fields.html.erb27
-rw-r--r--app/views/admin_public_body_headings/_form.html.erb69
-rw-r--r--app/views/admin_public_body_headings/_locale_fields.html.erb9
-rw-r--r--app/views/info_request_batch/_batch_sent.html.erb69
-rw-r--r--app/views/public_body/show.html.erb2
-rw-r--r--app/views/request/_request_filter_form.html.erb2
-rw-r--r--app/views/request/new.html.erb4
23 files changed, 475 insertions, 283 deletions
diff --git a/app/assets/javascripts/general.js b/app/assets/javascripts/general.js
index 002eef760..856f4c6d4 100644
--- a/app/assets/javascripts/general.js
+++ b/app/assets/javascripts/general.js
@@ -34,12 +34,12 @@ $(document).ready(function() {
box.width(location.length + " em");
box.find('input').val(location).attr('size', location.length + " em");
box.show();
- box.find('input').select();
box.position({
my: "right center",
at: "left bottom",
of: this,
collision: "fit" });
+ box.find('input').select();
return false;
});
diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss
index 31fe7e95a..9b792dee3 100644
--- a/app/assets/stylesheets/admin.scss
+++ b/app/assets/stylesheets/admin.scss
@@ -123,6 +123,14 @@ body.admin {
padding: 3px 0;
}
+ .fieldWithErrors {
+ display:block;
+ padding:0.2em;
+ textarea, input {
+ border:solid 1px Red !important;
+ }
+ }
+
/* Holidays */
.day_select {
width: 75px;
diff --git a/app/assets/stylesheets/responsive/_public_body_layout.scss b/app/assets/stylesheets/responsive/_public_body_layout.scss
index 7a9637bc9..2afd67ffb 100644
--- a/app/assets/stylesheets/responsive/_public_body_layout.scss
+++ b/app/assets/stylesheets/responsive/_public_body_layout.scss
@@ -64,10 +64,4 @@
}
-.list-filter-item {
- .title {
- display: inline;
- font-size: 1em;
- font-weight: normal;
- }
-}
+
diff --git a/app/assets/stylesheets/responsive/_public_body_style.scss b/app/assets/stylesheets/responsive/_public_body_style.scss
index 748f6218b..79ee4764a 100644
--- a/app/assets/stylesheets/responsive/_public_body_style.scss
+++ b/app/assets/stylesheets/responsive/_public_body_style.scss
@@ -35,42 +35,9 @@
}
-.list-filter-item {
- ul {
- list-style: none outside none;
- margin: 0;
- padding: 0;
- }
- li {
- display: inline-block;
- &:after {
- content:' | ';
- display: inline-block;
- color: #ccc; //Unsupported browsers will ignore the rgba declaration below
- color: rgba(0,0,0,0.1);
- }
- &:last-child {
- &:after {
- content: '';
- }
- }
-
- }
-}
-
.authority__body__sidebar__links {
a {
display: inline-block;
margin-bottom: 0.5em;
}
}
-
-#list-filter {
- margin-bottom: 3em;
-}
-
-#filter_requests_form label.title {
- display: block;
- width: auto;
- margin-bottom: 0.3em;
-}
diff --git a/app/assets/stylesheets/responsive/_search_layout.scss b/app/assets/stylesheets/responsive/_search_layout.scss
index 48dd0c6a7..93a94f951 100644
--- a/app/assets/stylesheets/responsive/_search_layout.scss
+++ b/app/assets/stylesheets/responsive/_search_layout.scss
@@ -57,3 +57,11 @@
#advanced-search-tips{
@include grid-column(12);
}
+
+.list-filter-item {
+ .title {
+ display: inline;
+ font-size: 1em;
+ font-weight: normal;
+ }
+}
diff --git a/app/assets/stylesheets/responsive/_search_style.scss b/app/assets/stylesheets/responsive/_search_style.scss
index dfd40fc67..94ec1cf88 100644
--- a/app/assets/stylesheets/responsive/_search_style.scss
+++ b/app/assets/stylesheets/responsive/_search_style.scss
@@ -51,4 +51,87 @@ input.use-datepicker[type=text] {
}
}
+.list-filter-item {
+ ul {
+ list-style: none outside none;
+ margin: 0;
+ padding: 0;
+ }
+ li {
+ display: inline-block;
+ }
+}
+
+
+#list-filter {
+ margin-bottom: 3em;
+}
+#filter_requests_form label.title {
+ display: block;
+ width: auto;
+ margin-bottom: 0.3em;
+}
+
+.filter-request-types {
+ display: block;
+ margin-bottom: 1em;
+ @include respond-min( 20em ){
+ display: inline-block;
+ }
+ ul {
+ border: 1px solid #ccc;
+ border-radius: 3px;
+ width: 100%;
+ font-size: 0;
+ border-bottom: 0;
+ @include respond-min( 20em ){
+ border-right: 0;
+ }
+ @include respond-min( 44em ){
+ border-bottom: 1px solid #ccc;
+ }
+ }
+ li {
+ width: 100%;
+ @include respond-min( 20em ){
+ width: 50%;
+ }
+ @include respond-min( 44em ){
+ width: auto;
+ }
+ }
+ a, span {
+ width: 100%;
+ text-align: center;
+ display: block;
+ font-size: 14px;
+ padding: 0.5em 0.75em;
+ border-bottom: 1px solid #ccc;
+ text-decoration: none;
+ @include respond-min( 20em ){
+ display: inline-block;
+ border-right: 1px solid #ccc;
+ border-bottom: 0;
+ &:nth-child(1),
+ &:nth-child(2) {
+ border-bottom: 1px solid #ccc;
+ }
+ }
+
+ @include respond-min( 44em ){
+ &:nth-child(n) {
+ border-bottom: 0;
+ }
+ }
+ }
+ span {
+ font-weight: bold;
+ background-color: #f4f4f4;
+ //older browsers will just see a flat background, new browsers will see an indent
+ -webkit-box-shadow: inset 0 2px 5px 1px rgba(0, 0, 0, 0.1);
+ -moz-box-shadow: inset 0 2px 5px 1px rgba(0, 0, 0, 0.1);
+ -o-box-shadow: inset 0 2px 5px 1px rgba(0, 0, 0, 0.1);
+ box-shadow: inset 0 2px 5px 1px rgba(0, 0, 0, 0.1);
+ }
+}
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)
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index 438bbfd3f..380da285e 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -15,6 +15,11 @@ class GeneralController < ApplicationController
def frontpage
medium_cache
@locale = self.locale_from_params()
+ successful_query = InfoRequestEvent.make_query_from_params( :latest_status => ['successful'] )
+ @track_thing = TrackThing.create_track_for_search_query(successful_query)
+ @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'),
+ :title => _('Successful requests'),
+ :has_json => true } ]
end
# Display blog entries
diff --git a/app/helpers/public_body_helper.rb b/app/helpers/public_body_helper.rb
index 4a71f89ab..332e93284 100644
--- a/app/helpers/public_body_helper.rb
+++ b/app/helpers/public_body_helper.rb
@@ -32,4 +32,30 @@ module PublicBodyHelper
reasons.compact
end
+ # Use tags to describe what type of authority a PublicBody is.
+ #
+ # public_body - Instance of a PublicBody
+ #
+ # Returns a string
+ def type_of_authority(public_body)
+ types = public_body.tags.each_with_index.map do |tag, index|
+ if PublicBodyCategory.get().by_tag().include?(tag.name)
+ desc = PublicBodyCategory.get().singular_by_tag()[tag.name]
+
+ if index.zero?
+ desc = desc.sub(/\S/) { |m| Unicode.upcase(m) }
+ end
+ link_to(desc, list_public_bodies_path(tag.name))
+ end
+ end
+
+ types.compact!
+
+ if types.any?
+ types.to_sentence(:last_word_connector => ' and ').html_safe
+ else
+ _("A public authority")
+ end
+ end
+
end
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index c023b436c..232c0ffa1 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -64,7 +64,7 @@ class PublicBody < ActiveRecord::Base
}
translates :name, :short_name, :request_email, :url_name, :notes, :first_letter, :publication_scheme
- accepts_nested_attributes_for :translations
+ accepts_nested_attributes_for :translations, :reject_if => :empty_translation_in_params?
# Default fields available for importing from CSV, in the format
# [field_name, 'short description of field (basic html allowed)']
@@ -152,33 +152,15 @@ class PublicBody < ActiveRecord::Base
translations
end
- def translations_attributes=(translation_attrs)
- def empty_translation?(attrs)
- attrs_with_values = attrs.select{ |key, value| value != '' and key.to_s != 'locale' }
- attrs_with_values.empty?
- end
- if translation_attrs.respond_to? :each_value # Hash => updating
- translation_attrs.each_value do |attrs|
- next if empty_translation?(attrs)
- t = translation_for(attrs[:locale]) || PublicBody::Translation.new
- t.attributes = attrs
- calculate_cached_fields(t)
- t.save!
- end
- else # Array => creating
- warn "[DEPRECATION] PublicBody#translations_attributes= " \
- "will no longer accept an Array as of release 0.22. " \
- "Use Hash arguments instead. See " \
- "spec/models/public_body_spec.rb and " \
- "app/views/admin_public_body/_form.html.erb for more " \
- "details."
-
- translation_attrs.each do |attrs|
- next if empty_translation?(attrs)
- new_translation = PublicBody::Translation.new(attrs)
- calculate_cached_fields(new_translation)
- translations << new_translation
- end
+ def ordered_translations
+ translations.
+ select { |t| I18n.available_locales.include?(t.locale) }.
+ sort_by { |t| I18n.available_locales.index(t.locale) }
+ end
+
+ def build_all_translations
+ I18n.available_locales.each do |locale|
+ translations.build(:locale => locale) unless translations.detect{ |t| t.locale == locale }
end
end
@@ -345,35 +327,6 @@ class PublicBody < ActiveRecord::Base
end
end
-
- # Use tags to describe what type of thing this is
- def type_of_authority(html = false)
- types = tags.each_with_index.map do |tag, index|
- if PublicBodyCategory.get().by_tag().include?(tag.name)
- desc = PublicBodyCategory.get().singular_by_tag()[tag.name]
-
- if index.zero?
- desc = desc.sub(/\S/) { |m| Unicode.upcase(m) }
- end
-
- if html
- # TODO: this should call proper route helpers, but is in model sigh
- desc = '<a href="/body/list/' + tag.name + '">' + desc + '</a>'
- end
-
- desc
- end
- end
-
- types.compact!
-
- if types.any?
- types.to_sentence(:last_word_connector => ' and ').html_safe
- else
- _("A public authority")
- end
- end
-
# Guess home page from the request email, or use explicit override, or nil
# if not known.
def calculated_home_page
@@ -820,6 +773,13 @@ class PublicBody < ActiveRecord::Base
end
end
+ def empty_translation_in_params?(attributes)
+ attrs_with_values = attributes.select do |key, value|
+ value != '' and key.to_s != 'locale'
+ end
+ attrs_with_values.empty?
+ end
+
def request_email_if_requestable
# Request_email can be blank, meaning we don't have details
if self.is_requestable?
diff --git a/app/models/public_body_category.rb b/app/models/public_body_category.rb
index c313e5734..b88c683de 100644
--- a/app/models/public_body_category.rb
+++ b/app/models/public_body_category.rb
@@ -10,12 +10,15 @@ require 'forwardable'
class PublicBodyCategory < ActiveRecord::Base
attr_accessible :locale, :category_tag, :title, :description,
- :translated_versions, :display_order
+ :translated_versions, :translations_attributes,
+ :display_order
has_many :public_body_category_links, :dependent => :destroy
has_many :public_body_headings, :through => :public_body_category_links
translates :title, :description
+ accepts_nested_attributes_for :translations, :reject_if => :empty_translation_in_params?
+
validates_uniqueness_of :category_tag, :message => 'Tag is already taken'
validates_presence_of :title, :message => "Title can't be blank"
validates_presence_of :category_tag, :message => "Tag can't be blank"
@@ -49,11 +52,6 @@ class PublicBodyCategory < ActiveRecord::Base
PublicBodyCategory.find_by_sql(sql)
end
- # Called from the old-style public_body_categories_[locale].rb data files
- def self.add(locale, data_list)
- CategoryAndHeadingMigrator.add_categories_and_headings_from_list(locale, data_list)
- end
-
# Convenience methods for creating/editing translations via forms
def find_translation_by_locale(locale)
translations.find_by_locale(locale)
@@ -64,25 +62,48 @@ class PublicBodyCategory < ActiveRecord::Base
end
def translated_versions=(translation_attrs)
- def empty_translation?(attrs)
- attrs_with_values = attrs.select{ |key, value| value != '' and key != 'locale' }
- attrs_with_values.empty?
+ warn "[DEPRECATION] PublicBodyCategory#translated_versions= will be replaced " \
+ "by PublicBodyCategory#translations_attributes= as of release 0.22"
+ self.translations_attributes = translation_attrs
+ end
+
+ def ordered_translations
+ translations.
+ select { |t| I18n.available_locales.include?(t.locale) }.
+ sort_by { |t| I18n.available_locales.index(t.locale) }
+ end
+
+ def build_all_translations
+ I18n.available_locales.each do |locale|
+ translations.build(:locale => locale) unless translations.detect{ |t| t.locale == locale }
end
- if translation_attrs.respond_to? :each_value # Hash => updating
- translation_attrs.each_value do |attrs|
- next if empty_translation?(attrs)
- t = translation_for(attrs[:locale]) || PublicBodyCategory::Translation.new
- t.attributes = attrs
- t.save!
- end
- else # Array => creating
- translation_attrs.each do |attrs|
- next if empty_translation?(attrs)
- new_translation = PublicBodyCategory::Translation.new(attrs)
- translations << new_translation
- end
+ end
+
+ private
+
+ def empty_translation_in_params?(attributes)
+ attrs_with_values = attributes.select do |key, value|
+ value != '' and key.to_s != 'locale'
end
+ attrs_with_values.empty?
end
+
end
+PublicBodyCategory::Translation.class_eval do
+ with_options :if => lambda { |t| !t.default_locale? && t.required_attribute_submitted? } do |required|
+ required.validates :title, :presence => { :message => "Title can't be blank" }
+ required.validates :description, :presence => { :message => "Description can't be blank" }
+ end
+ def default_locale?
+ locale == I18n.default_locale
+ end
+
+ def required_attribute_submitted?
+ PublicBodyCategory.required_translated_attributes.compact.any? do |attribute|
+ !read_attribute(attribute).blank?
+ end
+ end
+
+end
diff --git a/app/models/public_body_heading.rb b/app/models/public_body_heading.rb
index f394c37c6..8c160ba8b 100644
--- a/app/models/public_body_heading.rb
+++ b/app/models/public_body_heading.rb
@@ -7,13 +7,15 @@
#
class PublicBodyHeading < ActiveRecord::Base
- attr_accessible :name, :display_order, :translated_versions
+ attr_accessible :locale, :name, :display_order, :translated_versions,
+ :translations_attributes
has_many :public_body_category_links, :dependent => :destroy
has_many :public_body_categories, :order => :category_display_order, :through => :public_body_category_links
default_scope order('display_order ASC')
translates :name
+ accepts_nested_attributes_for :translations, :reject_if => :empty_translation_in_params?
validates_uniqueness_of :name, :message => 'Name is already taken'
validates_presence_of :name, :message => 'Name can\'t be blank'
@@ -36,24 +38,20 @@ class PublicBodyHeading < ActiveRecord::Base
end
def translated_versions=(translation_attrs)
- def empty_translation?(attrs)
- attrs_with_values = attrs.select{ |key, value| value != '' and key != 'locale' }
- attrs_with_values.empty?
- end
+ warn "[DEPRECATION] PublicBodyHeading#translated_versions= will be replaced " \
+ "by PublicBodyHeading#translations_attributes= as of release 0.22"
+ self.translations_attributes = translation_attrs
+ end
+
+ def ordered_translations
+ translations.
+ select { |t| I18n.available_locales.include?(t.locale) }.
+ sort_by { |t| I18n.available_locales.index(t.locale) }
+ end
- if translation_attrs.respond_to? :each_value # Hash => updating
- translation_attrs.each_value do |attrs|
- next if empty_translation?(attrs)
- t = translation_for(attrs[:locale]) || PublicBodyHeading::Translation.new
- t.attributes = attrs
- t.save!
- end
- else # Array => creating
- translation_attrs.each do |attrs|
- next if empty_translation?(attrs)
- new_translation = PublicBodyHeading::Translation.new(attrs)
- translations << new_translation
- end
+ def build_all_translations
+ I18n.available_locales.each do |locale|
+ translations.build(:locale => locale) unless translations.detect{ |t| t.locale == locale }
end
end
@@ -71,4 +69,13 @@ class PublicBodyHeading < ActiveRecord::Base
end
end
+ private
+
+ def empty_translation_in_params?(attributes)
+ attrs_with_values = attributes.select do |key, value|
+ value != '' and key.to_s != 'locale'
+ end
+ attrs_with_values.empty?
+ end
+
end
diff --git a/app/views/admin_public_body/_form.html.erb b/app/views/admin_public_body/_form.html.erb
index c765c116e..cf0c0e3de 100644
--- a/app/views/admin_public_body/_form.html.erb
+++ b/app/views/admin_public_body/_form.html.erb
@@ -1,20 +1,39 @@
-<%= error_messages_for 'public_body' %>
+<% if @public_body.errors.any? %>
+ <ul>
+ <% @public_body.errors.each do |attr, message| %>
+ <% unless attr.to_s.starts_with?('translation') %>
+ <li><%= message %></li>
+ <% end %>
+ <% end %>
+ </ul>
+<% end %>
+
+<% @public_body.ordered_translations.each do |translation| %>
+ <% if translation.errors.any? %>
+ <%= locale_name(translation.locale.to_s) || translation.locale.to_s %>
+ <ul>
+ <% translation.errors.each do |attr, message| %>
+ <li><%= message %></li>
+ <% end %>
+ </ul>
+ <% end %>
+<% end %>
<!--[form:public_body]-->
<div id="div-locales">
<ul class="locales nav nav-tabs">
- <% @public_body.translations.each do |translation| %>
+ <% @public_body.ordered_translations.each do |translation| %>
<li>
<a href="#div-locale-<%= translation.locale.to_s %>" data-toggle="tab">
- <%= locale_name(translation.locale.to_s) || _("Default locale") %>
+ <%= locale_name(translation.locale.to_s) || translation.locale.to_s %>
</a>
</li>
<% end %>
</ul>
<div class="tab-content">
- <% @public_body.translations.each do |translation| %>
+ <% @public_body.ordered_translations.each do |translation| %>
<% if translation.locale.to_s == I18n.default_locale.to_s %>
<%= fields_for('public_body', @public_body) do |t| %>
<%= render :partial => 'locale_fields', :locals => { :t => t, :locale => translation.locale } %>
diff --git a/app/views/admin_public_body_categories/_form.html.erb b/app/views/admin_public_body_categories/_form.html.erb
index 1f033ac9b..00137b9ed 100644
--- a/app/views/admin_public_body_categories/_form.html.erb
+++ b/app/views/admin_public_body_categories/_form.html.erb
@@ -1,46 +1,49 @@
-<%= error_messages_for 'category' %>
+<% if @category.errors.any? %>
+ <ul>
+ <% @category.errors.each do |attr, message| %>
+ <% unless attr.to_s.starts_with?('translation') %>
+ <li><%= message %></li>
+ <% end %>
+ <% end %>
+ </ul>
+<% end %>
+
+<% @category.ordered_translations.each do |translation| %>
+ <% if translation.errors.any? %>
+ <%= locale_name(translation.locale.to_s) || translation.locale.to_s %>
+ <ul>
+ <% translation.errors.each do |attr, message| %>
+ <li><%= message %></li>
+ <% end %>
+ </ul>
+ <% end %>
+<% end %>
<!--[form:public_body_category]-->
<div id="div-locales">
<ul class="locales nav nav-tabs">
- <% I18n.available_locales.each_with_index do |locale, i| %>
- <li><a href="#div-locale-<%=locale.to_s%>" data-toggle="tab" ><%=locale_name(locale.to_s) || "Default locale"%></a></li>
- <% end %>
+ <% @category.ordered_translations.each do |translation| %>
+ <li>
+ <a href="#div-locale-<%= translation.locale.to_s %>" data-toggle="tab" >
+ <%= locale_name(translation.locale.to_s) || translation.locale.to_s %>
+ </a>
+ </li>
+ <% end %>
</ul>
+
<div class="tab-content">
-<%
- I18n.available_locales.each do |locale|
- if locale==I18n.default_locale # The default locale is submitted as part of the bigger object...
- prefix = 'public_body_category'
- object = @category
- else # ...but additional locales go "on the side"
- prefix = "public_body_category[translated_versions][]"
- object = @category.new_record? ?
- PublicBodyCategory::Translation.new :
- @category.find_translation_by_locale(locale.to_s) || PublicBodyCategory::Translation.new
- end
-%>
- <%= fields_for prefix, object do |t| %>
- <div class="tab-pane" id="div-locale-<%=locale.to_s%>">
- <div class="control-group">
- <%= t.hidden_field :locale, :value => locale.to_s %>
- <label for="<%= form_tag_id(t.object_name, :title, locale) %>" class="control-label">Title</label>
- <div class="controls">
- <%= t.text_field :title, :id => form_tag_id(t.object_name, :title, locale), :class => "span4" %>
- </div>
- </div>
- <div class="control-group">
- <label for="<%= form_tag_id(t.object_name, :description, locale) %>" class="control-label">Description</label>
- <div class="controls">
- <%= t.text_field :description, :id => form_tag_id(t.object_name, :description, locale), :class => "span4" %>
- </div>
- </div>
- </div>
- <%
- end
-end
-%>
+ <% @category.ordered_translations.each do |translation| %>
+ <% if translation.locale.to_s == I18n.default_locale.to_s %>
+ <%= fields_for('public_body_category', @category) do |t| %>
+ <%= render :partial => 'locale_fields', :locals => { :t => t, :locale => translation.locale } %>
+ <% end %>
+ <% else %>
+ <%= f.fields_for(:translations, translation, :child_index => translation.locale) do |t| %>
+ <%= render :partial => 'locale_fields', :locals => { :t => t, :locale => translation.locale } %>
+ <% end %>
+ <% end %>
+ <% end %>
</div>
</div>
diff --git a/app/views/admin_public_body_categories/_locale_fields.html.erb b/app/views/admin_public_body_categories/_locale_fields.html.erb
new file mode 100644
index 000000000..aff001098
--- /dev/null
+++ b/app/views/admin_public_body_categories/_locale_fields.html.erb
@@ -0,0 +1,27 @@
+<div class="tab-pane" id="div-locale-<%=locale.to_s%>">
+ <div class="control-group">
+ <%= t.hidden_field :locale, :value => locale.to_s %>
+ <label for="<%= form_tag_id(t.object_name, :title, locale) %>" class="control-label">Title</label>
+ <div class="controls">
+ <% if locale == I18n.default_locale && t.object.errors[:title].any? %>
+ <span class="fieldWithErrors">
+ <% end %>
+ <%= t.text_field :title, :id => form_tag_id(t.object_name, :title, locale), :class => "span4" %>
+ <% if locale == I18n.default_locale && t.object.errors[:title].any? %>
+ </span>
+ <%end %>
+ </div>
+ </div>
+ <div class="control-group">
+ <label for="<%= form_tag_id(t.object_name, :description, locale) %>" class="control-label">Description</label>
+ <div class="controls">
+ <% if locale == I18n.default_locale && t.object.errors[:description].any? %>
+ <span class="fieldWithErrors">
+ <% end %>
+ <%= t.text_field :description, :id => form_tag_id(t.object_name, :description, locale), :class => "span4" %>
+ <% if locale == I18n.default_locale && t.object.errors[:description].any? %>
+ </span>
+ <%end %>
+ </div>
+ </div>
+</div>
diff --git a/app/views/admin_public_body_headings/_form.html.erb b/app/views/admin_public_body_headings/_form.html.erb
index d4e914ca1..7eaa4bff7 100644
--- a/app/views/admin_public_body_headings/_form.html.erb
+++ b/app/views/admin_public_body_headings/_form.html.erb
@@ -1,40 +1,49 @@
-<%= error_messages_for 'heading' %>
+<% if @heading.errors.any? %>
+ <ul>
+ <% @heading.errors.each do |attr, message| %>
+ <% unless attr.to_s.starts_with?('translation') %>
+ <li><%= message %></li>
+ <% end %>
+ <% end %>
+ </ul>
+<% end %>
+
+<% @heading.ordered_translations.each do |translation| %>
+ <% if translation.errors.any? %>
+ <%= locale_name(translation.locale.to_s) || translation.locale.to_s %>
+ <ul>
+ <% translation.errors.each do |attr, message| %>
+ <li><%= message %></li>
+ <% end %>
+ </ul>
+ <% end %>
+<% end %>
+
<!--[form:public_body_heading]-->
<div id="div-locales">
<ul class="locales nav nav-tabs">
- <% I18n.available_locales.each_with_index do |locale, i| %>
- <li><a href="#div-locale-<%=locale.to_s%>" data-toggle="tab" ><%=locale_name(locale.to_s) || "Default locale"%></a></li>
- <% end %>
+ <% @heading.ordered_translations.each do |translation| %>
+ <li>
+ <a href="#div-locale-<%= translation.locale.to_s %>" data-toggle="tab" >
+ <%= locale_name(translation.locale.to_s) || translation.locale.to_s %>
+ </a>
+ </li>
+ <% end %>
</ul>
<div class="tab-content">
-<%
- for locale in I18n.available_locales do
- if locale==I18n.default_locale # The default locale is submitted as part of the bigger object...
- prefix = 'public_body_heading'
- object = @heading
- else # ...but additional locales go "on the side"
- prefix = "public_body_heading[translated_versions][]"
- object = @heading.new_record? ?
- PublicBodyHeading::Translation.new :
- @heading.find_translation_by_locale(locale.to_s) || PublicBodyHeading::Translation.new
- end
-%>
- <%= fields_for prefix, object do |t| %>
- <div class="tab-pane" id="div-locale-<%=locale.to_s%>">
- <div class="control-group">
- <%= t.hidden_field :locale, :value => locale.to_s %>
- <label for="<%= form_tag_id(t.object_name, :name, locale) %>" class="control-label">Name</label>
- <div class="controls">
- <%= t.text_field :name, :id => form_tag_id(t.object_name, :name, locale), :class => "span4" %>
- </div>
- </div>
- </div>
- <%
- end
-end
-%>
+ <% @heading.ordered_translations.each do |translation| %>
+ <% if translation.locale.to_s == I18n.default_locale.to_s %>
+ <%= fields_for('public_body_heading', @heading) do |t| %>
+ <%= render :partial => 'locale_fields', :locals => { :t => t, :locale => translation.locale } %>
+ <% end %>
+ <% else %>
+ <%= f.fields_for(:translations, translation, :child_index => translation.locale) do |t| %>
+ <%= render :partial => 'locale_fields', :locals => { :t => t, :locale => translation.locale } %>
+ <% end %>
+ <% end %>
+ <% end %>
</div>
</div>
diff --git a/app/views/admin_public_body_headings/_locale_fields.html.erb b/app/views/admin_public_body_headings/_locale_fields.html.erb
new file mode 100644
index 000000000..3846bfafa
--- /dev/null
+++ b/app/views/admin_public_body_headings/_locale_fields.html.erb
@@ -0,0 +1,9 @@
+<div class="tab-pane" id="div-locale-<%=locale.to_s%>">
+ <div class="control-group">
+ <%= t.hidden_field :locale, :value => locale.to_s %>
+ <label for="<%= form_tag_id(t.object_name, :name, locale) %>" class="control-label">name</label>
+ <div class="controls">
+ <%= t.text_field :name, :id => form_tag_id(t.object_name, :name, locale), :class => "span4" %>
+ </div>
+ </div>
+</div>
diff --git a/app/views/info_request_batch/_batch_sent.html.erb b/app/views/info_request_batch/_batch_sent.html.erb
index eed93916d..b7d54d75c 100644
--- a/app/views/info_request_batch/_batch_sent.html.erb
+++ b/app/views/info_request_batch/_batch_sent.html.erb
@@ -1,18 +1,57 @@
-<div id="notice">
- <p>
- <%= _("Your requests will be <strong>sent</strong> shortly!") %>
- </p>
+<div id="content">
+ <div class="request-sent-message" id="notice">
+ <h1>
+ <%= _("Your requests will be <strong>sent</strong> shortly!") %>
+ </h1>
+ <div class="request-sent-message__row">
+ <div class="request-sent-message__column-1">
+ <p class="subtitle">
+ <%= _("<strong>We will email you</strong> when they have been sent. " \
+ "We will also email you when there is a response to any of them, or " \
+ "after {{late_number_of_days}} working days if the authorities still " \
+ "haven't replied by then.",
+ :late_number_of_days => AlaveteliConfiguration::reply_late_after_days) %>
+ </p>
- <p>
- <%= _("<strong>We will email you</strong> when they have been sent. " \
- "We will also email you when there is a response to any of them, or " \
- "after {{late_number_of_days}} working days if the authorities still " \
- "haven't replied by then.",
- :late_number_of_days => AlaveteliConfiguration::reply_late_after_days) %>
- </p>
+ <h2><%= _("Share your batch request") %></h2>
- <p>
- <%= _("If you write about these requests (for example in a forum or a blog) " \
- "please link to this page.") %>
- </p>
+ <%= link_to image_tag("next-step-twitter.png",
+ :alt => _("Tweet it"),
+ :width => "120",
+ :height => "37"),
+ "https://twitter.com/intent/tweet?" << {
+ :url => request.url,
+ :via => AlaveteliConfiguration.twitter_username,
+ :text => "'#{ @info_request_batch.title }'",
+ :related => _('alaveteli_foi:The software that runs {{site_name}}', :site_name => site_name)
+ }.to_query, :class => 'share-link' %>
+
+ <%= link_to image_tag("next-step-facebook.png",
+ :alt => _("Share on Facebook"),
+ :width => "120",
+ :height => "37"),
+ "https://www.facebook.com/sharer/sharer.php?" << {
+ :u => request.url
+ }.to_query, :class => 'share-link' %>
+
+ <h2><%= _("Keep your requests up to date") %></h2>
+ <p>
+ <%= _('If you write about these requests ' \
+ '(for example in a forum or a blog) ' \
+ 'please link to this page.') %>
+ </p>
+ </div>
+ <div class="request-sent-message__column-2">
+ <div class="what-next">
+ <h2><%= _("What next?") %></h2>
+ <ul class="what-next__list">
+ <li>
+ <%= link_to _("Help us classify requests that haven't " \
+ "been updated"), categorise_play_path %>
+ </li>
+ </ul>
+ </div>
+ </div>
+ </div>
+ </div>
</div>
diff --git a/app/views/public_body/show.html.erb b/app/views/public_body/show.html.erb
index 5c11c9428..016c2460d 100644
--- a/app/views/public_body/show.html.erb
+++ b/app/views/public_body/show.html.erb
@@ -13,7 +13,7 @@
<div class="authority__header">
<h1><%=h(@public_body.name)%></h1>
<p class="authority__header__subtitle">
- <%=@public_body.type_of_authority(true)%><% if not @public_body.short_name.empty? %>,
+ <%= type_of_authority(@public_body) %><% if not @public_body.short_name.empty? %>,
<%= _('also called {{public_body_short_name}}', :public_body_short_name => h(@public_body.short_name))%><% end %>
<% if !@user.nil? && @user.admin_page_links? %>
(<%= link_to _("admin"), admin_body_path(@public_body) %>)
diff --git a/app/views/request/_request_filter_form.html.erb b/app/views/request/_request_filter_form.html.erb
index 19961ddfc..549ddb32c 100644
--- a/app/views/request/_request_filter_form.html.erb
+++ b/app/views/request/_request_filter_form.html.erb
@@ -14,7 +14,7 @@
<%= link_to label, url_for(:controller => "request", :action => "list", :view => status) + "?" + request.query_string + '#results' %>
<% end %>
<% else %>
- <%= label %>
+ <span><%= label %></span>
<% end %>
</li>
<% end %>
diff --git a/app/views/request/new.html.erb b/app/views/request/new.html.erb
index cbcf5a0a5..486a89d45 100644
--- a/app/views/request/new.html.erb
+++ b/app/views/request/new.html.erb
@@ -70,9 +70,9 @@
<%= foi_error_messages_for :info_request, :outgoing_message %>
- <% if @info_request.public_body.override_request_email %>
+ <% if !AlaveteliConfiguration::override_all_public_body_request_emails.blank? %>
<div class="warning">
- <%= _("<strong>Note:</strong> Because we're testing, requests are being sent to {{email}} rather than to the actual authority.", :email => @info_request.public_body.override_request_email) %>
+ <%= _("<strong>Note:</strong> Because we're testing, requests are being sent to {{email}} rather than to the actual authority.", :email => AlaveteliConfiguration::override_all_public_body_request_emails) %>
</div>
<% end %>