Subversion Repositories wpShopGermany4

Rev

Rev 7934 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php

        declare(strict_types=1);

        /**
         * User: Daschmi (daschmi@daschmi.de)
         * Date: 03.08.2021
         * Time: 07:17
         */

        namespace wpsg;
        
        $arTemplateSelect = ['0' => __('Bitte auswählen', 'wpsg')];
        
        foreach ($this->view['arTemplates'] as $t) $arTemplateSelect[$t['filename']] = $t['name'];
        
?>

<fieldset id="wpsg_mod_kundenkontakt_layer" style="display:none;">
    <legend><?php echo __('Kundenkontakt', 'wpsg'); ?></legend>
    <div>
        
        <?php echo wpsg_drawForm_Select('wpsg_mod_kundenkontakt_template', __('Template', 'wpsg'), $arTemplateSelect, '0'); ?>
        <?php echo wpsg_drawForm_Input('wpsg_mod_kundenkontakt_subject', __('Betreff', 'wpsg'), '', ['wrap_id' => 'wpsg_mod_kundenkontakt_subject_wrap']); ?>
        <?php echo wpsg_drawForm_Textarea('wpsg_mod_kundenkontakt_text', __('Text', 'wpsg'), '', ['wrap_id' => 'wpsg_mod_kundenkontakt_text_wrap']); ?>
              
        <?php echo wpsg_drawForm_Button(__('Kunden informieren', 'wpsg'), '', ['wrap_id' => 'wpsg_mod_kundenkontakt_submit_wrap', 'field_id' => 'wpsg_mod_kundenkontakt_submit']); ?>
        
    </div>
</fieldset>

<script>
            
    let el_wpsg_mod_kundenkontakt_layer = document.getElementById('wpsg_mod_kundenkontakt_layer');
    
    let el_wpsg_mod_kundenkontakt_subject = document.getElementById('wpsg_mod_kundenkontakt_subject');
    let el_wpsg_mod_kundenkontakt_subject_wrap = document.getElementById('wpsg_mod_kundenkontakt_subject_wrap');
    
    let el_wpsg_mod_kundenkontakt_text = document.getElementById('wpsg_mod_kundenkontakt_text');
    let el_wpsg_mod_kundenkontakt_text_wrap = document.getElementById('wpsg_mod_kundenkontakt_text_wrap');
    
    let el_wpsg_mod_kundenkontakt_submit = document.getElementById('wpsg_mod_kundenkontakt_submit');
    let el_wpsg_mod_kundenkontakt_submit_wrap = document.getElementById('wpsg_mod_kundenkontakt_submit_wrap');
    
    let el_doaction = document.getElementById('doaction');
    
    document.getElementById('wpsg_mod_kundenkontakt_template').addEventListener('change', (event) => {
            
        if (event.target.value !== '0') {
                                
            jQuery.ajax({ 
                url: "<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Order&action=ajax&mod=wpsg_mod_kundenkontakt&noheader=1&do=kk_switchTemplate",
                dataType: 'json',
                data: {                                 
                    template_file: event.target.value
                },
                success: function(data) {
            
                        el_wpsg_mod_kundenkontakt_subject_wrap.style.display = 'block';
                        el_wpsg_mod_kundenkontakt_text_wrap.style.display = 'block';  
                        el_wpsg_mod_kundenkontakt_submit_wrap.style.display = 'block';  
                        
                    el_wpsg_mod_kundenkontakt_subject.value = data.subject;
                    el_wpsg_mod_kundenkontakt_text.value = data.content;
                    
                }
            });

            } else {
                                
                el_wpsg_mod_kundenkontakt_subject_wrap.style.display = 'none';
                el_wpsg_mod_kundenkontakt_text_wrap.style.display = 'none';
                el_wpsg_mod_kundenkontakt_submit_wrap.style.display = 'none';
                                
        }
        
    });
    
    el_wpsg_mod_kundenkontakt_submit.addEventListener('click', (event) => {
        
        event.preventDefault();
        
        let arOrderID = [];
        
        for (let el of document.querySelectorAll('.col_set_checkbox')) {
                
                if (el.checked) arOrderID.push(el.getAttribute('data-order_id'));
                
        }
                
        if (arOrderID.length <= 0) {
                
                alert('<?php echo __('Bitte mindestens eine Bestellung auswählen.', 'wpsg'); ?>');
                return;
        }       
        
        el_wpsg_mod_kundenkontakt_submit.setAttribute("disabled", "disabled");
        
        jQuery.ajax({ 
            url: "<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Order&action=ajax&mod=wpsg_mod_kundenkontakt&noheader=1&do=kk_sendMail",
            data: {                                     
                arOrderID: arOrderID,
                text: el_wpsg_mod_kundenkontakt_text.value,
                el_wpsg_mod_kundenkontakt_subject: el_wpsg_mod_kundenkontakt_subject.value
            },
            success: function(data) {
        
                el_wpsg_mod_kundenkontakt_submit.removeAttribute("disabled");
                
                alert(data);
                
            }
        });
        
    });
    
    document.getElementById('wpsg_action').addEventListener('change', (event) => {
        
        if (event.target.value === 'customercontact') {
            
                el_doaction.style.display = 'none';
            el_wpsg_mod_kundenkontakt_layer.style.display = 'block';
            
        } else {
        
                el_doaction.style.display = 'inline-block';
                el_wpsg_mod_kundenkontakt_layer.style.display = 'none';
                
        }
        
    });
    
</script>

<style>
    
    #wpsg_mod_kundenkontakt_text { height:300px; }
    #wpsg_mod_kundenkontakt_subject_wrap { display:none; }
    #wpsg_mod_kundenkontakt_text_wrap { display:none; }
    #wpsg_mod_kundenkontakt_submit_wrap { display:none; }
    
</style>