Merge pull request #332 from foodcoops/feature/edit-address
Allow to edit address from user profile
This commit is contained in:
commit
1c0db4374f
4 changed files with 28 additions and 4 deletions
|
@ -15,7 +15,8 @@ class HomeController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_profile
|
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
|
session[:locale] = @current_user.locale
|
||||||
redirect_to my_profile_url, notice: I18n.t('home.changes_saved')
|
redirect_to my_profile_url, notice: I18n.t('home.changes_saved')
|
||||||
else
|
else
|
||||||
|
@ -61,4 +62,20 @@ class HomeController < ApplicationController
|
||||||
redirect_to my_profile_path, notice: I18n.t('home.ordergroup_cancelled', :group => membership.group.name)
|
redirect_to my_profile_path, notice: I18n.t('home.ordergroup_cancelled', :group => membership.group.name)
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
= h(t('.user.title', user: show_user))
|
= h(t('.user.title', user: show_user))
|
||||||
%small= t '.user.since', when: distance_of_time_in_words(Time.now, @current_user.created_on)
|
%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|
|
= 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
|
.form-actions
|
||||||
= submit_tag t('ui.save'), class: 'btn'
|
= submit_tag t('ui.save'), class: 'btn'
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,17 @@
|
||||||
-# You can control password autocompletion by passing `password_autocomplete` to this partial.
|
-# You can control password autocompletion by passing `password_autocomplete` to this partial.
|
||||||
-# Possible values: undefined/nil, true, false, 'store-only'
|
-# Possible values: undefined/nil, true, false, 'store-only'
|
||||||
-# see also https://github.com/foodcoops/foodsoft/wiki/Form-autocompletion
|
-# see also https://github.com/foodcoops/foodsoft/wiki/Form-autocompletion
|
||||||
- password_autocomplete = nil unless defined?(:password_autocomplete)
|
- password_html = autocomplete_flag_to_password_html(local_assigns[:password_autocomplete])
|
||||||
- password_html = autocomplete_flag_to_password_html(password_autocomplete)
|
|
||||||
= f.input :password, :required => f.object.new_record?, input_html: password_html
|
= 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 :password_confirmation, :required => f.object.new_record?, input_html: password_html
|
||||||
= f.input :phone
|
= 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|
|
||||||
|
- 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|
|
= f.simple_fields_for :settings_attributes do |s|
|
||||||
= s.simple_fields_for :profile, defaults: { inline_label: true } do |profile|
|
= 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']
|
= profile.input 'language', as: :select, collection: available_locales, required: false, selected: f.object.settings.profile['language']
|
||||||
|
|
|
@ -1423,6 +1423,8 @@ en:
|
||||||
title: Current orders
|
title: Current orders
|
||||||
total_sum: Total sum
|
total_sum: Total sum
|
||||||
who_ordered: Who ordered?
|
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:
|
workgroup_members:
|
||||||
title: Group memberships
|
title: Group memberships
|
||||||
simple_form:
|
simple_form:
|
||||||
|
|
Loading…
Reference in a new issue