Noosfero/noosfero

View on GitHub
app/views/cms/_blog.html.erb

Summary

Maintainability
Test Coverage
<%= error_messages_for 'blog' %>

<h1><%= _('My Blog') %></h1>

<%= required f.text_field(:name, :size => '64', :onchange => "updateUrlField(this, 'article_slug')") %>

<%= render :partial => 'general_fields' %>

<script type="text/javascript">
  function submit_button(index) {
    var form = $($("#article_slug")[0].form)
     return form.find("input[type=submit]")[index];
  }
  function warn_value_change() {
     show_warning('article-formitem', "slug-change-confirmation");
     disable_button(submit_button(0));
     disable_button(submit_button(1));
  }
  function confirm_change() {
     enable_button(submit_button(0));
     enable_button(submit_button(1));
     hide_warning('slug-change-confirmation');
  }
  function no_change() {
     jQuery("#article_slug").val(jQuery("#old_article_slug").val());
     enable_button(submit_button(0));
     enable_button(submit_button(1));
     hide_warning('slug-change-confirmation');
  }
</script>

<%= hidden_field_tag 'old_article_slug', @article.slug %>
<div id="article-formitem">
  <%= labelled_form_field( _('Address'),
        content_tag('code',
          url_for(@article.url).gsub(/#{@article.slug}$/, '').html_safe +
          text_field(:article, :slug, :onchange => "warn_value_change()", :size => 25)
        ) +
        content_tag('div',
          content_tag('strong', _('WARNING!')) + '&nbsp;' +
            _("You are about to change the address, and this will break external links to this blog or to posts inside it. Do you really want to change?") +
          content_tag('div',
            button_to_function(:ok, _("Yes"), "confirm_change()") + ' ' +
            button_to_function(:cancel, _('No'), 'no_change()')
          ),
          :id => 'slug-change-confirmation',
          :class => 'change-confirmation',
          :style => 'display: none;'
        )
      )
  %>
</div>

<%= labelled_form_field(_('Description:'), text_area(:article, :body, :rows => 10, :class => current_editor)) %>

<div id="blog-image-builder">
  <%= file_field_or_thumbnail(_('Cover image:'), @article.image, 'article[image_builder]', 'blog')%>
</div>

<%= labelled_form_field(_('How to display posts:'), f.select(:visualization_format, [
  [ _('Full post'), 'full'],
  [ _('First paragraph'), 'short'],
  [ _('First paragraph, with post picture'), 'short+pic'],
  [ _("Title, Image, Lead"), 'compact']
])) %>

<%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, Blog.posts_per_page_options)) %>

<%= labelled_check_box(_("List only translated posts"), 'article[display_posts_in_current_language]', '1', @article.display_posts_in_current_language?) %>

<%= f.fields_for 'feed', @article.feed do |feed| %>
  <%= labelled_form_field(_('Limit of posts in RSS Feed'), feed.select(:limit, [5, 10, 20, 50])) %>
  <%= labelled_form_field(_('Include in RSS Feed only posts from language:'), feed.select(:language, [[_('All'),  nil ]] + environment.locales.map { |k,v| [v, k]})) %>
<% end %>

<%= f.fields_for 'external_feed_builder', @article.external_feed do |efeed| %>
  <div id='fetch-external-feed'>
    <% enabled = @article.external_feed && @article.external_feed.enabled %>
    <% only_once = @article.external_feed ? @article.external_feed.only_once : true %>
    <%= labelled_check_box(_('Fetch posts from an external feed'), 'article[external_feed_builder][enabled]', 'true', enabled, {:onchange => "jQuery('#external-feed-options').toggle()"}) %>
    <div id='external-feed-options' style="display: <%= enabled ? 'block' : 'none' %>">
      <%= efeed.hidden_field(:id) %>
      <%= labelled_form_field( _('Feed address'), efeed.text_field(:address) ) %>
      <div id='external-feed-options-only-once'>
        <%= labelled_radio_button( _('Fetch posts only once'), 'article[external_feed_builder][only_once]', 'true', only_once) %>
        <%= labelled_radio_button( _('Fetch posts periodically'), 'article[external_feed_builder][only_once]', 'false', !only_once) %>
        <p>
          <em><%= _('Feeds are updated in batches periodically. Please note that your posts will not be fetched immediately.') %></em>
        </p>
      </div>
    </div>
  </div>
<% end %>