Commit 0b8db772dc24fa6e039018cd9f467dc94beed49c

Authored by Rodrigo Souto
2 parents 657be12f 3583e31a

Merge branch 'AI2892-display_content_order_attributes' of /mnt/ebs/repositories/…

…participa/noosfero into next
app/views/shared/_lead_and_body.rhtml
@@ -7,11 +7,18 @@ @@ -7,11 +7,18 @@
7 <% lead_id ||= 0%> 7 <% lead_id ||= 0%>
8 <% f ||= false%> 8 <% f ||= false%>
9 9
  10 +<% if @article %>
  11 + <% fields_for 'article[image_builder]', @article.image do |i| %>
  12 + <%= file_field_or_thumbnail(_('Image:'), @article.image, i) %>
  13 + <% end %>
  14 +<% end %>
  15 +
10 <br style="clear: both;"/> 16 <br style="clear: both;"/>
11 <%= button :add, _("Lead"), '#', :class => "lead-button", :article_id => "#article-lead-"+lead_id.to_s, :style => "margin-left: 0px;" %> 17 <%= button :add, _("Lead"), '#', :class => "lead-button", :article_id => "#article-lead-"+lead_id.to_s, :style => "margin-left: 0px;" %>
12 <em><%= _('Used when a short version of your text is needed.') %></em> 18 <em><%= _('Used when a short version of your text is needed.') %></em>
13 19
14 <div class='article-lead' id="article-lead-<%=lead_id.to_s%>"> 20 <div class='article-lead' id="article-lead-<%=lead_id.to_s%>">
  21 +
15 <% if f %> 22 <% if f %>
16 <%= labelled_form_field(_(abstract_label), f.text_area(abstract_method, :style => 'width: 98%; height: 200px;', :class => editor_type)) %> 23 <%= labelled_form_field(_(abstract_label), f.text_area(abstract_method, :style => 'width: 98%; height: 200px;', :class => editor_type)) %>
17 <% else %> 24 <% else %>
plugins/display_content/README
@@ -33,7 +33,7 @@ As a Noosfero administrator user, go to administrator panel: @@ -33,7 +33,7 @@ As a Noosfero administrator user, go to administrator panel:
33 DEVELOPMENT 33 DEVELOPMENT
34 =========== 34 ===========
35 35
36 -Noosfero uses jQuery 1.5.1 and the jsTree doesn't works fine with this jQuery version. 36 +Noosfero uses jQuery 1.5.1 and the jsTree doesn't works fine with this jQuery version.
37 Until Noosfero upgrade its JQuery version to a newer one is necessary to load jQuery 1.8.3 inside plugin and apply some changes in jsTree to avoid jQuery conflit. 37 Until Noosfero upgrade its JQuery version to a newer one is necessary to load jQuery 1.8.3 inside plugin and apply some changes in jsTree to avoid jQuery conflit.
38 38
39 Get the Display Content (Noosfero with Display Content Plugin) development repository: 39 Get the Display Content (Noosfero with Display Content Plugin) development repository:
plugins/display_content/controllers/display_content_plugin_admin_controller.rb
@@ -4,6 +4,6 @@ class DisplayContentPluginAdminController &lt; AdminController @@ -4,6 +4,6 @@ class DisplayContentPluginAdminController &lt; AdminController
4 4
5 append_view_path File.join(File.dirname(__FILE__) + '/../views') 5 append_view_path File.join(File.dirname(__FILE__) + '/../views')
6 6
7 - include DisplayContentPluginController 7 + include DisplayContentPluginController
8 8
9 end 9 end
plugins/display_content/controllers/display_content_plugin_module.rb
@@ -18,10 +18,10 @@ module DisplayContentPluginController @@ -18,10 +18,10 @@ module DisplayContentPluginController
18 node[:data] = article.title 18 node[:data] = article.title
19 node[:attr] = { 'node_id' => article.id, 'parent_id' => article.parent_id} 19 node[:attr] = { 'node_id' => article.id, 'parent_id' => article.parent_id}
20 if block.nodes.include?(article.id) 20 if block.nodes.include?(article.id)
21 - node[:attr].merge!('class' => 'jstree-checked') 21 + node[:attr].merge!('class' => 'jstree-checked')
22 elsif block.parent_nodes.include?(article.id) 22 elsif block.parent_nodes.include?(article.id)
23 node[:children] = get_node(block, article.children) 23 node[:children] = get_node(block, article.children)
24 - node[:attr].merge!('class' => 'jstree-undetermined') 24 + node[:attr].merge!('class' => 'jstree-undetermined')
25 end 25 end
26 node[:state] = 'closed' if Article.exists?(:parent_id => article.id) 26 node[:state] = 'closed' if Article.exists?(:parent_id => article.id)
27 nodes.push(node) 27 nodes.push(node)
plugins/display_content/controllers/display_content_plugin_myprofile_controller.rb
@@ -4,6 +4,6 @@ class DisplayContentPluginMyprofileController &lt; MyProfileController @@ -4,6 +4,6 @@ class DisplayContentPluginMyprofileController &lt; MyProfileController
4 4
5 append_view_path File.join(File.dirname(__FILE__) + '/../views') 5 append_view_path File.join(File.dirname(__FILE__) + '/../views')
6 6
7 - include DisplayContentPluginController 7 + include DisplayContentPluginController
8 8
9 end 9 end
plugins/display_content/lib/display_content_block.rb
1 class DisplayContentBlock < Block 1 class DisplayContentBlock < Block
2 2
  3 + MONTHS = [
  4 + N_('January'),
  5 + N_('February'),
  6 + N_('March'),
  7 + N_('April'),
  8 + N_('May'),
  9 + N_('June'),
  10 + N_('July'),
  11 + N_('August'),
  12 + N_('September'),
  13 + N_('October'),
  14 + N_('November'),
  15 + N_('December')
  16 + ]
  17 +
