Commit 1064a46c96dae48da2a0b430578bc4817cf81f56
1 parent
9bc8cc2a
Exists in
master
and in
29 other branches
profile-editor: use timepicker on birth-date field
Showing
5 changed files
with
8 additions
and
58 deletions
Show diff stats
app/controllers/my_profile/profile_editor_controller.rb
@@ -15,20 +15,14 @@ class ProfileEditorController < MyProfileController | @@ -15,20 +15,14 @@ class ProfileEditorController < MyProfileController | ||
15 | @possible_domains = profile.possible_domains | 15 | @possible_domains = profile.possible_domains |
16 | if request.post? | 16 | if request.post? |
17 | params[:profile_data][:fields_privacy] ||= {} if profile.person? && params[:profile_data].is_a?(Hash) | 17 | params[:profile_data][:fields_privacy] ||= {} if profile.person? && params[:profile_data].is_a?(Hash) |
18 | - begin | ||
19 | - Profile.transaction do | ||
20 | - Image.transaction do | ||
21 | - if profile.update_attributes!(params[:profile_data]) | ||
22 | - redirect_to :action => 'index', :profile => profile.identifier | ||
23 | - end | 18 | + Profile.transaction do |
19 | + Image.transaction do | ||
20 | + if @profile_data.update_attributes(params[:profile_data]) | ||
21 | + redirect_to :action => 'index', :profile => profile.identifier | ||
22 | + else | ||
23 | + profile.identifier = params[:profile] if profile.identifier.blank? | ||
24 | end | 24 | end |
25 | - end | ||
26 | - rescue Exception => ex | ||
27 | - if profile.identifier.blank? | ||
28 | - profile.identifier = params[:profile] | ||
29 | - end | ||
30 | - session[:notice] = _('Cannot update profile') | ||
31 | - logger.error ex.to_s | 25 | + end |
32 | end | 26 | end |
33 | end | 27 | end |
34 | end | 28 | end |
app/models/person.rb
@@ -157,11 +157,6 @@ class Person < Profile | @@ -157,11 +157,6 @@ class Person < Profile | ||
157 | 157 | ||
158 | validates_multiparameter_assignments | 158 | validates_multiparameter_assignments |
159 | 159 | ||
160 | - validates_each :birth_date do |record,attr,value| | ||
161 | - date_str = record.birth_date_before_type_cast | ||
162 | - record.errors.add(attr) if value.blank? && !date_str.blank? | ||
163 | - end | ||
164 | - | ||
165 | def self.fields | 160 | def self.fields |
166 | FIELDS | 161 | FIELDS |
167 | end | 162 | end |
app/views/profile_editor/_person_form.html.erb
@@ -16,7 +16,7 @@ | @@ -16,7 +16,7 @@ | ||
16 | <%= optional_field(@person, 'jabber_id', f.text_field(:jabber_id, :rel => _('Jabber'))) %> | 16 | <%= optional_field(@person, 'jabber_id', f.text_field(:jabber_id, :rel => _('Jabber'))) %> |
17 | <%= optional_field(@person, 'personal_website', f.text_field(:personal_website, :rel => _('Personal website'))) %> | 17 | <%= optional_field(@person, 'personal_website', f.text_field(:personal_website, :rel => _('Personal website'))) %> |
18 | <%= optional_field(@person, 'sex', f.radio_group(:profile_data, :sex, [ ['male',_('Male')], ['female',_('Female')] ])) %> | 18 | <%= optional_field(@person, 'sex', f.radio_group(:profile_data, :sex, [ ['male',_('Male')], ['female',_('Female')] ])) %> |
19 | -<%= optional_field(@person, 'birth_date', labelled_form_field(_('Birth date'), '<div class="select-birth-date">' + pick_date(:profile_data, :birth_date, {:start_year => (Date.today.year - 100), :end_year => (Date.today.year - 5)}) + '</div>')) %> | 19 | +<%= optional_field(@person, 'birth_date', labelled_form_field(_('Birth date'), date_field('profile_data[birth_date]', @profile_data. birth_date, '%Y-%m-%d', {:change_month => true, :change_year => true, :year_range => '-100:-5', :date_format => 'yy-mm-dd'}, {:id => 'profile_data_birth_date'}))) %> |
20 | <%= optional_field(@person, 'nationality', f.text_field(:nationality, :rel => _('Nationality'))) %> | 20 | <%= optional_field(@person, 'nationality', f.text_field(:nationality, :rel => _('Nationality'))) %> |
21 | <%= optional_field(@person, 'country', select_country(_('Country'), 'profile_data', 'country', {:class => 'type-select'})) %> | 21 | <%= optional_field(@person, 'country', select_country(_('Country'), 'profile_data', 'country', {:class => 'type-select'})) %> |
22 | <%= optional_field(@person, 'state', f.text_field(:state, :id => 'state_field', :rel => _('State'))) %> | 22 | <%= optional_field(@person, 'state', f.text_field(:state, :id => 'state_field', :rel => _('State'))) %> |
features/edit_profile.feature
@@ -6,30 +6,6 @@ Feature: edit profile | @@ -6,30 +6,6 @@ Feature: edit profile | ||
6 | | joao | | 6 | | joao | |
7 | Given I am logged in as "joao" | 7 | Given I am logged in as "joao" |
8 | 8 | ||
9 | - Scenario: Warn about invalid birth date when active | ||
10 | - Given the following person fields are active fields | ||
11 | - | display_name | | ||
12 | - | birth_date | | ||
13 | - When I go to joao's control panel | ||
14 | - And I follow "Edit Profile" | ||
15 | - And I select "November" from "profile_data_birth_date_2i" | ||
16 | - And I select "15" from "profile_data_birth_date_3i" | ||
17 | - And I press "Save" | ||
18 | - Then I should see "Birth date is invalid" | ||
19 | - And I should not see "Birth date can't be blank" | ||
20 | - | ||
21 | - Scenario: Warn about invalid birth date when required | ||
22 | - Given the following person fields are required fields | ||
23 | - | display_name | | ||
24 | - | birth_date | | ||
25 | - When I go to joao's control panel | ||
26 | - And I follow "Edit Profile" | ||
27 | - And I select "November" from "profile_data_birth_date_2i" | ||
28 | - And I select "15" from "profile_data_birth_date_3i" | ||
29 | - And I press "Save" | ||
30 | - Then I should see "Birth date is invalid" | ||
31 | - And I should not see "Birth date can't be blank" | ||
32 | - | ||
33 | Scenario: Not warn if birth date is valid when active | 9 | Scenario: Not warn if birth date is valid when active |
34 | Given the following person fields are active fields | 10 | Given the following person fields are active fields |
35 | | display_name | | 11 | | display_name | |
test/unit/person_test.rb
@@ -1152,21 +1152,6 @@ class PersonTest < ActiveSupport::TestCase | @@ -1152,21 +1152,6 @@ class PersonTest < ActiveSupport::TestCase | ||
1152 | assert_includes Person.more_active, profile | 1152 | assert_includes Person.more_active, profile |
1153 | end | 1153 | end |
1154 | 1154 | ||
1155 | - should 'handle multiparameter attribute exception on birth date field' do | ||
1156 | - assert_nothing_raised ActiveRecord::MultiparameterAssignmentErrors do | ||
1157 | - p = Person.new( | ||
1158 | - :name => 'birthday', :identifier => 'birthday', | ||
1159 | - 'birth_date(1i)' => '', 'birth_date(2i)' => '6', 'birth_date(3i)' => '16' | ||
1160 | - ) | ||
1161 | - end | ||
1162 | - end | ||
1163 | - | ||
1164 | - should 'not accept an empty year on birth date' do | ||
1165 | - p = Person.new(:birth_date => "1115") | ||
1166 | - p.valid? | ||
1167 | - assert p.errors[:birth_date.to_s].present? | ||
1168 | - end | ||
1169 | - | ||
1170 | should 'associate report with the correct complaint' do | 1155 | should 'associate report with the correct complaint' do |
1171 | p1 = create_user('user1').person | 1156 | p1 = create_user('user1').person |
1172 | p2 = create_user('user2').person | 1157 | p2 = create_user('user2').person |