1
0
Fork 0

Settings save

This commit is contained in:
magnolia-fan 2011-09-15 09:20:50 +04:00
parent d50d584bf8
commit d0f5e35100
3 changed files with 17 additions and 11 deletions

View File

@ -39,6 +39,5 @@ $ ->
$(this).parent('li').toggleClass('open')
false
$('.dropdown-menu li a').live 'click', ->
console.log(1)
$(this).parent().parent().parent().toggleClass('open')
false

View File

@ -49,8 +49,11 @@ $('#settings-forms form').live 'submit', ->
params = {}
$(this).find('input, select').each ->
if $(this).attr('name')
params[$(this).attr('name')] = $(this).val()
console.log(params)
if $(this).attr('type') is 'checkbox'
params[$(this).attr('name')] = ($(this).attr('checked') is 'checked')
else
params[$(this).attr('name')] = $(this).val()
_session.query '/user/update/', { params: params }
false
$('#settings-forms input[type$="submit"]').live 'mouseup', ->

View File

@ -40,19 +40,23 @@ class UserController < ApplicationController
def update
return unless authorized?
allowed_params = [:name, :email, :lang, :show]
@res = {}
user = User.find_by_vkid(params[:mid])
update_params = {}
params[:params] = params[:params].each{ |k, v| update_params[k.to_sym] = v }
if (update_params.keys - allowed_params).empty?
if update_params.include? :show
update_params[:show].map!{ |k, v| k.to_sym }
end
render :json => request
return
unless params[:username].nil? or params[:email].nil?
user.name = params[:username]
user.email = params[:email]
user.lang = params[:lang] if ['ru', 'en'].include? params[:lang]
params[:params].each do |k, v|
user[k] = v
end
user.save
end
@res[:user] = {
:id => user.id,
:name => user.name,