3 settings_items :nodes, :type => Array, :default => [] 18 settings_items :nodes, :type => Array, :default => []
4 settings_items :parent_nodes, :type => Array, :default => [] 19 settings_items :parent_nodes, :type => Array, :default => []
5 - settings_items :chosen_attributes, :type => Array, :default => ['title'] 20 + settings_items :sections,
  21 + :type => Array,
  22 + :default => [{:name => _('Publish date'), :checked => true},
  23 + {:name => _('Title'), :checked => true},
  24 + {:name => _('Abstract'), :checked => true},
  25 + {:name => _('Body'), :checked => false},
  26 + {:name => _('Image'), :checked => false},
  27 + {:name => _('Tags'), :checked => false}]
6 28
7 def self.description 29 def self.description
8 _('Display your contents') 30 _('Display your contents')
@@ -33,20 +55,50 @@ class DisplayContentBlock &lt; Block @@ -33,20 +55,50 @@ class DisplayContentBlock &lt; Block
33 55
34 def articles_of_parent(parent = nil) 56 def articles_of_parent(parent = nil)
35 return [] if self.holder.nil? 57 return [] if self.holder.nil?
36 - holder.articles.find(:all, :conditions => {:type => VALID_CONTENT, :parent_id => (parent.nil? ? nil : parent)}) 58 + holder.articles.find(:all, :conditions => {:type => VALID_CONTENT, :parent_id => (parent.nil? ? nil : parent)})
37 end 59 end
38 60
39 include ActionController::UrlWriter 61 include ActionController::UrlWriter
40 def content(args={}) 62 def content(args={})
41 docs = owner.articles.find(:all, :conditions => {:id => self.nodes}) 63 docs = owner.articles.find(:all, :conditions => {:id => self.nodes})
  64 +
