1
0
Fork 0

Form submit ability

This commit is contained in:
magnolia-fan 2011-09-14 23:51:51 +04:00
parent 442995dbc9
commit 2f31a6fd65
8 changed files with 47 additions and 65 deletions

View File

@ -2,13 +2,6 @@ class window.Ajax
referer: false referer: false
loadSettingsPage: ->
_session.query '/settings/', {}, (data) ->
_ajax.setArchor '/settings/'
_page.renderSettings data
false
false
load404Page: -> load404Page: ->
$.get '/404.html', (data) -> $.get '/404.html', (data) ->
$('.data-container .inner').html data $('.data-container .inner').html data
@ -40,7 +33,7 @@ class window.Ajax
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() _settings.loadSettingsPage()
else if _ajax.getAnchor().match /\/about\// else if _ajax.getAnchor().match /\/about\//
_ajax.loadAboutPage() _ajax.loadAboutPage()
else else
@ -48,5 +41,5 @@ class window.Ajax
false false
$(window).bind 'hashchange', -> $(window).bind 'hashchange', ->
#_ajax.detectPage() _ajax.detectPage()
false false

View File

@ -264,6 +264,7 @@
this.enabled = false; this.enabled = false;
this.selectedIndex = -1; this.selectedIndex = -1;
this.container.hide(); this.container.hide();
$('.popover-wrapper').hide();
}, },
suggest: function() { suggest: function() {
@ -292,6 +293,7 @@
} }
this.enabled = true; this.enabled = true;
this.container.show(); this.container.show();
$('.popover-wrapper').show();
}, },
processResponse: function(text) { processResponse: function(text) {

View File

@ -27,21 +27,6 @@ class window.Page
$('.search_field').first().focus() $('.search_field').first().focus()
, 1 , 1
false false
renderSettings: (data) ->
unless _session.getUser().id?
#_ajax.go('/')
false
$('#content').html data
#yaCounter7596904.hit _ajax.getAnchor(), 'Settings', _ajax.referer
_ajax.setTitle 'Settings'
false
renderTextpage: (data) ->
$('.data-container').css background: 'url(/images/concrete_wall_2.png) 0 -30px repeat'
$('.data-container .inner').html data
_beathaven.redrawScrollbar()
false
$ -> $ ->
$('.about').live 'click', -> $('.about').live 'click', ->

View File

@ -25,6 +25,11 @@ class window.Session
$.post url, q_params, callback $.post url, q_params, callback
false false
secureLoad: (url, callback) ->
q_params = $.extend {}, @vk_params
$('#content').load url, q_params, callback
false
reloadSession: -> reloadSession: ->
_session.query '/user/auth', {}, (ar) -> _session.query '/user/auth', {}, (ar) ->
_session.setUser ar.user _session.setUser ar.user

View File

@ -1,5 +1,15 @@
class window.Settings class window.Settings
loadSettingsPage: ->
unless _session.getUser().id?
_ajax.go('/')
false
_session.secureLoad '/settings/', (data) ->
false
#yaCounter7596904.hit _ajax.getAnchor(), 'Settings', _ajax.referer
_ajax.setTitle 'Settings'
false
getAccountInfo: (callback) -> getAccountInfo: (callback) ->
_session.query '/user/update/', {}, callback _session.query '/user/update/', {}, callback
false false
@ -7,16 +17,6 @@ class window.Settings
saveAccountInfo: (params, callback) -> saveAccountInfo: (params, callback) ->
_session.query '/user/update', params, callback _session.query '/user/update', params, callback
false false
loadFormData: (form) ->
if form == 'account'
$('.settings-container .form input[name$="username"]').val _session.getUser().name
$('.settings-container .form input[name$="email"]').val _session.getUser().email
$('.settings-container .form select').val _session.getUser().lang
else if form == 'lastfm'
if _session.getUser().lastfm_username
$('.form-container input[name$="username"]').first().val _session.getUser().lastfm_username
false
updateLastfmLogin: -> updateLastfmLogin: ->
if window.lastfm_popup.closed if window.lastfm_popup.closed
@ -28,7 +28,7 @@ class window.Settings
false false
$('#preferences') .live 'click', -> $('#preferences').live 'click', ->
_ajax.go('/settings/'); _ajax.go('/settings/');
false false
@ -40,25 +40,19 @@ $('#settings-tabs li').live 'click', ->
$('#settings-forms > .'+ $(this).find('a').attr('data-tab')).show() $('#settings-forms > .'+ $(this).find('a').attr('data-tab')).show()
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-forms form').live 'submit', ->
active_tab = $('.settings-container .tabs .tab.active').attr 'data-fieldset' params = {}
if active_tab == 'account' $(this).find('input, select').each ->
params = if $(this).attr('name')
username: $('.settings-container .form input[name$="username"]').first().val() params[$(this).attr('name')] = $(this).val()
email: $('.settings-container .form input[name$="email"]').first().val() console.log(params)
lang: $('.settings-container .form select').first().val() false
lang_changed = params.lang != _session.getUser().lang
if lang_changed $('#settings-forms input[type$="submit"]').live 'mouseup', ->
if not confirm _beathaven.ls 'WINDOW_LANG_RELOAD', params.lang $(this).parent().parent().parent().submit();
$('.settings-container .form select').val _session.getUser().lang false
_settings.saveAccountInfo params, ->
if lang_changed
window.location.reload()
$('.header-container .hello .greating span').text (if params.username.length > 0 then params.username else '%username%')
false
false

View File

@ -9,6 +9,7 @@
} }
.popover-wrapper { .popover-wrapper {
display: none;
position: fixed; position: fixed;
left: 50%; left: 50%;
margin-left: -280px; margin-left: -280px;

View File

@ -43,6 +43,10 @@ class UserController < ApplicationController
@res = {} @res = {}
user = User.find_by_vkid(params[:mid]) user = User.find_by_vkid(params[:mid])
render :json => request
return
unless params[:username].nil? or params[:email].nil? unless params[:username].nil? or params[:email].nil?
user.name = params[:username] user.name = params[:username]
user.email = params[:email] user.email = params[:email]

View File

@ -11,7 +11,7 @@
.forms#settings-forms .forms#settings-forms
.form.account .form.account
%form %form{ :action => "/", :method => 'post' }
%fieldset %fieldset
.clearfix .clearfix
%label{ :for => "name" }= I18n.t 'settings.username' %label{ :for => "name" }= I18n.t 'settings.username'
@ -42,20 +42,20 @@
.input .input
%ul.inputs-list %ul.inputs-list
%li %li
%label.disabled %label{ :for => "show_album" }
%input{ :name => "show_album", :type => "checkbox", :checked => "checked", :disabled => "disabled" } %input#show_album{ :name => "show[album]", :type => "checkbox", :checked => "checked" }
%span= I18n.t 'settings.music.albums' %span= I18n.t 'settings.music.albums'
%li %li
%label %label{ :for => "show_single" }
%input{ :name => "show_single", :type => "checkbox", :disabled => "disabled" } %input#show_single{ :name => "show[single]", :type => "checkbox" }
%span= I18n.t 'settings.music.singles' %span= I18n.t 'settings.music.singles'
%li %li
%label %label.disabled{ :for => "show_live" }
%input{ :name => "show_live", :type => "checkbox", :disabled => "disabled" } %input#show_live{ :name => "show[live]", :type => "checkbox", :disabled => "disabled" }
%span= I18n.t 'settings.music.live' %span= I18n.t 'settings.music.live'
%li %li
%label %label.disabled{ :for => "show_bootleg" }
%input{ :name => "show_bootleg", :type => "checkbox", :disabled => "disabled" } %input#show_bootleg{ :name => "show[bootleg]", :type => "checkbox", :disabled => "disabled" }
%span= I18n.t 'settings.music.bootlegs' %span= I18n.t 'settings.music.bootlegs'
.actions .actions
%input.btn.primary{ :type => "submit", :value => I18n.t('settings.save') } %input.btn.primary{ :type => "submit", :value => I18n.t('settings.save') }
@ -68,5 +68,3 @@
%input.borderless#lastfm_username{ :type => "text", :readonly => "readonly", :value => (@user.lastfm_username || I18n.t('settings.not_connected')) } %input.borderless#lastfm_username{ :type => "text", :readonly => "readonly", :value => (@user.lastfm_username || I18n.t('settings.not_connected')) }
%span.help-inline %span.help-inline
%input.btn{ :type => "submit", :value => I18n.t('settings.connect') } %input.btn{ :type => "submit", :value => I18n.t('settings.connect') }
.actions
%input.btn.primary{ :type => "submit", :value => I18n.t('settings.save') }