Move search autocomplete call to dispatcher

This commit is contained in:
Dmitriy Zaporozhets 2013-05-02 14:51:47 +03:00
parent 0b981eb9b3
commit 92f0473354
4 changed files with 21 additions and 11 deletions

View file

@ -1,5 +1,5 @@
@Admin = class Admin
init: -> constructor: ->
$('input#user_force_random_password').on 'change', (elem) -> $('input#user_force_random_password').on 'change', (elem) ->
elems = $('#user_password, #user_password_confirmation') elems = $('#user_password, #user_password_confirmation')
@ -26,3 +26,5 @@
$('.change-owner-cancel-link').bind "click", -> $('.change-owner-cancel-link').bind "click", ->
modal.hide() modal.hide()
$('.change-owner-link').show() $('.change-owner-link').show()
@Admin = Admin

View file

@ -3,6 +3,10 @@ $ ->
class Dispatcher class Dispatcher
constructor: () -> constructor: () ->
@initSearch()
@initPageScripts()
initPageScripts: ->
page = $('body').attr('data-page') page = $('body').attr('data-page')
project_id = $('body').attr('data-project-id') project_id = $('body').attr('data-project-id')
@ -25,6 +29,9 @@ class Dispatcher
new Wall(project_id) new Wall(project_id)
switch path.first() switch path.first()
when 'admin' then Admin.init() when 'admin' then new Admin()
when 'wikis' then new Wikis() when 'wikis' then new Wikis()
initSearch: ->
autocomplete_json = $('.search-autocomplete-json').data('autocomplete-opts')
new SearchAutocomplete(autocomplete_json)

View file

@ -0,0 +1,8 @@
class SearchAutocomplete
constructor: (json) ->
$("#search").autocomplete
source: json
select: (event, ui) ->
location.href = ui.item.url
@SearchAutocomplete = SearchAutocomplete

View file

@ -3,11 +3,4 @@
= text_field_tag "search", nil, placeholder: "Search", class: "search-input" = text_field_tag "search", nil, placeholder: "Search", class: "search-input"
= hidden_field_tag :group_id, @group.try(:id) = hidden_field_tag :group_id, @group.try(:id)
= hidden_field_tag :project_id, @project.try(:id) = hidden_field_tag :project_id, @project.try(:id)
.search-autocomplete-json.hide{:'data-autocomplete-opts' => search_autocomplete_source }
:javascript
$(function(){
$("#search").autocomplete({
source: #{raw search_autocomplete_source},
select: function(event, ui) { location.href = ui.item.url }
});
});