42 block_title(title) + 65 block_title(title) +
43 - content_tag('ul', docs.map {|item|  
44 - content_tag('li',  
45 - (display_attribute?('title') ? content_tag('div', link_to(h(item.title), item.url), :class => 'title') : '') +  
46 - (display_attribute?('abstract') ? content_tag('div', item.abstract ,:class => 'lead') : '') +  
47 - (display_attribute?('body') ? content_tag('div', item.body ,:class => 'body') : '')  
48 - )  
49 - }.join("\n")) 66 + content_tag('ul', docs.map {|item|
  67 +
  68 + content_sections = ''
  69 + read_more_section = ''
  70 + tags_section = ''
  71 +
  72 + sections.select { |section|
  73 + case section[:name]
  74 + when 'Publish date'
  75 + content_sections += (display_section?(section) ? (content_tag('div', show_date(item.published_at, false), :class => 'published-at') ) : '')
  76 + when 'Title'
  77 + content_sections += (display_section?(section) ? (content_tag('div', link_to(h(item.title), item.url), :class => 'title') ) : '')
  78 + when 'Abstract'
  79 + content_sections += (display_section?(section) ? (content_tag('div', item.abstract , :class => 'lead')) : '' )
  80 + if display_section?(section)
  81 + read_more_section = content_tag('div', link_to(_('Read more'), item.url), :class => 'read_more')
  82 + end
  83 + when 'Body'
  84 + content_sections += (display_section?(section) ? (content_tag('div', item.body ,:class => 'body')) : '' )
  85 + when 'Image'
  86 + image_section = image_tag item.image.public_filename if item.image
  87 + if !image_section.blank?
  88 + content_sections += (display_section?(section) ? (content_tag('div', link_to( image_section, item.url ) ,:class => 'image')) : '' )
  89 + end
  90 + when 'Tags'
  91 + if !item.tags.empty?
  92 + tags_section = item.tags.map { |t| content_tag('span', t.name) }.join("")
  93 + content_sections += (display_section?(section) ? (content_tag('div', tags_section, :class => 'tags')) : '')
  94 + end
  95 + end
  96 + }
  97 +
  98 + content_sections += read_more_section if !read_more_section.blank?
  99 +
  100 + content_tag('li', content_sections)
  101 + }.join(" "))
50 102
51 end 103 end
52 104
@@ -61,15 +113,15 @@ class DisplayContentBlock &lt; Block @@ -61,15 +113,15 @@ class DisplayContentBlock &lt; Block
61 params 113 params
62 end 114 end
63 115
64 - def display_attribute?(attr)  
65 - chosen_attributes.include?(attr) 116 + def display_section?(section)
  117 + section[:checked]
66 end 118 end
67 119
68 protected 120 protected
69 121
70 def holder 122 def holder
71 return nil if self.box.nil? || self.box.owner.nil? 123 return nil if self.box.nil? || self.box.owner.nil?
72 - if self.box.owner.kind_of?(Environment) 124 + if self.box.owner.kind_of?(Environment)
73 return nil if self.box.owner.portal_community.nil? 125 return nil if self.box.owner.portal_community.nil?
74 self.box.owner.portal_community 126 self.box.owner.portal_community
75 else 127 else
@@ -87,4 +139,20 @@ class DisplayContentBlock &lt; Block @@ -87,4 +139,20 @@ class DisplayContentBlock &lt; Block
87 { :profile => [:article], :environment => [:article] } 139 { :profile => [:article], :environment => [:article] }
88 end 140 end
89 141
  142 + def show_date(date, use_numbers = false, year=true)
  143 + if date && use_numbers
  144 + date_format = year ? _('%{month}/%{day}/%{year}') : _('%{month}/%{day}')
  145 + date_format % { :day => date.day, :month => date.month, :year => date.year }
  146 + elsif date
  147 + date_format = year ? _('%{month_name} %{day}, %{year}') : _('%{month_name} %{day}')
  148 + date_format % { :day => date.day, :month_name => month_name(date.month), :year => date.year }
  149 + else
  150 + ''
  151 + end
  152 + end
  153 +
  154 + def month_name(n)
  155 + _(MONTHS[n-1])
  156 + end
  157 +
