Replace typeahead, working registrar selection

This commit is contained in:
Martin Lensment 2014-09-09 12:39:32 +03:00
parent c24c8c7181
commit 13349a6bc9
9 changed files with 79 additions and 23 deletions

View file

@ -1,19 +1,20 @@
$(".js-registrars-typeahead").typeahead
source: (query, process) ->
$.get "/admin/registrars/search", {query: query}, (data) ->
map = {}
registrars = []
registrarSource = new Bloodhound(
datumTokenizer: (d) ->
Bloodhound.tokenizers.whitespace d.display_key
$.each data, (i, registrar) ->
map[registrar.id] = registrar
registrars.push registrar.display
process registrars
updater: (item) ->
$('input[name="domain[registrar_id]"]').val()
$(".js-contacts-typeahead").typeahead
source: (query, process) ->
$.get "/admin/contacts/search", {query: query}, (data) ->
process data
queryTokenizer: Bloodhound.tokenizers.whitespace
remote: "/admin/registrars/search?q=%QUERY"
)
registrarSource.initialize()
$(".js-registrars-typeahead").typeahead(
highlight: true,
hint: false
,
displayKey: "display_key"
source: registrarSource.ttAdapter()
).on('typeahead:selected', (e, obj) ->
$('input[name="domain[registrar_id]"]').val obj.id
$('.js-registrar-selected').removeClass('hidden')
$('.js-registrar-unselected').addClass('hidden')
)

View file

@ -4,7 +4,7 @@
#= require bootstrap-sprockets
#= require nprogress
#= require nprogress-turbolinks
#= require bootstrap3-typeahead.min
#= require typeahead.bundle.min
#= require_tree .
NProgress.configure