mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 18:59:38 +02:00
Typeaheads refactor
This commit is contained in:
parent
d3e3c9e8b0
commit
bfe89c7a09
6 changed files with 38 additions and 19 deletions
|
@ -1,13 +1,6 @@
|
||||||
ready = ->
|
ready = ->
|
||||||
Autocomplete.bindTypeahead
|
Autocomplete.bindContactSearch()
|
||||||
remote: '/admin/registrars/search'
|
Autocomplete.bindRegistrarSearch()
|
||||||
selector: '.js-registrar-typeahead'
|
|
||||||
hiddenSelector: '.js-registrar-id'
|
|
||||||
|
|
||||||
Autocomplete.bindTypeahead
|
|
||||||
remote: '/admin/contacts/search'
|
|
||||||
selector: '.js-contact-typeahead'
|
|
||||||
hiddenSelector: '.js-contact-id'
|
|
||||||
|
|
||||||
$(document).ready(ready)
|
$(document).ready(ready)
|
||||||
$(document).on('page:load', ready)
|
$(document).on('page:load', ready)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
class @Autocomplete
|
class @Autocomplete
|
||||||
@bindTypeahead: (obj) ->
|
@bindTypeahead: (obj) ->
|
||||||
Autocomplete.toggleOkFeedback(obj.hiddenSelector)
|
Autocomplete.toggleOkFeedbacksOnLoad(obj)
|
||||||
|
# Autocomplete.toggleOkFeedback(obj.hiddenSelector)
|
||||||
$(obj.selector).typeahead(
|
$(obj.selector).typeahead(
|
||||||
highlight: true,
|
highlight: true,
|
||||||
hint: false
|
hint: false
|
||||||
|
@ -8,8 +9,9 @@ class @Autocomplete
|
||||||
displayKey: "display_key"
|
displayKey: "display_key"
|
||||||
source: Autocomplete.constructSourceAdapter(obj.remote)
|
source: Autocomplete.constructSourceAdapter(obj.remote)
|
||||||
).on('typeahead:selected', (e, item) ->
|
).on('typeahead:selected', (e, item) ->
|
||||||
$(obj.hiddenSelector).val item.id
|
parent = $(e.currentTarget).parents('div.has-feedback')
|
||||||
Autocomplete.toggleOkFeedback(obj.hiddenSelector)
|
jObj = parent.find(obj.hiddenSelector).val item.id
|
||||||
|
Autocomplete.toggleOkFeedback(jObj)
|
||||||
)
|
)
|
||||||
|
|
||||||
@constructSourceAdapter: (remote) ->
|
@constructSourceAdapter: (remote) ->
|
||||||
|
@ -24,10 +26,29 @@ class @Autocomplete
|
||||||
source.initialize()
|
source.initialize()
|
||||||
source.ttAdapter()
|
source.ttAdapter()
|
||||||
|
|
||||||
@toggleOkFeedback: (hiddenSelector) ->
|
@toggleOkFeedback: (jObj) ->
|
||||||
if $(hiddenSelector).val()
|
ok = jObj.parents('div.has-feedback').find('.js-typeahead-ok')
|
||||||
ok = $(hiddenSelector).parent('div.has-feedback').find('.js-typeahead-ok')
|
remove = jObj.parents('div.has-feedback').find('.js-typeahead-remove')
|
||||||
remove = $(hiddenSelector).parents('div.has-feedback').find('.js-typeahead-remove')
|
|
||||||
|
|
||||||
|
if jObj.val()
|
||||||
ok.removeClass('hidden')
|
ok.removeClass('hidden')
|
||||||
remove.addClass('hidden')
|
remove.addClass('hidden')
|
||||||
|
else
|
||||||
|
remove.removeClass('hidden')
|
||||||
|
ok.addClass('hidden')
|
||||||
|
|
||||||
|
@toggleOkFeedbacksOnLoad: (obj) ->
|
||||||
|
$.each $(obj.hiddenSelector), (k, v) ->
|
||||||
|
Autocomplete.toggleOkFeedback($(v))
|
||||||
|
|
||||||
|
@bindContactSearch: ->
|
||||||
|
Autocomplete.bindTypeahead
|
||||||
|
remote: '/admin/contacts/search'
|
||||||
|
selector: '.js-contact-typeahead'
|
||||||
|
hiddenSelector: '.js-contact-id'
|
||||||
|
|
||||||
|
@bindRegistrarSearch: ->
|
||||||
|
Autocomplete.bindTypeahead
|
||||||
|
remote: '/admin/registrars/search'
|
||||||
|
selector: '.js-registrar-typeahead'
|
||||||
|
hiddenSelector: '.js-registrar-id'
|
||||||
|
|
|
@ -6,7 +6,7 @@ class DomainContact < ActiveRecord::Base
|
||||||
def epp_code_map
|
def epp_code_map
|
||||||
{
|
{
|
||||||
'2302' => [
|
'2302' => [
|
||||||
[:contact, :taken, {value: {obj: 'contact', val: contact.code}}]
|
[:contact, :taken, { value: { obj: 'contact', val: contact.code } }]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -15,7 +15,7 @@ class DomainContact < ActiveRecord::Base
|
||||||
ADMIN = 'admin'
|
ADMIN = 'admin'
|
||||||
TYPES = [TECH, ADMIN]
|
TYPES = [TECH, ADMIN]
|
||||||
|
|
||||||
# TODO: Fix EPP problems
|
validates :contact, presence: true
|
||||||
validates :contact, uniqueness: { scope: [:domain_id, :contact_type] }
|
validates :contact, uniqueness: { scope: [:domain_id, :contact_type] }
|
||||||
|
|
||||||
scope :admin, -> { where(contact_type: ADMIN) }
|
scope :admin, -> { where(contact_type: ADMIN) }
|
||||||
|
|
|
@ -28,3 +28,5 @@
|
||||||
item.find('.errors').html('');
|
item.find('.errors').html('');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
= contact_fields.label :contact_type
|
= contact_fields.label :contact_type
|
||||||
= contact_fields.select :contact_type, options_for_select(DomainContact::TYPES, contact_fields.object.contact_type), {}, {class: 'form-control'}
|
= contact_fields.select :contact_type, options_for_select(DomainContact::TYPES, contact_fields.object.contact_type), {}, {class: 'form-control'}
|
||||||
.col-md-6
|
.col-md-6
|
||||||
.form-group.has-feedback
|
.form-group.has-feedback.js-typeahead-container
|
||||||
= label_tag :contact
|
= label_tag :contact
|
||||||
= text_field_tag(:contact, params[:contact], class: 'form-control js-contact-typeahead', placeholder: t('shared.contact_code'), autocomplete: 'off')
|
= text_field_tag(:contact, params[:contact], class: 'form-control js-contact-typeahead', placeholder: t('shared.contact_code'), autocomplete: 'off')
|
||||||
%span.glyphicon.glyphicon-ok.form-control-feedback.js-typeahead-ok.hidden
|
%span.glyphicon.glyphicon-ok.form-control-feedback.js-typeahead-ok.hidden
|
||||||
|
@ -24,5 +24,7 @@
|
||||||
bindAddTo: $(".add-domain-contact"),
|
bindAddTo: $(".add-domain-contact"),
|
||||||
afterAdd: function(item) {
|
afterAdd: function(item) {
|
||||||
item.find('.errors').html('');
|
item.find('.errors').html('');
|
||||||
|
item.find('.js-contact-id').val('')
|
||||||
|
Autocomplete.bindContactSearch();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -120,6 +120,7 @@ en:
|
||||||
domain_contact:
|
domain_contact:
|
||||||
attributes:
|
attributes:
|
||||||
contact:
|
contact:
|
||||||
|
blank: 'Contact was not found'
|
||||||
taken: 'Contact already exists on this domain!'
|
taken: 'Contact already exists on this domain!'
|
||||||
|
|
||||||
setting:
|
setting:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue