summaryrefslogtreecommitdiff
path: root/views/mods/mod_revocation/wp_footer.phtml
diff options
context:
space:
mode:
authorDaniel Schmitzer <noreply@maennchen1.de>2026-05-28 04:16:42 +0000
committerDaniel Schmitzer <noreply@maennchen1.de>2026-05-28 04:16:42 +0000
commitfe1b43a2645ee78032acffc581d52609a6d1698a (patch)
tree3d7b0bb74c67a9bac23ea2fb513b8012f4e13dbc /views/mods/mod_revocation/wp_footer.phtml
parentfd9122e4359db02258da7f6a0460c0fc962e5420 (diff)
- Widerrufsformular
git-svn-id: https://[internal]/wordpress/plugins/wpsg4@8520 0d5edaf7-2b12-4e95-93f4-047927463d4b
Diffstat (limited to 'views/mods/mod_revocation/wp_footer.phtml')
-rw-r--r--views/mods/mod_revocation/wp_footer.phtml331
1 files changed, 331 insertions, 0 deletions
diff --git a/views/mods/mod_revocation/wp_footer.phtml b/views/mods/mod_revocation/wp_footer.phtml
new file mode 100644
index 0000000..3c0f225
--- /dev/null
+++ b/views/mods/mod_revocation/wp_footer.phtml
@@ -0,0 +1,331 @@
+<?php
+
+ declare(strict_types=1);
+
+ /**
+ * @author: Daniel Schmitzer
+ * @date: 27.01.26
+ * @time: 09:26
+ */
+
+ namespace wpsgRevocation;
+
+?>
+
+<?php if (\wpsg_ShopController::getShop()->get_option('wpsg_mod_revocation_view_flyout') === '1') { ?>
+
+ <div id="wpsg_revocation_button">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19,15V3H23V15H19M15,3A2,2 0 0,1 17,5V15C17,15.55 16.78,16.05 16.41,16.41L9.83,23L8.77,21.94C8.5,21.67 8.33,21.3 8.33,20.88L8.36,20.57L9.31,16H3C1.89,16 1,15.1 1,14V12C1,11.74 1.05,11.5 1.14,11.27L4.16,4.22C4.46,3.5 5.17,3 6,3H15M15,5H5.97L3,12V14H11.78L10.65,19.32L15,14.97V5Z" /></svg>
+ <span><?php echo __('Widerrufsformular', 'wpsgRevocation'); ?></span>
+ </div>
+
+<?php } else { ?>
+
+ <div id="wpsg_revocation_button" style="display:none;"></div>
+
+<?php } ?>
+
+<!-- Dialog -->
+<div id="wpsg_revocation_dialog" class="">
+ <div class="inner">
+ <div class="header">
+ <span><?php echo __('Widerrufsformular', 'wpsgRevocation'); ?></span>
+ <a href="#" class="close">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z" /></svg>
+ </a>
+ </div>
+ <div class="content"></div>
+ <div class="footer">
+ <button class="button button-primary wpsg_revocation_button_submit"><?php echo __('Abschicken', 'wpsgRevocation'); ?></button>
+ </div>
+ <div class="loading">
+ <img src="<?php echo WPSG_URL; ?>views/gfx/ajax-loader.gif" alt="<?php echo __('Bitte warten ...', 'wpsgRevocation'); ?>" />
+ </div>
+ </div>
+</div>
+
+<script>
+
+ console.log('ok');
+
+ const wpsg_revocation_nonce = '<?php echo wp_create_nonce('wpsg_mod_revocation_nonce'); ?>';
+ const el_dialog = document.getElementById('wpsg_revocation_dialog');
+ const el_dialog_content = document.getElementById('wpsg_revocation_dialog').querySelector('.inner > .content');
+
+ const formDataToObject = (formData) => {
+
+ const obj = {};
+
+ for (const [key, value] of formData.entries()) {
+
+ const keys = key.split(/\[|\]/).filter(Boolean);
+ let current = obj;
+
+ keys.forEach((k, i) => {
+
+ const isLast = i === keys.length - 1;
+
+ if (isLast) { current[k] = value; }
+ else {
+
+ if (!current[k]) { current[k] = isNaN(keys[i + 1]) ? {} : []; }
+
+ current = current[k];
+
+ }
+
+ });
+
+ }
+
+ return obj;
+
+ }
+
+ const submit_dialog = event => {
+
+ event.preventDefault();
+ event.stopPropagation();
+
+ el_dialog.classList.add('loading');
+
+ // const form_data = Object.fromEntries(new FormData(el_dialog.querySelector('form#wpsg_revocation_form')).entries());
+ const form = el_dialog.querySelector('form#wpsg_revocation_form');
+ const formData = new FormData(form);
+ const form_data = formDataToObject(formData);
+
+ fetch('<?php echo admin_url('admin-ajax.php'); ?>?action=wpsg_mod_revocation&do=ajaxDialogSubmit', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({
+ nonce: wpsg_revocation_nonce,
+ form_data: form_data,
+ })
+ }).then(res => res.json()).then(res => {
+
+ let html = '';
+
+ if ((res.success??false) === false) {
+
+ html += '<ul id="wpsg_error" class="wpsg_error">';
+ (res.arError??[]).forEach(error => { html += `<li>${error}</li>`; });
+ html += '</ul>';
+
+ el_dialog_content.querySelector('#msg_target').innerHTML = html;
+
+ el_dialog.classList.remove('loading');
+
+ } else {
+
+ alert('<?php echo __('Ihr Widerruf ist bei uns eingegangen und wird bearbeitet.', 'wpsgRevocation'); ?>');
+ close_dialog(event);
+
+ document.querySelectorAll('.wpsg_revocation_order_product_checkbox:checked').forEach(el => {
+
+ el.checked = false;
+
+ });
+
+ }
+
+ });
+
+ }
+ const close_dialog = event => {
+
+ event.preventDefault();
+ event.stopPropagation();
+
+ el_dialog.classList.remove('visible');
+
+ };
+ const open_dialog = el => {
+
+ el_dialog.classList.toggle('visible');
+ el_dialog.classList.add('loading');
+
+ const dialog_config = {
+ arProductID: [],
+ arOrderProductID: [],
+ set_product_anr: ''
+ }
+
+ // Produkte auf der Seite
+ document.querySelectorAll('input[name="wpsg[produkt_id]"]').forEach(el => { dialog_config.arProductID.push(parseInt(el.value)); })
+
+ if (el !== undefined && el.classList.contains('wpsg_revocation_order_product')) {
+
+ el.querySelector('input').checked = true;
+
+ }
+
+ if (el !== undefined && el.classList.contains('wpsg_revocation_product_button')) {
+
+ dialog_config.set_product_anr = el.dataset.product_anr;
+
+ }
+
+ // Bestellung / Produkte
+ document.querySelectorAll('.wpsg_revocation_order_product_checkbox:checked').forEach(el => {
+
+ const order_id = parseInt(el.dataset.order_id);
+ const order_product_id = parseInt(el.dataset.order_product_id);
+ const product_id = parseInt(el.dataset.product_id);
+ const amount = parseInt(el.dataset.amount);
+
+ dialog_config.arOrderProductID.push({
+ order_id: order_id,
+ order_product_id: order_product_id,
+ amount: amount
+ });
+
+ dialog_config.arProductID.push(product_id);
+
+ });
+
+ fetch('<?php echo admin_url('admin-ajax.php'); ?>', {
+ method: 'POST',
+ body: new URLSearchParams({
+ nonce: wpsg_revocation_nonce,
+ action: 'wpsg_mod_revocation',
+ do: 'ajaxDialogContent',
+ dialog_config: JSON.stringify(dialog_config),
+ })
+ }).then(res => res.text()).then(html => {
+
+ el_dialog_content.innerHTML = html;
+ el_dialog.classList.remove('loading');
+
+ });
+
+ };
+
+ // Button am Produkt
+ document.querySelectorAll('.wpsg_revocation_product_button').forEach(el => {
+
+ el.addEventListener('click', event => {
+
+ open_dialog(el);
+
+ });
+
+ });
+
+ // Button Listener FlyOut
+ document.getElementById('wpsg_revocation_button').addEventListener('click', event => { open_dialog(); });
+
+ // GET Parameter verarbeiten
+ const urlParams = new URLSearchParams(window.location.search);
+
+ const get_order_nr = urlParams.get('wpsg_revo_order');
+ const get_product_nr = urlParams.get('wpsg_revo_product');
+ const get_amount = urlParams.get('wpsg_revo_amount');
+ const get_contact = urlParams.get('wpsg_revo_contact');
+
+ if (get_order_nr !== null) {
+
+ document.addEventListener('DOMContentLoaded', () => {
+
+ open_dialog();
+
+ const checkAndFillForm = () => {
+
+ const form = el_dialog.querySelector('form#wpsg_revocation_form');
+
+ if (!form) {
+
+ setTimeout(checkAndFillForm, 100);
+ return;
+
+ }
+
+ if (get_product_nr) {
+
+ const productNrInput = form.querySelector('input[name*="[product_nr]"]');
+
+ if (productNrInput) productNrInput.value = get_product_nr;
+
+ }
+
+ if (get_order_nr) {
+
+ const orderNrInput = form.querySelector('input[name*="[order_nr]"]');
+
+ if (orderNrInput) orderNrInput.value = get_order_nr;
+
+ }
+
+ if (get_amount) {
+
+ const amountInput = form.querySelector('input[name*="[amount]"]');
+
+ if (amountInput) amountInput.value = get_amount;
+
+ }
+
+ if (get_contact) {
+
+ const contactInput = form.querySelector('input[name="wpsg_revocation_reason[contact]"]');
+
+ if (contactInput) contactInput.value = get_contact;
+
+ }
+
+ };
+
+ checkAndFillForm();
+
+ });
+
+ }
+
+ // Layer Listener
+ el_dialog.addEventListener('click', event => {
+
+ if (!event.target.closest('.inner')) close_dialog(event);
+
+ });
+
+ // Produkte in Bestellung auf der Seite Listener
+ document.querySelectorAll('.wpsg_revocation_order_product')?.forEach(el => {
+
+ el.addEventListener('click', event => {
+
+ if (!event.target.closest('input[type="checkbox"]')) {
+
+ open_dialog(el);
+
+ }
+
+ });
+
+ });
+
+ // Close Button Listener
+ el_dialog.querySelectorAll('.close')?.forEach(el => {
+
+ el.addEventListener('click', event => { close_dialog(event); })
+
+ })
+
+ // Submit Button Listener
+ el_dialog.querySelectorAll('.wpsg_revocation_button_submit')?.forEach(el => {
+
+ el.addEventListener('click', event => { submit_dialog(event); });
+
+ })
+
+ // ESC Taste lauschen
+ document.addEventListener('keydown', function (e) {
+
+ if (e.key === 'Escape') {
+
+ el_dialog.classList.remove('visible');
+
+ }
+
+ });
+
+</script> \ No newline at end of file