_article_block.rhtml 1.51 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 => 'this.changedTo(this.value)'
  )%>
  <div id="block_blog_options" style="display:none">
    <%= labelled_form_field(
      _('Number of posts:'),
      text_field_tag('block[posts_per_page]', @block.posts_per_page)
    )%>
  </div>
  <%= labelled_form_field(
    _('How to display this content:'),
    select_tag(
      'block[visualization_format]',
      options_for_select([[_('Lead'), 'short'], [_('Full post'), 'full']], @block.visualization_format)
    )
  )%>
  <% blogs = @block.available_articles.select{|a|a.blog?} %>
  <script>
    var select = jQuery("#block_article_id")[0];
    select.blogs = <%= blogs.map{|b| b.id.to_s }.to_json %>;
    select.changedTo = function(articleId) {
      var blogSelected = this.blogs.indexOf(articleId) != -1;
      jQuery("#block_blog_options").toggle(blogSelected);
    }
    select.changedTo('<%= selected.id %>');
  </script>
<% end %>
</div>