From 61122b83d041216b3a12dc2bbf8ce6b3ac0b4dda Mon Sep 17 00:00:00 2001
From: danielvincent <danielgrippi@gmail.com>
Date: Wed, 20 Oct 2010 12:19:06 -0700
Subject: [PATCH] make profile button on photo show page.  (removed clean hash
 on usercontroller)

---
 app/controllers/users_controller.rb      | 17 ++--------------
 app/models/user.rb                       |  2 +-
 app/views/photos/show.html.haml          |  5 ++++-
 public/javascripts/view.js               | 13 +++++++++++-
 public/stylesheets/sass/application.sass | 26 ++++++++++++++++++++++++
 5 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index a0f03877dc..aacff85043 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -36,10 +36,8 @@ class UsersController < ApplicationController
         flash[:error] = "Password Change Failed"
       end
     else
-      data = clean_hash params[:user]
-      prep_image_url(data)
-
-      if @user.update_profile data
+      prep_image_url(params[:user])
+      if @user.update_profile params[:user][:profile]
         flash[:notice] = "Profile updated"
       else
         flash[:error] = "Failed to update profile"
@@ -120,15 +118,4 @@ class UsersController < ApplicationController
     end
   end
 
-  def clean_hash(params)
-    return {
-      :profile =>
-        {
-        :first_name => params[:profile][:first_name],
-        :last_name => params[:profile][:last_name],
-        :image_url => params[:profile][:image_url]
-        }
-    }
-  end
-
 end
diff --git a/app/models/user.rb b/app/models/user.rb
index cc9531c8c8..0e28357f2e 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -281,7 +281,7 @@ class User
 
   ########### Profile ######################
   def update_profile(params)
-    if self.person.update_attributes(params)
+    if self.person.profile.update_attributes(params)
       push_to_aspects profile, :all
       true
     else
diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml
index 8fe22cc9bc..12b6a1af17 100644
--- a/app/views/photos/show.html.haml
+++ b/app/views/photos/show.html.haml
@@ -76,7 +76,10 @@
 
   %div{:id => @photo.id}
     #show_photo
-      = linked_scaled_photo @photo, @album
+      .edit_pane
+        .controls{:data=>{:actor=>"#{@photo.person.owner.id}",:image_url=>"#{@photo.url(:thumb_medium)}"}}
+          = link_to 'make profile photo', '#', :class => "make_profile_photo"
+        = linked_scaled_photo @photo, @album
       .caption
         -if current_user.owns? @photo
           -if @photo.caption and @photo.caption != ""
diff --git a/public/javascripts/view.js b/public/javascripts/view.js
index 1096b532cd..575007819d 100644
--- a/public/javascripts/view.js
+++ b/public/javascripts/view.js
@@ -67,7 +67,6 @@ $(document).ready(function(){
     };
   });
 
-
 });//end document ready
 
 
@@ -105,3 +104,15 @@ function openVideo(type, videoid, link) {
   $(container).slideDown('fast', function() { });
   link.onclick = function() { $(container).slideToggle('fast', function() { } ); }
 }
+
+$(".make_profile_photo").live("click", function(){
+  var user_id   = $(this).closest(".controls").attr('data-actor');
+      photo_url = $(this).closest(".controls").attr('data-image_url');
+
+  $.ajax({
+    type: "PUT",
+    url: '/users/'+user_id,
+    data: {"user":{"profile":{ "image_url": photo_url }}},
+    success: window.location.reload()
+  });
+});
diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass
index 56a781be52..716c4e2386 100644
--- a/public/stylesheets/sass/application.sass
+++ b/public/stylesheets/sass/application.sass
@@ -1089,3 +1089,29 @@ header
   img
     :height 27px
     :width 27px
+
+
+.edit_pane
+  :display inline
+  :position relative
+
+  .controls
+    :display none
+    :background
+      :color rgba(51,51,51,0.9)
+    :padding 10px
+    :position absolute
+    :right 0
+
+    a
+      :font
+        :weight bold
+      :color #eee
+      :text-shadow 0 1px #000
+
+      &:hover
+        :color #fff
+    
+  &:hover
+    .controls
+      :display inline
-- 
GitLab