diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin_public_body_controller.rb | 34 | ||||
-rwxr-xr-x | app/helpers/link_to_helper.rb | 2 | ||||
-rw-r--r-- | app/views/admin_public_body/_form.rhtml | 39 |
3 files changed, 53 insertions, 22 deletions
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb index 021122734..239aca6ec 100644 --- a/app/controllers/admin_public_body_controller.rb +++ b/app/controllers/admin_public_body_controller.rb @@ -90,14 +90,30 @@ class AdminPublicBodyController < AdminController end def create - @locale = self.locale_from_params() - PublicBody.with_locale(@locale) do - params[:public_body][:last_edit_editor] = admin_http_auth_user() - @public_body = PublicBody.new(params[:public_body]) - if @public_body.save - flash[:notice] = 'PublicBody was successfully created.' - redirect_to admin_url('body/show/' + @public_body.id.to_s) - else + # Start creating the public body in the default locale + PublicBody.with_locale(I18n.default_locale) do + begin + ActiveRecord::Base.transaction do + params[:public_body][:last_edit_editor] = admin_http_auth_user() + @public_body = PublicBody.new(params[:public_body]) + @public_body.save! + + # Next, save the translations in the additional locales + I18n.available_locales.each do |locale| + PublicBody.with_locale(locale) do + unless (attr_values = params["public_body_#{locale}"]).nil? + # 'publication_scheme' can't be null in the current DB schema + attr_values[:publication_scheme] = attr_values[:publication_scheme] || '' + @public_body.attributes = attr_values + @public_body.save! + end + end + end + + flash[:notice] = 'PublicBody was successfully created.' + redirect_to admin_url('body/show/' + @public_body.id.to_s) + end + rescue ActiveRecord::RecordInvalid render :action => 'new' end end @@ -157,7 +173,7 @@ class AdminPublicBodyController < AdminController # Try with dry run first csv_contents = params[:csv_file].read - en = PublicBody.import_csv(csv_contents, params[:tag], true, admin_http_auth_user(), I18n.available_locales) + en = PublicBody.import_csv(csv_contents, params[:tag], true, admin_http_auth_user(), available_locales) errors = en[0] notes = en[1] diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 444129052..558479c26 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -61,7 +61,7 @@ module LinkToHelper # Public bodies def public_body_url(public_body) - return show_public_body_url(:url_name => public_body.url_name, :only_path => true) + public_body.url_name.nil? ? '' : show_public_body_url(:url_name => public_body.url_name, :only_path => true) end def public_body_link_short(public_body) link_to h(public_body.short_or_long_name), public_body_url(public_body) diff --git a/app/views/admin_public_body/_form.rhtml b/app/views/admin_public_body/_form.rhtml index b1516be2e..1fb573994 100644 --- a/app/views/admin_public_body/_form.rhtml +++ b/app/views/admin_public_body/_form.rhtml @@ -21,14 +21,35 @@ <% end %> </div> -<p><label for="public_body_name">Name</label><br/> -<%= text_field 'public_body', 'name', :size => 60 %></p> +<h3>Localized Fields</h3> -<p><label for="public_body_short_name">Short name <small>(only put in abbreviations which are really used, otherwise leave blank. Short or long name is used in the URL - don't worry about breaking URLs through renaming, as the history is used to redirect)</small></label><br/> -<%= text_field 'public_body', 'short_name', :size => 60 %></p> +<% + for locale in I18n.available_locales do + object_name = locale==:en ? 'public_body' : "public_body_#{locale.to_s}" +%> +<div> + <p>Locale: <%= locale_name(locale.to_s) %></p> -<p><label for="public_body_request_email">Request email <small>(set to <strong>blank</strong> (empty string) if can't find an address; these emails are <strong>public</strong> as anyone can view with a CAPTCHA)</small></label><br/> -<%= text_field 'public_body', 'request_email', :size => 40 %></p> + <p><label for="public_body_name">Name</label><br/> + <%= text_field object_name, 'name', :size => 60 %></p> + + <p><label for="public_body_short_name">Short name <small>(only put in abbreviations which are really used, otherwise leave blank. Short or long name is used in the URL - don't worry about breaking URLs through renaming, as the history is used to redirect)</small></label><br/> + <%= text_field object_name, 'short_name', :size => 60 %></p> + + <p><label for="public_body_request_email">Request email <small>(set to <strong>blank</strong> (empty string) if can't find an address; these emails are <strong>public</strong> as anyone can view with a CAPTCHA)</small></label><br/> + <%= text_field object_name, 'request_email', :size => 40 %></p> + + <p><label for="public_body_publication_scheme">Publication scheme URL</label><br/> + <%= text_field object_name, 'publication_scheme', :size => 60 %></p> + + <p><label for="public_body_notes">Public notes</label> <small>(HTML, for users to consider when making FOI requests to the authority)</small><br/> + <%= text_area object_name, 'notes', :rows => 3, :cols => 60 %></p> +</div> +<% + end +%> + +<h3>Common Fields</h3> <p><label for="public_body_tag_string">Tags <small>(space separated; see list of tags on the right; also <strong>not_apply</strong> if FOI and EIR no longer apply to authority, <strong>eir_only</strong> if EIR but not FOI applies to authority, <strong>defunct</strong> if the authority no longer exists; charity:NUMBER if a registered charity)</small></label><br/> <%= text_field 'public_body', 'tag_string', :size => 60 %></p> @@ -36,12 +57,6 @@ <p><label for="public_body_home_page">Home page <small>(of whole authority, not just their FOI page; set to <strong>blank</strong> (empty string) to guess it from the email)</small></label><br/> <%= text_field 'public_body', 'home_page', :size => 60 %></p> -<p><label for="public_body_publication_scheme">Publication scheme URL</label><br/> -<%= text_field 'public_body', 'publication_scheme', :size => 60 %></p> - -<p><label for="public_body_notes">Public notes</label> <small>(HTML, for users to consider when making FOI requests to the authority)</small><br/> -<%= text_area 'public_body', 'notes', :rows => 3, :cols => 60 %></p> - <p><label for="public_body_last_edit_comment"><strong>Comment</strong> for this edit</label> <small>(put URL or other source of new info)</small><br/> <%= text_area 'public_body', 'last_edit_comment', :rows => 3, :cols => 60 %></p> <!--[eoform:public_body]--> |