made sure the table refreshes after an update

This commit is contained in:
Ken Johnson
2013-05-20 17:35:24 -04:00
parent 2ec81eb0de
commit 4337cb9a46
5 changed files with 59 additions and 47 deletions
+4
View File
@@ -1,7 +1,11 @@
class AdminController < ApplicationController
def dashboard
end
def get_all_users
@users = User.all
render :partial => "layouts/admin/get_all_users"
end
def get_user
+9 -47
View File
@@ -33,52 +33,9 @@
Manage Users
</div>
</div>
<div class="widget-body">
<div id="dt_example" class="example_alt_pagination">
<table class="table table-striped table-hover table-bordered pull-left" id="data-table">
<thead>
<tr>
<th>
Name
</th>
<th>
Email
</th>
<th>
Admin User
</th>
<th>
Action
</th>
</tr>
</thead>
<tbody>
<% @users.each do |u|%>
<tr>
<td style="word-wrap:break-word;">
<%= "#{u.first_name} #{u.last_name}"%>
</td>
<td>
<%= u.email%>
</td>
<td>
<%= u.admin ? %{<span class="fs1" aria-hidden="true" data-icon="&#xe0fe;"}.html_safe : nil %>
</td>
<td>
<%= 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>
<div id="editAcct" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
</div>
<div class="clearfix">
</div>
</div>
</div>
</div>
<div id="userDataTable" class="widget-body">
</div> <!-- End widget-body-->
</div> <!-- End widget header-->
</div>
</div>
@@ -107,8 +64,13 @@ function openModal(id){
$("#editAcct").modal('show');
};
function loadTable(){
$("#userDataTable").load("/admin/"+ <%=current_user.id %> + "/get_all_users");
};
$(document).ready(
makeActive,
dataTablePagination()
dataTablePagination(),
loadTable()
);
</script>
@@ -0,0 +1,44 @@
<div id="dt_example" class="example_alt_pagination">
<table class="table table-striped table-hover table-bordered pull-left" id="data-table">
<thead>
<tr>
<th>
Name
</th>
<th>
Email
</th>
<th>
Admin User
</th>
<th>
Action
</th>
</tr>
</thead>
<tbody>
<% @users.each do |u|%>
<tr>
<td style="word-wrap:break-word;">
<%= "#{u.first_name} #{u.last_name}"%>
</td>
<td>
<%= u.email%>
</td>
<td>
<%= u.admin ? %{<span class="fs1" aria-hidden="true" data-icon="&#xe0fe;"}.html_safe : nil %>
</td>
<td>
<%= 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>
<div id="editAcct" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
</div>
<div class="clearfix">
</div>
</div>
</div>
@@ -54,6 +54,7 @@
type: "POST",
success: function(response) {
$('#success').show(500).delay(1500).fadeOut();
loadTable();
},
error: function(event) {
$('#failure').show(500).delay(1500).fadeOut();
+1
View File
@@ -32,6 +32,7 @@ resources :admin do
get "dashboard"
get "get_user"
put "update_user"
get "get_all_users"
end
resources :dashboard do