2011-09-07 23:47:11 +00:00
|
|
|
class window.Search
|
2011-09-08 10:56:10 +00:00
|
|
|
|
|
|
|
showSpinner: ->
|
2011-09-09 22:13:02 +00:00
|
|
|
$('#search').attr(disabled: 'disabled').blur()
|
2011-09-08 10:56:10 +00:00
|
|
|
$('#autocomplete-container').hide()
|
2011-09-09 22:13:02 +00:00
|
|
|
$('#artist-load-spinner').show()
|
2011-09-08 10:56:10 +00:00
|
|
|
false
|
|
|
|
|
|
|
|
hideSpinner: ->
|
2011-09-09 22:13:02 +00:00
|
|
|
$('#search').val("").removeAttr 'disabled'
|
|
|
|
$('#artist-load-spinner').hide()
|
|
|
|
false
|
|
|
|
|
|
|
|
loadArtistData: (name) ->
|
2011-11-27 12:37:51 +00:00
|
|
|
log "Loading artist page ..."
|
2011-09-09 22:13:02 +00:00
|
|
|
_search.showSpinner()
|
|
|
|
name = name.split(' ').join('+')
|
|
|
|
$.get '/artist/' +name+ '/', (data) ->
|
|
|
|
if data.status in ['ok', 'loading']
|
2011-11-27 12:37:51 +00:00
|
|
|
_page.render data
|
2011-09-09 22:13:02 +00:00
|
|
|
_search.hideSpinner()
|
2011-11-27 12:37:51 +00:00
|
|
|
if _session.getUser().id?
|
2011-11-27 18:17:09 +00:00
|
|
|
$('.authorized-action').show()
|
2011-11-27 12:37:51 +00:00
|
|
|
else
|
2011-11-27 18:17:09 +00:00
|
|
|
$('.authorized-action').hide()
|
2011-09-09 22:13:02 +00:00
|
|
|
if data.status is 'loading'
|
|
|
|
setTimeout () ->
|
|
|
|
_search.loadArtistData name
|
2011-09-26 09:58:04 +00:00
|
|
|
, 10000
|
2011-09-09 22:13:02 +00:00
|
|
|
else if data.status is 'corrected'
|
|
|
|
_search.loadArtistData data.correct_name
|
2011-10-20 18:16:46 +00:00
|
|
|
else if data.status == 'not_found'
|
|
|
|
_search.hideSpinner()
|
|
|
|
alert "Not found"
|
2011-11-27 12:37:51 +00:00
|
|
|
else
|
|
|
|
_search.hideSpinner()
|
|
|
|
_page.print data.html
|
2011-09-08 10:56:10 +00:00
|
|
|
false
|
2011-06-27 18:41:36 +00:00
|
|
|
|
2011-09-09 22:13:02 +00:00
|
|
|
$('#search-form').live 'submit', ->
|
2011-11-23 22:52:43 +00:00
|
|
|
$('#autocomplete-container').hide()
|
2011-09-09 22:13:02 +00:00
|
|
|
_search.loadArtistData $('#search').val()
|
2011-09-08 10:56:10 +00:00
|
|
|
false
|
2011-06-28 22:10:57 +00:00
|
|
|
$('.data.artist').live 'click', ->
|
2011-11-27 12:37:51 +00:00
|
|
|
_ajax.go "/artist/"+$(this).html().split(' ').join('+')
|
2011-11-24 10:14:06 +00:00
|
|
|
false
|