90 end 158 end
plugins/display_content/lib/display_content_plugin.rb
@@ -20,7 +20,6 @@ class DisplayContentPlugin &lt; Noosfero::Plugin @@ -20,7 +20,6 @@ class DisplayContentPlugin &lt; Noosfero::Plugin
20 false 20 false
21 end 21 end
22 22
23 - #FIXME make this test  
24 def stylesheet? 23 def stylesheet?
25 true 24 true
26 end 25 end
plugins/display_content/public/style.css
1 -#display_content_plugin ul { 1 +#display_content_plugin .sections {
  2 + width: auto;
  3 +}
  4 +
  5 +#display_content_plugin .sections td {
  6 + padding: 2px;
  7 +}
  8 +
  9 +.block.display-content-block ul {
2 list-style: none; 10 list-style: none;
  11 + padding: 0px;
  12 +}
  13 +
  14 +.block.display-content-block li {
  15 + margin: 5px;
  16 +}
  17 +
  18 +.block.display-content-block .published-at,
  19 +.block.display-content-block .title,
  20 +.block.display-content-block .lead,
  21 +.block.display-content-block .body,
  22 +.block.display-content-block .image,
  23 +.block.display-content-block .read_more,
  24 +.block.display-content-block .tags {
  25 + margin: 2px 0px 2px 0px;
  26 +}
  27 +
  28 +.block.display-content-block .tags span {
  29 + margin-right: 3px;
3 } 30 }
4 31
5 -#display_content_plugin .display_attributes li{  
6 - display: inline; 32 +.block.display-content-block .tags a {
  33 + text-decoration: none;
  34 + -webkit-border-radius: 3px;
  35 + background-color: #BBB;
  36 + color: #FFF;
  37 + padding: 2px;
7 } 38 }
plugins/display_content/test/functional/display_content_plugin_admin_controller_test.rb
@@ -19,7 +19,7 @@ class DisplayContentPluginAdminControllerTest &lt; ActionController::TestCase @@ -19,7 +19,7 @@ class DisplayContentPluginAdminControllerTest &lt; ActionController::TestCase
19 @environment.enabled_plugins = ['DisplayContentPlugin'] 19 @environment.enabled_plugins = ['DisplayContentPlugin']
20 @environment.portal_community = fast_create(Community, :name => 'my test profile', :identifier => 'mytestcommunity') 20 @environment.portal_community = fast_create(Community, :name => 'my test profile', :identifier => 'mytestcommunity')
21 @environment.save! 21 @environment.save!
22 - 22 +
23 box = Box.new(:owner => @environment, :position => 1) 23 box = Box.new(:owner => @environment, :position => 1)
24 box.save 24 box.save
25 25
plugins/display_content/test/unit/display_content_block_test.rb
@@ -515,7 +515,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase @@ -515,7 +515,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
515 Article.delete_all 515 Article.delete_all
516 a1 = fast_create(invalid_article, :name => 'test article 1', :profile_id => profile.id) 516 a1 = fast_create(invalid_article, :name => 'test article 1', :profile_id => profile.id)
517 a2 = fast_create(VALID_KIND_OF_ARTICLE.first, :name => 'test article 2', :profile_id => profile.id) 517 a2 = fast_create(VALID_KIND_OF_ARTICLE.first, :name => 'test article 2', :profile_id => profile.id)
518 - 518 +
519 block = DisplayContentBlock.new 519 block = DisplayContentBlock.new
520 box = mock() 520 box = mock()
521 box.stubs(:owner).returns(profile) 521 box.stubs(:owner).returns(profile)
@@ -523,7 +523,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase @@ -523,7 +523,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
523 assert_equal [], [a2] - block.articles_of_parent 523 assert_equal [], [a2] - block.articles_of_parent
524 assert_equal [], block.articles_of_parent - [a2] 524 assert_equal [], block.articles_of_parent - [a2]
525 end 525 end
526 - 526 +
527 end 527 end
528 528
529 VALID_KIND_OF_ARTICLE.map do |valid_article| 529 VALID_KIND_OF_ARTICLE.map do |valid_article|
@@ -533,14 +533,14 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase @@ -533,14 +533,14 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
533 Article.delete_all 533 Article.delete_all
534 a1 = fast_create(valid_article, :name => 'test article 1', :profile_id => profile.id) 534 a1 = fast_create(valid_article, :name => 'test article 1', :profile_id => profile.id)
535 a2 = fast_create(INVALID_KIND_OF_ARTICLE.first, :name => 'test article 2', :profile_id => profile.id) 535 a2 = fast_create(INVALID_KIND_OF_ARTICLE.first, :name => 'test article 2', :profile_id => profile.id)
536 - 536 +
537 block = DisplayContentBlock.new 537 block = DisplayContentBlock.new
538 box = mock() 538 box = mock()
539 box.stubs(:owner).returns(profile) 539 box.stubs(:owner).returns(profile)
540 block.stubs(:box).returns(box) 540 block.stubs(:box).returns(box)
541 assert_equal [a1], block.articles_of_parent 541 assert_equal [a1], block.articles_of_parent
542 end 542 end
543 - 543 +
544 end 544 end
545 545
546 should 'list links for all articles title defined in nodes' do 546 should 'list links for all articles title defined in nodes' do
@@ -554,7 +554,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase @@ -554,7 +554,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
554 box = mock() 554 box = mock()
555 block.stubs(:box).returns(box) 555 block.stubs(:box).returns(box)
556 box.stubs(:owner).returns(profile) 556 box.stubs(:owner).returns(profile)
557 - 557 +
558 assert_match /.*<a.*>#{a1.title}<\/a>/, block.content 558 assert_match /.*<a.*>#{a1.title}<\/a>/, block.content
559 assert_match /.*<a.*>#{a2.title}<\/a>/, block.content 559 assert_match /.*<a.*>#{a2.title}<\/a>/, block.content
560 end 560 end
@@ -566,12 +566,12 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase @@ -566,12 +566,12 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
566 a2 = fast_create(TextArticle, :name => 'test article 2', :profile_id => profile.id, :abstract => 'abstract article 2') 566 a2 = fast_create(TextArticle, :name => 'test article 2', :profile_id => profile.id, :abstract => 'abstract article 2')
567 567
568 block = DisplayContentBlock.new 568 block = DisplayContentBlock.new
569 - block.chosen_attributes = ['abstract'] 569 + block.sections = [{:name => 'Abstract', :checked => true}]
570 block.nodes = [a1.id, a2.id] 570 block.nodes = [a1.id, a2.id]
571 box = mock() 571 box = mock()
572 block.stubs(:box).returns(box) 572 block.stubs(:box).returns(box)
573 box.stubs(:owner).returns(profile) 573 box.stubs(:owner).returns(profile)
574 - 574 +
575 assert_match /<div class="lead">#{a1.lead}<\/div>/, block.content 575 assert_match /<div class="lead">#{a1.lead}<\/div>/, block.content
576 assert_match /<div class="lead">#{a2.lead}<\/div>/, block.content 576 assert_match /<div class="lead">#{a2.lead}<\/div>/, block.content
577 end 577 end
@@ -585,7 +585,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase @@ -585,7 +585,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
585 box = mock() 585 box = mock()
586 block.stubs(:box).returns(box) 586 block.stubs(:box).returns(box)
587 box.stubs(:owner).returns(profile) 587 box.stubs(:owner).returns(profile)
588 - 588 +
589 Article.delete_all 589 Article.delete_all
590 assert_match /<ul><\/ul>/, block.content 590 assert_match /<ul><\/ul>/, block.content
591 end 591 end
@@ -595,7 +595,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase @@ -595,7 +595,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
595 block = DisplayContentBlock.new 595 block = DisplayContentBlock.new
596 block.box = profile.boxes.first 596 block.box = profile.boxes.first
597 block.save! 597 block.save!
598 - 598 +
599 params = {:block_id => block.id} 599 params = {:block_id => block.id}
600 params[:controller] = "display_content_plugin_myprofile" 600 params[:controller] = "display_content_plugin_myprofile"
601 params[:profile] = profile.identifier 601 params[:profile] = profile.identifier
@@ -607,7 +607,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase @@ -607,7 +607,7 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
607 block = DisplayContentBlock.new 607 block = DisplayContentBlock.new
608 block.box = environment.boxes.first 608 block.box = environment.boxes.first
609 block.save! 609 block.save!
610 - 610 +
611 params = {:block_id => block.id} 611 params = {:block_id => block.id}
612 params[:controller] = "display_content_plugin_admin" 612 params[:controller] = "display_content_plugin_admin"
613 assert_equal params, block.url_params 613 assert_equal params, block.url_params
@@ -619,11 +619,11 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase @@ -619,11 +619,11 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
619 619
620 block = DisplayContentBlock.new 620 block = DisplayContentBlock.new
621 block.nodes = [a.id] 621 block.nodes = [a.id]
622 - block.chosen_attributes = ['title'] 622 + block.sections = [{:name => 'Title', :checked => true}]
623 box = mock() 623 box = mock()
624 block.stubs(:box).returns(box) 624 block.stubs(:box).returns(box)
625 box.stubs(:owner).returns(profile) 625 box.stubs(:owner).returns(profile)
626 - 626 +
627 assert_match /.*<a.*>#{a.title}<\/a>/, block.content 627 assert_match /.*<a.*>#{a.title}<\/a>/, block.content
628 end 628 end
629 629
@@ -633,11 +633,11 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase @@ -633,11 +633,11 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
633 633
634 block = DisplayContentBlock.new 634 block = DisplayContentBlock.new
635 block.nodes = [a.id] 635 block.nodes = [a.id]
636 - block.chosen_attributes = ['abstract'] 636 + block.sections = [{:name => 'Abstract', :checked => true}]
637 box = mock() 637 box = mock()
638 block.stubs(:box).returns(box) 638 block.stubs(:box).returns(box)
639 box.stubs(:owner).returns(profile) 639 box.stubs(:owner).returns(profile)
640 - 640 +
641 assert_match /#{a.abstract}/, block.content 641 assert_match /#{a.abstract}/, block.content
642 end 642 end
643 643
@@ -647,11 +647,11 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase @@ -647,11 +647,11 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
647 647
648 block = DisplayContentBlock.new 648 block = DisplayContentBlock.new
649 block.nodes = [a.id] 649 block.nodes = [a.id]
650 - block.chosen_attributes = ['body'] 650 + block.sections = [{:name => 'Body', :checked => true}]
651 box = mock() 651 box = mock()
652 block.stubs(:box).returns(box) 652 block.stubs(:box).returns(box)
653 box.stubs(:owner).returns(profile) 653 box.stubs(:owner).returns(profile)
654 - 654 +
655 assert_match /#{a.body}/, block.content 655 assert_match /#{a.body}/, block.content
656 end 656 end
657 657
@@ -659,17 +659,41 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase @@ -659,17 +659,41 @@ class DisplayContentBlockTest &lt; ActiveSupport::TestCase
659 profile = create_user('testuser').person 659 profile = create_user('testuser').person
660 660
661 block = DisplayContentBlock.new 661 block = DisplayContentBlock.new
662 -  
663 - assert block.display_attribute?('title') 662 +
  663 + assert block.display_section?({:name => 'Title', :checked => true})
