Skip to content

Commit

Permalink
Example of custom JS
Browse files Browse the repository at this point in the history
  • Loading branch information
pablobm committed Dec 22, 2023
1 parent 200578c commit 7a98c46
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions spec/example_app/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//= link administrate/application.css
//= link administrate/application.js
//= link admin.css
//= link admin.js
1 change: 1 addition & 0 deletions spec/example_app/app/assets/javascripts/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//= require_tree ./admin
10 changes: 10 additions & 0 deletions spec/example_app/app/assets/javascripts/admin/identity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let mainContent = document.querySelector(".main-content");
if (mainContent) {
mainContent.addEventListener("click", evt => {
if (evt.target.classList.contains("identity__become-action")) {
if (!confirm("Change identity?")) {
evt.preventDefault();
}
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
<% end %>

<td>
<%= link_to("Become", become_admin_customer_path(resource)) %>
<%= link_to("Become", become_admin_customer_path(resource), class: "identity__become-action") %>
</td>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<%= content_for(:title) %>
</h1>

<p class="identity__banner<%= " identity__banner--admin" if pundit_user.admin? %>">You are logged in as <em><%= pundit_user.name %></em>. <%= link_to("Become the Admin", become_admin_customer_path("admin")) unless pundit_user.admin? %></p>
<p class="identity__banner<%= " identity__banner--admin" if pundit_user.admin? %>">You are logged in as <em><%= pundit_user.name %></em>. <%= link_to("Become the Admin", become_admin_customer_path("admin"), class: "identity__become-action") unless pundit_user.admin? %></p>

<% if show_search_bar %>
<%= render(
Expand Down
1 change: 1 addition & 0 deletions spec/example_app/config/initializers/administrate.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Administrate::Engine.add_stylesheet("admin")
Administrate::Engine.add_javascript("admin")

0 comments on commit 7a98c46

Please sign in to comment.