From 56f6efa5900fda4d20ebe00c7a29f789d7ee7331 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 10 Dec 2014 21:27:53 +0100 Subject: [PATCH 1/2] Allow to edit address from user profile --- app/controllers/home_controller.rb | 19 ++++++++++++++++++- app/views/home/profile.html.haml | 2 +- app/views/shared/_user_form_fields.html.haml | 7 +++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 99f108ce..8e7ac638 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -15,7 +15,8 @@ class HomeController < ApplicationController end def update_profile - if @current_user.update_attributes(params[:user]) + if @current_user.update_attributes(user_params) + @current_user.ordergroup.update_attributes(ordergroup_params) if ordergroup_params session[:locale] = @current_user.locale redirect_to my_profile_url, notice: I18n.t('home.changes_saved') else @@ -62,4 +63,20 @@ class HomeController < ApplicationController redirect_to my_profile_path end + protected + + def user_params + params + .require(:user) + .permit(:first_name, :last_name, :email, :phone, + :password, :password_confirmation).merge(params[:user].slice(:settings_attributes)) + end + + def ordergroup_params + params + .require(:user) + .require(:ordergroup) + .permit(:contact_address) + end + end diff --git a/app/views/home/profile.html.haml b/app/views/home/profile.html.haml index b0094e83..40edd4aa 100644 --- a/app/views/home/profile.html.haml +++ b/app/views/home/profile.html.haml @@ -6,7 +6,7 @@ = h(t('.user.title', user: show_user)) %small= t '.user.since', when: distance_of_time_in_words(Time.now, @current_user.created_on) = simple_form_for(@current_user, :url => update_profile_path) do |f| - = render :partial => 'shared/user_form_fields', :locals => {:f => f, :password_autocomplete => 'store-only'} + = render :partial => 'shared/user_form_fields', :locals => {:f => f, :password_autocomplete => 'store-only', with_address: true} .form-actions = submit_tag t('ui.save'), class: 'btn' .span5 diff --git a/app/views/shared/_user_form_fields.html.haml b/app/views/shared/_user_form_fields.html.haml index deb574ef..c327924a 100644 --- a/app/views/shared/_user_form_fields.html.haml +++ b/app/views/shared/_user_form_fields.html.haml @@ -6,12 +6,15 @@ -# You can control password autocompletion by passing `password_autocomplete` to this partial. -# Possible values: undefined/nil, true, false, 'store-only' -# see also https://github.com/foodcoops/foodsoft/wiki/Form-autocompletion -- password_autocomplete = nil unless defined?(:password_autocomplete) -- password_html = autocomplete_flag_to_password_html(password_autocomplete) +- password_html = autocomplete_flag_to_password_html(local_assigns[:password_autocomplete]) = f.input :password, :required => f.object.new_record?, input_html: password_html = f.input :password_confirmation, :required => f.object.new_record?, input_html: password_html = f.input :phone +- if local_assigns[:with_address] && (f.object.ordergroup || f.object.new_record?) + = f.fields_for [:ordergroup, f.object.ordergroup || Ordergroup.new] do |ogf| + = ogf.input :contact_address, label: t('activerecord.attributes.ordergroup.contact_address'), required: false + = f.simple_fields_for :settings_attributes do |s| = s.simple_fields_for :profile, defaults: { inline_label: true } do |profile| = profile.input 'language', as: :select, collection: available_locales, required: false, selected: f.object.settings.profile['language'] From 86eee9424970c96c2a63211bc903bf86b8ca7692 Mon Sep 17 00:00:00 2001 From: wvengen Date: Tue, 16 Dec 2014 20:48:40 +0100 Subject: [PATCH 2/2] Add hint for ordergroup address in user form --- app/views/shared/_user_form_fields.html.haml | 4 +++- config/locales/en.yml | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/views/shared/_user_form_fields.html.haml b/app/views/shared/_user_form_fields.html.haml index c327924a..afca2598 100644 --- a/app/views/shared/_user_form_fields.html.haml +++ b/app/views/shared/_user_form_fields.html.haml @@ -13,7 +13,9 @@ - if local_assigns[:with_address] && (f.object.ordergroup || f.object.new_record?) = f.fields_for [:ordergroup, f.object.ordergroup || Ordergroup.new] do |ogf| - = ogf.input :contact_address, label: t('activerecord.attributes.ordergroup.contact_address'), required: false + - address_hint = f.object.ordergroup.users.count > 1 ? t('.contact_address_hint') : nil + = ogf.input :contact_address, label: t('activerecord.attributes.ordergroup.contact_address'), required: false, + input_html: { title: address_hint, data: {toggle: 'tooltip', placement: 'right'} } = f.simple_fields_for :settings_attributes do |s| = s.simple_fields_for :profile, defaults: { inline_label: true } do |profile| diff --git a/config/locales/en.yml b/config/locales/en.yml index cf925ed3..a50adf5e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1423,6 +1423,8 @@ en: title: Current orders total_sum: Total sum who_ordered: Who ordered? + user_form_fields: + contact_address_hint: The address of your ordergroup. If you update this, it changes for other members of the ordergroup as well. workgroup_members: title: Group memberships simple_form: