1
0
Fork 0

Saving settings works ok

This commit is contained in:
magnolia-fan 2011-06-22 03:29:18 +04:00
parent 79c34273c8
commit 9531230f6e
8 changed files with 68 additions and 16 deletions

View File

@ -26,7 +26,21 @@ class UserController < ApplicationController
end end
def update def update
@res = {}
check = check_auth(params)
if check == true
user = User.find_by_vkid(params[:mid])
unless params[:username].nil? or params[:email].nil?
user.name = params[:username]
user.email = params[:email]
user.save
end
@res[:username] = user.name
@res[:email] = user.email
end
render :json => @res
end end
private private

View File

@ -57,6 +57,8 @@ Beathaven::Application.routes.draw do
# match ':controller(/:action(/:id(.:format)))' # match ':controller(/:action(/:id(.:format)))'
match 'user/auth' => 'user#auth' match 'user/auth' => 'user#auth'
match 'user/update' => 'user#update'
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

View File

@ -14,14 +14,14 @@
<script type="text/javascript" charset="utf-8" src="/javascripts/jquery/jquery.autocomplete.js"></script> <script type="text/javascript" charset="utf-8" src="/javascripts/jquery/jquery.autocomplete.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/jquery/jquery.contentchange.js"></script> <script type="text/javascript" charset="utf-8" src="/javascripts/jquery/jquery.contentchange.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/layout.js"></script> <script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/layout.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/vkontakte.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/session.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/ajax.js"></script> <script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/ajax.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/search.js"></script> <script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/search.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/settings.js"></script> <script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/settings.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/pages.js"></script> <script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/pages.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/audio.js"></script> <script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/audio.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/player.js"></script> <script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/player.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/vkontakte.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/session.js"></script>
<script type="text/javascript" charset="windows-1251" src="http://vkontakte.ru/js/api/openapi.js"></script> <script type="text/javascript" charset="windows-1251" src="http://vkontakte.ru/js/api/openapi.js"></script>
</head> </head>
<body> <body>

View File

@ -88,5 +88,5 @@ $(function(){
Ajax.loadArtistData($(this).html()); Ajax.loadArtistData($(this).html());
return false; return false;
}); });
$(window).bind('hashchange', Ajax.detectPage); //$(window).bind('hashchange', Ajax.detectPage);
}) })

View File

@ -91,5 +91,6 @@ var Pages = {
$('#data-container .inner').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');
$('.settings-container .tabs .tab').first().trigger('click');
} }
} }

View File

@ -1,13 +1,42 @@
var Settings = { var Settings = {
getAccountInfo: function(callback) {
Session.query('/user/update', {}, callback);
},
saveAccountInfo: function(params, callback) {
Session.query('/user/update', params, callback);
},
loadFormData: function(form) {
if (form == 'account') {
this.getAccountInfo(function(data){
$('.settings-container .form input[name$="username"]').val(data.username);
$('.settings-container .form input[name$="email"]').val(data.email);
})
}
}
} }
$('.settings').live('click', function() { $('.settings').live('click', function() {
Ajax.loadSettingsPage(); Ajax.loadSettingsPage();
}) });
$('.settings-container .tabs .tab').live('click', function(){ $('.settings-container .tabs .tab').live('click', function(){
if (!$(this).hasClass('active')) { if (!$(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());
Settings.loadFormData($(this).attr('data-fieldset'));
} }
});
$('.settings-container .form input').live('blur', function(){
params = {
'username': $('.settings-container .form input[name$="username"]').first().val(),
'email': $('.settings-container .form input[name$="email"]').first().val(),
};
Settings.saveAccountInfo(params, function(){
console.log('saved');
});
}) })

View File

@ -1,11 +1,12 @@
<div class="settings-container"> <div class="settings-container">
<div class="tabs"> <div class="tabs">
<div class="left-space"></div> <div class="left-space"></div>
<div class="tab active">Account</div> <div class="tab" data-fieldset="account">Account</div>
<div class="middle-space"></div> <div class="middle-space"></div>
<div class="tab">Music</div>
</div> </div>
<div class="form-container"> <div class="form-container"></div>
<div class="forms">
<div class="account">
<div class="form"> <div class="form">
<div class="field"> <div class="field">
<div class="label">Username:</div> <div class="label">Username:</div>
@ -18,3 +19,4 @@
</div> </div>
</div> </div>
</div> </div>
</div>

View File

@ -81,4 +81,8 @@
-webkit-border-radius: 3px; -webkit-border-radius: 3px;
-moz-border-radius: 3px; -moz-border-radius: 3px;
border-radius: 3px; border-radius: 3px;
width: 300px;
}
.settings-container .forms {
display: none;
} }