Sha256: 529441547d01d36bd3baff41fd6dc1201526cbb0734109f1631b854309158074

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

import * as bootstrap from "bootstrap";
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();
      },
      error: function (error) {
        console.error("Error:", error);
      },
    });
  });
}

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cm-admin-4.1.0 app/assets/javascripts/cm_admin/custom_action.js
cm-admin-4.0.0 app/assets/javascripts/cm_admin/custom_action.js
cm-admin-3.0.16 app/assets/javascripts/cm_admin/custom_action.js