]> git.openstreetmap.org Git - rails.git/commitdiff
Move support for adding and deleting user images to the user settings
authorTom Hughes <tom@compton.nu>
Fri, 26 Feb 2010 23:44:43 +0000 (23:44 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 26 Feb 2010 23:44:43 +0000 (23:44 +0000)
page and reposition the user image ont he user page in the top right
corner of the page.

app/controllers/user_controller.rb
app/views/user/account.html.erb
app/views/user/view.html.erb
config/locales/en.yml
config/routes.rb

index 430e56cb05c1ae0719d5540874a6e681e721ab94..c8adc214ec1b72f4317d11630f59b30d3cb16fd1 100644 (file)
@@ -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|
index e4fa87cc1109ea390bc78b344f3e3096253acbd1..6f5191fbe6b5ab56841c64094a96b1a1a276fff0 100644 (file)
@@ -1,6 +1,6 @@
 <h2><%= t 'user.account.my settings' %></h2>
 <%= error_messages_for 'user' %>
-<% form_for :user, @user do |f| %>
+<% form_for :user, :html => { :multipart => true } do |f| %>
 <table id="accountForm">
   <tr><td class="fieldName"><%= t 'user.new.display name' %></td><td><%= f.text_field :display_name %></td></tr>
   <tr><td class="fieldName" style="padding-bottom:0px;"><%= t 'user.account.current email address' %></td><td style="padding-bottom:0px;"><%= @user.email %> <span class="minorNote"><%= t 'user.account.email never displayed publicly' %></span></td></tr>
 
   <tr><td class="fieldName" valign="top"><%= t 'user.account.preferred languages' %></td><td><%= f.text_field :languages %></td></tr>
 
+  <tr>
+    <td class="fieldName" valign="top">
+      <%= t 'user.account.image' %>
+    </td>
+    <td valign="top">
+      <% if @user.image.nil? %>
+        <%= hidden_field_tag "image_action", "new" %>
+        <%= t 'user.account.new image' %><br /><%= file_column_field "user", "image" %>
+      <% else %>
+        <table>
+          <tr>
+            <td rowspan="3" valign="top"><%= image_tag url_for_file_column(@user, "image") %></td>
+            <td><%= radio_button_tag "image_action", "keep", true %></td>
+            <td><%= t 'user.account.keep image' %></td>
+          </tr>
+          <tr>
+            <td><%= radio_button_tag "image_action", "delete" %></td>
+            <td><%= t 'user.account.delete image' %></td>
+          </tr>
+          <tr>
+            <td><%= radio_button_tag "image_action", "new" %></td>
+            <td><%= t 'user.account.replace image' %><br /><%= file_column_field "user", "image", :onchange => "$('image_action_new').checked = true" %></td>
+          </tr>
+        </table>
+      <% end %>
+    </td>
+  </tr>
+
   <tr id="homerow" <% unless @user.home_lat and @user.home_lon %> class="nohome" <%end%> ><td class="fieldName"><%= t 'user.account.home location' %></td><td><em class="message"><%= t 'user.account.no home location' %></em><span class="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" %></span></td></tr>
 
   <tr><td></td><td>
index f05b262208c2dedef904dc80368c1c70965587a7..4fb973ef4694c3aa2b14162fd8dfb53862c75273 100644 (file)
@@ -1,3 +1,6 @@
+<% if @this_user.image %>
+<%= image_tag url_for_file_column(@this_user, "image"), :align => "right", :float => "left" %>
+<% end %>
 <h2><%= h(@this_user.display_name) %>
 <% UserRole::ALL_ROLES.each do |role| %>
 <% if @user and @user.administrator? %>
 <p><b><%= t 'user.view.created from' %></b> <%= @this_user.creation_ip %></p>
 <% end %>
 
-<h3><%= t 'user.view.user image heading' %></h3>
-<% 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 %>
-<br />
-
-<% if @user and @this_user.id == @user.id %>
-  <%= t 'user.view.upload an image' %><br />
-  <%= form_tag({:action=>'upload_image'}, :multipart => true)%>
-    <%= file_column_field 'user', 'image' %>
-    <%= submit_tag t('user.view.add image') %>
-  </form>
-<% end %>
-
 <h3><%= t 'user.view.description' %></h3>
 <div id="description"><%= htmlize(@this_user.description) %></div>
 
index 37538cc1a76d88257d73527360a7edede6f9026d..b662a513b73c5d5732a44388e51ba3c2a9a8af62 100644 (file)
@@ -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. <b>Since the 0.6 API changeover, only public users can edit map data</b>. (<a href=\"http://wiki.openstreetmap.org/wiki/Anonymous_edits\">find out why</a>).<ul><li>Your email address will not be revealed by becoming public.</li><li>This action cannot be reversed and all new users are now public by default.</li></ul>"
       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:"
index 90364c3955cf2427ee1ac1b6f90492876b4933b5..856dcd9f415038d84ece219794172ce5d03fcb75 100644 (file)
@@ -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'