Commit e7b563e65a9c4e39270d00bbc52967834def1552
1 parent
cb16e304
Exists in
master
and in
29 other branches
[language-selection] Available languages interface and params treatment
Showing
4 changed files
with
39 additions
and
9 deletions
Show diff stats
app/controllers/admin/admin_panel_controller.rb
... | ... | @@ -8,6 +8,9 @@ class AdminPanelController < AdminController |
8 | 8 | |
9 | 9 | def site_info |
10 | 10 | if request.post? |
11 | + if params[:environment][:languages] | |
12 | + params[:environment][:languages] = params[:environment][:languages].map {|lang, value| lang if value=='true'}.compact | |
13 | + end | |
11 | 14 | if @environment.update_attributes(params[:environment]) |
12 | 15 | session[:notice] = _('Environment settings updated') |
13 | 16 | redirect_to :action => 'index' | ... | ... |
app/helpers/forms_helper.rb
... | ... | @@ -123,6 +123,25 @@ module FormsHelper |
123 | 123 | options_for_select.join("\n") |
124 | 124 | end |
125 | 125 | |
126 | + def balanced_table(items, per_row=3) | |
127 | + items = items.map {|item| content_tag('td', item, :style => 'border: none; background: transparent;')} | |
128 | + rows = [] | |
129 | + row = [] | |
130 | + counter = 0 | |
131 | + items.each do |item| | |
132 | + counter += 1 | |
133 | + row << item | |
134 | + if counter % per_row == 0 | |
135 | + rows << content_tag('tr', row.join("\n")) | |
136 | + counter = 0 | |
137 | + row = [] | |
138 | + end | |
139 | + end | |
140 | + rows << content_tag('tr', row.join("\n")) | |
141 | + | |
142 | + content_tag('table',rows.join("\n")) | |
143 | + end | |
144 | + | |
126 | 145 | protected |
127 | 146 | def self.next_id_number |
128 | 147 | if defined? @@id_num | ... | ... |
app/views/admin_panel/_site_info.rhtml
... | ... | @@ -3,14 +3,13 @@ |
3 | 3 | <%= labelled_form_field(_('Default language'), select(:environment, :default_language, environment.locales.invert, { :selected => environment.default_locale, :include_blank => true })) %> |
4 | 4 | <%= label_tag :languages, _('Available languages') %> |
5 | 5 | <br /> |
6 | -<% counter = 0 %> | |
7 | -<table> | |
8 | -<% Noosfero.locales.each do |value, name| %> | |
9 | - <%= "<tr>" if counter%3==0 %> | |
10 | - <% counter += 1 %> | |
11 | - <%= content_tag('td', labelled_check_box(name, "environment[languages][#{value}]", true, environment.available_locales.include?(value))) %> | |
12 | - <%= "</tr>" if counter%3==0 %> | |
13 | -<% end %> | |
14 | -</table> | |
6 | + | |
7 | +<% | |
8 | + fields = Noosfero.locales.map do |value, name| | |
9 | + labelled_check_box(name, "environment[languages][#{value}]", true, environment.available_locales.include?(value)) | |
10 | + end | |
11 | +%> | |
12 | +<%= balanced_table(fields)%> | |
13 | + | |
15 | 14 | <br /> |
16 | 15 | <%= labelled_form_field _('Homepage content'), text_area(:environment, :description, :cols => 40, :style => 'width: 90%', :class => 'mceEditor') %> | ... | ... |
test/functional/admin_panel_controller_test.rb
... | ... | @@ -351,4 +351,13 @@ class AdminPanelControllerTest < ActionController::TestCase |
351 | 351 | assert_tag :tag => 'a', :content => /Plugin2 link/, :attributes => {:href => /plugin2.com/} |
352 | 352 | end |
353 | 353 | |
354 | + should 'save available languages and default language properly' do | |
355 | + post :site_info, :environment => {:default_language => 'pt', :languages => {'pt' => 'true', 'en' => 'false'}} | |
356 | + environment = Environment.default | |
357 | + | |
358 | + assert_equal 'pt', environment.default_language | |
359 | + assert_includes environment.languages, 'pt' | |
360 | + assert_not_includes environment.languages, 'en' | |
361 | + end | |
362 | + | |
354 | 363 | end | ... | ... |