From b9ba56cbacedda34e2f31966dafbe67d48fe481e Mon Sep 17 00:00:00 2001 From: Larissa Reis Date: Fri, 28 Sep 2012 11:21:18 -0300 Subject: [PATCH] Improves the removal interface of wall itens --- app/controllers/public/profile_controller.rb | 31 +++++++++++++++++++++++++------ app/views/profile/_comment.rhtml | 2 +- app/views/profile/_create_article.rhtml | 2 +- app/views/profile/_default_activity.rhtml | 2 +- app/views/profile/_leave_scrap.rhtml | 2 +- app/views/profile/_profile_scrap.rhtml | 2 +- app/views/profile/_upload_image.rhtml | 2 +- po/pt/noosfero.po | 8 +++++++- public/javascripts/application.js | 18 ++++++++++++++++++ public/stylesheets/application.css | 4 ++++ 10 files changed, 60 insertions(+), 13 deletions(-) diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 81b3078..2b40be7 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -212,9 +212,9 @@ class ProfileController < PublicController begin scrap = current_user.person.scraps(params[:scrap_id]) scrap.destroy - render :text => _('Scrap successfully removed.') + finish_successful_removal 'Scrap successfully removed.' rescue - render :text => _('You could not remove this scrap') + finish_unsuccessful_removal 'You could not remove this scrap.' end end @@ -227,9 +227,9 @@ class ProfileController < PublicController else activity.destroy end - render :text => _('Activity successfully removed.') + finish_successful_removal 'Activity successfully removed.' rescue - render :text => _('You could not remove this activity') + finish_unsuccessful_removal 'You could not remove this activity.' end end @@ -244,6 +244,24 @@ class ProfileController < PublicController end end + def finish_successful_removal(msg) + if request.xhr? + render :text => {'ok' => true}.to_json, :content_type => 'application/json' + else + session[:notice] = _(msg) + redirect_to :action => :index + end + end + + def finish_unsuccessful_removal(msg) + session[:notice] = _(msg) + if request.xhr? + render :text => {'redirect' => url_for(:action => :index)}.to_json, :content_type => 'application/json' + else + redirect_to :action => :index + end + end + def profile_info begin @block = profile.blocks.find(params[:block_id]) @@ -303,9 +321,10 @@ class ProfileController < PublicController @comment = Comment.find(params[:comment_id]) if (user == @comment.author || user == profile || user.has_permission?(:moderate_comments, profile)) @comment.destroy - session[:notice] = _('Comment successfully deleted') + finish_successful_removal 'Comment successfully removed.' + else + finish_unsuccessful_removal 'You could not remove this comment.' end - redirect_to :action => :index end protected diff --git a/app/views/profile/_comment.rhtml b/app/views/profile/_comment.rhtml index 8b40ba5..4380a33 100644 --- a/app/views/profile/_comment.rhtml +++ b/app/views/profile/_comment.rhtml @@ -30,7 +30,7 @@ <% if logged_in? && (user == profile || user == comment.author || user.has_permission?(:moderate_comments, profile)) %> <% button_bar(:style => 'float: right; margin-top: 0px;') do %> - <%= icon_button(:delete, _('Remove'), { :action => :remove_comment, :comment_id => comment.id }, :method => :get, :confirm => _('Are you sure you want to remove this comment and all its replies?')) %> + <%= link_to_function(_('Remove'), 'remove_item_wall(this, %s, %s, %s); return false ;' % ["'.article-comment'", url_for(:profile => params[:profile], :action => :remove_comment, :comment_id => comment.id, :view => params[:view]).to_json, _('Are you sure you want to remove this comment and all its replies?').to_json], :class => 'button icon-button icon-delete') %> <% end %> <% end %>
diff --git a/app/views/profile/_create_article.rhtml b/app/views/profile/_create_article.rhtml index f9da5a6..c955ac7 100644 --- a/app/views/profile/_create_article.rhtml +++ b/app/views/profile/_create_article.rhtml @@ -15,7 +15,7 @@

<%= time_ago_as_sentence(activity.created_at) %>

<%= link_to s_('profile|Comment'), '#', { :class => 'focus-on-comment'} %> - <%= link_to_remote(content_tag(:span, _('Remove')), :url =>{:action => 'remove_activity', :activity_id => activity.id, :only_hide => true}, :confirm => _('Are you sure?'), :update => "profile-activity-item-#{activity.id}") if logged_in? && current_person == @profile %> + <%= link_to_function(_('Remove'), 'remove_item_wall(this, %s, %s, %s); return false ;' % ["'.profile-activity-item'", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :only_hide => true, :view => params[:view]).to_json, _('Are you sure you want to remove this activity and all its replies?').to_json]) if logged_in? && current_person == @profile %>
diff --git a/app/views/profile/_default_activity.rhtml b/app/views/profile/_default_activity.rhtml index 2558d54..9f1be9c 100644 --- a/app/views/profile/_default_activity.rhtml +++ b/app/views/profile/_default_activity.rhtml @@ -6,7 +6,7 @@

<%= time_ago_as_sentence(activity.created_at) %>

<%= link_to s_('profile|Comment'), '#', { :class => 'focus-on-comment'} %> - <%= link_to_remote(content_tag(:span, _('Remove')), :confirm => _('Are you sure?'), :url =>{:action => 'remove_activity', :activity_id => activity.id}, :update => "profile-activity-item-#{activity.id}") if logged_in? && current_person == @profile %> + <%= link_to_function(_('Remove'), 'remove_item_wall(this, %s, %s, %s); return false ;' % ["'.profile-activity-item'", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]).to_json, _('Are you sure you want to remove this activity and all its replies?').to_json]) if logged_in? && current_person == @profile %>
diff --git a/app/views/profile/_leave_scrap.rhtml b/app/views/profile/_leave_scrap.rhtml index 307fede..03aaec3 100644 --- a/app/views/profile/_leave_scrap.rhtml +++ b/app/views/profile/_leave_scrap.rhtml @@ -5,7 +5,7 @@

