1
0
Fork 0

Settings mockup

This commit is contained in:
magnolia-fan 2011-09-10 03:30:03 +04:00
parent fe7737574d
commit 60cde9084f
10 changed files with 221 additions and 143 deletions

View File

@ -3,9 +3,10 @@ class window.Ajax
referer: false referer: false
loadSettingsPage: -> loadSettingsPage: ->
$.get '/templates/settings.html', (data) -> $.get '/settings/', (data) ->
_ajax.setArchor '/settings/' _ajax.setArchor '/settings/'
_page.renderSettings _beathaven.localizeHTML $(data) _page.renderSettings data
false
false false
load404Page: -> load404Page: ->
@ -37,7 +38,7 @@ class window.Ajax
if m = _ajax.getAnchor().match /\/artist\/(.+)\// if m = _ajax.getAnchor().match /\/artist\/(.+)\//
_search.loadArtistData m[1] _search.loadArtistData m[1]
else if _ajax.getAnchor() == '' or _ajax.getAnchor().match /\/search\// else if _ajax.getAnchor() == '' or _ajax.getAnchor().match /\/search\//
_ajax.loadSearchPage(); #_ajax.loadSearchPage();
else if _ajax.getAnchor().match /\/settings\// else if _ajax.getAnchor().match /\/settings\//
_ajax.loadSettingsPage() _ajax.loadSettingsPage()
else if _ajax.getAnchor().match /\/about\// else if _ajax.getAnchor().match /\/about\//

View File

@ -37,7 +37,6 @@ class window.BeatHaven
window._settings = new Settings() window._settings = new Settings()
this.setupAutocomplete() this.setupAutocomplete()
window._ajax.detectPage()
false false

View File

@ -3,48 +3,56 @@ class window.Page
print: (html) -> print: (html) ->
$('#content').html(html) $('#content').html(html)
false false
renderArtist: (data) -> renderArtist: (data) ->
$('#content').html(data) $('#content').html(data)
yaCounter7596904.hit _ajax.getAnchor(), data.artist.name, _ajax.referer yaCounter7596904.hit _ajax.getAnchor(), data.artist.name, _ajax.referer
_ajax.setTitle data.artist.name _ajax.setTitle data.artist.name
false false
renderSearch: (data) -> renderSearch: (data) ->
$('.pulldown').html data $('.pulldown').html data
setTimeout -> setTimeout ->
$('.search_field').first().bh_autocomplete $('.search_field').first().bh_autocomplete
serviceUrl: '/artist/autocomplete' # Страница для обработки запросов автозаполнения serviceUrl: '/artist/autocomplete' # Страница для обработки запросов автозаполнения
minChars: 2 # Минимальная длина запроса для срабатывания автозаполнения minChars: 2 # Минимальная длина запроса для срабатывания автозаполнения
delimiter: /(,|;)\s*/ # Разделитель для нескольких запросов, символ или регулярное выражение delimiter: /(,|;)\s*/ # Разделитель для нескольких запросов, символ или регулярное выражение
maxHeight: 400 # Максимальная высота списка подсказок, в пикселях maxHeight: 400 # Максимальная высота списка подсказок, в пикселях
width: 415 # Ширина списка width: 415 # Ширина списка
zIndex: 9999 # z-index списка zIndex: 9999 # z-index списка
deferRequestBy: 500 # Задержка запроса (мсек) deferRequestBy: 500 # Задержка запроса (мсек)
onSelect: -> onSelect: ->
_ajax.loadArtistData $('.search_field').first().val() _ajax.loadArtistData $('.search_field').first().val()
$('.search_field').first().focus() $('.search_field').first().focus()
, 1 , 1
false false
renderSettings: (data) -> renderSettings: (data) ->
unless _session.getUser().id? unless _session.getUser().id?
_ajax.go('/search/') #_ajax.go('/')
return false false
$('.data-container').css background: 'none' $('#content').html data
$('.data-container .inner').html data #yaCounter7596904.hit _ajax.getAnchor(), 'Settings', _ajax.referer
yaCounter7596904.hit _ajax.getAnchor(), 'Settings', _ajax.referer _ajax.setTitle 'Settings'
_ajax.setTitle 'Settings' false
$('.settings-container .tabs .tab').first().trigger 'click'
false renderTextpage: (data) ->
$('.data-container').css background: 'url(/images/concrete_wall_2.png) 0 -30px repeat'
renderTextpage: (data) -> $('.data-container .inner').html data
$('.data-container').css background: 'url(/images/concrete_wall_2.png) 0 -30px repeat' _beathaven.redrawScrollbar()
$('.data-container .inner').html data false
_beathaven.redrawScrollbar()
false
$('.about').live 'click', -> $ ->
_ajax.go '/about/' $('.about').live 'click', ->
false _ajax.go '/about/'
false
$('body').live 'click', ->
$('.dropdown-toggle, .menu').parent('li').removeClass('open')
false
$('.dropdown-toggle, .menu').live 'click', ->
$(this).parent('li').toggleClass('open')
false
$('.dropdown-toggle li, .menu li').live 'click', ->
$(this).parent('li').toggleClass('open')
false

