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
|
|
|
this.hideSuggestions()
|
|
|
|
false
|
|
|
|
|
|
|
|
hideSpinner: ->
|
2011-09-09 22:13:02 +00:00
|
|
|
$('#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
|
|
|
|
_search.hideSpinner()
|
|
|
|
if data.status is 'loading'
|
|
|
|
setTimeout () ->
|
|
|
|
_search.loadArtistData name
|
|
|
|
, 5000
|
|
|
|
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
|
2011-09-08 10:56:10 +00:00
|
|
|
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
|
2011-06-27 18:41:36 +00:00
|
|
|
|
2011-09-08 10:56:10 +00:00
|
|
|
hideSuggestions: ->
|
|
|
|
$('.suggestions ul li').remove()
|
|
|
|
$('.suggestions').hide()
|
|
|
|
false
|
2011-06-27 18:41:36 +00:00
|
|
|
|
2011-09-08 10:56:10 +00:00
|
|
|
showArtistPics: (pics) ->
|
|
|
|
$('.artist_loading.ok, .artist_pics').show()
|
|
|
|
for pic in pics
|
|
|
|
if @pics.indexOf(pic) == -1
|
|
|
|
@pics.push(pic);
|
|
|
|
$('.artist_pics').append '
|
|
|
|
<div class="pic">
|
|
|
|
<img src="' +pic+ '" alt=""/>
|
|
|
|
</div>'
|
|
|
|
false
|
|
|
|
|
|
|
|
showError: ->
|
|
|
|
$('.artist_loading.ok, .artist_pics').hide()
|
|
|
|
$('.artist_loading.failed').show()
|
|
|
|
@pics = []
|
2011-06-27 18:41:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
$('.search').live 'click', ->
|
2011-09-08 10:56:10 +00:00
|
|
|
if $('.pulldown').css('display') is 'none'
|
|
|
|
$('.pulldown').width $('.data-container').width() - 50
|
|
|
|
$('.pulldown').height 300#38
|
|
|
|
$('.pulldown').slideDown 'fast', ->
|
|
|
|
data = '<div class="search-container">'+$('.subpages .search-container').html()+'</div>'
|
|
|
|
_pages.renderSearch _beathaven.localizeHTML $(data)
|
|
|
|
_beathaven.adjustSizes()
|
|
|
|
_beathaven.redrawScrollbar()
|
|
|
|
else
|
|
|
|
$('.pulldown').slideUp 'fast', ->
|
|
|
|
$('.pulldown').height 0
|
|
|
|
_beathaven.adjustSizes()
|
|
|
|
_beathaven.redrawScrollbar()
|
|
|
|
false
|
2011-09-09 22:13:02 +00:00
|
|
|
$('#search-form').live 'submit', ->
|
|
|
|
$('#autocomplete-container').remove()
|
|
|
|
_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-09-09 22:13:02 +00:00
|
|
|
_search.loadArtistData $(this).html()
|
|
|
|
false
|