Commit 950a07082d85808991b63c99f0c30386af945a86
Exists in
master
and in
29 other branches
Merge branch 'article_display_media_panel' into 'master'
Allow article types to define when media panel should be displayed See merge request !633
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,6 +635,14 @@ class Article < ActiveRecord::Base | ||
| 635 | can_display_hits? && display_hits | 635 | can_display_hits? && display_hits |
| 636 | end | 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 | def image? | 646 | def image? |
| 639 | false | 647 | false |
| 640 | end | 648 | end |
app/models/enterprise_homepage.rb
app/models/event.rb
| @@ -134,6 +134,10 @@ class Event < Article | @@ -134,6 +134,10 @@ class Event < Article | ||
| 134 | true | 134 | true |
| 135 | end | 135 | end |
| 136 | 136 | ||
| 137 | + def can_display_media_panel? | ||
| 138 | + true | ||
| 139 | + end | ||
| 140 | + | ||
| 137 | include Noosfero::TranslatableContent | 141 | include Noosfero::TranslatableContent |
| 138 | include MaybeAddHttp | 142 | include MaybeAddHttp |
| 139 | 143 |
app/models/textile_article.rb
| @@ -24,6 +24,10 @@ class TextileArticle < TextArticle | @@ -24,6 +24,10 @@ class TextileArticle < TextArticle | ||
| 24 | true | 24 | true |
| 25 | end | 25 | end |
| 26 | 26 | ||
| 27 | + def can_display_media_panel? | ||
| 28 | + true | ||
| 29 | + end | ||
| 30 | + | ||
| 27 | protected | 31 | protected |
| 28 | 32 | ||
| 29 | def convert_to_html(textile) | 33 | def convert_to_html(textile) |
app/models/tiny_mce_article.rb
app/views/cms/edit.html.erb
| 1 | <%= error_messages_for 'article' %> | 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 | <%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %> | 4 | <%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %> |
| 7 | 5 | ||
| 8 | <%= hidden_field_tag("type", @type) if @type %> | 6 | <%= hidden_field_tag("type", @type) if @type %> |
| @@ -68,7 +66,7 @@ | @@ -68,7 +66,7 @@ | ||
| 68 | <% end %> | 66 | <% end %> |
| 69 | </div> | 67 | </div> |
| 70 | 68 | ||
| 71 | -<% if show_media_panel %> | 69 | +<% if @article.display_media_panel? %> |
| 72 | <%= render :partial => 'text_editor_sidebar' %> | 70 | <%= render :partial => 'text_editor_sidebar' %> |
| 73 | <% end %> | 71 | <% end %> |
| 74 | 72 |
test/unit/article_test.rb
| @@ -2191,4 +2191,27 @@ class ArticleTest < ActiveSupport::TestCase | @@ -2191,4 +2191,27 @@ class ArticleTest < ActiveSupport::TestCase | ||
| 2191 | article.destroy | 2191 | article.destroy |
| 2192 | end | 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 | end | 2217 | end |
test/unit/enterprise_homepage_test.rb
| @@ -26,4 +26,9 @@ class EnterpriseHomepageTest < ActiveSupport::TestCase | @@ -26,4 +26,9 @@ class EnterpriseHomepageTest < ActiveSupport::TestCase | ||
| 26 | assert_equal false, a.can_display_hits? | 26 | assert_equal false, a.can_display_hits? |
| 27 | end | 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 | end | 34 | end |
test/unit/event_test.rb
| @@ -346,4 +346,9 @@ class EventTest < ActiveSupport::TestCase | @@ -346,4 +346,9 @@ class EventTest < ActiveSupport::TestCase | ||
| 346 | assert event.translatable? | 346 | assert event.translatable? |
| 347 | end | 347 | end |
| 348 | 348 | ||
| 349 | + should 'have can_display_media_panel with default true' do | ||
| 350 | + a = Event.new | ||
| 351 | + assert a.can_display_media_panel? | ||
| 352 | + end | ||
| 353 | + | ||
| 349 | end | 354 | end |
test/unit/textile_article_test.rb
| @@ -174,6 +174,11 @@ class TextileArticleTest < ActiveSupport::TestCase | @@ -174,6 +174,11 @@ class TextileArticleTest < ActiveSupport::TestCase | ||
| 174 | assert_equal "<p>one\nparagraph</p>", build_article("one\nparagraph").to_html | 174 | assert_equal "<p>one\nparagraph</p>", build_article("one\nparagraph").to_html |
| 175 | end | 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 | protected | 182 | protected |
| 178 | 183 | ||
| 179 | def build_article(input = nil, options = {}) | 184 | def build_article(input = nil, options = {}) |
test/unit/tiny_mce_article_test.rb
| @@ -235,4 +235,9 @@ end | @@ -235,4 +235,9 @@ end | ||
| 235 | :attributes => { :colspan => 2, :rowspan => 3 } | 235 | :attributes => { :colspan => 2, :rowspan => 3 } |
| 236 | end | 236 | end |
| 237 | 237 | ||
| 238 | + should 'have can_display_media_panel with default true' do | ||
| 239 | + a = TinyMceArticle.new | ||
| 240 | + assert a.can_display_media_panel? | ||
| 241 | + end | ||
| 242 | + | ||
| 238 | end | 243 | end |
-
mentioned in commit c6a2cc536afa7390c498ef50acc4a450d8e6c2e9