     $('.modal').on 'hidden', () =>
       @clearModalForm($(@))
     @initModals()
+    @initSearchTypeahead()
 
   clearModalForm: (modal) ->
     form = modal.find('form')


    $(alert).insertBefore($('h1'))

class AdminInPlaceEditor extends AdminEditor
  init: () ->
    super
    @initEditors()

  initEditors: () ->
    $('#admin-in-place-editor .editable').editable
      placement: 'right'
      ajaxOptions:
        dataType: 'json'
        type: 'put'
      params: (params) ->
        #originally params contain pk, name and value
        newParams = id: params.pk
        newParams[$(@).attr('data-resource')] = {}
        newParams[$(@).attr('data-resource')][params.name] = params.value
        return newParams

    $('a[data-toggle="popover"]').popover(html: true, placement: 'bottom')

    $('#admin-in-place-editor .editable-required').editable('option',
      validate: (v) ->
        return 'Required field!' if (v == '')
    )

    $('#admin-in-place-editor .editable-geo-entity-type').editable(
      'option', 'source', window.geoEntityTypes
    )

    $('#admin-in-place-editor .editable-geo-relationship-type').editable(
      'option', 'source', window.geoRelationshipTypes
    )

    $('#admin-in-place-editor .editable-geo-entity').editable(
      'option', 'source', window.geoEntities
    )

class TaxonConceptsEditor extends AdminEditor
  init: () ->
    super
    $('.modal .modal-footer .save-and-reopen-button').click () =>
      @saveAndReopen = true

  initModals: () ->
    super
    @saveAndReopen = false
    @initTaxonConceptTypeaheads()
    @initReferencesTypeahead()
    $('.distributions-list > a').popover({});

  initTaxonConceptTypeaheads: () ->
    $('.search-typeahead').typeahead
      source: (query, process) ->
        $.get('/admin/taxon_concepts/autocomplete',

          )
          return process(labels)
        )

class AdminInPlaceEditor extends AdminEditor
  init: () ->
    super
    @initEditors()

  initEditors: () ->
    $('#admin-in-place-editor .editable').editable
      placement: 'right'
      ajaxOptions:
        dataType: 'json'
        type: 'put'
      params: (params) ->
        #originally params contain pk, name and value
        newParams = id: params.pk
        newParams[$(@).attr('data-resource')] = {}
        newParams[$(@).attr('data-resource')][params.name] = params.value
        return newParams

    $('a[data-toggle="popover"]').popover(html: true, placement: 'bottom')

    $('#admin-in-place-editor .editable-required').editable('option',
      validate: (v) ->
        return 'Required field!' if (v == '')
    )

    $('#admin-in-place-editor .editable-geo-entity-type').editable(
      'option', 'source', window.geoEntityTypes
    )

    $('#admin-in-place-editor .editable-geo-relationship-type').editable(
      'option', 'source', window.geoRelationshipTypes
    )

    $('#admin-in-place-editor .editable-geo-entity').editable(
      'option', 'source', window.geoEntities
    )

class TaxonConceptsEditor extends AdminEditor
  init: () ->
    super
    $('.modal .modal-footer .save-and-reopen-button').click () =>
      @saveAndReopen = true

  initModals: () ->
    super
    @saveAndReopen = false
    @initTaxonConceptTypeaheads()
    @initReferencesTypeahead()
    $('.distributions-list > a').popover({});

  initTaxonConceptTypeaheads: () ->

    $('input.typeahead').each (idx) ->
      formId = $(@).closest('form').attr('id')
