Commit 5ba67c24fbf817389497a5254db3f29ccb07c788

Authored by Victor Costa
1 parent 6b50d1d9

Allow article types to define when media panel should be displayed

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
@@ -35,4 +35,8 @@ class EnterpriseHomepage < Article @@ -35,4 +35,8 @@ class EnterpriseHomepage < Article
35 false 35 false
36 end 36 end
37 37
  38 + def can_display_media_panel?
  39 + true
  40 + end
  41 +
38 end 42 end
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
@@ -28,4 +28,8 @@ class TinyMceArticle < TextArticle @@ -28,4 +28,8 @@ class TinyMceArticle < TextArticle
28 true 28 true
29 end 29 end
30 30
  31 + def can_display_media_panel?
  32 + true
  33 + end
  34 +
31 end 35 end
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 &lt; ActiveSupport::TestCase @@ -2180,4 +2180,27 @@ class ArticleTest &lt; 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 &lt; ActiveSupport::TestCase @@ -26,4 +26,9 @@ class EnterpriseHomepageTest &lt; 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 &lt; ActiveSupport::TestCase @@ -357,4 +357,9 @@ class EventTest &lt; 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 &lt; ActiveSupport::TestCase @@ -175,6 +175,11 @@ class TextileArticleTest &lt; 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