<%= link_to activity.user.name, activity.user.url %> <%= describe activity %>

<%= time_ago_as_sentence(activity.created_at) %>

- <%= link_to_remote(content_tag(:span, _('Remove')), :confirm => _('Are you sure?'), :url =>{:action => 'remove_activity', :activity_id => activity.id}, :update => "profile-activity-item-#{activity.id}") if logged_in? && current_person == @profile %> + <%= link_to_function(_('Remove'), 'remove_item_wall(this, %s, %s, %s); return false ;' % ["'.profile-activity-item'", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]).to_json, _('Are you sure you want to remove this activity and all its replies?').to_json]) if logged_in? && current_person == @profile %>
diff --git a/app/views/profile/_profile_scrap.rhtml b/app/views/profile/_profile_scrap.rhtml index be62faf..670e33a 100644 --- a/app/views/profile/_profile_scrap.rhtml +++ b/app/views/profile/_profile_scrap.rhtml @@ -12,7 +12,7 @@ <%= link_to_function s_('profile|Comment'), "hide_and_show(['#profile-wall-message-response-#{scrap.id}'],['#profile-wall-reply-#{scrap.id}', '#profile-wall-reply-form-#{scrap.id}']);$('reply_content_#{scrap.id}').value='';$('reply_content_#{scrap.id}').focus();return false", :class => "profile-send-reply" %> <% end %> - <%= link_to_remote(content_tag(:span, _('Remove')), :confirm => _('Are you sure?'), :url =>{:action => 'remove_scrap', :scrap_id => scrap.id}, :update => "profile-activity-item-#{scrap.id}") if logged_in? && user.can_control_scrap?(scrap) %> + <%= link_to_function(_('Remove'), 'remove_item_wall(this, %s, %s, %s); return false ;' % ["'.profile-activity-item'", url_for(:profile => params[:profile], :action => :remove_scrap, :scrap_id => scrap.id, :view => params[:view]).to_json, _('Are you sure you want to remove this scrap and all its replies?').to_json]) if logged_in? && user.can_control_scrap?(scrap) %> diff --git a/app/views/profile/_upload_image.rhtml b/app/views/profile/_upload_image.rhtml index 9e49394..ab2e901 100644 --- a/app/views/profile/_upload_image.rhtml +++ b/app/views/profile/_upload_image.rhtml @@ -6,7 +6,7 @@

<%= link_to activity.user.name, activity.user.url %> <%= describe activity %>

<%= time_ago_as_sentence(activity.created_at) %>

- <%= link_to_remote(content_tag(:span, _('Remove')), :confirm => _('Are you sure?'), :url =>{:action => 'remove_activity', :activity_id => activity.id}, :update => "profile-activity-item-#{activity.id}") if logged_in? && current_person == @profile %> + <%= link_to_function(_('Remove'), 'remove_item_wall(this, %s, %s, %s); return false ;' % ["'.profile-activity-item'", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]).to_json, _('Are you sure you want to remove this activity and all its replies?').to_json]) if logged_in? && current_person == @profile %>
diff --git a/po/pt/noosfero.po b/po/pt/noosfero.po index 11d1abd..a8a18c6 100644 --- a/po/pt/noosfero.po +++ b/po/pt/noosfero.po @@ -5805,8 +5805,14 @@ msgstr "Remover" #: app/views/profile/_create_article.rhtml:18 #: app/views/profile/_default_activity.rhtml:9 #: app/views/profile/_leave_scrap_to_self.rhtml:8 -#: app/views/profile/_upload_image.rhtml:10 +#: app/views/profile/_upload_image.rhtml:9 +msgid "Are you sure you want to remove this activity and all its replies?" +msgstr "Você tem certeza que quer remover esta atividade e todas as suas respostas?" + #: app/views/profile/_profile_scrap.rhtml:15 +msgid "Are you sure you want to remove this scrap and all its replies?" +msgstr "Você tem certeza que quer remover esta mensagem e todas as suas respostas?" + #: plugins/bsc/views/bsc_plugin_myprofile/manage_contracts.html.erb:35 msgid "Are you sure?" msgstr "Você tem certeza?" diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 1cd2e03..ca5aeb3 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -683,6 +683,24 @@ function add_comment_reply_form(button, comment_id) { return f; } +function remove_item_wall(button, item, url, msg) { + var $ = jQuery; + var $wall_item = $(button).closest(item); + $wall_item.addClass('remove-item-loading'); + if (msg && !confirm(msg)) { + $wall_item.removeClass('remove-item-loading'); + return; + } + $.post(url, function(data) { + if (data.ok) { + $wall_item.slideUp(); + } else { + $wall_item.removeClass('remove-item-loading'); + window.location.replace(data.redirect); + } + }); +} + function original_image_dimensions(src) { var img = new Image(); img.src = src; diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 85bf012..3fdd726 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -4772,6 +4772,10 @@ h1#agenda-title { color: #000; } +.remove-item-loading { + background: transparent url(../images/loading-small.gif) no-repeat left center !important; +} + li.profile-activity-item.upload_image .more, li.profile-activity-item.upload_image .upimg { display: block; -- libgit2 0.21.2