Commit 1e0dca799b847ac3bdaac3c70ae9107fe658e542

Authored by Antonio Terceiro
2 parents 326a7bd6 b9ba56cb

Merge commit 'refs/merge-requests/234' of git://gitorious.org/noosfero/noosfero …

…into merge-requests/234
app/controllers/public/profile_controller.rb
... ... @@ -212,9 +212,9 @@ class ProfileController < PublicController
212 212 begin
213 213 scrap = current_user.person.scraps(params[:scrap_id])
214 214 scrap.destroy
215   - render :text => _('Scrap successfully removed.')
  215 + finish_successful_removal 'Scrap successfully removed.'
216 216 rescue
217   - render :text => _('You could not remove this scrap')
  217 + finish_unsuccessful_removal 'You could not remove this scrap.'
218 218 end
219 219 end
220 220  
... ... @@ -227,9 +227,9 @@ class ProfileController < PublicController
227 227 else
228 228 activity.destroy
229 229 end
230   - render :text => _('Activity successfully removed.')
  230 + finish_successful_removal 'Activity successfully removed.'
231 231 rescue
232   - render :text => _('You could not remove this activity')
  232 + finish_unsuccessful_removal 'You could not remove this activity.'
233 233 end
234 234 end
235 235  
... ... @@ -244,6 +244,24 @@ class ProfileController < PublicController
244 244 end
245 245 end
246 246  
  247 + def finish_successful_removal(msg)
  248 + if request.xhr?
  249 + render :text => {'ok' => true}.to_json, :content_type => 'application/json'
  250 + else
  251 + session[:notice] = _(msg)
  252 + redirect_to :action => :index
  253 + end
  254 + end
  255 +
  256 + def finish_unsuccessful_removal(msg)
  257 + session[:notice] = _(msg)
  258 + if request.xhr?
  259 + render :text => {'redirect' => url_for(:action => :index)}.to_json, :content_type => 'application/json'
  260 + else
  261 + redirect_to :action => :index
  262 + end
  263 + end
  264 +
247 265 def profile_info
248 266 begin
249 267 @block = profile.blocks.find(params[:block_id])
... ... @@ -303,9 +321,10 @@ class ProfileController < PublicController
303 321 @comment = Comment.find(params[:comment_id])
304 322 if (user == @comment.author || user == profile || user.has_permission?(:moderate_comments, profile))
305 323 @comment.destroy
306   - session[:notice] = _('Comment successfully deleted')
  324 + finish_successful_removal 'Comment successfully removed.'
  325 + else
  326 + finish_unsuccessful_removal 'You could not remove this comment.'
307 327 end
308   - redirect_to :action => :index
309 328 end
310 329  
311 330 protected
... ...
app/views/profile/_comment.rhtml
... ... @@ -46,7 +46,7 @@
46 46  
47 47 <% if logged_in? && (user == profile || user == comment.author || user.has_permission?(:moderate_comments, profile)) %>
48 48 <% button_bar(:style => 'float: right; margin-top: 0px;') do %>
49   - <%= 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?')) %>
  49 + <%= 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') %>
50 50 <% end %>
51 51 <% end %>
52 52 <br style="clear: both;" />
... ...
app/views/profile/_create_article.rhtml
... ... @@ -15,7 +15,7 @@
15 15 <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p>
16 16 <div class='profile-wall-actions'>
17 17 <%= link_to s_('profile|Comment'), '#', { :class => 'focus-on-comment'} %>
18   - <%= 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 %>
  18 + <%= 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 %>
19 19 </div>
20 20 </div>
21 21  
... ...
app/views/profile/_default_activity.rhtml
... ... @@ -6,7 +6,7 @@
6 6 <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p>
7 7 <div class='profile-wall-actions'>
8 8 <%= link_to s_('profile|Comment'), '#', { :class => 'focus-on-comment'} %>
9   - <%= 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 %>
  9 + <%= 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 %>
10 10 </div>
11 11 </div>
12 12  
... ...
app/views/profile/_leave_scrap.rhtml
... ... @@ -5,7 +5,7 @@
5 5 <p class='profile-activity-text'><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></p>
6 6 <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p>
7 7 <div class='profile-wall-actions'>
8   - <%= 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 %>
  8 + <%= 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 %>
9 9 </div>
10 10 </div>
11 11  
... ...
app/views/profile/_profile_scrap.rhtml
... ... @@ -12,7 +12,7 @@
12 12 <%= 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" %>
13 13 </span>
14 14 <% end %>
15   - <%= 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) %>
  15 + <%= 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) %>
16 16 </div>
17 17 </div>
18 18  
... ...
app/views/profile/_upload_image.rhtml
... ... @@ -6,7 +6,7 @@
6 6 <p class='profile-activity-text'><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></p>
7 7 <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p>
8 8 <div class='profile-wall-actions'>
9   - <%= 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 %>
  9 + <%= 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 %>
10 10 </div>
11 11 </div>
12 12 </div>
... ...
po/pt/noosfero.po
... ... @@ -5805,8 +5805,14 @@ msgstr &quot;Remover&quot;
5805 5805 #: app/views/profile/_create_article.rhtml:18
5806 5806 #: app/views/profile/_default_activity.rhtml:9
5807 5807 #: app/views/profile/_leave_scrap_to_self.rhtml:8
5808   -#: app/views/profile/_upload_image.rhtml:10
  5808 +#: app/views/profile/_upload_image.rhtml:9
  5809 +msgid "Are you sure you want to remove this activity and all its replies?"
  5810 +msgstr "Você tem certeza que quer remover esta atividade e todas as suas respostas?"
  5811 +
5809 5812 #: app/views/profile/_profile_scrap.rhtml:15
  5813 +msgid "Are you sure you want to remove this scrap and all its replies?"
  5814 +msgstr "Você tem certeza que quer remover esta mensagem e todas as suas respostas?"
  5815 +
5810 5816 #: plugins/bsc/views/bsc_plugin_myprofile/manage_contracts.html.erb:35
5811 5817 msgid "Are you sure?"
5812 5818 msgstr "Você tem certeza?"
... ...
public/javascripts/application.js
... ... @@ -683,6 +683,24 @@ function add_comment_reply_form(button, comment_id) {
683 683 return f;
684 684 }
685 685  
  686 +function remove_item_wall(button, item, url, msg) {
  687 + var $ = jQuery;
  688 + var $wall_item = $(button).closest(item);
  689 + $wall_item.addClass('remove-item-loading');
  690 + if (msg && !confirm(msg)) {
  691 + $wall_item.removeClass('remove-item-loading');
  692 + return;
  693 + }
  694 + $.post(url, function(data) {
  695 + if (data.ok) {
  696 + $wall_item.slideUp();
  697 + } else {
  698 + $wall_item.removeClass('remove-item-loading');
  699 + window.location.replace(data.redirect);
  700 + }
  701 + });
  702 +}
  703 +
686 704 function original_image_dimensions(src) {
687 705 var img = new Image();
688 706 img.src = src;
... ...
public/stylesheets/application.css
... ... @@ -4778,6 +4778,10 @@ h1#agenda-title {
4778 4778 color: #000;
4779 4779 }
4780 4780  
  4781 +.remove-item-loading {
  4782 + background: transparent url(../images/loading-small.gif) no-repeat left center !important;
  4783 +}
  4784 +
4781 4785 li.profile-activity-item.upload_image .more,
4782 4786 li.profile-activity-item.upload_image .upimg {
4783 4787 display: block;
... ...