mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
11068: update setModalDataset logic to generic logic
This commit is contained in:
@@ -70,8 +70,9 @@
|
||||
= render(VerticalEllipsisMenu::Component.new) do
|
||||
= link_to t('admin.products_page.actions.edit'), edit_admin_product_path(product)
|
||||
= link_to t('admin.products_page.actions.clone'), clone_admin_product_path(product)
|
||||
%a{ "data-controller": "modal-link product-actions", "data-action": "click->product-actions#setDeleteModalDataSet click->modal-link#open",
|
||||
"data-modal-link-target-value": "product-delete-modal", "class": "delete", "data-product-actions-id-value": product.id }
|
||||
%a{ "data-controller": "modal-link", "data-action": "click->modal-link#setModalDataSetOnConfirm click->modal-link#open",
|
||||
"data-modal-link-target-value": "product-delete-modal", "class": "delete",
|
||||
"data-modal-link-modal-dataset-value": {'data-current-id': product.id}.to_json }
|
||||
= t('admin.products_page.actions.delete')
|
||||
|
||||
- product.variants.each_with_index do |variant, variant_index|
|
||||
@@ -112,6 +113,7 @@
|
||||
= render(VerticalEllipsisMenu::Component.new) do
|
||||
= link_to t('admin.products_page.actions.edit'), edit_admin_product_variant_path(product, variant)
|
||||
- if product.variants.size > 1
|
||||
%a{ "data-controller": "modal-link product-actions", "data-action": "click->product-actions#setDeleteModalDataSet click->modal-link#open",
|
||||
"data-modal-link-target-value": "variant-delete-modal", "class": "delete", "data-product-actions-id-value": variant.id }
|
||||
%a{ "data-controller": "modal-link", "data-action": "click->modal-link#setModalDataSetOnConfirm click->modal-link#open",
|
||||
"data-modal-link-target-value": "variant-delete-modal", "class": "delete",
|
||||
"data-modal-link-modal-dataset-value": {'data-current-id': variant.id}.to_json }
|
||||
= t('admin.products_page.actions.delete')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Controller } from "stimulus";
|
||||
|
||||
export default class extends Controller {
|
||||
static values = { target: String };
|
||||
static values = { target: String, modalDataset: Object };
|
||||
|
||||
open() {
|
||||
let modal = document.getElementById(this.targetValue);
|
||||
@@ -12,6 +12,21 @@ export default class extends Controller {
|
||||
modalController.open();
|
||||
}
|
||||
|
||||
setModalDataSetOnConfirm(event) {
|
||||
try {
|
||||
const modalId = this.targetValue;
|
||||
const moodalConfirmButtonQuery = `#${modalId} #modal-confirm-button`;
|
||||
const confirmButton = document.querySelector(moodalConfirmButtonQuery);
|
||||
Object.keys(this.modalDatasetValue).forEach((datasetKey) => {
|
||||
confirmButton.setAttribute(datasetKey, this.modalDatasetValue[datasetKey]);
|
||||
});
|
||||
} catch (e) {
|
||||
// In case of any type of error in setting the dataset value, stop the further actions i.e. opening the modal
|
||||
event.stopImmediatePropagation();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
getIdentifier() {
|
||||
return "modal";
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import ApplicationController from "./application_controller";
|
||||
|
||||
export default class extends ApplicationController {
|
||||
static values = { id: Number };
|
||||
|
||||
setDeleteModalDataSet(event) {
|
||||
try {
|
||||
const modalId = this.element.dataset.modalLinkTargetValue; // whether variant or product delete modal
|
||||
const deleteButtonQuery = `#${modalId} #modal-confirm-button`;
|
||||
const deleteButton = document.querySelector(deleteButtonQuery);
|
||||
deleteButton.setAttribute("data-current-id", this.idValue);
|
||||
} catch (e) {
|
||||
// In case of any type of error in setting the dataset value, stop the further actions i.e. opening the modal
|
||||
event.stopImmediatePropagation();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user