View File

@ -1,32 +1,32 @@
class window.Session class window.Session
vk_params: null vk_params: null
user: null user: null
constructor: (params) -> constructor: (params) ->
attrs = ['expire', 'mid', 'secret', 'sid', 'sig'] attrs = ['expire', 'mid', 'secret', 'sid', 'sig']
_params = {} _params = {}
for key in attrs for key in attrs
if params[key]? if params[key]?
_params[key] = params[key] _params[key] = params[key]
@vk_params = _params @vk_params = _params
setUser: (user) -> setUser: (user) ->
@user = user @user = user
_beathaven.lang = @user.lang || 'ru' _beathaven.lang = @user.lang || 'ru'
_beathaven.localizeHTML() _beathaven.localizeHTML()
false false
getUser: -> getUser: ->
@user @user
query: (url, params, callback) -> query: (url, params, callback) ->
q_params = $.extend {}, @vk_params, params q_params = $.extend {}, @vk_params, params
$.post url, q_params, callback $.post url, q_params, callback
false false
reloadSession: -> reloadSession: ->
_session.query '/user/auth', {}, (ar) -> _session.query '/user/auth', {}, (ar) ->
_session.setUser ar.user _session.setUser ar.user
false false
false false

View File

@ -1,64 +1,64 @@
class window.Settings class window.Settings
getAccountInfo: (callback) -> getAccountInfo: (callback) ->
_session.query '/user/update/', {}, callback _session.query '/user/update/', {}, callback
false false
saveAccountInfo: (params, callback) -> saveAccountInfo: (params, callback) ->
_session.query '/user/update', params, callback _session.query '/user/update', params, callback
false false
loadFormData: (form) -> loadFormData: (form) ->
if form == 'account' if form == 'account'
$('.settings-container .form input[name$="username"]').val _session.getUser().name $('.settings-container .form input[name$="username"]').val _session.getUser().name
$('.settings-container .form input[name$="email"]').val _session.getUser().email $('.settings-container .form input[name$="email"]').val _session.getUser().email
$('.settings-container .form select').val _session.getUser().lang $('.settings-container .form select').val _session.getUser().lang
else if form == 'lastfm' else if form == 'lastfm'
if _session.getUser().lastfm_username if _session.getUser().lastfm_username
$('.form-container input[name$="username"]').first().val _session.getUser().lastfm_username $('.form-container input[name$="username"]').first().val _session.getUser().lastfm_username
false false
updateLastfmLogin: -> updateLastfmLogin: ->
if window.lastfm_popup.closed if window.lastfm_popup.closed
_session.query '/user/auth', {}, (ar) -> _session.query '/user/auth', {}, (ar) ->
_session.setUser ar.user _session.setUser ar.user
_settings.loadFormData 'lastfm' _settings.loadFormData 'lastfm'
else else
setTimeout _settings.updateLastfmLogin, 100 setTimeout _settings.updateLastfmLogin, 100
false false
$('.settings') .live 'click', -> $('#preferences') .live 'click', ->
_ajax.go('/settings/'); _ajax.go('/settings/');
false false
$('.settings-container .tabs .tab').live 'click', -> $('.settings-container .tabs .tab').live 'click', ->
if not $(this).hasClass 'active' if not $(this).hasClass 'active'
$('.settings-container .tabs .tab').removeClass 'active' $('.settings-container .tabs .tab').removeClass 'active'
$(this).addClass 'active' $(this).addClass 'active'
$('.form-container').html $('.forms .'+ $(this).attr 'data-fieldset').html() $('.form-container').html $('.forms .'+ $(this).attr 'data-fieldset').html()
_settings.loadFormData $(this).attr 'data-fieldset' _settings.loadFormData $(this).attr 'data-fieldset'
false false
$('.lastfm-connect') .live 'click', -> $('.lastfm-connect') .live 'click', ->
window.lastfm_popup = window.open _session.getUser().lastfm_login_url window.lastfm_popup = window.open _session.getUser().lastfm_login_url
setTimeout _settings.updateLastfmLogin, 100 setTimeout _settings.updateLastfmLogin, 100
false false
$('.settings-container .form input, .settings-container .form select').live 'blur', -> $('.settings-container .form input, .settings-container .form select').live 'blur', ->
active_tab = $('.settings-container .tabs .tab.active').attr 'data-fieldset' active_tab = $('.settings-container .tabs .tab.active').attr 'data-fieldset'
if active_tab == 'account' if active_tab == 'account'
params = params =
username: $('.settings-container .form input[name$="username"]').first().val() username: $('.settings-container .form input[name$="username"]').first().val()
email: $('.settings-container .form input[name$="email"]').first().val() email: $('.settings-container .form input[name$="email"]').first().val()
lang: $('.settings-container .form select').first().val() lang: $('.settings-container .form select').first().val()
lang_changed = params.lang != _session.getUser().lang lang_changed = params.lang != _session.getUser().lang
if lang_changed if lang_changed
if not confirm _beathaven.ls 'WINDOW_LANG_RELOAD', params.lang if not confirm _beathaven.ls 'WINDOW_LANG_RELOAD', params.lang
$('.settings-container .form select').val _session.getUser().lang $('.settings-container .form select').val _session.getUser().lang
_settings.saveAccountInfo params, -> _settings.saveAccountInfo params, ->
if lang_changed if lang_changed
window.location.reload() window.location.reload()
$('.header-container .hello .greating span').text (if params.username.length > 0 then params.username else '%username%') $('.header-container .hello .greating span').text (if params.username.length > 0 then params.username else '%username%')
false false
false false

