<commit_before><% if flash[:notice].present? %>
  <div class="alert alert-success"><%= flash[:notice] %></div>
<% end %>

<% if artefact.errors.count > 0 %>
  <div class="alert alert-error">
    <ul>
      <% artefact.errors.full_messages.each do |message| %>
      <li><%= message %></li>
      <% end %>
    </ul>
  </div>
<% end %>

<div class="well">
  <%= semantic_form_for(artefact, :html => { :class => '', :id => 'edit_artefact'}) do |f| %>
    <%= f.inputs do %>
      <%= f.input :name, :input_html => { :class => "span6" } %>
      <%= f.input :slug, :input_html => { :class => "span6", :disabled => f.object.persisted? } %>
      <%= f.input :need_id, :input_html => { :class => "span6", :disabled => f.object.persisted? } %>
      <% if ! artefact.new_record? && ! artefact.business_proposition %>
          <%= link_to "View in Need-O-Tron", need_url(f.object), :rel => 'external', :class => "btn btn-primary" %>
          <%= link_to "View on site", published_url(f.object), :rel => 'external', :class => "btn btn-primary" %>
      <% end %>      

      <hr>

      <%= f.input :business_proposition, :label => 'Business Content?', :as => :boolean %>

      <hr>

      <% if artefact.new_record? %>
        <%= f.input :kind, :collection => Artefact::FORMATS.map { |s| [s.humanize, s]}, :as => :select, :class => "span6", :prompt => "Select a kind" %>
      <% end %>
      <%= f.input :primary_section, :as => :select, :collection => all_sections, :input_html => { :multiple => false } %>
      <input name="artefact[sections][]" type="hidden" value="">
      <%= f.input :sections, :as => :select, :collection => all_sections(:except=> artefact.primary_section), :input_html => { :multiple => true } %>
    <% end %>

    <hr>

    <%= f.inputs do %>
      <input name="artefact[related_artefact_ids][]" type="hidden" value="">
      <%= f.input :related_artefacts, :collection => Artefact.in_alphabetical_order, :input_html => { :multiple => true, :class => "span6 chzn-select" } %>
      <%= f.input :relatedness_done, :label => "Is relatedness done?", :as => :boolean %>
    <% end %>

    <hr>

    <%= f.inputs do %>

      <%= f.input :department, :label => "Writing team", :input_html => { :disabled => f.object.persisted?, :class => "span6"} %>
      <%= f.input :fact_checkers, :input_html => { :disabled => f.object.persisted?, :class => "span6"} %>
      <%= f.input :contact, :as => :hidden, :collection => Contact.in_alphabetical_order %>

    <% end %>

    <% if artefact.new_record? %>
      <%= f.input :owning_app, :as => :hidden, :input_html => {:value => "publisher"} %>
    <% end %>

    <hr>
    
    <%= f.input :tags, :input_html => {:class => "span6"} %>

    <% if f.object.persisted? %>
      <%= f.submit :value => "Save and continue editing", :class => "btn" %>
    <% end %>
    <%= f.submit :value => "Save and go to item", :class => "btn btn-success" %>
  <% end %>
</div>

<%= content_for :extra_javascript do %>
<%= javascript_include_tag('chosen.jquery.min.js', 'artefacts') %>
  <script type="text/javascript"> 
    $(".chzn-select").chosen();
    // Onchange handler needed here.
  </script>
<% end %>
<% content_for :extra_headers, stylesheet_link_tag('chosen') %><commit_msg>Remove sections from UI when updating primary section.<commit_after><% if flash[:notice].present? %>
  <div class="alert alert-success"><%= flash[:notice] %></div>
<% end %>

<% if artefact.errors.count > 0 %>
  <div class="alert alert-error">
    <ul>
      <% artefact.errors.full_messages.each do |message| %>
      <li><%= message %></li>
      <% end %>
    </ul>
  </div>
<% end %>

