_article_block.rhtml 1.32 KB
<div class="article-block-edition">
<% if @block.box.owner.kind_of?(Environment) and @block.box.owner.portal_community.nil? %>
  <p id="no_portal_community">
  <%= _("You don't have an community defined as the portal community. Define it before use this block properly.") %>
  </p>
<% else %>
  <%
    articles = @block.available_articles.select {|a| !a.folder? || a.blog? }
    firstText = articles[articles.find_index{|a| a.kind_of?TextArticle}||-1]
    selected = @block.article || firstText
  %>
  <%= select_tag('block[article_id]', options_for_select_with_title(articles.map {|item| [item.path, item.id]}, selected.id), :onchange => 'jQuery("#block_blog_options").toggle(this.blogs.indexOf(this.value) != -1)') %>
  <div id="block_blog_options">
    <%= labelled_form_field( _('Number of posts:'), text_field_tag('block[posts_per_page]', @block.posts_per_page) ) %>
    <%= labelled_form_field( _('How to display posts:'), select_tag('block[visualization_format]', options_for_select([[_('First paragraph'), 'short'], [_('Full post'), 'full']], @block.visualization_format))) %>
  </div>
  <% blogs = @block.available_articles.select{|a|a.blog?} %>
  <script>
    jQuery("#block_article_id")[0].blogs = <%= blogs.map{|b| b.id.to_s }.to_json %>;
    jQuery("#block_blog_options").toggle(<%= blogs.include?(selected) %>);
  </script>
<% end %>
</div>