 
 $(document).ready ->
   
-  class HarvestApplication extends Backbone.View
+  class HarvestApplication extends Backbone.Viewl
     jade: new root.Jade '/static/templates/harvest-application.jade'
     
     responseJade: new root.Jade '/static/templates/harvest-response.jade'

      'click': 'doHarvest'
      
    doHarvest: ->
      postBody =
        recordUrl: $('#input-url').val()
        inputFormat: $('input[name=harvestFormat]:checked').val()
        destinationCollections: [ $('#selected-collection').val() ]
      opts =
        type: 'POST'
        contentType: 'application/json'

      @render()
      
      # Setup the Collection Name autocomplete
      split = (val) ->
        return val.split /,\s*/
      
      extractLast = (term) ->
        return split(term).pop()
      
      opts =
        source: (req, res) ->
          res $.ui.autocomplete.filter root.collections, extractLast req.term
        focus: ->
          return false
        select: (event, ui) ->
          terms = split this.value
          terms.pop()
          terms.push ui.item.value
          terms.push ''
          
          ids = []
          for collection in root.collections
            for term in terms
              if collection.value == term then ids.push collection.id
          
          $('#selected-collection').val ids.join ", "
          $(this).val terms.join ", "
          return false
        change: (event, ui) ->
          terms = split this.value

          ids = []
          for collection in root.collections
            for term in terms
              if collection.value == term then ids.push collection.id
          $('#selected-collection').val ids.join ", "           
            
      $('#collection-selector').autocomplete opts
      return 
      
