<% if @article.text_coding == Article::CODING_HTML %>
  <%= render partial: "javascripts/mce_full" %>
<% end %>

<h1>Editing Article</h1>

<%= form_for(@article, html: { class: 'article square' }) do |f| %>
  <%= render 'shared/errors', messages: @article.errors.full_messages %>

  <div class="fields horizontal">
    <%= f.label :title %>
    <%= f.text_field :title %>
  </div>
  <% if cuser.admin? %>
    <div class="fields horizontal">
      <%= f.label :status %>
      <%= f.select :status, @article.statuses.invert %>
    </div>
  <% end %>
  <div class="fields horizontal">
    <%= f.label :text_coding %>
    <%= f.select :text_coding, @article.codings.invert %>
  </div>
  <div class="fields horizontal">
    <%= f.label :category_id %>
    <%= f.select :category_id, Category.ordered.collect{|c| ["#{c.domains[c.domain]} - #{c}", c.id]} %>
  </div>
  <div class="fields horizontal wide">
    <h4>Content</h4>
    <%= f.text_area :text, :rows => 30, :cols => 80 %>
  </div>
  <div class="controls inline">
    <%= f.submit %>
  </div>
<% end %>

<% unless @article.new_record? %>
  <div class="files">
    <h4>Files</h4>

    <%= render partial: "data_files/list", locals: { files: @article.files } %>

    <% if @file && @file.can_create?(cuser) %>
      <h4>New File</h4>

      <%= form_for @file, html: { multipart: true } do |f| %>
        <%= render 'shared/errors', messages: @file.errors.full_messages %>

        <%= f.hidden_field :directory_id %>
        <%= f.hidden_field :article_id %>

        <div class="fields">
          <%= f.file_field :name %>  
        </div>
        <div class="controls">
          <%= f.submit 'Create' %>  
        </div>
      <% end %>
    <% end %>  
  </div>  
<% end %>
