Commit 950a0708 authored by Victor Costa's avatar Victor Costa
Browse files

Merge branch 'article_display_media_panel' into 'master'

Allow article types to define when media panel should be displayed

See merge request !633
parents 03e838f1 16b6f59f
......@@ -635,6 +635,14 @@ class Article < ActiveRecord::Base
can_display_hits? && display_hits
end
def display_media_panel?
can_display_media_panel? && environment.enabled?('media_panel')
end
def can_display_media_panel?
false
end
def image?
false
end
......
......@@ -35,4 +35,8 @@ class EnterpriseHomepage < Article
false
end
def can_display_media_panel?
true
end
end
......@@ -134,6 +134,10 @@ class Event < Article
true
end
def can_display_media_panel?
true
end
include Noosfero::TranslatableContent
include MaybeAddHttp
......
......@@ -24,6 +24,10 @@ class TextileArticle < TextArticle
true
end
def can_display_media_panel?
true
end
protected
def convert_to_html(textile)
......
......@@ -28,4 +28,8 @@ class TinyMceArticle < TextArticle
true
end
def can_display_media_panel?
true
end
end
<%= error_messages_for 'article' %>
<% show_media_panel = environment.enabled?('media_panel') && [TinyMceArticle, TextileArticle, Event, EnterpriseHomepage].any?{|klass| @article.kind_of?(klass)} %>
<div class='<%= (show_media_panel ? 'with_media_panel' : 'no_media_panel') %>'>
<div class='<%= (@article.display_media_panel? ? 'with_media_panel' : 'no_media_panel') %>'>
<%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %>
<%= hidden_field_tag("type", @type) if @type %>
......@@ -68,7 +66,7 @@
<% end %>
</div>
<% if show_media_panel %>
<% if @article.display_media_panel? %>
<%= render :partial => 'text_editor_sidebar' %>
<% end %>
......
......@@ -2191,4 +2191,27 @@ class ArticleTest < ActiveSupport::TestCase
article.destroy
end
should 'have can_display_media_panel with default false' do
a = Article.new
assert !a.can_display_media_panel?
end
should 'display media panel when allowed by the environment' do
a = Article.new
a.expects(:can_display_media_panel?).returns(true)
environment = mock
a.expects(:environment).returns(environment)
environment.expects(:enabled?).with('media_panel').returns(true)
assert a.display_media_panel?
end
should 'not display media panel when not allowed by the environment' do
a = Article.new
a.expects(:can_display_media_panel?).returns(true)
environment = mock
a.expects(:environment).returns(environment)
environment.expects(:enabled?).with('media_panel').returns(false)
assert !a.display_media_panel?
end
end
......@@ -26,4 +26,9 @@ class EnterpriseHomepageTest < ActiveSupport::TestCase
assert_equal false, a.can_display_hits?
end
should 'have can_display_media_panel with default true' do
a = EnterpriseHomepage.new
assert a.can_display_media_panel?
end
end
......@@ -346,4 +346,9 @@ class EventTest < ActiveSupport::TestCase
assert event.translatable?
end
should 'have can_display_media_panel with default true' do
a = Event.new
assert a.can_display_media_panel?
end
end
......@@ -174,6 +174,11 @@ class TextileArticleTest < ActiveSupport::TestCase
assert_equal "<p>one\nparagraph</p>", build_article("one\nparagraph").to_html
end
should 'have can_display_media_panel with default true' do
a = TextileArticle.new
assert a.can_display_media_panel?
end
protected
def build_article(input = nil, options = {})
......
......@@ -235,4 +235,9 @@ end
:attributes => { :colspan => 2, :rowspan => 3 }
end
should 'have can_display_media_panel with default true' do
a = TinyMceArticle.new
assert a.can_display_media_panel?
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment