Commit 684589bcfc84f59dea7cda47969bf3c19734d02d
Exists in
master
and in
27 other branches
Merge branch 'rails3' of gitlab.com:noosfero/noosfero into rails3
Showing
18 changed files
with
43 additions
and
54 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
| ... | ... | @@ -231,7 +231,7 @@ class CmsController < MyProfileController |
| 231 | 231 | @current_category = Category.find(params[:category_id]) |
| 232 | 232 | @categories = @current_category.children |
| 233 | 233 | end |
| 234 | - render :partial => 'shared/select_categories', :locals => {:object_name => 'article', :multiple => true}, :layout => false | |
| 234 | + render :template => 'shared/update_categories', :locals => { :category => @current_category } | |
| 235 | 235 | end |
| 236 | 236 | |
| 237 | 237 | def publish | ... | ... |
app/controllers/my_profile/profile_editor_controller.rb
| ... | ... | @@ -60,7 +60,7 @@ class ProfileEditorController < MyProfileController |
| 60 | 60 | @current_category = Category.find(params[:category_id]) |
| 61 | 61 | @categories = @current_category.children |
| 62 | 62 | end |
| 63 | - render :partial => 'shared/select_categories', :locals => {:object_name => 'profile_data', :multiple => true}, :layout => false | |
| 63 | + render :template => 'shared/update_categories', :locals => { :category => @current_category } | |
| 64 | 64 | end |
| 65 | 65 | |
| 66 | 66 | def header_footer | ... | ... |
app/helpers/application_helper.rb
| ... | ... | @@ -589,7 +589,7 @@ module ApplicationHelper |
| 589 | 589 | extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' ) |
| 590 | 590 | links = links_for_balloon(profile) |
| 591 | 591 | content_tag('div', content_tag(tag, |
| 592 | - (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{j(links.to_json)}); return false", :class => "menu-submenu-trigger #{trigger_class}", :url => url) : "") + | |
| 592 | + (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{CGI::escapeHTML(links.to_json)}); return false", :class => "menu-submenu-trigger #{trigger_class}", :url => url) : "") + | |
| 593 | 593 | link_to( |
| 594 | 594 | content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) + |
| 595 | 595 | content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) + | ... | ... |
app/helpers/categories_helper.rb
| ... | ... | @@ -50,11 +50,17 @@ module CategoriesHelper |
| 50 | 50 | |
| 51 | 51 | #FIXME make this test |
| 52 | 52 | def selected_category_link(cat) |
| 53 | - js_remove = j("jQuery('#selected-category-#{cat.id}').remove();") | |
| 53 | + js_remove = "jQuery('#selected-category-#{cat.id}').remove();" | |
| 54 | 54 | content_tag('div', button_to_function_without_text(:remove, _('Remove'), js_remove) + |
| 55 | 55 | link_to_function(cat.full_name(' → '), js_remove, :id => "remove-selected-category-#{cat.id}-button", :class => 'select-subcategory-link'), |
| 56 | 56 | :class => 'selected-category' |
| 57 | 57 | ) |
| 58 | 58 | end |
| 59 | 59 | |
| 60 | + def update_categories_link(body, category_id=nil, html_options={}) | |
| 61 | + link_to body, | |
| 62 | + { :action => "update_categories", :category_id => category_id, :id => @object }, | |
| 63 | + {:id => category_id ? "select-category-#{category_id}-link" : nil, :remote => true, :class => 'select-subcategory-link'}.merge(html_options) | |
| 64 | + end | |
| 65 | + | |
| 60 | 66 | end | ... | ... |
app/views/profile/_comment.html.erb
| ... | ... | @@ -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 | - <%= link_to_function(_('Remove'), 'remove_item_wall(this, %s, %s, %s); return false ;' % ["'.article-comment'", j(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') %> | |
| 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]), _('Are you sure you want to remove this comment and all its replies?')], :class => 'button icon-button icon-delete') %> | |
| 50 | 50 | <% end %> |
| 51 | 51 | <% end %> |
| 52 | 52 | <br style="clear: both;" /> | ... | ... |
app/views/profile/_create_article.html.erb
| ... | ... | @@ -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_function(_('Remove'), 'remove_item_wall(this, %s, %s, %s); return false ;' % ["'.profile-activity-item'", j(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 %> | |
| 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]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> | |
| 19 | 19 | </div> |
| 20 | 20 | </div> |
| 21 | 21 | ... | ... |
app/views/profile/_default_activity.html.erb
| ... | ... | @@ -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_function(_('Remove'), 'remove_item_wall(this, %s, %s, %s); return false ;' % ["'.profile-activity-item'", j(url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]).to_json), j(_('Are you sure you want to remove this activity and all its replies?').to_json)]) 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]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> | |
| 10 | 10 | </div> |
| 11 | 11 | </div> |
| 12 | 12 | ... | ... |
app/views/profile/_leave_scrap.html.erb
| ... | ... | @@ -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_function(_('Remove'), 'remove_item_wall(this, %s, %s, %s); return false ;' % ["'.profile-activity-item'", j(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 %> | |
| 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]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> | |
| 9 | 9 | </div> |
| 10 | 10 | </div> |
| 11 | 11 | ... | ... |
app/views/profile/_profile_scrap.html.erb
| ... | ... | @@ -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_function(_('Remove'), 'remove_item_wall(this, %s, %s, %s); return false ;' % ["'.profile-activity-item'", j(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) %> | |
| 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]), _('Are you sure you want to remove this scrap and all its replies?')]) if logged_in? && user.can_control_scrap?(scrap) %> | |
| 16 | 16 | </div> |
| 17 | 17 | </div> |
| 18 | 18 | ... | ... |
app/views/profile/_profile_scraps.html.erb
| ... | ... | @@ -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_function(_('Remove'), 'remove_item_wall(this, %s, %s, %s); return false ;' % ["'.profile-activity-item'", j(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) %> | |
| 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]), _('Are you sure you want to remove this scrap and all its replies?')]) if logged_in? && user.can_control_scrap?(scrap) %> | |
| 16 | 16 | </div> |
| 17 | 17 | </div> |
| 18 | 18 | ... | ... |
app/views/profile/_upload_image.html.erb
| ... | ... | @@ -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_function(_('Remove'), 'remove_item_wall(this, %s, %s, %s); return false ;' % ["'.profile-activity-item'", j(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 | + <%= 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]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> | |
| 10 | 10 | </div> |
| 11 | 11 | </div> |
| 12 | 12 | </div> | ... | ... |
app/views/profile/report_abuse.html.erb
| ... | ... | @@ -24,7 +24,7 @@ |
| 24 | 24 | $('#report-abuse-submit-button').css('cursor', 'progress'); |
| 25 | 25 | $.ajax({ |
| 26 | 26 | type: 'POST', |
| 27 | - url: <%= j(url_for({:controller => 'profile', :action => 'register_report', :profile => profile.identifier}).to_json) %>, | |
| 27 | + url: <%= url_for({:controller => 'profile', :action => 'register_report', :profile => profile.identifier}) %>, | |
| 28 | 28 | data: $(form).serialize(), |
| 29 | 29 | dataType: 'json', |
| 30 | 30 | success: function(data, status, ajax){ | ... | ... |
app/views/shared/_select_categories.html.erb
| ... | ... | @@ -3,30 +3,25 @@ |
| 3 | 3 | <% if !@current_category.nil? %> |
| 4 | 4 | <%= hidden_field_tag "#{object_name}[#{object_name}_category_id]", @current_category.id unless multiple %> |
| 5 | 5 | <%= hidden_field_tag "#{object_name}[category_ids][]", @current_category.id if multiple %> |
| 6 | - <%= button_to_remote_without_text(:back, _('Back'), | |
| 7 | - { :update => "select-categories", | |
| 8 | - :url => { :action => 'update_categories', :id => @object }, | |
| 9 | - :loaded => visual_effect(:highlight, "select-categories") | |
| 10 | - }, | |
| 11 | - :id => 'cancel-category-button') %> | |
| 6 | + | |
| 7 | + <%= update_categories_link("", nil, :id => "cancel-category-button", :class => "button icon-back") %> | |
| 12 | 8 | <% |
| 13 | 9 | categories = [@current_category] |
| 14 | 10 | categories.push(@current_category) while @current_category = @current_category.parent |
| 15 | 11 | %> |
| 16 | - <%= categories.compact.reverse.map{|i| | |
| 17 | - link_to_remote(i.name, | |
| 18 | - :update => "select-categories", | |
| 19 | - :url => { :action => 'update_categories', :category_id => i.id, :id => @object }, | |
| 20 | - :loaded => visual_effect(:highlight, "select-categories"), | |
| 21 | - :class => 'select-current-category-link')}.join(' → ') | |
| 22 | - %> | |
| 23 | - <%= button_to_function_without_text(:add, _('Add'), nil, :id => 'save-category-button') do |page| | |
| 24 | - page.insert_html :bottom, 'selected-categories', content_tag('div', | |
| 25 | - hidden_field_tag("#{object_name}[category_ids][]", categories.first.id) + | |
| 26 | - selected_category_link(categories.first), :id => "selected-category-#{categories.first.id}") | |
| 27 | - page.replace_html 'select-categories', :partial => 'shared/select_subcategories', | |
| 28 | - :locals => {:object_name => object_name, :categories => @toplevel_categories} | |
| 29 | - end if multiple %> | |
| 12 | + <%= categories.compact.reverse.map{|i| update_categories_link(i.name, i.id)}.join %> | |
| 13 | + | |
| 14 | + <script> | |
| 15 | + function add_category() { | |
| 16 | + var hidden_field = '<%= j hidden_field_tag("#{object_name}[category_ids][]", categories.first.id) %>'; | |
| 17 | + var category_link = '<%= j selected_category_link(categories.first) %>'; | |
| 18 | + jQuery('#selected-categories').append('<div id="selected-category-<%= categories.first.id %>">' + hidden_field + category_link + '</div>'); | |
| 19 | + var subcategories = '<%= j(render :partial => 'shared/select_subcategories', :locals => {:object_name => object_name, :categories => @toplevel_categories}) %>'; | |
| 20 | + jQuery('#select-categories').html(subcategories); | |
| 21 | + } | |
| 22 | + </script> | |
| 23 | + | |
| 24 | + <%= button_to_function_without_text(:add, _('Add'), 'add_category()', :id => 'save-category-button') %> | |
| 30 | 25 | <% end %> |
| 31 | 26 | |
| 32 | 27 | <div class="toplevel-categories"> | ... | ... |
app/views/shared/_select_subcategories.html.erb
| ... | ... | @@ -3,14 +3,6 @@ |
| 3 | 3 | <div class="category-helper-label"><%= _('Click to select a category') %></div> |
| 4 | 4 | |
| 5 | 5 | <% categories.select{|i| @object.accept_category?(i)}.each do |category| %> |
| 6 | - | |
| 7 | - <%= link_to_remote category.name, | |
| 8 | - { :update => "select-categories", | |
| 9 | - :url => { :action => "update_categories", :category_id => category.id, :id => @object}, | |
| 10 | - :loaded => j(visual_effect(:highlight, "select-categories")) | |
| 11 | - }, | |
| 12 | - :class => 'select-subcategory-link', | |
| 13 | - :id => "select-category-#{category.id}-link" | |
| 14 | - %> | |
| 6 | + <%= update_categories_link(category.name, category.id) %> | |
| 15 | 7 | <% end %> |
| 16 | 8 | <% end %> | ... | ... |
config/initializers/json_escape.rb
test/functional/cms_controller_test.rb
| ... | ... | @@ -682,8 +682,8 @@ class CmsControllerTest < ActionController::TestCase |
| 682 | 682 | top = env.categories.create!(:display_in_menu => true, :name => 'Top-Level category') |
| 683 | 683 | c1 = env.categories.create!(:display_in_menu => true, :name => "Test category 1", :parent_id => top.id) |
| 684 | 684 | c2 = env.categories.create!(:display_in_menu => true, :name => "Test category 2", :parent_id => top.id) |
| 685 | - get :update_categories, :profile => profile.identifier, :category_id => top.id | |
| 686 | - assert_template 'shared/_select_categories' | |
| 685 | + xhr :get, :update_categories, :profile => profile.identifier, :category_id => top.id | |
| 686 | + assert_template 'shared/update_categories' | |
| 687 | 687 | assert_equal top, assigns(:current_category) |
| 688 | 688 | assert_equal [c1, c2], assigns(:categories) |
| 689 | 689 | end | ... | ... |
test/functional/profile_editor_controller_test.rb
| ... | ... | @@ -474,8 +474,8 @@ class ProfileEditorControllerTest < ActionController::TestCase |
| 474 | 474 | top = env.categories.create!(:display_in_menu => true, :name => 'Top-Level category') |
| 475 | 475 | c1 = env.categories.create!(:display_in_menu => true, :name => "Test category 1", :parent_id => top.id) |
| 476 | 476 | c2 = env.categories.create!(:display_in_menu => true, :name => "Test category 2", :parent_id => top.id) |
| 477 | - get :update_categories, :profile => profile.identifier, :category_id => top.id | |
| 478 | - assert_template 'shared/_select_categories' | |
| 477 | + xhr :get, :update_categories, :profile => profile.identifier, :category_id => top.id | |
| 478 | + assert_template 'shared/update_categories' | |
| 479 | 479 | assert_equal top, assigns(:current_category) |
| 480 | 480 | assert_equal [c1, c2], assigns(:categories) |
| 481 | 481 | end | ... | ... |