diff options
author | Francis Irving <francis@mysociety.org> | 2010-07-15 15:12:31 +0100 |
---|---|---|
committer | Francis Irving <francis@mysociety.org> | 2010-07-15 15:12:31 +0100 |
commit | fa7274cbeb071cd333255cda52388f04fc7beb5f (patch) | |
tree | 4b0de7f145b1a3be43e5abbaa512f0c13b95fed8 | |
parent | 4686732f95698eaa3c92fd8540236d35802d374f (diff) |
Draft stage
-rw-r--r-- | app/controllers/user_controller.rb | 58 | ||||
-rw-r--r-- | app/views/user/set_crop_profile_photo.rhtml | 26 | ||||
-rw-r--r-- | app/views/user/set_draft_profile_photo.rhtml (renamed from app/views/user/set_profile_photo.rhtml) | 10 | ||||
-rw-r--r-- | config/routes.rb | 1 |
4 files changed, 68 insertions, 27 deletions
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index b45b98001..a07701208 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -349,35 +349,49 @@ class UserController < ApplicationController redirect_to frontpage_url return end - if params[:submitted_profile_photo].nil? - # default page - return - end + if !params[:submitted_draft_profile_photo].nil? + # check for uploaded image + file_name = nil + file_content = nil + if !params[:file].nil? + file_name = params[:file].original_filename + file_content = params[:file].read + end + if file_name.nil? + flash[:error] = "Please choose a file containing your photo" + render :template => 'user/set_draft_profile_photo.rhtml' + return + end - # check for uploaded image - file_name = nil - file_content = nil - if !params[:file].nil? - file_name = params[:file].original_filename - file_content = params[:file].read - end - if file_name.nil? - flash[:error] = "Please choose a file containing your photo" - return - end + # validate it + @draft_profile_photo = ProfilePhoto.new(:data => file_content, :draft => true) + if !@draft_profile_photo.valid? + # error page (uses @profile_photo's error fields in view to show errors) + render :template => 'user/set_draft_profile_photo.rhtml' + return + end + @draft_profile_photo.save - # change user's photo - @profile_photo = ProfilePhoto.new(:data => file_content) - @user.set_profile_photo(@profile_photo) - if !@profile_photo.valid? - # error page (uses @profile_photo's error fields in view to show errors) + render :template => 'user/set_crop_profile_photo.rhtml' return + elsif !params[:submitted_crop_profile_photo].nil? + # change user's photo + @user.set_profile_photo(@profile_photo) + flash[:notice] = "Thank you for updating your profile photo" + redirect_to user_url(@user) + else + render :template => 'user/set_draft_profile_photo.rhtml' end + end - flash[:notice] = "Thank you for updating your profile photo" - redirect_to user_url(@user) + # before they've cropped it + def get_draft_profile_photo + profile_photo = ProfilePhoto.find(params[:id]) + response.content_type = "image/png" + render_for_text(profile_photo.data) end + # actual profile photo of a user def get_profile_photo @display_user = User.find(:first, :conditions => [ "url_name = ? and email_confirmed = ?", params[:url_name], true ]) if !@display_user diff --git a/app/views/user/set_crop_profile_photo.rhtml b/app/views/user/set_crop_profile_photo.rhtml new file mode 100644 index 000000000..d96b6812e --- /dev/null +++ b/app/views/user/set_crop_profile_photo.rhtml @@ -0,0 +1,26 @@ +<% @title = "Change profile photo" %> + +<% raise "internal error" if not @user %> + +<h2>2. Crop your profile photo</h2> + +<%= foi_error_messages_for :set_profile_photo %> + +<div id="set_crop_profile_photo"> + +<% form_tag 'set_profile_photo', :id => 'set_crop_profile_photo_form', :multipart => true do %> + + <img src="<%= get_draft_profile_photo_url(:id => @draft_profile_photo.id) %>"> + + <p><strong>Privacy note:</strong> Your photo will be shown in public on the Internet, + wherever you do something on WhatDoTheyKnow. + + <p> + <%= hidden_field_tag 'submitted_crop_profile_photo', 1 %> + <%= submit_tag "Set my profile photo" %> + </p> + +<% end %> + + +</div> diff --git a/app/views/user/set_profile_photo.rhtml b/app/views/user/set_draft_profile_photo.rhtml index 67647b260..2fffd519f 100644 --- a/app/views/user/set_profile_photo.rhtml +++ b/app/views/user/set_draft_profile_photo.rhtml @@ -2,13 +2,13 @@ <% raise "internal error" if not @user %> -<h2>Change your profile photo</h2> +<h2>1. Choose your profile photo</h2> <%= foi_error_messages_for :set_profile_photo %> -<div id="set_profile_photo"> +<div id="set_draft_profile_photo"> -<% form_tag 'set_profile_photo', :id => 'set_profile_photo_form', :multipart => true do %> +<% form_tag 'set_profile_photo', :id => 'set_draft_profile_photo_form', :multipart => true do %> <p> <label class="form_label" for="file_1">Photo of you:</label> <%= file_field_tag :file, :size => 35, :id => 'file_1' %> @@ -18,8 +18,8 @@ wherever you do something on WhatDoTheyKnow. <p> - <%= hidden_field_tag 'submitted_profile_photo', 1 %> - <%= submit_tag "Change profile photo" %> + <%= hidden_field_tag 'submitted_draft_profile_photo', 1 %> + <%= submit_tag "Next, crop your photo >>" %> </p> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 1705f66ba..dc80a1a9e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -64,6 +64,7 @@ ActionController::Routing::Routes.draw do |map| user.river '/river', :action => 'river' user.set_profile_photo '/set_profile_photo', :action => 'set_profile_photo' user.get_profile_photo '/user/:url_name/photo', :action => 'get_profile_photo' + user.get_draft_profile_photo '/draft_profile_photo/:id', :action => 'get_draft_profile_photo' end map.with_options :controller => 'public_body' do |body| |