<div class="well">
  <%= semantic_form_for(artefact, :html => { :class => '', :id => 'edit_artefact'}) do |f| %>
    <%= f.inputs do %>
      <%= f.input :name, :input_html => { :class => "span6" } %>
      <%= f.input :slug, :input_html => { :class => "span6", :disabled => f.object.persisted? } %>
      <%= f.input :need_id, :input_html => { :class => "span6", :disabled => f.object.persisted? } %>
      <% if ! artefact.new_record? && ! artefact.business_proposition %>
          <%= link_to "View in Need-O-Tron", need_url(f.object), :rel => 'external', :class => "btn btn-primary" %>
          <%= link_to "View on site", published_url(f.object), :rel => 'external', :class => "btn btn-primary" %>
      <% end %>      

      <hr>

      <%= f.input :business_proposition, :label => 'Business Content?', :as => :boolean %>

      <hr>

      <% if artefact.new_record? %>
        <%= f.input :kind, :collection => Artefact::FORMATS.map { |s| [s.humanize, s]}, :as => :select, :class => "span6", :prompt => "Select a kind" %>
      <% end %>
      <%= f.input :primary_section, :as => :select, :collection => all_sections, :input_html => { :multiple => false, :class => "chzn-select" } %>
      <input name="artefact[sections][]" type="hidden" value="">
      <%= f.input :sections, :as => :select, :collection => all_sections(:except=> artefact.primary_section), :input_html => { :multiple => true, :class => "chzn-select" } %>
    <% end %>

    <hr>

    <%= f.inputs do %>
      <input name="artefact[related_artefact_ids][]" type="hidden" value="">
      <%= f.input :related_artefacts, :collection => Artefact.in_alphabetical_order, :input_html => { :multiple => true, :class => "span6 chzn-select" } %>
      <%= f.input :relatedness_done, :label => "Is relatedness done?", :as => :boolean %>
    <% end %>

    <hr>

    <%= f.inputs do %>

      <%= f.input :department, :label => "Writing team", :input_html => { :disabled => f.object.persisted?, :class => "span6"} %>
      <%= f.input :fact_checkers, :input_html => { :disabled => f.object.persisted?, :class => "span6"} %>
      <%= f.input :contact, :as => :hidden, :collection => Contact.in_alphabetical_order %>

    <% end %>

    <% if artefact.new_record? %>
      <%= f.input :owning_app, :as => :hidden, :input_html => {:value => "publisher"} %>
    <% end %>

    <hr>
    
    <%= f.input :tags, :input_html => {:class => "span6"} %>

    <% if f.object.persisted? %>
      <%= f.submit :value => "Save and continue editing", :class => "btn" %>
    <% end %>
    <%= f.submit :value => "Save and go to item", :class => "btn btn-success" %>
  <% end %>
</div>

<%= content_for :extra_javascript do %>
<%= javascript_include_tag('chosen.jquery.min.js', 'artefacts') %>
  <script type="text/javascript">
    $(".chzn-select").chosen();

    // Need to prevent our selected primary section from appearing in the sections box
    var current_primary_section = $("select#artefact_primary_section option:selected").clone();
    // onchange event listener of chosen we want to append/remove some section options
    $("#artefact_primary_section").chosen().change(function() {
      var new_primary_section = $("select#artefact_primary_section option:selected").clone();
      new_primary_section.removeAttr('selected');
      $("select#artefact_sections").find("option[value='" + new_primary_section.val() + "']").remove();

      if (current_primary_section.val() != "") {
        current_primary_section.removeAttr('selected');
        $("select#artefact_sections").append(current_primary_section);
      }
      current_primary_section = new_primary_section;

      // this trigger will cause chosen to update its own lists
      $("select#artefact_sections").trigger("liszt:updated");
    });
  </script>
<% end %>
<% content_for :extra_headers, stylesheet_link_tag('chosen') %>
{'fraction_non_alphanumeric': 0.21091346796843655, 'fraction_numerical': 0.0024073826400962954, 'mean_word_length': 3.3962375073486184, 'pattern_counts': {'":': 0, '<': 133, '<?xml version=': 0, '>': 245, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4380157', 'n_tokens_mistral': 2679, 'n_tokens_neox': 2467, 'n_words': 542}