From 752d50a6a9d96378fbd4024eae76e6a9baeaa8c9 Mon Sep 17 00:00:00 2001 From: danielvincent <danielgrippi@gmail.com> Date: Sun, 21 Nov 2010 19:51:20 -0800 Subject: [PATCH] editing captions on photos uses remote forms. removed photo in album from WSR. --- app/controllers/photos_controller.rb | 18 +++-- app/models/photo.rb | 5 +- app/views/photos/show.html.haml | 85 ++++++++++++---------- app/views/shared/_author_info.html.haml | 3 +- app/views/shared/_stream_element.html.haml | 20 ++--- public/javascripts/photo.js | 53 -------------- public/javascripts/web-socket-receiver.js | 17 ----- public/stylesheets/sass/application.sass | 15 +++- 8 files changed, 84 insertions(+), 132 deletions(-) diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 03f6d08708..d5aebe1990 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -78,8 +78,8 @@ class PhotosController < ApplicationController photo.destroy flash[:notice] = I18n.t 'photos.destroy.notice' end - - respond_with :location => photos_path + + respond_with :location => photo.status_message end def show @@ -106,11 +106,17 @@ class PhotosController < ApplicationController photo = current_user.my_posts.where(:_id => params[:id]).first if photo if current_user.update_post( photo, params[:photo] ) - flash[:notice] = I18n.t 'photos.update.notice' - respond_with photo + flash.now[:notice] = I18n.t 'photos.update.notice' + respond_to do |format| + format.html + format.js{ render :json => photo, :status => 200 } + end else - flash[:error] = I18n.t 'photos.update.error' - redirect_to [:edit, photo] + flash.now[:error] = I18n.t 'photos.update.error' + respond_to do |format| + format.html{ redirect_to [:edit, photo] } + format.js{ render :status => 403 } + end end else redirect_to person_photos_path(current_user.person) diff --git a/app/models/photo.rb b/app/models/photo.rb index 285458437b..38c96372e3 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -95,8 +95,9 @@ class Photo < Post def as_json(opts={}) { :photo => { - :id => self.id, - :url => self.url(:thumb_medium) + :id => self.id, + :url => self.url(:thumb_medium), + :caption => self.caption } } end diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index cfc70a5c97..2208e1096d 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -3,74 +3,81 @@ -# the COPYRIGHT file. - content_for :head do - =javascript_include_tag 'photo' - + :javascript + $(document).ready( function(){ + $("#edit_photo_toggle").bind('click', function() { + $("#photo_edit_options").toggle(); + $(".edit_photo input[type='text']").first().focus(); + }); + + $('.edit_photo').bind('ajax:loading', function(data, json, xhr) { + $("#photo_edit_options").toggle(); + $("#photo_spinner").show(); + $("#show_photo").find("img").fadeTo(200,0.3); + }); + + $('.edit_photo').bind('ajax:failure', function(data, json, xhr) { + alert('Failed to delete photo. Are you sure you own this?'); + $("#show_photo").find("img").fadeTo(200,1); + $("#photo_spinner").hide(); + }); + + $('.edit_photo').bind('ajax:success', function(data, json, xhr) { + json = $.parseJSON(json); + $(".edit_photo input[type='text']").val(json['photo']['caption']); + $("#caption").html(json['photo']['caption']); + $("#show_photo").find("img").fadeTo(200,1); + $("#photo_spinner").hide(); + }); + }); = render 'shared/author_info', :person => @photo.person, :post => @photo -/ we need to do next photo here -/- if @photo.album -/= link_to "<< #{t('.prev')}", url_to_prev(@photo, @album), :rel => 'prefetch', :id => "prev_photo" -/| -/= link_to "#{t('.full_size')}", @photo.url -/| -/= link_to "#{t('.next')} >>", url_to_next(@photo, @album), :rel => 'prefetch', :id => "next_photo" - .span-14.append-1.last %div{:data=>{:guid=>@photo.id}} #show_photo - -if @ownership + = image_tag 'ajax-loader.gif', :id => "photo_spinner", :class => "hidden" .edit_pane .controls{:data=>{:actor=>"#{@photo.person.owner.id}",:actor_person=>"#{@photo.person.id}",:image_url=>"#{@photo.url(:thumb_medium)}"}} = link_to t('.make_profile_photo'), '#', :class => "make_profile_photo" + | + = link_to 'edit', '#', :id => "edit_photo_toggle" = image_tag @photo.url(:scaled_full) -else = image_tag @photo.url(:scaled_full) - .caption + #caption = @photo.caption - %br - %br - %br - - -if @ownership - = link_to t('.edit_photo'),'javascript:void(0)', :id => "edit-desc", :class => "edit-desc" - - -if @ownership - %div{:class => 'clear'} - -if !@photo.caption or @photo.caption == "" - = link_to t('.add_a_description'),'javascript:void(0)', :id => "add-description", :class => "edit-desc" - %br - %br - - = form_for @photo do |p| - = p.text_field :caption, :value => @photo.caption - = p.submit t('.update_photo') - %div{:class => 'clear'} -if @ownership - = link_to t('.delete_photo'), @photo, :confirm => t('are_you_sure'), :method => :delete, :class => 'button' + #photo_edit_options + %h4 Edit photo description / delete photo + %p + = form_for @photo, :remote => true do |p| + = p.text_field :caption, :value => @photo.caption + = p.submit t('.update_photo') + %p + = button_to t('.delete_photo'), @photo, :confirm => t('are_you_sure'), :method => :delete .span-9.last - - if @photo.status_message_id #original_post_info - %h4{:style=>"margin-bottom:5px;position:relative;"} + %h4{:style=>"position:relative;"} Original Post - =link_to 'view', @photo.status_message + = link_to 'view', @photo.status_message %p = @photo.status_message.message - - for photo in @photo.status_message.photos - = link_to (image_tag photo.url(:thumb_small)), object_path(photo) - %br + %p + - for photo in @photo.status_message.photos + = link_to (image_tag photo.url(:thumb_small)), object_path(photo) - %h4{:style=>"margin-bottom:5px;"} Comments - %div{id => 'photo_stream', :class => 'stream show'} + %h4 Comments + %div{:id => 'photo_stream', :class => 'stream show'} %li.message{:data=>{:guid=>@photo.id}} = render "comments/comments", :post => @photo diff --git a/app/views/shared/_author_info.html.haml b/app/views/shared/_author_info.html.haml index af6601c4ac..9cebe4f87d 100644 --- a/app/views/shared/_author_info.html.haml +++ b/app/views/shared/_author_info.html.haml @@ -3,7 +3,7 @@ .from %h2 = person.real_name - - if defined?(post) + - if defined?(post) && current_user.owns?(post) .aspect âž” %ul @@ -15,4 +15,3 @@ #person_nav_links = link_to t('.view_profile'), person_path(person) = link_to t('_photos'), person_photos_path(person) - = link_to t('.status_messages'), person_status_messages_path(person) diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index 7169158b82..75adefe4c6 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -9,14 +9,16 @@ .content .from = link_to post.person.real_name, post.person - .aspect - âž” - %ul - - if post.public? - %li= t('the_world') - - else - - for aspect in current_user.aspects_with_post( post.id ) - %li= link_to aspect.name, aspect + + - if current_user.owns?(post) + .aspect + âž” + %ul + - if post.public? + %li= t('the_world') + - else + - for aspect in current_user.aspects_with_post( post.id ) + %li= link_to aspect.name, aspect - if current_user.owns?(post) .right @@ -29,5 +31,5 @@ %span.time= link_to(how_long_ago(post), object_path(post)) = link_to "#{t('.show_comments')} (#{post.comments.count})", '#', :class => "show_post_comments" - = render "comments/comments", :post => post + = render "comments/comments", :post => post diff --git a/public/javascripts/photo.js b/public/javascripts/photo.js index ff20a17355..85649d625c 100644 --- a/public/javascripts/photo.js +++ b/public/javascripts/photo.js @@ -4,56 +4,3 @@ */ -$(document).keydown(function(e){ - switch(e.keyCode) { - case 37: - if(!$("textarea").hasClass("hasfocus")){//prevent redirect if textarea has focus - window.location = $("#prev_photo").attr('href'); - } - break; - case 39: - if(!$("textarea").hasClass("hasfocus")){ - window.location = $("#next_photo").attr('href'); - } - break; - } -}); - -$(document).ready(function(){ - var $edit_photo = $(".edit_photo"); - - //add a clas to verify if a textarea has focus - $("textarea").live('focus',function(){ - $(this).addClass("hasfocus"); - }); - $("textarea").live('blur',function(){ - $(this).removeClass("hasfocus"); - }); - - //show form to add description - $(".edit-desc").click(function(){ - $(".edit_photo").toggle(); - }); - - //Add a description with ajax request - $("#photo_submit").click(function(event){ - event.preventDefault(); - var method = $edit_photo.attr("method"); - var url = $edit_photo.attr("action"); - var data = $edit_photo.serialize(); - $(".description").text($("#photo_caption").val()); - $edit_photo.toggle(); - - $.ajax({ - type: method, - url: url, - data: data, - success: function(response){ - $("#add-description").remove(); - } - }); - - }); - -}); - diff --git a/public/javascripts/web-socket-receiver.js b/public/javascripts/web-socket-receiver.js index 5eb2704461..4fa546f937 100644 --- a/public/javascripts/web-socket-receiver.js +++ b/public/javascripts/web-socket-receiver.js @@ -29,8 +29,6 @@ var WebSocketReceiver = { }else if (obj['class']=="comments"){ WebSocketReceiver.processComment(obj['post_id'], obj['html'], {'notification':obj['notification'], 'mine?':obj['mine?'], 'my_post?':obj['my_post?']}) - }else if (obj['class']=='photos' && WebSocketReceiver.onPageForClass('albums')){ - WebSocketReceiver.processPhotoInAlbum(obj['photo_hash']) }else{ WebSocketReceiver.processPost(obj['class'], obj['html'], obj['aspect_ids']) } @@ -104,21 +102,6 @@ var WebSocketReceiver = { ); }, - processPhotoInAlbum: function(photoHash){ - if (location.href.indexOf(photoHash['album_id']) == -1){ - return ; - } - - html = "<div class=\'image_thumb\' id=\'"+photoHash['id']+"\' style=\'padding-right:3px;\'> \ - <a href=\"/photos/"+ photoHash['id'] +"\"> \ - <img alt=\"New thumbnail\" src=\""+ photoHash['thumb_url'] +"\" /> \ - </a> </div>" - $("#thumbnails").append( $(html) ) - $("#"+ photoHash['id'] + " img").load( function() { - $(this).fadeIn("slow"); - }); - }, - onPageForClass: function(className){ return (location.href.indexOf(className) != -1 ); }, diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index d503f8e08f..1fcbfb9514 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -29,6 +29,10 @@ a h1, h2, h3, h4 :color #444 +h4 + :margin + :bottom 5px + ol, ul :list-style none @@ -679,7 +683,12 @@ li.message .from .right :border 1px solid #eee :bottom 1px solid #ddd - .caption + #photo_spinner + :position absolute + :height 100px + :width 100px + + #caption :min-height 20px :padding 0 10px :font @@ -1279,7 +1288,7 @@ input[type="search"] .fancybox_content :display none -.edit_photo +#photo_edit_options :display none #section_header @@ -1922,8 +1931,6 @@ h3,h4 a :font :size 12px - - img :-webkit-box-shadow 0 1px 2px #666 :-moz-box-shadow 0 1px 2px #666 -- GitLab