View File

@ -32,17 +32,16 @@ class window.Vkontakte
VK.Api.call 'getVariable', key: 1281, (r) -> VK.Api.call 'getVariable', key: 1281, (r) ->
_session.query '/user/update', name: r.response, (ar2) -> _session.query '/user/update', name: r.response, (ar2) ->
_session.setUser ar2.user _session.setUser ar2.user
$('.header-container .hello .greating') $('#username')
.html _beathaven.ls('HELLO')+', <span class="settings">' +(if _session.getUser().name then _session.getUser().name else '%username%')+ '</span>!' .html (if _session.getUser().name then _session.getUser().name else '%username%')
window._session = _session window._session = _session
_ajax.detectPage() _ajax.detectPage()
$('.fullscreen').hide(); $('.fullscreen').hide();
else else
_session.setUser ar.user _session.setUser ar.user
$('.header-container .hello').show() $('#username')
$('.header-container .hello .greating') .html (if _session.getUser().name then _session.getUser().name else '%username%')
.html _beathaven.ls('HELLO')+', <span class="settings">' +(if _session.getUser().name then _session.getUser().name else '%username%')+ '</span>!'
window._session = _session window._session = _session
_ajax.detectPage() _ajax.detectPage()
$('.fullscreen').hide(); $('.fullscreen').hide();

View File

@ -32,6 +32,10 @@ class UserController < ApplicationController
render :json => @res render :json => @res
end end
def settings
render :partial => 'settings'
end
def update def update
return unless authorized? return unless authorized?
@res = {} @res = {}

View File

@ -27,13 +27,13 @@
= image_tag "artist_loader.gif" = image_tag "artist_loader.gif"
%ul.nav.secondary-nav %ul.nav.secondary-nav
%li.dropdown %li.dropdown
%a.dropdown-toggle{ :href => "#" } chez %a.dropdown-toggle#username{ :href => "#" } %username%
%ul.dropdown-menu %ul.dropdown-menu
%li %li
%a{ :href => "#" } Preferences %a#preferences{ :href => "#" } Preferences
%li.divider %li.divider
%li %li
%a{ :href => "#" } Logout %a#logout{ :href => "#" } Logout
.popover-wrapper .popover-wrapper
.popover.below#autocomplete-container .popover.below#autocomplete-container

View File

@ -0,0 +1,65 @@
%h1 Settings
%ul.tabs
%li.active
%a{ :href => "#" } Account
%li
%a{ :href => "#" } Site
%li
%a{ :href => "#" } Music
%li
%a{ :href => "#" } Last.fm
.forms
.form.account
%form
%fieldset
.clearfix
%label{ :for => "input-username" } Username
.input
%input.xlarge#input-username{ :name => "input-username", :size => 30, :type => "text" }
.clearfix
%label{ :for => "input-email" } Email
.input
%input.xlarge#input-email{ :name => "input-email", :size => 30, :type => "text" }
.form.site
%form
%fieldset
.clearfix
%label{ :for => "select-lang" } Language
.input
%select.medium#select-lang{ :name => "select-lang" }
%option English
%option Русский
.form.music
%form
%fieldset
.clearfix
%label{ :for => "select-lang" } Show
.input
%ul.inputs-list
%li
%label.disabled
%input{ :name => "show-album", :type => "checkbox", :checked => "checked", :disabled => "disabled" }
%span Albums
%li
%label
%input{ :name => "show-single", :type => "checkbox" }
%span Singles
%li
%label
%input{ :name => "show-live", :type => "checkbox" }
%span Live shows
%li
%label
%input{ :name => "show-bootleg", :type => "checkbox" }
%span Bootlegs
.form.lastfm
%form
%fieldset
.clearfix
%label{ :for => "input-username" } Username
.input
.input-append
%input#input-username{ :name => "input-username", :type => "text", :size => 30 }
%label.add-on
%input{ :type => "checkbox" }

View File

@ -66,6 +66,8 @@ Beathaven::Application.routes.draw do
match 'lastfm/listening' => 'last_fm#listening' match 'lastfm/listening' => 'last_fm#listening'
match 'lastfm/scrobble' => 'last_fm#scrobble' match 'lastfm/scrobble' => 'last_fm#scrobble'
match 'settings' => 'user#settings'
match 'artist/autocomplete' => 'artist#autocomplete' match 'artist/autocomplete' => 'artist#autocomplete'
match 'artist/(:name)/' => 'artist#data', :constraints => { :name => /[^\/]*/ } match 'artist/(:name)/' => 'artist#data', :constraints => { :name => /[^\/]*/ }
end end