27 lines
848 B
JavaScript
27 lines
848 B
JavaScript
export class TemplateApply extends HTMLButtonElement {
|
|
constructor() {
|
|
super();
|
|
this.addEventListener('click', this.apply.bind(this));
|
|
}
|
|
|
|
apply() {
|
|
const selectorId = this.getAttribute('data-selector');
|
|
const urlPattern = this.getAttribute('data-url-pattern');
|
|
const selector = document.querySelector(selectorId);
|
|
|
|
if (!selector) return;
|
|
|
|
const templateId = selector.value;
|
|
if (!templateId) return;
|
|
|
|
if (!confirm('Appliquer ce modèle ? Cela ajoutera les points de contrôle au produit.')) return;
|
|
|
|
const form = document.createElement('form');
|
|
form.method = 'POST';
|
|
form.action = urlPattern.replace('TEMPLATE_ID', templateId);
|
|
|
|
document.body.appendChild(form);
|
|
form.submit();
|
|
}
|
|
}
|