664 end 664 end
665 665
666 should 'display_attribute be true if the attribute was chosen' do 666 should 'display_attribute be true if the attribute was chosen' do
667 profile = create_user('testuser').person 667 profile = create_user('testuser').person
668 668
669 block = DisplayContentBlock.new 669 block = DisplayContentBlock.new
670 - block.chosen_attributes = ['body']  
671 -  
672 - assert block.display_attribute?('body') 670 +
  671 + block.sections = [{:name => 'Body', :checked => true}]
  672 + section = block.sections.first
  673 +
  674 + assert block.display_section?(section)
  675 + end
  676 +
  677 + should 'display_attribute be true for publish date by default' do
  678 + profile = create_user('testuser').person
  679 +
  680 + block = DisplayContentBlock.new
  681 +
  682 + assert block.display_section?({:name => 'Publish date', :checked => true})
  683 + end
  684 +
  685 + should 'show publishd date if defined by user' do
  686 + profile = create_user('testuser').person
  687 + a = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id, :body => 'some body')
  688 +
  689 + block = DisplayContentBlock.new
  690 + block.nodes = [a.id]
  691 + block.sections = [{:name => 'Publish date', :checked => true}]
  692 + box = mock()
  693 + block.stubs(:box).returns(box)
  694 + box.stubs(:owner).returns(profile)
  695 +
  696 + assert_match /#{a.published_at}/, block.content
