Simplify admin user editing - remove modal, use regular CRUD pages

Remove complex modal implementation and replace with simple page navigation:
- Convert get_user view from modal partial to full edit page
- Add proper form with Bootstrap 5 styling
- Link directly from users list to edit page
- Update controller actions to redirect instead of returning JSON
- Add flash messages for success/error feedback
- Remove all modal JavaScript and markup
- Remove modal CSS and backdrop handling

Benefits:
- Much simpler and more maintainable
- No JavaScript errors or complexity
- Standard Rails CRUD pattern
- Better user experience with proper navigation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ken Johnson
2025-12-07 22:26:17 +00:00
parent 844acfc8e6
commit decf82962d
3 changed files with 65 additions and 144 deletions
+10 -9
View File
@@ -2,7 +2,7 @@
class AdminController < ApplicationController
before_action :administrative, if: :admin_param, except: [:get_user]
skip_before_action :has_info
layout false, only: [:get_all_users, :get_user]
layout false, only: [:get_all_users]
def dashboard
end
@@ -38,10 +38,11 @@ class AdminController < ApplicationController
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"} }
flash[:success] = "User updated successfully"
redirect_to admin_get_all_users_path(current_user.id)
else
flash[:error] = "User not found"
redirect_to admin_get_all_users_path(current_user.id)
end
end
@@ -51,11 +52,11 @@ class AdminController < ApplicationController
# Call destroy here so that all association records w/ id are destroyed as well
# Example user.retirement records would be destroyed
user.destroy
message = true
end
respond_to do |format|
format.json { render json: { msg: message ? "success" : "failure"} }
flash[:success] = "User deleted successfully"
else
flash[:error] = "Cannot delete this user"
end
redirect_to admin_get_all_users_path(current_user.id)
end
private
+1 -42
View File
@@ -29,59 +29,18 @@
<%= u.admin ? %{<span class="fs1" aria-label="check" data-icon="&#xe0fe;"}.html_safe : nil %>
</td>
<td>
<%= link_to "Edit", "#", {:onClick => "javascript:openEditModal(#{u.id}); return false;", :role => "button", :style => "width:70px", :class => "btn btn-inverse"}%>
<%= link_to "Edit", admin_get_user_path(u.id), {:style => "width:70px", :class => "btn btn-inverse"}%>
</td>
</tr>
<% end %>
</tbody>
</table>
<div id="editAcct" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<!-- Content will be loaded here dynamically -->
</div>
</div>
</div>
<div class="clearfix">
</div>
</div>
</div>
<script type="text/javascript">
function openEditModal(id){
var link = '/admin/'+ id +'/get_user';
console.log('Loading modal content from:', link);
$("#editAcct .modal-content").load(link, function(response, status, xhr) {
console.log('Load status:', status);
if (status == "success") {
console.log('Initializing Bootstrap 5 modal');
var modalEl = document.getElementById('editAcct');
// Ensure any existing instance is disposed
var existingModal = bootstrap.Modal.getInstance(modalEl);
if (existingModal) {
existingModal.dispose();
}
// Create new modal with options
var modal = new bootstrap.Modal(modalEl, {
backdrop: true,
keyboard: true,
focus: true
});
console.log('Modal created, calling show()');
modal.show();
console.log('Modal should be visible now');
} else {
console.error('Failed to load modal content:', xhr.statusText);
}
});
};
function dataTablePagination(){
$('#data-table').dataTable({
"sPaginationType": "full_numbers"
+54 -93
View File
@@ -1,94 +1,55 @@
<!-- Begin Modal -->
<div class="modal-header">
<h5 class="modal-title" id="myModalLabel1">
Account Settings
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
<div class="container-fluid">
<div class="row">
<div class="col-lg-8 mx-auto">
<div class="card shadow-sm mt-4">
<div class="card-header bg-white d-flex justify-content-between align-items-center py-3">
<h4 class="mb-0">
<i class="bi bi-person-gear text-primary"></i> Edit User Account
</h4>
<%= link_to "Back to Users", admin_get_all_users_path(current_user.id), class: "btn btn-outline-secondary btn-sm" %>
</div>
<div class="card-body p-4">
<%= form_for @user, url: admin_update_user_path(params[:admin_id]), method: :patch do |f| %>
<div class="mb-3">
<%= f.label :email, nil, {:class => "form-label"}%>
<%= f.text_field :email, {:class => "form-control"}%>
</div>
<div class="mb-3">
<%= f.label :first_name, nil, {:class => "form-label"}%>
<%= f.text_field :first_name, {:class => "form-control"} %>
</div>
<div class="mb-3">
<%= f.label :last_name, nil, {:class => "form-label"}%>
<%= f.text_field :last_name, {:class => "form-control"} %>
</div>
<div class="mb-3">
<%= f.label :password, "Password (leave blank to keep current)", {:class => "form-label"}%>
<%= f.password_field :password, {:class => "form-control", :placeholder => "Enter new password"}%>
</div>
<div class="mb-3">
<%= f.label :password_confirmation, nil, {:class => "form-label"}%>
<%= f.password_field :password_confirmation, {:class => "form-control", :placeholder => "Confirm new password"} %>
</div>
<div class="mb-4">
<%= f.label :admin, "Administrator", {:class => "form-label"}%>
<%= f.select(:admin, @admin_select, {}, {:class => "form-select"}) %>
</div>
<div class="d-flex justify-content-between">
<%= link_to "Delete User", admin_delete_user_path(params[:admin_id]), method: :post, data: { confirm: "Are you sure you want to delete this user?" }, class: "btn btn-danger" %>
<div>
<%= link_to "Cancel", admin_get_all_users_path(current_user.id), class: "btn btn-secondary me-2" %>
<%= f.submit "Save Changes", class: "btn btn-primary" %>
</div>
</div>
<% end %>
</div>
</div>
</div>
<div class="modal-body">
<%= form_for @user, :html => {:id => "account_edit"} do |f| %>
<div class="mb-3">
<%= f.label :email, nil, {:class => "form-label"}%>
<%= f.text_field :email, {:class => "form-control"}%>
</div>
<div class="mb-3">
<%= f.label :first_name, nil, {:class => "form-label"}%>
<%= f.text_field :first_name, {:class => "form-control"} %>
</div>
<div class="mb-3">
<%= f.label :last_name, nil, {:class => "form-label"}%>
<%= f.text_field :last_name, {:class => "form-control"} %>
</div>
<div class="mb-3">
<%= f.label :password, nil, {:class => "form-label"}%>
<%= f.password_field :password, {:class => "form-control", :placeholder => "Enter Password"}%>
</div>
<div class="mb-3">
<%= f.label :password_confirmation, nil, {:class => "form-label"}%>
<%= f.password_field :password_confirmation, {:class => "form-control", :placeholder => "Enter Password"} %>
</div>
<div class="mb-3">
<%= f.label :admin, nil, {:class => "form-label"}%>
<%= f.select(:admin, @admin_select, {}, {:class => "form-select", :id => "user_admin", :name => "user[admin]"}) %>
</div>
</div>
<div class="modal-footer">
<%= link_to "Delete", "#", {:id => "delete_button", :class => "btn btn-danger"} %>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<%= f.submit "Submit", {:id => 'submit_button', :class => "btn btn-primary"} %>
</div>
<% end %>
<!-- End Modal -->
<%= javascript_include_tag ('validation.js')%>
<script type="text/javascript">
$('#submit_button').click(function(e) {
e.preventDefault();
var valuesToSubmit = $("#account_edit").serialize();
var modalElement = document.getElementById('editAcct');
var modal = bootstrap.Modal.getInstance(modalElement);
modal.hide();
$.ajax({
url: "/admin/" + <%= @user.id %> + "/update_user.json",
data: valuesToSubmit,
type: "POST",
success: function(response) {
$('#success').show(500).delay(1500).fadeOut();
loadTable();
},
error: function(event) {
$('#failure').show(500).delay(1500).fadeOut();
}
});
});
$('#delete_button').click(function(e) {
e.preventDefault();
var modalElement = document.getElementById('editAcct');
var modal = bootstrap.Modal.getInstance(modalElement);
modal.hide();
$.ajax({
url: "/admin/" + <%= params[:admin_id] %> + "/delete_user.json",
type: "POST",
success: function(response) {
$('#success').show(500).delay(1500).fadeOut();
loadTable();
},
error: function(event) {
$('#failure').show(500).delay(1500).fadeOut();
}
});
});
</script>
</div>
</div>