move photo-show js to assets. remove EM::next_tick from controller#create actions. make photo show pages render again.

This commit is contained in:
danielvincent 2010-11-28 02:30:25 -05:00
parent 845e1fe7a3
commit d7c5e12d64
8 changed files with 58 additions and 49 deletions

View file

@ -93,15 +93,24 @@ class PhotosController < ApplicationController
end
def show
@aspect = :none
@photo = current_user.find_visible_post_by_id params[:id]
unless @photo
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else
@ownership = current_user.owns? @photo
@parent = @photo.status_message
respond_with @photo
#if photo is not an attachment, fetch comments for self
unless @parent
@parent = @photo
end
comments_hash = Comment.hash_from_post_ids [@parent.id]
person_hash = Person.from_post_comment_hash comments_hash
@comment_hashes = comments_hash[@parent.id].map do |comment|
{:comment => comment,
:person => person_hash[comment.person_id]
}
end
@ownership = current_user.owns? @photo
respond_with @photo
end
def edit

View file

@ -26,10 +26,10 @@ class StatusMessagesController < ApplicationController
raise 'MongoMapper failed to catch a failed save' unless @status_message.id
@status_message.photos += photos unless photos.nil?
EM::next_tick {current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids])}
current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids])
for photo in photos
EM::next_tick { current_user.dispatch_post(photo, :to => params[:status_message][:aspect_ids])}
current_user.dispatch_post(photo, :to => params[:status_message][:aspect_ids])
end
respond_to do |format|

View file

@ -3,34 +3,7 @@
-# the COPYRIGHT file.
- content_for :head do
:javascript
$(document).ready( function(){
$("#edit_photo_toggle").bind('click', function(evt) {
evt.preventDefault();
$("#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();
});
});
= include_javascripts :photos
= render 'shared/author_info', :person => @photo.person, :post => @photo
@ -79,12 +52,6 @@
%h4= t('_comments')
- if @photo.status_message_id
%div{:id => 'status_message_stream', :class => 'stream show'}
%li.message{:data=>{:guid=>@photo.status_message_id}}
= render "comments/comments", :post_id => @photo.status_message.id, :comments => @photo.status_message.comments
- else
%div{:id => 'photo_stream', :class => 'stream show'}
%li.message{:data=>{:guid=>@photo.id}}
= render "comments/comments", :post_id => @photo.id, :comments => @photo.comments
%div{:id => 'photo_stream', :class => 'stream show'}
%li.message{:data=>{:guid=>@parent.id}}
= render "comments/comments", :post_id => @parent.id, :comment_hashes => @comment_hashes

View file

@ -27,6 +27,8 @@ javascripts:
- public/javascripts/vendor/jquery-ui-1.8.6.custom.min.js
- public/javascripts/aspect-edit.js
- public/javascripts/contact-list.js
photos:
- public/javascripts/photo-show.js
stylesheets:
default:

View file

@ -0,0 +1,32 @@
/* Copyright (c) 2010, Diaspora Inc. This file is
* licensed under the Affero General Public License version 3 or later. See
* the COPYRIGHT file.
*/
$(document).ready( function(){
$("#edit_photo_toggle").bind('click', function(evt) {
evt.preventDefault();
$("#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();
});
});

View file

@ -24,7 +24,9 @@ a
:color #22AAE0
&:active
:color #005D9C
p
:word-wrap break-word
h1, h2, h3, h4
:color #444

View file

@ -15,7 +15,6 @@ describe CommentsController do
before do
sign_in :user, user
EM.stub!(:next_tick).and_yield(:block)
end
describe '#create' do

View file

@ -18,8 +18,6 @@ describe StatusMessagesController do
request.env["HTTP_REFERER"] = ""
sign_in :user, user
@controller.stub!(:current_user).and_return(user)
EM.stub!(:next_tick).and_yield(:block)
end
describe '#show' do