Settings save
This commit is contained in:
parent
d50d584bf8
commit
d0f5e35100
|
@ -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
|
|
@ -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', ->
|
||||
|
|
|
@ -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])
|
||||
|
||||
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]
|
||||
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
|
||||
|
||||
params[:params].each do |k, v|
|
||||
user[k] = v
|
||||
end
|
||||
user.save
|
||||
end
|
||||
|
||||
@res[:user] = {
|
||||
:id => user.id,
|
||||
:name => user.name,
|
||||
|
|
Loading…
Reference in New Issue