Commit 92f04733 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Move search autocomplete call to dispatcher

parent 0b981eb9
@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 @@ ...@@ -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
...@@ -3,6 +3,10 @@ $ -> ...@@ -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 ...@@ -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)
class SearchAutocomplete
constructor: (json) ->
$("#search").autocomplete
source: json
select: (event, ui) ->
location.href = ui.item.url
@SearchAutocomplete = SearchAutocomplete
...@@ -3,11 +3,4 @@ ...@@ -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 }
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment