From 5fd72fcd6fb997c38d79c4f84dfff789e015b26b Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Mon, 20 May 2013 16:31:59 -0400 Subject: [PATCH] update users info via ajax is working, yay. Next thing is we need to move the datatables into an ajax call and so that we can refresh the table upon any changes occuring --- app/controllers/admin_controller.rb | 19 +++++ app/controllers/users_controller.rb | 4 +- app/models/user.rb | 7 +- app/views/admin/dashboard.html.erb | 90 +++++++++------------- app/views/layouts/admin/_get_user.html.erb | 64 +++++++++++++++ app/views/users/account_settings.html.erb | 41 ---------- config/routes.rb | 2 + 7 files changed, 129 insertions(+), 98 deletions(-) create mode 100644 app/views/layouts/admin/_get_user.html.erb diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index e39c011..eb51fb0 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -4,4 +4,23 @@ class AdminController < ApplicationController @users = User.all end + def get_user + @user = User.find_by_id(params[:admin_id].to_s) + render :partial => "layouts/admin/get_user" + end + + def update_user + user = User.find_by_id(params[:admin_id]) + if user + user.update_attributes(params[:user].reject { |k| k == ("password" || "password_confirmation") }) + pass = params[:user][:password] + user.password = pass if !(pass.blank?) + user.save! + message = true + end + respond_to do |format| + format.json { render :json => { :msg => message ? "success" : "failure"} } + end + end + end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3f77781..228d0b1 100755 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -22,11 +22,11 @@ class UsersController < ApplicationController end def update - current_user.update_attributes(params[:user].reject { |k| k == "password" }) + current_user.update_attributes(params[:user].reject { |k| k == ("password" || "password_confirmation") }) pass = params[:user][:password] current_user.password = pass if !(pass.blank?) current_user.save! - redirect_to user_account_settings_path(:user_id => current_user.id) + redirect_to user_account_settings_path(:user_id => current_user.id) end end diff --git a/app/models/user.rb b/app/models/user.rb index ca3b328..7178fa8 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,9 +1,10 @@ class User < ActiveRecord::Base attr_accessible :email, :password, :user_id, :admin, :password_confirmation, :first_name, :last_name - validates_confirmation_of :password, :password_confirmation + validates_confirmation_of :password, :password_confirmation, :on => :create validates :password, :presence => true, - :confirmation => true, - :length => {:within => 6..40} + :confirmation => true, + :length => {:within => 6..40}, + :on => :create validates_presence_of :email validates_uniqueness_of :email validates_format_of :email, :with => /.+@.+\..+/i diff --git a/app/views/admin/dashboard.html.erb b/app/views/admin/dashboard.html.erb index e496aaf..6a4534b 100644 --- a/app/views/admin/dashboard.html.erb +++ b/app/views/admin/dashboard.html.erb @@ -1,5 +1,35 @@
+
+
+ +
+
+
+
+ +
+
@@ -41,65 +71,15 @@ <%= u.admin ? %{
@@ -127,6 +107,12 @@ function makeActive(){ $('li[id="admin"]').addClass('active'); }; +function openModal(id){ + var link = '/admin/'+ id +'/get_user'; + $("#editAcct").load(link); + $("#editAcct").modal('show'); +}; + $(document).ready( makeActive, dataTablePagination() diff --git a/app/views/layouts/admin/_get_user.html.erb b/app/views/layouts/admin/_get_user.html.erb new file mode 100644 index 0000000..e2b3b2d --- /dev/null +++ b/app/views/layouts/admin/_get_user.html.erb @@ -0,0 +1,64 @@ + + + + + + <% end %> + + + + diff --git a/app/views/users/account_settings.html.erb b/app/views/users/account_settings.html.erb index 7bfaa89..a9c0d18 100644 --- a/app/views/users/account_settings.html.erb +++ b/app/views/users/account_settings.html.erb @@ -35,47 +35,6 @@
<% end %> -
diff --git a/config/routes.rb b/config/routes.rb index 0067cb9..5288ebd 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,6 +30,8 @@ end resources :admin do get "dashboard" + get "get_user" + put "update_user" end resources :dashboard do