 
   onEscapePressed: ->
     @$el.find('input#thang-search').val('')
-    @runSearch
+    @runSearch()

add_thangs_template = require 'templates/editor/level/add-thangs-view'
ThangType = require 'models/ThangType'
CocoCollection = require 'collections/CocoCollection'

class ThangTypeSearchCollection extends CocoCollection
  url: '/db/thang.type?project=original,name,version,description,slug,kind,rasterIcon'

    super options
    @world = options.world

    @thangTypes = new Backbone.Collection()
    thangTypeCollection = new ThangTypeSearchCollection([])
    thangTypeCollection.fetch({data: {limit: PAGE_SIZE}})
    thangTypeCollection.skip = 0
    # should load depended-on Components, too
    @supermodel.loadCollection(thangTypeCollection, 'thangs')
    @listenTo thangTypeCollection, 'sync', @onThangCollectionSynced

  onThangCollectionSynced: (collection) ->
    getMore = collection.models.length is PAGE_SIZE
    @thangTypes.add(collection.models)
    @render()
    if getMore
      collection.skip += PAGE_SIZE
      collection.fetch({data: {skip: collection.skip, limit: PAGE_SIZE}})
      @supermodel.loadCollection(collection, 'thangs')


  getRenderData: (context={}) ->
    context = super(context)
