Settings save
This commit is contained in:
		
							parent
							
								
									d50d584bf8
								
							
						
					
					
						commit
						d0f5e35100
					
				| @ -39,6 +39,5 @@ $ -> | |||||||
|     $(this).parent('li').toggleClass('open') |     $(this).parent('li').toggleClass('open') | ||||||
|     false |     false | ||||||
|   $('.dropdown-menu li a').live 'click', -> |   $('.dropdown-menu li a').live 'click', -> | ||||||
|     console.log(1) |  | ||||||
|     $(this).parent().parent().parent().toggleClass('open') |     $(this).parent().parent().parent().toggleClass('open') | ||||||
|     false |     false | ||||||
| @ -49,8 +49,11 @@ $('#settings-forms form').live 'submit', -> | |||||||
|   params = {} |   params = {} | ||||||
|   $(this).find('input, select').each -> |   $(this).find('input, select').each -> | ||||||
|     if $(this).attr('name') |     if $(this).attr('name') | ||||||
|       params[$(this).attr('name')] = $(this).val() |       if $(this).attr('type') is 'checkbox' | ||||||
|   console.log(params) |         params[$(this).attr('name')] = ($(this).attr('checked') is 'checked') | ||||||
|  |       else | ||||||
|  |         params[$(this).attr('name')] = $(this).val() | ||||||
|  |   _session.query '/user/update/', { params: params } | ||||||
|   false |   false | ||||||
| 
 | 
 | ||||||
| $('#settings-forms input[type$="submit"]').live 'mouseup', -> | $('#settings-forms input[type$="submit"]').live 'mouseup', -> | ||||||
|  | |||||||
| @ -40,19 +40,23 @@ class UserController < ApplicationController | |||||||
|    |    | ||||||
|   def update |   def update | ||||||
|     return unless authorized? |     return unless authorized? | ||||||
|  |     allowed_params = [:name, :email, :lang, :show] | ||||||
|     @res = {} |     @res = {} | ||||||
|      |      | ||||||
|     user = User.find_by_vkid(params[:mid]) |     user = User.find_by_vkid(params[:mid]) | ||||||
|      |     update_params = {} | ||||||
|     render :json => request |     params[:params] = params[:params].each{ |k, v| update_params[k.to_sym] = v } | ||||||
|     return |     if (update_params.keys - allowed_params).empty? | ||||||
|      |       if update_params.include? :show | ||||||
|     unless params[:username].nil? or params[:email].nil? |         update_params[:show].map!{ |k, v| k.to_sym } | ||||||
|       user.name = params[:username] |       end | ||||||
|       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 |       user.save | ||||||
|     end |     end | ||||||
|  |      | ||||||
|     @res[:user] = { |     @res[:user] = { | ||||||
|       :id => user.id, |       :id => user.id, | ||||||
|       :name => user.name, |       :name => user.name, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user