diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index da23ae5..a4a3424 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -26,7 +26,21 @@ class UserController < ApplicationController end 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 private diff --git a/config/routes.rb b/config/routes.rb index 2be460f..6ca6e5d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -57,6 +57,8 @@ Beathaven::Application.routes.draw do # match ':controller(/:action(/:id(.:format)))' match 'user/auth' => 'user#auth' + match 'user/update' => 'user#update' + match 'artist/autocomplete' => 'artist#autocomplete' match 'artist/(:name)/' => 'artist#data', :constraints => { :name => /[^\/]*/ } end diff --git a/public/index.html b/public/index.html index 3f9f5b7..60fe278 100644 --- a/public/index.html +++ b/public/index.html @@ -14,14 +14,14 @@ + + - - diff --git a/public/javascripts/beathaven/ajax.js b/public/javascripts/beathaven/ajax.js index 58efb81..3ee9fdf 100644 --- a/public/javascripts/beathaven/ajax.js +++ b/public/javascripts/beathaven/ajax.js @@ -88,5 +88,5 @@ $(function(){ Ajax.loadArtistData($(this).html()); return false; }); - $(window).bind('hashchange', Ajax.detectPage); + //$(window).bind('hashchange', Ajax.detectPage); }) \ No newline at end of file diff --git a/public/javascripts/beathaven/pages.js b/public/javascripts/beathaven/pages.js index 4f81e1b..733c4ac 100644 --- a/public/javascripts/beathaven/pages.js +++ b/public/javascripts/beathaven/pages.js @@ -91,5 +91,6 @@ var Pages = { $('#data-container .inner').html(data); yaCounter7596904.hit(Ajax.getAnchor(), 'Settings', Ajax.referer); Ajax.setTitle('Settings'); + $('.settings-container .tabs .tab').first().trigger('click'); } } \ No newline at end of file diff --git a/public/javascripts/beathaven/settings.js b/public/javascripts/beathaven/settings.js index 68d78ad..d9d9ffb 100644 --- a/public/javascripts/beathaven/settings.js +++ b/public/javascripts/beathaven/settings.js @@ -1,13 +1,42 @@ 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() { Ajax.loadSettingsPage(); -}) +}); + $('.settings-container .tabs .tab').live('click', function(){ if (!$(this).hasClass('active')) { $('.settings-container .tabs .tab').removeClass('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'); + }); }) \ No newline at end of file diff --git a/public/settings.html b/public/settings.html index f445a6b..a7f7e97 100644 --- a/public/settings.html +++ b/public/settings.html @@ -1,19 +1,21 @@
-
Account
+
Account
-
Music
-
-
-
-
Username:
-
-
-
-
Email:
-
+
+
+
diff --git a/public/stylesheets/settings.css b/public/stylesheets/settings.css index f07734a..26a111b 100644 --- a/public/stylesheets/settings.css +++ b/public/stylesheets/settings.css @@ -81,4 +81,8 @@ -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; - } \ No newline at end of file + width: 300px; + } + .settings-container .forms { + display: none; + } \ No newline at end of file