%h2 Instructions
%h3 Overview
%p Make each recorded track first, then the mix, and then finally the claimed recordings.
%h3 Entering users and bands
%p Autocomplete is used to supply users and bands. Just starting typing and pick from the resulting options.
%h3 Adding Tracks and Mixes
%p To add a track or mix, you first click 'Add track' or 'Add mix', and fill out any values present.  However, to upload an ogg file for a mix or track, you must first click 'Update Recording' after you initially click 'Add Track/Mix'.  When the form re-displays after the update, you will then seen an upload file input.   Finally, after you have uploaded an ogg file, you can then click the Download link to verify your ogg file, or mp3, in the case of mixes.
%h4 Specific to Mixes
%ul
  %li When you first click 'Add Mix', there is nothing to fill out.  So click 'Add Mix', then click 'Update Recording'.  The page will prompt you, as well.
  %li When you upload a mix ogg file, it will be converted to mp3 too.  This makes the request take a little bit of time.  Just wait it out.
%h3 Add Claimed Recordings
%p Once your recorded tracks are added, you then want to add one Claimed Recording for each user you want to have access to the recording.  Making a claimed recording is basically making a recording 'visible' for a given user. The user must have a recorded track to have a claimed recording.
%h3 Validations
%p It should not be possible to create an invalid recording/track/mix/claim; there are a great deal of validations that will prevent you from doing something invalid. If you find otherwise, please fill out a JIRA  .

= semantic_form_for([:admin, @recording], :html => {:multipart => true}, :url => @recording.new_record? ? admin_recordings_path : "#{ENV['RAILS_RELATIVE_URL_ROOT']}/admin/recordings/#{@recording.id}") do |f|
  = f.semantic_errors *f.object.errors.keys
  = f.inputs name: 'Recording Fields' do

    = f.input :name, :hint => 'something to remember this recording by. This is used solely for display in jam-admin; nowhere else.'

    = f.input :owner, :as => :autocomplete, :url => autocomplete_user_email_admin_users_path, :input_html => { :id => "jam_ruby_recording_owner", :name => "", :id_element => "#jam_ruby_recording_owner_id" }
    = f.input :owner_id, :as => :hidden, :input_html => { :name => "jam_ruby_recording[owner_id]" }

    = f.input :band, :as => :autocomplete, :url => autocomplete_band_name_admin_bands_path, :input_html => { :id => "jam_ruby_recording_band", :name => "", :id_element => "#jam_ruby_recording_band_id" }
    = f.input :band_id, :as => :hidden, :input_html => { :name => "jam_ruby_recording[band_id]" }

    = f.input :duration, :hint => 'how long the recording is (in seconds)'

    = f.semantic_fields_for :recorded_tracks do |recorded_track, index|
      = render 'recorded_track_fields', f: recorded_track
    .links
      = link_to_add_association 'Add Track', f, :recorded_tracks, class: 'button', style: 'margin:20px;padding:10px 20px'

    = f.semantic_fields_for :mixes do |mix, index|
      = render 'mix_fields', f: mix
    .links
      = link_to_add_association 'Add Mix', f, :mixes, class: 'button', style: 'margin:20px; padding:10px 20px'

    = f.semantic_fields_for :claimed_recordings do |claimed_recording, index|
      = render 'claimed_recording_fields', f: claimed_recording
    .links
      = link_to_add_association 'Add Claimed Recording', f, :claimed_recordings, class: 'button', style: 'margin:20px; padding:10px 20px'

    = f.actions


:javascript
  $(document).ready( function() {
    $('body').on('cocoon:before-insert', function(e, insertedItem) {

      // handle recorded tracks
      var idForHiddenUserId = $('input[class="jam_ruby_recorded_track[user_id]"]', insertedItem).attr('id');
      if(idForHiddenUserId) {
       $('input[id="jam_ruby_recorded_track_user_id"]', insertedItem).attr('data-id-element', '#' + idForHiddenUserId)
      }

      // handle claimed recordings
      idForHiddenUserId = $('input[class="jam_ruby_claimed_recording[user_id]"]', insertedItem).attr('id');
      if(idForHiddenUserId) {
       $('input[id="jam_ruby_claimed_recording_user_id"]', insertedItem).attr('data-id-element', '#' + idForHiddenUserId)
      }
    });
  });
