Commit a778c26196568ef0468c7425d07338a27078e75c
1 parent
24c78ad5
Exists in
master
and in
28 other branches
Refactor logic in the article toolbar
Maximum nesting level reduced from 4 to 2. Pretty good, hm? (ActionItem2345)
Showing
2 changed files
with
48 additions
and
36 deletions
Show diff stats
app/models/article.rb
| ... | ... | @@ -408,6 +408,14 @@ class Article < ActiveRecord::Base |
| 408 | 408 | user && user.has_permission?('view_private_content', profile) |
| 409 | 409 | end |
| 410 | 410 | |
| 411 | + alias :allow_delete? :allow_post_content? | |
| 412 | + alias :allow_spread? :allow_post_content? | |
| 413 | + alias :allow_edit? :allow_post_content? | |
| 414 | + | |
| 415 | + def allow_create?(user) | |
| 416 | + allow_post_content?(user) || allow_publish_content?(user) | |
| 417 | + end | |
| 418 | + | |
| 411 | 419 | def comments_updated |
| 412 | 420 | ferret_update |
| 413 | 421 | end | ... | ... |
app/views/content_viewer/_article_toolbar.rhtml
| 1 | -<div<%= " class='logged-in'" if user %>> | |
| 1 | +<div<%= user && " class='logged-in'" %>> | |
| 2 | 2 | <div id="article-actions"> |
| 3 | - <% if @page.allow_post_content?(user) || @page.allow_publish_content?(user) %> | |
| 4 | - <% if @page.allow_post_content?(user) %> | |
| 5 | - <%= link_to content_tag( 'span', label_for_edit_article(@page) ), | |
| 6 | - profile.admin_url.merge({ :controller => 'cms', :action => 'edit', :id => @page.id }), | |
| 7 | - :class => 'button with-text icon-edit' %> | |
| 8 | - <% if @page != profile.home_page && !@page.has_posts? %> | |
| 9 | - <%= link_to content_tag( 'span', _('Delete') ), | |
| 10 | - profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page}), | |
| 11 | - :method => :post, | |
| 12 | - :class => 'button with-text icon-delete', | |
| 13 | - :confirm => delete_article_message(@page) %> | |
| 14 | - <% end %> | |
| 15 | - <% if !@page.folder? %> | |
| 16 | - <% if profile.kind_of?(Person) %> | |
| 17 | - <%= link_to content_tag( 'span', _('Spread this') ), | |
| 18 | - profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }), | |
| 19 | - :class => 'button with-text icon-spread' %> | |
| 20 | - <% elsif profile.kind_of?(Community) && environment.portal_community %> | |
| 21 | - <%= link_to content_tag( 'span', _('Spread this') ), | |
| 22 | - profile.admin_url.merge({ :controller => 'cms', :action => 'publish_on_portal_community', :id => @page }), | |
| 23 | - :class => 'button with-text icon-spread' %> | |
| 24 | - <% end %> | |
| 25 | - <% end %> | |
| 26 | - <% end %> | |
| 27 | - <% if !@page.gallery? %> | |
| 28 | - <%= link_to _('Add translation'), | |
| 29 | - profile.admin_url.merge(:controller => 'cms', :action => 'new', | |
| 30 | - :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)), | |
| 31 | - :type => @page.type, :article => { :translation_of_id => @page.native_translation.id }), | |
| 32 | - :class => 'button with-text icon-locale' if @page.translatable? && !@page.native_translation.language.blank? %> | |
| 33 | - <%= lightbox_remote_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)))) %> | |
| 34 | - <% end %> | |
| 35 | - <% if @page.accept_uploads? %> | |
| 36 | - <%= button('upload-file', _('Upload files'), profile.admin_url.merge(:controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent))) %> | |
| 3 | + | |
| 4 | + <% if @page.allow_edit?(user) %> | |
| 5 | + <%= link_to content_tag( 'span', label_for_edit_article(@page) ), | |
| 6 | + profile.admin_url.merge({ :controller => 'cms', :action => 'edit', :id => @page.id }), | |
| 7 | + :class => 'button with-text icon-edit' %> | |
| 8 | + <% end %> | |
| 9 | + | |
| 10 | + <% if @page != profile.home_page && !@page.has_posts? && @page.allow_delete?(user) %> | |
| 11 | + <%= link_to content_tag( 'span', _('Delete') ), | |
| 12 | + profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page}), | |
| 13 | + :method => :post, | |
| 14 | + :class => 'button with-text icon-delete', | |
| 15 | + :confirm => delete_article_message(@page) %> | |
| 16 | + <% end %> | |
| 17 | + | |
| 18 | + <% if !@page.folder? && @page.allow_spread?(user) %> | |
| 19 | + <% if profile.kind_of?(Person) %> | |
| 20 | + <%= link_to content_tag( 'span', _('Spread this') ), | |
| 21 | + profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }), | |
| 22 | + :class => 'button with-text icon-spread' %> | |
| 23 | + <% elsif profile.kind_of?(Community) && environment.portal_community %> | |
| 24 | + <%= link_to content_tag( 'span', _('Spread this') ), | |
| 25 | + profile.admin_url.merge({ :controller => 'cms', :action => 'publish_on_portal_community', :id => @page }), | |
| 26 | + :class => 'button with-text icon-spread' %> | |
| 37 | 27 | <% end %> |
| 28 | + <% end %> | |
| 29 | + | |
| 30 | + <% if !@page.gallery? && @page.allow_create?(user) %> | |
| 31 | + <%= link_to _('Add translation'), | |
| 32 | + profile.admin_url.merge(:controller => 'cms', :action => 'new', | |
| 33 | + :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)), | |
| 34 | + :type => @page.type, :article => { :translation_of_id => @page.native_translation.id }), | |
| 35 | + :class => @page.translatable? && !@page.native_translation.language.blank? && 'button with-text icon-locale' %> | |
| 36 | + <%= lightbox_remote_button(:new, label_for_new_article(@page), profile.admin_url.merge(:controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent)))) %> | |
| 37 | + <% end %> | |
| 38 | + | |
| 39 | + <% if @page.accept_uploads? && @page.allow_create?(user) %> | |
| 40 | + <%= button('upload-file', _('Upload files'), profile.admin_url.merge(:controller => 'cms', :action => 'upload_files', :parent_id => (@page.folder? ? @page : @page.parent))) %> | |
| 41 | + <% end %> | |
| 38 | 42 | |
| 39 | - <% elsif profile.community? && (@page.blog? || @page.parent && @page.parent.blog?) %> | |
| 43 | + <% if !@page.allow_create?(user) && profile.community? && (@page.blog? || @page.parent && @page.parent.blog?) %> | |
| 40 | 44 | <%= link_to content_tag( 'span', _('Suggest an article') ), profile.admin_url.merge({ :controller => 'cms', :action => 'suggest_an_article'}), :id => 'suggest-article-link', :class => 'button with-text icon-new' %> |
| 41 | 45 | <% end %> |
| 42 | 46 | ... | ... |