Commit b8e132f6d89bc96c7c419caa141fb2555584fad6
1 parent
7e2ba029
Exists in
master
and in
27 other branches
Choose content type for display
Showing
4 changed files
with
118 additions
and
46 deletions
Show diff stats
plugins/display_content/lib/display_content_block.rb
| ... | ... | @@ -18,13 +18,16 @@ class DisplayContentBlock < Block |
| 18 | 18 | settings_items :nodes, :type => Array, :default => [] |
| 19 | 19 | settings_items :sections, |
| 20 | 20 | :type => Array, |
| 21 | - :default => [{:name => _('Publish date'), :checked => true}, | |
| 22 | - {:name => _('Title'), :checked => true}, | |
| 23 | - {:name => _('Abstract'), :checked => true}, | |
| 24 | - {:name => _('Body'), :checked => false}, | |
| 25 | - {:name => _('Image'), :checked => false}, | |
| 26 | - {:name => _('Tags'), :checked => false}] | |
| 21 | +#FIXME make test for values | |
| 22 | +#Refactoring section stuff | |
| 23 | + :default => [{:value => 'publish_date', :checked => true}, | |
| 24 | + {:value => 'title', :checked => true}, | |
| 25 | + {:value => 'abstract', :checked => true}, | |
| 26 | + {:value => 'body', :checked => false}, | |
| 27 | + {:value => 'image', :checked => false}, | |
| 28 | + {:value => 'tags', :checked => false}] | |
| 27 | 29 | settings_items :display_folder_children, :type => :boolean, :default => true |
| 30 | + settings_items :types, :type => Array, :default => ['UploadedFile'] | |
| 28 | 31 | |
| 29 | 32 | def self.description |
| 30 | 33 | _('Display your contents') |
| ... | ... | @@ -34,6 +37,44 @@ class DisplayContentBlock < Block |
| 34 | 37 | _('This block displays articles chosen by you. You can edit the block to select which of your articles is going to be displayed in the block.') |
| 35 | 38 | end |
| 36 | 39 | |
| 40 | + def section_name(section) | |
| 41 | + { | |
| 42 | + 'publish_date' => _('Publish date'), | |
| 43 | + 'title' => _('Title'), | |
| 44 | + 'abstract' => _('Abstract'), | |
| 45 | + 'body' => _('Body'), | |
| 46 | + 'image' => _('Image'), | |
| 47 | + 'tags' => _('Tags') | |
| 48 | + }[section] || section | |
| 49 | + end | |
| 50 | + | |
| 51 | + #FIXME make this test copy of Context Content | |
| 52 | + def available_content_types | |
| 53 | + @available_content_types ||= [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed] + plugins.dispatch(:content_types) | |
| 54 | + checked_types = types.map {|t| t.constantize} | |
| 55 | + checked_types + (@available_content_types - checked_types) | |
| 56 | + end | |
| 57 | + | |
| 58 | + #FIXME make this test copy of Context Content | |
| 59 | + def first_content_types | |
| 60 | + available_content_types.first(first_types_count) | |
| 61 | + end | |
| 62 | + | |
| 63 | + #FIXME make this test copy of Context Content | |
| 64 | + def more_content_types | |
| 65 | + available_content_types.drop(first_types_count) | |
| 66 | + end | |
| 67 | + | |
| 68 | + #FIXME make this test copy of Context Content | |
| 69 | + def first_types_count | |
| 70 | + [2, types.length].max | |
| 71 | + end | |
| 72 | + | |
| 73 | + #FIXME make this test copy of Context Content | |
| 74 | + def types=(new_types) | |
| 75 | + settings[:types] = new_types.reject(&:blank?) | |
| 76 | + end | |
| 77 | + | |
| 37 | 78 | def checked_nodes= params |
| 38 | 79 | self.nodes = params.keys |
| 39 | 80 | end |
| ... | ... | @@ -71,8 +112,12 @@ class DisplayContentBlock < Block |
| 71 | 112 | |
| 72 | 113 | include ActionController::UrlWriter |
| 73 | 114 | def content(args={}) |
| 74 | - extra_condition = display_folder_children ? 'OR articles.parent_id IN(:nodes)':'' | |
| 75 | - docs = nodes.blank? ? [] : owner.articles.find(:all, :conditions => ["(articles.id IN(:nodes) #{extra_condition}) AND articles.type IN(:types)", {:nodes => self.nodes, :types => VALID_CONTENT}]) | |
| 115 | + nodes_conditions = nodes.blank? ? '' : " articles.id IN(:nodes) " | |
| 116 | + nodes_conditions += ' OR articles.parent_id IN(:nodes) ' if !nodes.blank? && display_folder_children | |
| 117 | + | |
| 118 | +# docs = owner.articles.find(:all, :conditions => ["articles.type IN(:types) #{nodes.blank? ? '' : " AND (#{nodes_conditions})"}", {:nodes => self.nodes, :types => (types || VALID_CONTENT)}]) | |
| 119 | + | |
| 120 | + docs = owner.articles.find(:all, :conditions => ["articles.type IN(:types)", {:nodes => self.nodes, :types => (self.types || VALID_CONTENT)}]) | |
| 76 | 121 | |
| 77 | 122 | block_title(title) + |
| 78 | 123 | content_tag('ul', docs.map {|item| |
| ... | ... | @@ -82,24 +127,24 @@ class DisplayContentBlock < Block |
| 82 | 127 | tags_section = '' |
| 83 | 128 | |
| 84 | 129 | sections.select { |section| |
| 85 | - case section[:name] | |
| 86 | - when 'Publish date' | |
| 130 | + case section[:value] | |
| 131 | + when 'publish_date' | |
| 87 | 132 | content_sections += (display_section?(section) ? (content_tag('div', show_date(item.published_at, false), :class => 'published-at') ) : '') |
| 88 | - when 'Title' | |
| 133 | + when 'title' | |
| 89 | 134 | content_sections += (display_section?(section) ? (content_tag('div', link_to(h(item.title), item.url), :class => 'title') ) : '') |
| 90 | - when 'Abstract' | |
| 135 | + when 'abstract' | |
| 91 | 136 | content_sections += (display_section?(section) ? (content_tag('div', item.abstract , :class => 'lead')) : '' ) |
| 92 | 137 | if display_section?(section) |
| 93 | 138 | read_more_section = content_tag('div', link_to(_('Read more'), item.url), :class => 'read_more') |
| 94 | 139 | end |
| 95 | - when 'Body' | |
| 140 | + when 'body' | |
| 96 | 141 | content_sections += (display_section?(section) ? (content_tag('div', item.body ,:class => 'body')) : '' ) |
| 97 | - when 'Image' | |
| 142 | + when 'image' | |
| 98 | 143 | image_section = image_tag item.image.public_filename if item.image |
| 99 | 144 | if !image_section.blank? |
| 100 | 145 | content_sections += (display_section?(section) ? (content_tag('div', link_to( image_section, item.url ) ,:class => 'image')) : '' ) |
| 101 | 146 | end |
| 102 | - when 'Tags' | |
| 147 | + when 'tags' | |
| 103 | 148 | if !item.tags.empty? |
| 104 | 149 | tags_section = item.tags.map { |t| content_tag('span', t.name) }.join("") |
| 105 | 150 | content_sections += (display_section?(section) ? (content_tag('div', tags_section, :class => 'tags')) : '') |
| ... | ... | @@ -108,7 +153,7 @@ class DisplayContentBlock < Block |
| 108 | 153 | } |
| 109 | 154 | |
| 110 | 155 | content_sections += read_more_section if !read_more_section.blank? |
| 111 | - | |
| 156 | +#raise sections.inspect | |
| 112 | 157 | content_tag('li', content_sections) |
| 113 | 158 | end |
| 114 | 159 | }.join(" ")) | ... | ... |
plugins/display_content/views/box_organizer/_choose_by_content_type.rhtml
0 → 100644
| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | +<%= label :block, :types, _('Display content types:'), :class => 'formlabel' %> | |
| 2 | +<div class="content_types"> | |
| 3 | + <% @block.first_content_types.each do |type| %> | |
| 4 | + <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %> | |
| 5 | + <% end %> | |
| 6 | + <% if !@block.more_content_types.empty? %> | |
| 7 | + <a href="#" onclick="jQuery('.content_types .more').toggle(); return false;"><%= _('more') %></a> | |
| 8 | + <% end %> | |
| 9 | + <div class="more" style="display: none"> | |
| 10 | + <% @block.more_content_types.each do |type| %> | |
| 11 | + <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %> | |
| 12 | + <% end %> | |
| 13 | + </div> | |
| 14 | +</div> | |
| 15 | + | ... | ... |
plugins/display_content/views/box_organizer/_choose_directly.rhtml
0 → 100644
| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | +<div id="display_content"> | |
| 2 | +</div> | |
| 3 | + | |
| 4 | +<div class="display_folder_children"> | |
| 5 | + <%= labelled_form_field check_box(:block, :display_folder_children) + _('Dinamically load children of selected folders'), '' %> | |
| 6 | +</div> | |
| 7 | + | |
| 8 | +<script type="text/javascript" > | |
| 9 | + | |
| 10 | +jQuery_1_8_3("#display_content").jstree({ | |
| 11 | + plugins : ["themes","json_data", "checkbox"], | |
| 12 | + checkbox : { | |
| 13 | + real_checkboxes : true, | |
| 14 | + real_checkboxes_names : function (n) { return [("block[checked_nodes[" + n.attr('node_id') + "]]"), 1]; } | |
| 15 | + }, | |
| 16 | + themes : {"theme" : "classic", "icons" : true, "url": "/plugins/display_content/javascripts/jstree/themes/classic/style.css"}, | |
| 17 | + json_data : { | |
| 18 | + ajax : { | |
| 19 | + url : '<%= url_for @block.url_params %>', | |
| 20 | + async: true, | |
| 21 | + data : function (m) { | |
| 22 | + return m.attr ? {"id" : m.attr("node_id")} : {}; | |
| 23 | + } | |
| 24 | + } | |
| 25 | + } | |
| 26 | +}); | |
| 27 | + | |
| 28 | +jQuery( "#sortable" ).sortable(); | |
| 29 | + | |
| 30 | +</script> | ... | ... |
plugins/display_content/views/box_organizer/_display_content_block.rhtml
| 1 | 1 | <div id="display_content_plugin"> |
| 2 | 2 | |
| 3 | +<%= noosfero_javascript %> | |
| 4 | + | |
| 3 | 5 | <h3> <%= _('Choose which attributes should be displayed and drag to reorder them:') %> </h3> |
| 4 | 6 | |
| 5 | 7 | <table class="sections"> |
| 6 | 8 | <tbody id="sortable"> |
| 7 | 9 | <% for section in @block.sections do %> |
| 8 | 10 | <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 | + <td> | |
| 12 | + <%= hidden_field_tag 'block[sections][][value]', section[:value] %> | |
| 13 | + <%= check_box_tag 'block[sections][][checked]', section[:value], section[:checked] %> | |
| 14 | + </td> | |
| 15 | + <td><%= @block.section_name(section[:value]) %></td> | |
| 11 | 16 | </tr> |
| 12 | 17 | <% end %> |
| 13 | 18 | </tbody> |
| 14 | 19 | </table> |
| 15 | 20 | |
| 16 | 21 | <h3> <%= _('Choose which content should be displayed:') %> </h3> |
| 17 | -<div id="display_content"> | |
| 18 | -</div> | |
| 19 | - | |
| 20 | -<div class="display_folder_children"> | |
| 21 | - <%= labelled_form_field check_box(:block, :display_folder_children) + _('Dinamically load children of selected folders'), '' %> | |
| 22 | -</div> | |
| 22 | +<% tabs = [] %> | |
| 23 | +<% tabs << {:title => _('Choose directly'), :id => 'choose-directly', :content => (render :partial => 'choose_directly')} %> | |
| 24 | +<% tabs << {:title => _('Choose by Content Type'), :id => 'choose_by_content_type', :content => (render :partial => 'choose_by_content_type')} %> | |
| 23 | 25 | |
| 24 | -<script type="text/javascript" > | |
| 26 | +<%= render_tabs(tabs) %> | |
| 25 | 27 | |
| 26 | -jQuery_1_8_3("#display_content").jstree({ | |
| 27 | - plugins : ["themes","json_data", "checkbox"], | |
| 28 | - checkbox : { | |
| 29 | - real_checkboxes : true, | |
| 30 | - real_checkboxes_names : function (n) { return [("block[checked_nodes[" + n.attr('node_id') + "]]"), 1]; } | |
| 31 | - }, | |
| 32 | - themes : {"theme" : "classic", "icons" : true, "url": "/plugins/display_content/javascripts/jstree/themes/classic/style.css"}, | |
| 33 | - json_data : { | |
| 34 | - ajax : { | |
| 35 | - url : '<%= url_for @block.url_params %>', | |
| 36 | - async: true, | |
| 37 | - data : function (m) { | |
| 38 | - return m.attr ? {"id" : m.attr("node_id")} : {}; | |
| 39 | - } | |
| 40 | - } | |
| 41 | - } | |
| 42 | -}); | |
| 43 | - | |
| 44 | -jQuery( "#sortable" ).sortable(); | |
| 45 | - | |
| 46 | -</script> | |
| 47 | 28 | </div> |
| 29 | + | ... | ... |