1
0
Fork 0
oldhaven/app/assets/javascripts/search.coffee

67 lines
1.9 KiB
CoffeeScript

class window.Search
showSpinner: ->
$('#search').attr(disabled: 'disabled').blur()
$('#autocomplete-container').hide()
$('#artist-load-spinner').show()
this.hideSuggestions()
false
hideSpinner: ->
$('#search').val("").removeAttr 'disabled'
$('#artist-load-spinner').hide()
false
loadArtistData: (name) ->
_search.showSpinner()
name = name.split(' ').join('+')
$.get '/artist/' +name+ '/', (data) ->
if data.status in ['ok', 'loading']
_ajax.setArchor '/artist/' +name+ '/'
_page.print data.html
if _session.getUser().id
if data.artist.albums?
for album in data.artist.albums
_player.albums[album.id] = album
$('.button-container').show()
_search.hideSpinner()
if data.status is 'loading'
setTimeout () ->
_search.loadArtistData name
, 10000
_ajax.setTitle $('#main h2').text()
else if data.status is 'corrected'
_search.loadArtistData data.correct_name
else if data.status is 'suggestions'
_search.hideSpinner()
_page.print data.html
else if data.status == 'fail'
_search.hideSpinner()
_page.print data.html
else if data.status == 'not_found'
_search.hideSpinner()
alert "Not found"
false
showSuggestions: (values) ->
for item in values
$('.suggestions ul').append '
<li>
<a class="data artist">' +item.name+ '</a>
' +(if item.desc? then '<br/><span>'+item.desc+'</span>' else '')+ '
</li>'
$('.suggestions').show()
false
hideSuggestions: ->
$('.suggestions ul li').remove()
$('.suggestions').hide()
false
$('#search-form').live 'submit', ->
$('#autocomplete-container').remove()
_search.loadArtistData $('#search').val()
false
$('.data.artist').live 'click', ->
_search.loadArtistData $(this).html()
false