diff options
author | Raphael Sofaer <raphael@joindiaspora.com> | 2011-07-23 04:43:05 +0400 |
---|---|---|
committer | Raphael Sofaer <raphael@joindiaspora.com> | 2011-07-23 04:43:05 +0400 |
commit | 00885be738a2e737e7ed18d016eb7a537213d49e (patch) | |
tree | c023125a207fb63d0b733cbc091bf3e352dc7384 /app | |
parent | 99aafb18cd041cf382fbd1fc795231e5d3ec62df (diff) |
Provide feedback when a user tries to double-reshare
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/reshares_controller.rb | 2 | ||||
-rw-r--r-- | app/helpers/reshares_helper.rb | 7 | ||||
-rw-r--r-- | app/views/reshares/create.js.erb | 13 |
3 files changed, 17 insertions, 5 deletions
diff --git a/app/controllers/reshares_controller.rb b/app/controllers/reshares_controller.rb index d1511f634..856426ef7 100644 --- a/app/controllers/reshares_controller.rb +++ b/app/controllers/reshares_controller.rb @@ -4,7 +4,7 @@ class ResharesController < ApplicationController def create @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.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root.author) end diff --git a/app/helpers/reshares_helper.rb b/app/helpers/reshares_helper.rb index f1b23f522..8c6cf0ea6 100644 --- a/app/helpers/reshares_helper.rb +++ b/app/helpers/reshares_helper.rb @@ -1,2 +1,9 @@ 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 diff --git a/app/views/reshares/create.js.erb b/app/views/reshares/create.js.erb index ec6f7e515..f56a8218c 100644 --- a/app/views/reshares/create.js.erb +++ b/app/views/reshares/create.js.erb @@ -1,4 +1,9 @@ -$('.stream_element#<%=params[:root_guid]%>').addClass('reshared'); -ContentUpdater.addPostToStream( - "<%= escape_javascript(render(:partial => 'shared/stream_element', :locals => {:post => @reshare }))=%>" -); +<% if @reshare.persisted? %> + $('.stream_element#<%=params[:root_guid]%>').addClass('reshared'); + 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 %> |