mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 17:28:18 +02:00
Replace typeahead, working registrar selection
This commit is contained in:
parent
c24c8c7181
commit
13349a6bc9
9 changed files with 79 additions and 23 deletions
|
@ -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')
|
||||
)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#= require bootstrap-sprockets
|
||||
#= require nprogress
|
||||
#= require nprogress-turbolinks
|
||||
#= require bootstrap3-typeahead.min
|
||||
#= require typeahead.bundle.min
|
||||
#= require_tree .
|
||||
|
||||
NProgress.configure
|
||||
|
|
|
@ -3,4 +3,5 @@
|
|||
@import "nprogress";
|
||||
@import "nprogress-bootstrap";
|
||||
@import "bootstrap-ext";
|
||||
@import "typeaheadjs";
|
||||
@import "app";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Admin::RegistrarsController < ApplicationController
|
||||
def search
|
||||
render json: Registrar.search_by_query(params[:query])
|
||||
render json: Registrar.search_by_query(params[:q])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ class Registrar < ActiveRecord::Base
|
|||
class << self
|
||||
def search_by_query(query)
|
||||
res = Registrar.search(name_or_reg_no_cont: query).result
|
||||
res.reduce([]) { |o, v| o << { id: v[:id], display: "#{v[:name]} (#{v[:reg_no]})" } }
|
||||
res.reduce([]) { |o, v| o << { id: v[:id], display_key: "#{v[:name]} (#{v[:reg_no]})" } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,9 +10,11 @@
|
|||
= f.label :period
|
||||
= f.text_field(:period, class: 'form-control')
|
||||
.col-md-6
|
||||
.form-group
|
||||
.form-group.has-feedback
|
||||
= f.label :registrar
|
||||
= f.text_field(:registrar, class: 'form-control js-registrars-typeahead', placeholder: t('shared.registrar_name'), autocomplete: 'off')
|
||||
= f.text_field(:registrar, class: 'form-control js-typeahead js-registrars-typeahead', placeholder: t('shared.registrar_name'), autocomplete: 'off')
|
||||
%span.glyphicon.glyphicon-remove.form-control-feedback.js-registrar-unselected
|
||||
%span.glyphicon.glyphicon-ok.form-control-feedback.js-registrar-selected.hidden
|
||||
= f.hidden_field(:registrar_id)
|
||||
.form-group
|
||||
= f.label :owner_contact
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue