Provide feedback when a user tries to double-reshare

This commit is contained in:
Raphael Sofaer 2011-07-22 17:43:05 -07:00
parent 99aafb18cd
commit 00885be738
6 changed files with 27 additions and 8 deletions

View file

@ -4,7 +4,7 @@ class ResharesController < ApplicationController
def create def create
@reshare = current_user.build_post(:reshare, :root_guid => params[:root_guid]) @reshare = current_user.build_post(:reshare, :root_guid => params[:root_guid])
if @reshare.save! if @reshare.save
current_user.add_to_streams(@reshare, current_user.aspects) current_user.add_to_streams(@reshare, current_user.aspects)
current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root.author) current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root.author)
end end

View file

@ -1,2 +1,9 @@
module ResharesHelper module ResharesHelper
def reshare_error_message(reshare)
if @reshare.errors[:root_guid].present?
escape_javascript(@reshare.errors[:root_guid].first)
else
escape_javascript(t('reshares.create.failure'))
end
end
end end

View file

@ -1,4 +1,9 @@
$('.stream_element#<%=params[:root_guid]%>').addClass('reshared'); <% if @reshare.persisted? %>
ContentUpdater.addPostToStream( $('.stream_element#<%=params[:root_guid]%>').addClass('reshared');
"<%= escape_javascript(render(:partial => 'shared/stream_element', :locals => {:post => @reshare }))=%>" ContentUpdater.addPostToStream(
); "<%= escape_javascript(render(:partial => 'shared/stream_element', :locals => {:post => @reshare }))=%>"
);
<% else %>
Diaspora.widgets.flashes.render({success:false,
notice: "<%= reshare_error_message(@reshare) %>"});
<% end %>

View file

@ -26,3 +26,4 @@
attributes: attributes:
from_id: from_id:
taken: "is a duplicate of a pre-existing request." taken: "is a duplicate of a pre-existing request."

View file

@ -65,8 +65,10 @@ en:
attributes: attributes:
from_id: from_id:
taken: "is a duplicate of a pre-existing request." taken: "is a duplicate of a pre-existing request."
reshare:
attributes:
root_guid:
taken: "You've already reshared that post!"
error_messages: error_messages:
helper: helper:
invalid_fields: "Invalid Fields" invalid_fields: "Invalid Fields"
@ -579,7 +581,9 @@ en:
few: "%{count} new requests!" few: "%{count} new requests!"
many: "%{count} new requests!" many: "%{count} new requests!"
other: "%{count} new requests!" other: "%{count} new requests!"
reshares:
create:
failure: "There was an error resharing this post."
services: services:
index: index:
logged_in_as: "logged in as" logged_in_as: "logged in as"

View file

@ -47,3 +47,5 @@ en:
comments: comments:
show: "show all comments" show: "show all comments"
hide: "hide comments" hide: "hide comments"
reshares:
duplicate:"You've already reshared that post!"