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:
@@ -2,7 +2,7 @@
|
|||||||
class AdminController < ApplicationController
|
class AdminController < ApplicationController
|
||||||
before_action :administrative, if: :admin_param, except: [:get_user]
|
before_action :administrative, if: :admin_param, except: [:get_user]
|
||||||
skip_before_action :has_info
|
skip_before_action :has_info
|
||||||
layout false, only: [:get_all_users, :get_user]
|
layout false, only: [:get_all_users]
|
||||||
|
|
||||||
def dashboard
|
def dashboard
|
||||||
end
|
end
|
||||||
@@ -38,10 +38,11 @@ class AdminController < ApplicationController
|
|||||||
pass = params[:user][:password]
|
pass = params[:user][:password]
|
||||||
user.password = pass if !(pass.blank?)
|
user.password = pass if !(pass.blank?)
|
||||||
user.save!
|
user.save!
|
||||||
message = true
|
flash[:success] = "User updated successfully"
|
||||||
end
|
redirect_to admin_get_all_users_path(current_user.id)
|
||||||
respond_to do |format|
|
else
|
||||||
format.json { render json: { msg: message ? "success" : "failure"} }
|
flash[:error] = "User not found"
|
||||||
|
redirect_to admin_get_all_users_path(current_user.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -51,11 +52,11 @@ class AdminController < ApplicationController
|
|||||||
# Call destroy here so that all association records w/ id are destroyed as well
|
# Call destroy here so that all association records w/ id are destroyed as well
|
||||||
# Example user.retirement records would be destroyed
|
# Example user.retirement records would be destroyed
|
||||||
user.destroy
|
user.destroy
|
||||||
message = true
|
flash[:success] = "User deleted successfully"
|
||||||
end
|
else
|
||||||
respond_to do |format|
|
flash[:error] = "Cannot delete this user"
|
||||||
format.json { render json: { msg: message ? "success" : "failure"} }
|
|
||||||
end
|
end
|
||||||
|
redirect_to admin_get_all_users_path(current_user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -29,59 +29,18 @@
|
|||||||
<%= u.admin ? %{<span class="fs1" aria-label="check" data-icon=""}.html_safe : nil %>
|
<%= u.admin ? %{<span class="fs1" aria-label="check" data-icon=""}.html_safe : nil %>
|
||||||
</td>
|
</td>
|
||||||
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</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 class="clearfix">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<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(){
|
function dataTablePagination(){
|
||||||
$('#data-table').dataTable({
|
$('#data-table').dataTable({
|
||||||
"sPaginationType": "full_numbers"
|
"sPaginationType": "full_numbers"
|
||||||
|
|||||||
@@ -1,94 +1,55 @@
|
|||||||
<!-- Begin Modal -->
|
<div class="container-fluid">
|
||||||
<div class="modal-header">
|
<div class="row">
|
||||||
<h5 class="modal-title" id="myModalLabel1">
|
<div class="col-lg-8 mx-auto">
|
||||||
Account Settings
|
<div class="card shadow-sm mt-4">
|
||||||
</h5>
|
<div class="card-header bg-white d-flex justify-content-between align-items-center py-3">
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
<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>
|
||||||
<div class="modal-body">
|
</div>
|
||||||
<%= form_for @user, :html => {:id => "account_edit"} do |f| %>
|
</div>
|
||||||
<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>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user