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

47 lines
1.3 KiB
CoffeeScript

class window.Search
showSpinner: ->
$('#search').attr(disabled: 'disabled').blur()
$('#autocomplete-container').hide()
$('#artist-load-spinner').show()
false
hideSpinner: ->
$('#search').val("").removeAttr 'disabled'
$('#artist-load-spinner').hide()
false
loadArtistData: (name) ->
log "Loading artist page ..."
_search.showSpinner()
name = name.split(' ').join('+')
$.get '/artist/' +name+ '/', (data) ->
if data.status in ['ok', 'loading']
_page.render data
_search.hideSpinner()
if _session.getUser().id?
$('.authorized-action').show()
else
$('.authorized-action').hide()
if data.status is 'loading'
setTimeout () ->
_search.loadArtistData name
, 10000
else if data.status is 'corrected'
_search.loadArtistData data.correct_name
else if data.status == 'not_found'
_search.hideSpinner()
alert "Not found"
else
_search.hideSpinner()
_page.print data.html
false
$('#search-form').live 'submit', ->
$('#autocomplete-container').hide()
_search.loadArtistData $('#search').val()
false
$('.data.artist').live 'click', ->
_ajax.go "/artist/"+$(this).html().split(' ').join('+')
false