Commit 16b6f59fb1b90726b62623090bf6c9d2d4321e71
1 parent
03e838f1
Exists in
master
and in
21 other branches
Allow article types to define when media panel should be displayed
Showing
11 changed files
with
69 additions
and
4 deletions
Show diff stats
app/models/article.rb
| ... | ... | @@ -635,6 +635,14 @@ class Article < ActiveRecord::Base |
| 635 | 635 | can_display_hits? && display_hits |
| 636 | 636 | end |
| 637 | 637 | |
| 638 | + def display_media_panel? | |
| 639 | + can_display_media_panel? && environment.enabled?('media_panel') | |
| 640 | + end | |
| 641 | + | |
| 642 | + def can_display_media_panel? | |
| 643 | + false | |
| 644 | + end | |
| 645 | + | |
| 638 | 646 | def image? |
| 639 | 647 | false |
| 640 | 648 | end | ... | ... |
app/models/enterprise_homepage.rb
app/models/event.rb
app/models/textile_article.rb
app/models/tiny_mce_article.rb
app/views/cms/edit.html.erb
| 1 | 1 | <%= error_messages_for 'article' %> |
| 2 | 2 | |
| 3 | -<% show_media_panel = environment.enabled?('media_panel') && [TinyMceArticle, TextileArticle, Event, EnterpriseHomepage].any?{|klass| @article.kind_of?(klass)} %> | |
| 4 | - | |
| 5 | -<div class='<%= (show_media_panel ? 'with_media_panel' : 'no_media_panel') %>'> | |
| 3 | +<div class='<%= (@article.display_media_panel? ? 'with_media_panel' : 'no_media_panel') %>'> | |
| 6 | 4 | <%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %> |
| 7 | 5 | |
| 8 | 6 | <%= hidden_field_tag("type", @type) if @type %> |
| ... | ... | @@ -68,7 +66,7 @@ |
| 68 | 66 | <% end %> |
| 69 | 67 | </div> |
| 70 | 68 | |
| 71 | -<% if show_media_panel %> | |
| 69 | +<% if @article.display_media_panel? %> | |
| 72 | 70 | <%= render :partial => 'text_editor_sidebar' %> |
| 73 | 71 | <% end %> |
| 74 | 72 | ... | ... |
test/unit/article_test.rb
| ... | ... | @@ -2191,4 +2191,27 @@ class ArticleTest < ActiveSupport::TestCase |
| 2191 | 2191 | article.destroy |
| 2192 | 2192 | end |
| 2193 | 2193 | |
| 2194 | + should 'have can_display_media_panel with default false' do | |
| 2195 | + a = Article.new | |
| 2196 | + assert !a.can_display_media_panel? | |
| 2197 | + end | |
| 2198 | + | |
| 2199 | + should 'display media panel when allowed by the environment' do | |
| 2200 | + a = Article.new | |
| 2201 | + a.expects(:can_display_media_panel?).returns(true) | |
| 2202 | + environment = mock | |
| 2203 | + a.expects(:environment).returns(environment) | |
| 2204 | + environment.expects(:enabled?).with('media_panel').returns(true) | |
| 2205 | + assert a.display_media_panel? | |
| 2206 | + end | |
| 2207 | + | |
| 2208 | + should 'not display media panel when not allowed by the environment' do | |
| 2209 | + a = Article.new | |
| 2210 | + a.expects(:can_display_media_panel?).returns(true) | |
| 2211 | + environment = mock | |
| 2212 | + a.expects(:environment).returns(environment) | |
| 2213 | + environment.expects(:enabled?).with('media_panel').returns(false) | |
| 2214 | + assert !a.display_media_panel? | |
| 2215 | + end | |
| 2216 | + | |
| 2194 | 2217 | end | ... | ... |
test/unit/enterprise_homepage_test.rb
| ... | ... | @@ -26,4 +26,9 @@ class EnterpriseHomepageTest < ActiveSupport::TestCase |
| 26 | 26 | assert_equal false, a.can_display_hits? |
| 27 | 27 | end |
| 28 | 28 | |
| 29 | + should 'have can_display_media_panel with default true' do | |
| 30 | + a = EnterpriseHomepage.new | |
| 31 | + assert a.can_display_media_panel? | |
| 32 | + end | |
| 33 | + | |
| 29 | 34 | end | ... | ... |
test/unit/event_test.rb
test/unit/textile_article_test.rb
| ... | ... | @@ -174,6 +174,11 @@ class TextileArticleTest < ActiveSupport::TestCase |
| 174 | 174 | assert_equal "<p>one\nparagraph</p>", build_article("one\nparagraph").to_html |
| 175 | 175 | end |
| 176 | 176 | |
| 177 | + should 'have can_display_media_panel with default true' do | |
| 178 | + a = TextileArticle.new | |
| 179 | + assert a.can_display_media_panel? | |
| 180 | + end | |
| 181 | + | |
| 177 | 182 | protected |
| 178 | 183 | |
| 179 | 184 | def build_article(input = nil, options = {}) | ... | ... |
test/unit/tiny_mce_article_test.rb