src/rails_admin/ui.js in rails_admin-3.1.0.beta vs src/rails_admin/ui.js in rails_admin-3.1.0.rc
- old
+ new
@@ -5,10 +5,38 @@
(function ($) {
$(document).on("click", "#list input.toggle", function () {
$("#list [name='bulk_ids[]']").prop("checked", $(this).is(":checked"));
});
+ $(document)
+ .on("turbo:click", function () {
+ $("#loading").show();
+ })
+ .on("turbo:before-render", function (event) {
+ document
+ .querySelectorAll('.sidebar .btn-toggle[aria-expanded="false"]')
+ .forEach((element) => {
+ const newButton = event.detail.newBody.querySelector(
+ `.sidebar [data-bs-target="${element.dataset.bsTarget}"]`
+ );
+ const newMenu = event.detail.newBody.querySelector(
+ element.dataset.bsTarget
+ );
+ if (newButton) {
+ newButton.parentNode.replaceChild(
+ element.cloneNode(true),
+ newButton
+ );
+ }
+ if (newMenu) {
+ newMenu.classList.remove("show");
+ }
+ });
+
+ $("#loading").hide();
+ });
+
$(document).on("click", "[data-bs-target]", function () {
if (!$(this).hasClass("disabled")) {
if ($(this).has("i.fa-chevron-down").length) {
$(this)
.removeClass("active")
@@ -49,16 +77,18 @@
.siblings("i")
.toggleClass("fa-check fa-trash");
}
);
- document.addEventListener("turbo:load", function () {
+ function triggerDomReady() {
I18n.init($("html").attr("lang"), $("#admin-js").data("i18nOptions"));
const event = new CustomEvent("rails_admin.dom_ready");
document.dispatchEvent(event);
- });
+ }
+ $(document).ready(triggerDomReady);
+ document.addEventListener("turbo:render", triggerDomReady);
document.addEventListener("rails_admin.dom_ready", function () {
$(".nav.nav-pills li.active").removeClass("active");
$(
'.nav.nav-pills li[data-model="' + $(".page-header").data("model") + '"]'
@@ -78,24 +108,21 @@
$("form.main legend")
.has("i.fa-chevron-right")
.each(function () {
$(this).siblings(".control-group").hide();
});
- $('button[name][type="submit"]')
- .attr("type", "button")
- .on("click", function () {
- var form = $(this).closest("form");
- form.append(
- $("<input />")
- .attr("type", "hidden")
- .attr("name", $(this).attr("name"))
- .attr("value", true)
- );
- if ($(this).is("[formnovalidate]")) {
- form.attr("novalidate", true);
- }
- form.trigger("submit");
- });
+ $('button[name][type="submit"]').on("click", function () {
+ var form = $(this).closest("form");
+ form.append(
+ $("<input />")
+ .attr("type", "hidden")
+ .attr("name", $(this).attr("name"))
+ .attr("value", $(this).attr("value"))
+ );
+ if ($(this).is("[formnovalidate]")) {
+ form.attr("novalidate", true);
+ }
+ });
$.each($("#filters_box").data("options"), function () {
$.filters.append(this);
});
// Workaround for https://github.com/heartcombo/devise/issues/5458
$("a[data-method]").on("click", function (event) {