From: Tom Hughes Date: Fri, 26 Feb 2010 23:44:43 +0000 (+0000) Subject: Move support for adding and deleting user images to the user settings X-Git-Tag: live~6324^2~3 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/c55490d24ed176eebfa88a0a655462cd0b3b0d85?hp=9a3ef885bb72adbde0b968ce67135b8f7b257f35 Move support for adding and deleting user images to the user settings page and reposition the user image ont he user page in the top right corner of the page. --- diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 430e56cb0..c8adc214e 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -4,9 +4,9 @@ class UserController < ApplicationController before_filter :authorize, :only => [:api_details, :api_gpx_files] before_filter :authorize_web, :except => [:api_details, :api_gpx_files] before_filter :set_locale, :except => [:api_details, :api_gpx_files] - before_filter :require_user, :only => [:set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image, :delete_image] + before_filter :require_user, :only => [:set_home, :account, :go_public, :make_friend, :remove_friend] before_filter :check_database_readable, :except => [:api_details, :api_gpx_files] - before_filter :check_database_writable, :only => [:login, :new, :set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image, :delete_image] + before_filter :check_database_writable, :only => [:login, :new, :set_home, :account, :go_public, :make_friend, :remove_friend] before_filter :check_api_readable, :only => [:api_details, :api_gpx_files] before_filter :require_allow_read_prefs, :only => [:api_details] before_filter :require_allow_read_gpx, :only => [:api_gpx_files] @@ -57,6 +57,12 @@ class UserController < ApplicationController @user.description = params[:user][:description] @user.languages = params[:user][:languages].split(",") + + case params[:image_action] + when "new" then @user.image = params[:user][:image] + when "delete" then @user.image = nil + end + @user.home_lat = params[:user][:home_lat] @user.home_lon = params[:user][:home_lon] @@ -253,18 +259,6 @@ class UserController < ApplicationController end end - def upload_image - @user.image = params[:user][:image] - @user.save! - redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name - end - - def delete_image - @user.image = nil - @user.save! - redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name - end - def api_gpx_files doc = OSM::API.new.get_xml_doc @user.traces.each do |trace| diff --git a/app/views/user/account.html.erb b/app/views/user/account.html.erb index e4fa87cc1..6f5191fbe 100644 --- a/app/views/user/account.html.erb +++ b/app/views/user/account.html.erb @@ -1,6 +1,6 @@

<%= t 'user.account.my settings' %>

<%= error_messages_for 'user' %> -<% form_for :user, @user do |f| %> +<% form_for :user, :html => { :multipart => true } do |f| %> @@ -23,6 +23,34 @@ + + + + + class="nohome" <%end%> >
<%= t 'user.new.display name' %><%= f.text_field :display_name %>
<%= t 'user.account.current email address' %><%= @user.email %> <%= t 'user.account.email never displayed publicly' %>
<%= t 'user.account.preferred languages' %><%= f.text_field :languages %>
+ <%= t 'user.account.image' %> + + <% if @user.image.nil? %> + <%= hidden_field_tag "image_action", "new" %> + <%= t 'user.account.new image' %>
<%= file_column_field "user", "image" %> + <% else %> + + + + + + + + + + + + + + +
<%= image_tag url_for_file_column(@user, "image") %><%= radio_button_tag "image_action", "keep", true %><%= t 'user.account.keep image' %>
<%= radio_button_tag "image_action", "delete" %><%= t 'user.account.delete image' %>
<%= radio_button_tag "image_action", "new" %><%= t 'user.account.replace image' %>
<%= file_column_field "user", "image", :onchange => "$('image_action_new').checked = true" %>
+ <% end %> +
<%= t 'user.account.home location' %><%= t 'user.account.no home location' %><%= t 'user.account.latitude' %> <%= f.text_field :home_lat, :size => 20, :id => "home_lat" %><%= t 'user.account.longitude' %><%= f.text_field :home_lon, :size => 20, :id => "home_lon" %>
diff --git a/app/views/user/view.html.erb b/app/views/user/view.html.erb index f05b26220..4fb973ef4 100644 --- a/app/views/user/view.html.erb +++ b/app/views/user/view.html.erb @@ -1,3 +1,6 @@ +<% if @this_user.image %> +<%= image_tag url_for_file_column(@this_user, "image"), :align => "right", :float => "left" %> +<% end %>

<%= h(@this_user.display_name) %> <% UserRole::ALL_ROLES.each do |role| %> <% if @user and @user.administrator? %> @@ -64,23 +67,6 @@

<%= t 'user.view.created from' %> <%= @this_user.creation_ip %>

<% end %> -

<%= t 'user.view.user image heading' %>

-<% if @this_user.image %> - <%= image_tag url_for_file_column(@this_user, "image") %> - <% if @user and @this_user.id == @user.id %> - <%= button_to t('user.view.delete image'), :action => 'delete_image' %> - <% end %> -<% end %> -
- -<% if @user and @this_user.id == @user.id %> - <%= t 'user.view.upload an image' %>
- <%= form_tag({:action=>'upload_image'}, :multipart => true)%> - <%= file_column_field 'user', 'image' %> - <%= submit_tag t('user.view.add image') %> - -<% end %> -

<%= t 'user.view.description' %>

<%= htmlize(@this_user.description) %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 37538cc1a..b662a513b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1409,10 +1409,6 @@ en: ago: "({{time_in_words_ago}} ago)" email address: "Email address:" created from: "Created from:" - user image heading: User image - delete image: Delete Image - upload an image: Upload an image - add image: Add Image description: Description user location: User location no home location: "No home location has been set." @@ -1465,6 +1461,11 @@ en: text: "Currently your edits are anonymous and people cannot send you messages or see your location. To show what you edited and allow people to contact you through the website, click the button below. Since the 0.6 API changeover, only public users can edit map data. (find out why).
  • Your email address will not be revealed by becoming public.
  • This action cannot be reversed and all new users are now public by default.
" profile description: "Profile Description:" preferred languages: "Preferred Languages:" + image: "Image:" + new image: "Add an image" + keep image: "Keep the current image" + delete image: "Remove the current image" + replace image: "Replace the current image" home location: "Home Location:" no home location: "You have not entered your home location." latitude: "Latitude:" diff --git a/config/routes.rb b/config/routes.rb index 90364c395..856dcd9f4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -101,8 +101,6 @@ ActionController::Routing::Routes.draw do |map| map.connect '/user/confirm-email', :controller => 'user', :action => 'confirm_email' map.connect '/user/go_public', :controller => 'user', :action => 'go_public' map.connect '/user/reset-password', :controller => 'user', :action => 'reset_password' - map.connect '/user/upload-image', :controller => 'user', :action => 'upload_image' - map.connect '/user/delete-image', :controller => 'user', :action => 'delete_image' map.connect '/user/forgot-password', :controller => 'user', :action => 'lost_password' map.connect '/index.html', :controller => 'site', :action => 'index'