From 453e809646d55cedc33317e33b1987a8ed3b8f21 Mon Sep 17 00:00:00 2001 From: magnolia-fan Date: Sun, 27 Nov 2011 13:56:10 +0400 Subject: [PATCH] More stable, I hope... --- app/assets/javascripts/ajax.coffee | 27 ++++++++++++++++------- app/assets/javascripts/beathaven.coffee | 6 ++++- app/assets/javascripts/page.coffee | 17 ++++++++++++++ app/assets/javascripts/session.coffee | 2 ++ app/assets/javascripts/vkontakte.coffee | 11 +++++---- app/controllers/application_controller.rb | 8 ++++--- app/controllers/page_controller.rb | 16 ++++++++------ app/views/page/_stat.en.html.haml | 19 ---------------- app/views/page/_stat.html.haml | 19 ++++++++++++++++ app/views/page/_stat.ru.html.haml | 19 ---------------- config/locales/en.yml | 12 ++++++++++ config/locales/ru.yml | 12 ++++++++++ 12 files changed, 107 insertions(+), 61 deletions(-) delete mode 100644 app/views/page/_stat.en.html.haml create mode 100644 app/views/page/_stat.html.haml delete mode 100644 app/views/page/_stat.ru.html.haml diff --git a/app/assets/javascripts/ajax.coffee b/app/assets/javascripts/ajax.coffee index 434fedf..a22b72f 100644 --- a/app/assets/javascripts/ajax.coffee +++ b/app/assets/javascripts/ajax.coffee @@ -3,6 +3,14 @@ class window.Ajax referer: false previous_page: null + showSpinner: -> + $('#artist-load-spinner').show() + false + + hideSpinner: -> + $('#artist-load-spinner').hide() + false + load404Page: -> $.get '/404.html', (data) -> $('.data-container .inner').html data @@ -43,19 +51,22 @@ class window.Ajax detectPage: () -> return false if @previous_page == _ajax.getAnchor() @previous_page = _ajax.getAnchor() + path = _ajax.getAnchor() + if path == "/" + path = "/greetings/" - log "Ajax controller is detecting page ..." + log "Ajax controller is detecting page for #{path} ..." - if m = _ajax.getAnchor().match /\/artist\/(.+)\// + if m = path.match /\/artist\/(.+)\// _search.loadArtistData m[1] - else if _ajax.getAnchor().match /\/settings\// + else if path.match /\/settings\// _settings.loadSettingsPage() - else if _ajax.getAnchor().match /\/about\// - _ajax.loadAboutPage() - else if _ajax.getAnchor().match /\/stat\// - _ajax.loadStatPage() else - _ajax.loadIndexPage(); + this.showSpinner() + _session.query path, {}, (response) -> + _page.render response + _ajax.hideSpinner() + false false $(window).bind 'hashchange', -> diff --git a/app/assets/javascripts/beathaven.coffee b/app/assets/javascripts/beathaven.coffee index a44cefa..a02610b 100644 --- a/app/assets/javascripts/beathaven.coffee +++ b/app/assets/javascripts/beathaven.coffee @@ -15,6 +15,9 @@ jQuery -> l.href = 'http://beathaven.org/'+ l.hash window.log = (str) -> + _beathaven.logs.push + timestamp: Date() + info: str console.log(str) if console? $.ajaxSetup @@ -28,9 +31,10 @@ class window.BeatHaven last_height: false lang: 'ru' + logs: [] init: -> - log "Initiatin BeatHaven ..." + log "Initiating BeatHaven ..." window._vkontakte = new Vkontakte(2335068) window._vkontakte.init() diff --git a/app/assets/javascripts/page.coffee b/app/assets/javascripts/page.coffee index 235fadc..f7aab4d 100644 --- a/app/assets/javascripts/page.coffee +++ b/app/assets/javascripts/page.coffee @@ -1,5 +1,22 @@ class window.Page + @data: {} + @html: "" + @status: "" + + render: (params) -> + @data = params.data + @html = params.html + @title = params.title + @status = params.status + + log "Rendering page titled \"#{@title}\" of type \"#{params.renderer}\" ..." + $('#content').html(@html) + + # yaCounter7596904.hit _ajax.getAnchor(), @title, _ajax.referer + _ajax.setTitle @title + false + print: (html) -> $('#content').html(html) false diff --git a/app/assets/javascripts/session.coffee b/app/assets/javascripts/session.coffee index ec347ad..715774e 100644 --- a/app/assets/javascripts/session.coffee +++ b/app/assets/javascripts/session.coffee @@ -12,7 +12,9 @@ class window.Session @vk_params = _params setUser: (user) -> + log "Setting user ..." @user = user + log "Hello, #{if user.name? then user.name else "%username%"}!" false getUser: -> diff --git a/app/assets/javascripts/vkontakte.coffee b/app/assets/javascripts/vkontakte.coffee index 83c35bd..7637387 100644 --- a/app/assets/javascripts/vkontakte.coffee +++ b/app/assets/javascripts/vkontakte.coffee @@ -8,11 +8,10 @@ class window.Vkontakte @api_id init: -> - log "Initiatin Vkontakte API ..." + log "Initiating Vkontakte API ..." window.vkAsyncInit = -> VK.init apiId: _vkontakte.getApiId() - VK.Auth.getLoginStatus (response) -> - _vkontakte.authInfo(response) + _vkontakte.auth() setTimeout -> $('#vk_api_transport').append($('