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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -22,7 +22,7 @@ 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!
|
||||
|
||||
+3
-2
@@ -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}
|
||||
:length => {:within => 6..40},
|
||||
:on => :create
|
||||
validates_presence_of :email
|
||||
validates_uniqueness_of :email
|
||||
validates_format_of :email, :with => /.+@.+\..+/i
|
||||
|
||||
@@ -1,5 +1,35 @@
|
||||
<div class="dashboard-wrapper">
|
||||
<div class="main-container">
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<div id="success" style="display: none;" class="alert alert-block alert-success fade in">
|
||||
<button data-dismiss="alert" class="close" type="button">
|
||||
×
|
||||
</button>
|
||||
<h4 class="alert-heading">
|
||||
Success!
|
||||
</h4>
|
||||
<p>
|
||||
User information successfully updated.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<div id="failure" style="display: none;" class="alert alert-block alert-error fade in">
|
||||
<button data-dismiss="alert" class="close" type="button">
|
||||
×
|
||||
</button>
|
||||
<h4 class="alert-heading">
|
||||
Error!
|
||||
</h4>
|
||||
<p>
|
||||
Something went wrong.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<div class="widget">
|
||||
@@ -41,65 +71,15 @@
|
||||
<%= u.admin ? %{<span class="fs1" aria-hidden="true" data-icon=""}.html_safe : nil %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to "Edit", "#editAcct", {:role => "button", :class => "btn btn-inverse", "data-toggle" => "modal"}%>
|
||||
<%= link_to "Edit", "#", {:onClick => "javascript:openModal(#{u.id});" ,:role => "button", :class => "btn btn-inverse", "data-toggle" => "modal"}%>
|
||||
<%= link_to "Delete", "#", {:class => "btn btn-danger"}%>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- Begin Modal -->
|
||||
<div id="editAcct" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
|
||||
×
|
||||
</button>
|
||||
<h4 id="myModalLabel1">
|
||||
Account Settings
|
||||
</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="row-fluid">
|
||||
<div class="span4">
|
||||
<input type="text" class="span12" Placeholder="Frist name">
|
||||
</div>
|
||||
<div class="span4">
|
||||
<input type="text" class="span12" Placeholder="Last name">
|
||||
</div>
|
||||
<div class="span4">
|
||||
<input type="text" class="span12" Placeholder="email">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="span6">
|
||||
<button class="span12 btn btn-info">Edit name</button>
|
||||
</div>
|
||||
<div class="span6">
|
||||
<button class="span12 input-top-margin btn btn-warning">Edit email</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="btn-group pull-left">
|
||||
<button class="btn btn-warning2">
|
||||
<span class="fs1" aria-hidden="true" data-icon=""></span>
|
||||
</button>
|
||||
<button class="btn btn-info">
|
||||
<span class="fs1" aria-hidden="true" data-icon=""></span>
|
||||
</button>
|
||||
<button class="btn btn-success">
|
||||
<span class="fs1" aria-hidden="true" data-icon=""></span>
|
||||
</button>
|
||||
</div>
|
||||
<button class="btn" data-dismiss="modal" aria-hidden="true">
|
||||
Close
|
||||
</button>
|
||||
<button class="btn btn-primary">
|
||||
Save changes
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- End Modal -->
|
||||
<div class="clearfix">
|
||||
</div>
|
||||
</div>
|
||||
@@ -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()
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<!-- Begin Modal -->
|
||||
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
|
||||
×
|
||||
</button>
|
||||
<h4 id="myModalLabel1">
|
||||
Account Settings
|
||||
</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="row-fluid">
|
||||
<div class="span8">
|
||||
<%= form_for @user, :html => {:id => "account_edit"} do |f| %>
|
||||
|
||||
<%= f.label :email, nil, {:class => "control-label"}%>
|
||||
<%= f.text_field :email, {:class => "span12"}%>
|
||||
|
||||
<%= f.label :first_name, nil, {:class => "control-label"}%>
|
||||
<%= f.text_field :first_name, {:class => "span12"} %>
|
||||
|
||||
<%= f.label :last_name, nil, {:class => "control-label"}%>
|
||||
<%= f.text_field :last_name, {:class => "span12"} %>
|
||||
|
||||
<%= f.label :password, nil, {:class => "control-label"}%>
|
||||
<%= f.password_field :password, {:class => "span12", :placeholder => "Enter Password"}%>
|
||||
|
||||
<%= f.label :password_confirmation, nil, {:class => "control-label"}%>
|
||||
<%= f.password_field :password_confirmation, {:class => "span12", :placeholder => "Enter Password"} %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn" data-dismiss="modal" aria-hidden="true">
|
||||
Close
|
||||
</button>
|
||||
<%= f.submit "Submit", {:id => 'submit_button', :class => "btn btn-primary pull-right"} %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<!-- End Modal -->
|
||||
|
||||
<script type="text/javascript">
|
||||
//$(document).ready(alert(<%#= @id %>));
|
||||
$('#submit_button').click(function() {
|
||||
var valuesToSubmit = $("#account_edit").serialize();
|
||||
$("#editAcct").modal('hide');
|
||||
|
||||
$.ajax({
|
||||
url: "/admin/" + <%= @user.id %> + "/update_user.json",
|
||||
data: valuesToSubmit,
|
||||
type: "POST",
|
||||
success: function(response) {
|
||||
$('#success').show(500).delay(1500).fadeOut();
|
||||
},
|
||||
error: function(event) {
|
||||
$('#failure').show(500).delay(1500).fadeOut();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
@@ -35,47 +35,6 @@
|
||||
<div class="clearfix">
|
||||
</div>
|
||||
<% end %>
|
||||
<!--<form class="form-horizontal no-margin">
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="email1">
|
||||
Email Address
|
||||
</label>
|
||||
<div class="controls">
|
||||
<input type="text" name="email1" id="email1" class="span12" placeholder="Enter your Email Address" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="password1">
|
||||
Password
|
||||
</label>
|
||||
<div class="controls">
|
||||
<input type="password" name="password1" id="password1" class="span12" placeholder="6 or more characters" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="repPassword">
|
||||
Repeat Password
|
||||
</label>
|
||||
<div class="controls">
|
||||
<input type="password" name="repPassword" id="repPassword" class="span12" placeholder="Retype Password" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="name">
|
||||
Name
|
||||
</label>
|
||||
<div class="controls controls-row">
|
||||
<input class="span6" type="text" placeholder="First Name">
|
||||
<input class="span6 input-left-top-margins" type="text" placeholder="Last Name">
|
||||
</div>
|
||||
<div class="form-actions no-margin">
|
||||
<button type="submit" class="btn btn-info pull-right">
|
||||
Create Account
|
||||
</button>
|
||||
<div class="clearfix">
|
||||
</div>
|
||||
</div>
|
||||
</form>-->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -30,6 +30,8 @@ end
|
||||
|
||||
resources :admin do
|
||||
get "dashboard"
|
||||
get "get_user"
|
||||
put "update_user"
|
||||
end
|
||||
|
||||
resources :dashboard do
|
||||
|
||||
Reference in New Issue
Block a user