673 end 697 end
674 698
675 end 699 end
plugins/display_content/views/box_organizer/_display_content_block.rhtml
1 <div id="display_content_plugin"> 1 <div id="display_content_plugin">
2 2
3 -<h3> <%= _('Choose which attributes should be displayed:') %> </h3>  
4 -<ul class='display_attributes'>  
5 - <li> <%= _('Title: ')%> <%= check_box_tag "block[chosen_attributes][]", 'title', @block.display_attribute?('title') %> </li>  
6 - <li> <%= _('Abstract: ')%> <%= check_box_tag "block[chosen_attributes][]", 'abstract', @block.display_attribute?('abstract') %> </li>  
7 - <li> <%= _('Body: ')%> <%= check_box_tag "block[chosen_attributes][]", 'body', @block.display_attribute?('body') %> </li>  
8 -</ul> 3 +<h3> <%= _('Choose which attributes should be displayed and drag to reorder them:') %> </h3>
  4 +
  5 +<table class="sections">
  6 + <tbody id="sortable">
  7 + <% for section in @block.sections do %>
  8 + <tr>
  9 + <td><%= hidden_field_tag 'block[sections][][name]', section[:name] %> <%= check_box_tag 'block[sections][][checked]', section[:name], section[:checked] %></td>
  10 + <td><%= section[:name]%></td>
  11 + </tr>
  12 + <% end %>
  13 + </tbody>
  14 +</table>
