Commit 5ba67c24fbf817389497a5254db3f29ccb07c788
1 parent
6b50d1d9
Exists in
staging
and in
7 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
@@ -634,6 +634,14 @@ class Article < ActiveRecord::Base | @@ -634,6 +634,14 @@ class Article < ActiveRecord::Base | ||
634 | can_display_hits? && display_hits | 634 | can_display_hits? && display_hits |
635 | end | 635 | end |
636 | 636 | ||
637 | + def display_media_panel? | ||
638 | + can_display_media_panel? && environment.enabled?('media_panel') | ||
639 | + end | ||
640 | + | ||
641 | + def can_display_media_panel? | ||
642 | + false | ||
643 | + end | ||
644 | + | ||
637 | def image? | 645 | def image? |
638 | false | 646 | false |
639 | end | 647 | 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
@@ -2180,4 +2180,27 @@ class ArticleTest < ActiveSupport::TestCase | @@ -2180,4 +2180,27 @@ class ArticleTest < ActiveSupport::TestCase | ||
2180 | article.destroy | 2180 | article.destroy |
2181 | end | 2181 | end |
2182 | 2182 | ||
2183 | + should 'have can_display_media_panel with default false' do | ||
2184 | + a = Article.new | ||
2185 | + assert !a.can_display_media_panel? | ||
2186 | + end | ||
2187 | + | ||
2188 | + should 'display media panel when allowed by the environment' do | ||
2189 | + a = Article.new | ||
2190 | + a.expects(:can_display_media_panel?).returns(true) | ||
2191 | + environment = mock | ||
2192 | + a.expects(:environment).returns(environment) | ||
2193 | + environment.expects(:enabled?).with('media_panel').returns(true) | ||
2194 | + assert a.display_media_panel? | ||
2195 | + end | ||
2196 | + | ||
2197 | + should 'not display media panel when not allowed by the environment' do | ||
2198 | + a = Article.new | ||
2199 | + a.expects(:can_display_media_panel?).returns(true) | ||
2200 | + environment = mock | ||
2201 | + a.expects(:environment).returns(environment) | ||
2202 | + environment.expects(:enabled?).with('media_panel').returns(false) | ||
2203 | + assert !a.display_media_panel? | ||
2204 | + end | ||
2205 | + | ||
2183 | end | 2206 | 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
@@ -357,4 +357,9 @@ class EventTest < ActiveSupport::TestCase | @@ -357,4 +357,9 @@ class EventTest < ActiveSupport::TestCase | ||
357 | assert event.translatable? | 357 | assert event.translatable? |
358 | end | 358 | end |
359 | 359 | ||
360 | + should 'have can_display_media_panel with default true' do | ||
361 | + a = Event.new | ||
362 | + assert a.can_display_media_panel? | ||
363 | + end | ||
364 | + | ||
360 | end | 365 | end |
test/unit/textile_article_test.rb
@@ -175,6 +175,11 @@ class TextileArticleTest < ActiveSupport::TestCase | @@ -175,6 +175,11 @@ class TextileArticleTest < ActiveSupport::TestCase | ||
175 | assert_equal "<p>one\nparagraph</p>", build_article("one\nparagraph").to_html | 175 | assert_equal "<p>one\nparagraph</p>", build_article("one\nparagraph").to_html |
176 | end | 176 | end |
177 | 177 | ||
178 | + should 'have can_display_media_panel with default true' do | ||
179 | + a = TextileArticle.new | ||
180 | + assert a.can_display_media_panel? | ||
181 | + end | ||
182 | + | ||
178 | protected | 183 | protected |
179 | 184 | ||
180 | def build_article(input = nil, options = {}) | 185 | 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 |