diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-12-02 15:29:24 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-12-02 15:29:24 +0400 |
commit | 46bf3a094988327b08c88006c694f0a0a15f7da2 (patch) | |
tree | 82458b24bc2d77b1f711bc6579d39080748ab972 /app | |
parent | 2be5e6d44347dfb6374b4b2c87a953da06d6167d (diff) |
Refactored profile to resource. Added missing flash notice on successfull updated. Update username via ajax
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/profile.js.coffee | 10 | ||||
-rw-r--r-- | app/controllers/profiles_controller.rb (renamed from app/controllers/profile_controller.rb) | 29 | ||||
-rw-r--r-- | app/views/layouts/profile.html.haml | 14 | ||||
-rw-r--r-- | app/views/profile/index.html.haml | 1 | ||||
-rw-r--r-- | app/views/profiles/account.html.haml (renamed from app/views/profile/account.html.haml) | 18 | ||||
-rw-r--r-- | app/views/profiles/design.html.haml (renamed from app/views/profile/design.html.haml) | 2 | ||||
-rw-r--r-- | app/views/profiles/history.html.haml (renamed from app/views/profile/history.html.haml) | 0 | ||||
-rw-r--r-- | app/views/profiles/show.html.haml (renamed from app/views/profile/show.html.haml) | 6 | ||||
-rw-r--r-- | app/views/profiles/update.js.erb (renamed from app/views/profile/update.js.erb) | 0 | ||||
-rw-r--r-- | app/views/profiles/update_username.js.haml | 6 |
10 files changed, 64 insertions, 22 deletions
diff --git a/app/assets/javascripts/profile.js.coffee b/app/assets/javascripts/profile.js.coffee index e536afad939..42207a390b3 100644 --- a/app/assets/javascripts/profile.js.coffee +++ b/app/assets/javascripts/profile.js.coffee @@ -8,3 +8,13 @@ $ -> # Go up the hierarchy and show the corresponding submission feedback element $(@).closest('fieldset').find('.update-feedback').show('highlight', {color: '#DFF0D8'}, 500) + + $('.update-username form').on 'ajax:before', -> + $('.loading-gif').show() + $(this).find('.update-success').hide() + $(this).find('.update-failed').hide() + + $('.update-username form').on 'ajax:complete', -> + $(this).find('.save-btn').removeAttr('disabled') + $(this).find('.save-btn').removeClass('disabled') + $(this).find('.loading-gif').hide() diff --git a/app/controllers/profile_controller.rb b/app/controllers/profiles_controller.rb index 5f8b11fdded..1d1efb16f04 100644 --- a/app/controllers/profile_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -1,5 +1,6 @@ -class ProfileController < ApplicationController +class ProfilesController < ApplicationController before_filter :user + layout 'profile' def show end @@ -7,8 +8,15 @@ class ProfileController < ApplicationController def design end + def account + end + def update - @user.update_attributes(params[:user]) + if @user.update_attributes(params[:user]) + flash[:notice] = "Profile was successfully updated" + else + flash[:alert] = "Failed to update profile" + end respond_to do |format| format.html { redirect_to :back } @@ -19,7 +27,7 @@ class ProfileController < ApplicationController def token end - def password_update + def update_password params[:user].reject!{ |k, v| k != "password" && k != "password_confirmation"} if @user.update_attributes(params[:user]) @@ -31,14 +39,25 @@ class ProfileController < ApplicationController end def reset_private_token - current_user.reset_authentication_token! - redirect_to profile_account_path + if current_user.reset_authentication_token! + flash[:notice] = "Token was successfully updated" + end + + redirect_to account_profile_path end def history @events = current_user.recent_events.page(params[:page]).per(20) end + def update_username + @user.update_attributes(username: params[:user][:username]) + + respond_to do |format| + format.js + end + end + private def user diff --git a/app/views/layouts/profile.html.haml b/app/views/layouts/profile.html.haml index b2743222281..7852ed6f0e1 100644 --- a/app/views/layouts/profile.html.haml +++ b/app/views/layouts/profile.html.haml @@ -6,17 +6,17 @@ = render "layouts/head_panel", title: "Profile" .container %ul.main_menu - = nav_link(path: 'profile#show', html_options: {class: 'home'}) do + = nav_link(path: 'profiles#show', html_options: {class: 'home'}) do = link_to "Profile", profile_path - = nav_link(path: 'profile#account') do - = link_to "Account", profile_account_path + = nav_link(path: 'profiles#account') do + = link_to "Account", account_profile_path = nav_link(controller: :keys) do = link_to keys_path do SSH Keys %span.count= current_user.keys.count - = nav_link(path: 'profile#design') do - = link_to "Design", profile_design_path - = nav_link(path: 'profile#history') do - = link_to "History", profile_history_path + = nav_link(path: 'profiles#design') do + = link_to "Design", design_profile_path + = nav_link(path: 'profiles#history') do + = link_to "History", history_profile_path .content= yield diff --git a/app/views/profile/index.html.haml b/app/views/profile/index.html.haml deleted file mode 100644 index 84174ac5be7..00000000000 --- a/app/views/profile/index.html.haml +++ /dev/null @@ -1 +0,0 @@ -%h1 Profile diff --git a/app/views/profile/account.html.haml b/app/views/profiles/account.html.haml index e2c5bcdb8e2..1c51f48f401 100644 --- a/app/views/profile/account.html.haml +++ b/app/views/profiles/account.html.haml @@ -15,7 +15,7 @@ %span.cred.right keep it secret! .padded - = form_for @user, url: profile_reset_private_token_path, method: :put do |f| + = form_for @user, url: reset_private_token_profile_path, method: :put do |f| .data %p.slead Private token used to access application resources without authentication. @@ -31,7 +31,7 @@ %fieldset %legend Password - = form_for @user, url: profile_password_path, method: :put do |f| + = form_for @user, url: update_password_profile_path, method: :put do |f| .padded %p.slead After successful password update you will be redirected to login page where you should login with new password -if @user.errors.any? @@ -53,16 +53,24 @@ -%fieldset +%fieldset.update-username %legend Username - %small.right + %small.cred.right Changing your username can have unintended side effects! - = form_for @user, url: profile_update_path, method: :put do |f| + = form_for @user, url: update_username_profile_path, method: :put, remote: true do |f| .padded = f.label :username .input = f.text_field :username, required: true + + %span.loading-gif.hide= image_tag "ajax_loader.gif" + %span.update-success.cgreen.hide + %i.icon-ok + Saved + %span.update-failed.cred.hide + %i.icon-ok + Failed .input = f.submit 'Save username', class: "btn save-btn" diff --git a/app/views/profile/design.html.haml b/app/views/profiles/design.html.haml index 502cca42f2d..f4b50677203 100644 --- a/app/views/profile/design.html.haml +++ b/app/views/profiles/design.html.haml @@ -1,4 +1,4 @@ -= form_for @user, url: profile_update_path, remote: true, method: :put do |f| += form_for @user, url: profile_path, remote: true, method: :put do |f| %fieldset.application-theme %legend Application theme diff --git a/app/views/profile/history.html.haml b/app/views/profiles/history.html.haml index aa7006c569b..aa7006c569b 100644 --- a/app/views/profile/history.html.haml +++ b/app/views/profiles/history.html.haml diff --git a/app/views/profile/show.html.haml b/app/views/profiles/show.html.haml index 7d9e90cf3f8..ac36fa3aa55 100644 --- a/app/views/profile/show.html.haml +++ b/app/views/profiles/show.html.haml @@ -8,7 +8,7 @@ %hr -= form_for @user, url: profile_update_path, method: :put, html: { class: "edit_user form-horizontal" } do |f| += form_for @user, url: profile_path, method: :put, html: { class: "edit_user form-horizontal" } do |f| -if @user.errors.any? %div.alert-message.block-message.error %ul @@ -39,9 +39,9 @@ - if Gitlab.config.omniauth_enabled? && @user.provider? %li - %p.hint + %p You can login through #{@user.provider.titleize}! - = link_to "click here to change", profile_account_path + = link_to "click here to change", account_profile_path .row .span7 diff --git a/app/views/profile/update.js.erb b/app/views/profiles/update.js.erb index 04b5cf4827d..04b5cf4827d 100644 --- a/app/views/profile/update.js.erb +++ b/app/views/profiles/update.js.erb diff --git a/app/views/profiles/update_username.js.haml b/app/views/profiles/update_username.js.haml new file mode 100644 index 00000000000..abd90269c93 --- /dev/null +++ b/app/views/profiles/update_username.js.haml @@ -0,0 +1,6 @@ +- if @user.valid? + :plain + $('.update-username .update-success').show(); +- else + :plain + $('.update-username .update-failed').show(); |