9 15
10 <h3> <%= _('Choose which content should be displayed:') %> </h3> 16 <h3> <%= _('Choose which content should be displayed:') %> </h3>
11 <div id="display_content"> 17 <div id="display_content">
@@ -16,20 +22,22 @@ @@ -16,20 +22,22 @@
16 jQuery_1_8_3("#display_content").jstree({ 22 jQuery_1_8_3("#display_content").jstree({
17 plugins : ["themes","json_data", "checkbox"], 23 plugins : ["themes","json_data", "checkbox"],
18 checkbox : { 24 checkbox : {
19 - real_checkboxes : true,  
20 - real_checkboxes_names : function (n) { return [("block[checked_nodes[" + n.attr('node_id') + "]]"), 1]; } 25 + real_checkboxes : true,
  26 + real_checkboxes_names : function (n) { return [("block[checked_nodes[" + n.attr('node_id') + "]]"), 1]; }
21 }, 27 },
22 themes : {"theme" : "classic", "icons" : true, "url": "/plugins/display_content/javascripts/jstree/themes/classic/style.css"}, 28 themes : {"theme" : "classic", "icons" : true, "url": "/plugins/display_content/javascripts/jstree/themes/classic/style.css"},
23 json_data : { 29 json_data : {
24 - ajax : {  
25 - url : '<%= url_for @block.url_params %>', 30 + ajax : {
  31 + url : '<%= url_for @block.url_params %>',
26 async: true, 32 async: true,
27 - data : function (m) { 33 + data : function (m) {
28 return m.attr ? {"id" : m.attr("node_id")} : {}; 34 return m.attr ? {"id" : m.attr("node_id")} : {};
29 } 35 }
30 } 36 }
31 } 37 }
32 }); 38 });
33 39
  40 +jQuery( "#sortable" ).sortable();
  41 +
34 </script> 42 </script>
35 </div> 43 </div>