2011-06-27 18:41:36 +00:00
|
|
|
class Ajax
|
|
|
|
|
|
|
|
referer: false
|
|
|
|
|
|
|
|
loadArtistData: (name) ->
|
2011-06-27 20:43:54 +00:00
|
|
|
_search.showSpinner()
|
2011-06-27 18:41:36 +00:00
|
|
|
name = name.split(' ').join('+')
|
|
|
|
$.get '/artist/' +name+ '/', (data) ->
|
|
|
|
if data.status?
|
|
|
|
if data.status is 'loading'
|
2011-06-27 20:43:54 +00:00
|
|
|
_search.showArtistPics data.pics
|
2011-06-27 18:41:36 +00:00
|
|
|
setTimeout () ->
|
2011-06-27 20:43:54 +00:00
|
|
|
_ajax.loadArtistData name
|
2011-06-27 18:41:36 +00:00
|
|
|
, 3000
|
|
|
|
else if data.status is 'corrected'
|
2011-06-27 20:43:54 +00:00
|
|
|
_ajax.loadArtistData data.page
|
2011-06-27 18:41:36 +00:00
|
|
|
else if data.status is 'suggestions'
|
2011-06-27 20:43:54 +00:00
|
|
|
_search.hideSpinner()
|
|
|
|
_search.showSuggestions data.values
|
2011-06-27 18:41:36 +00:00
|
|
|
else if data.status == 'loading_failed'
|
2011-06-27 20:43:54 +00:00
|
|
|
_search.hideSpinner()
|
|
|
|
_search.showError()
|
2011-06-27 18:41:36 +00:00
|
|
|
else
|
2011-06-27 20:43:54 +00:00
|
|
|
_ajax.setArchor '/artist/' +name+ '/'
|
|
|
|
_pages.renderArtist data
|
|
|
|
_beathaven.redrawScrollbar()
|
|
|
|
false
|
2011-06-27 18:41:36 +00:00
|
|
|
|
|
|
|
loadSearchPage: ->
|
|
|
|
$.get '/templates/search.html', (data) ->
|
2011-06-27 20:43:54 +00:00
|
|
|
_ajax.setArchor '/search/'
|
|
|
|
_pages.renderSearch data
|
|
|
|
false
|
2011-06-27 18:41:36 +00:00
|
|
|
|
|
|
|
loadSettingsPage: ->
|
|
|
|
$.get '/templates/settings.html', (data) ->
|
2011-06-27 20:43:54 +00:00
|
|
|
_ajax.setArchor '/settings/'
|
|
|
|
_pages.renderSettings data
|
|
|
|
false
|
2011-06-27 18:41:36 +00:00
|
|
|
|
|
|
|
load404Page: ->
|
|
|
|
$.get '/404.html', (data) ->
|
|
|
|
$('.data-container .inner').html data
|
2011-06-27 20:43:54 +00:00
|
|
|
_beathaven.redrawScrollbar()
|
|
|
|
false
|
2011-06-27 18:41:36 +00:00
|
|
|
|
|
|
|
setArchor: (anchor) ->
|
|
|
|
@referer = this.getAnchor()
|
|
|
|
window.location.hash = '#' +anchor
|
|
|
|
|
|
|
|
getAnchor: () ->
|
|
|
|
window.location.hash.substring 1;
|
|
|
|
|
|
|
|
setTitle: (title) ->
|
|
|
|
document.title = title+ ' @ BeatHaven'
|
2011-06-27 20:43:54 +00:00
|
|
|
|
|
|
|
go: (url) ->
|
|
|
|
this.setArchor url
|
|
|
|
false
|
2011-06-27 18:41:36 +00:00
|
|
|
|
|
|
|
detectPage: () ->
|
2011-06-27 20:43:54 +00:00
|
|
|
if m = _ajax.getAnchor().match /\/artist\/(.+)\//
|
|
|
|
_ajax.loadArtistData m[1]
|
|
|
|
else if _ajax.getAnchor() == '' or _ajax.getAnchor().match /\/search\//
|
|
|
|
_ajax.loadSearchPage();
|
|
|
|
else if _ajax.getAnchor().match /\/settings\//
|
|
|
|
_ajax.loadSettingsPage()
|
2011-06-27 18:41:36 +00:00
|
|
|
else
|
2011-06-27 20:43:54 +00:00
|
|
|
_ajax.loadSearchPage()
|
|
|
|
false
|
2011-06-27 18:41:36 +00:00
|
|
|
|
|
|
|
|
2011-06-27 20:43:54 +00:00
|
|
|
$('a.data.artist').live 'click', ->
|
|
|
|
_ajax.loadArtistData $(this).html()
|
|
|
|
false
|
|
|
|
$(window).bind 'hashchange', ->
|
|
|
|
_ajax.detectPage()
|
|
|
|
false
|