Sha256: 6e47e24ebe6c192beed571e498efa08bf6205d6b7ba5f624d1c4fb3cd311eda1

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

import * as bootstrap from "bootstrap";
import { initializeComponents } from "./initialize_components";
window.bootstrap = bootstrap;

export function handleFetchModalClick() {
  $('[data-action="fetch-modal"]').on("click", function (e) {
    const actionName = $(this).attr("data-action_name");
    const modelName = $(this).attr("data-model_name");
    const recordId = $(this).attr("data-record_id");
    const modalContainer = $(
      "[data-behaviour='custom-action-modal-container']"
    );
    const routeMount = document.location.href.split("/")[3];

    if (!actionName || !modelName || !recordId || !modalContainer) return;
    $.ajax({
      url: `/${routeMount}/${modelName}/${recordId}/custom_action_modal/${actionName}`,
      method: "GET",
      success: function (response) {
        modalContainer.html(response);
        const actionModal = new bootstrap.Modal(
          modalContainer.children().first()
        );
        actionModal.show();
        initializeComponents();
      },
      error: function (error) {
        console.error("Error:", error);
      },
    });
  });
}

document.addEventListener("turbo:load", function () {
  handleFetchModalClick();
});

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cm-admin-4.4.8 app/assets/javascripts/cm_admin/custom_action.js
cm-admin-4.4.6 app/assets/javascripts/cm_admin/custom_action.js
cm-admin-4.4.1 app/assets/javascripts/cm_admin/custom_action.js
cm-admin-4.4.0 app/assets/javascripts/cm_admin/custom_action.js