# mxchat-basic/1.4/js/mxchat-admin.js

MxChat – AI Chatbot &amp; Content Generation for WordPress, version 1.4. 222 lines.

- Page: https://pluginprobe.com/plugins/mxchat-basic/1.4/code/js/mxchat-admin.js
- Raw: https://pluginprobe.com/plugins/mxchat-basic/1.4/raw/js/mxchat-admin.js
- Modified: 2024-11-13T02:46:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/mxchat-basic/1.4/code/js/mxchat-admin.js#L10-L20`.

```javascript
jQuery(document).ready(function($) {

    $('.mxchat-nav-tab').on('click', function(e) {
        e.preventDefault();
        $('.mxchat-nav-tab').removeClass('mxchat-nav-tab-active');
        $(this).addClass('mxchat-nav-tab-active');
        $('.mxchat-tab-content').removeClass('active').hide();
        var activeTab = $(this).attr('href');
        $(activeTab).addClass('active').show();
    });

    // Activate the first tab by default
    $('.mxchat-nav-tab-active').trigger('click');

    // Toggle visibility of API key
    $('#toggleApiKeyVisibility').on('click', function() {
        var apiKeyInput = $('#api_key');
        if (apiKeyInput.attr('type') === 'password') {
            apiKeyInput.attr('type', 'text');
            $(this).text('Hide');
        } else {
            apiKeyInput.attr('type', 'password');
            $(this).text('Show');
        }
    });
    
    // Toggle visibility of WooCommerce Consumer Secret
    $('#toggleWooCommerceSecretVisibility').on('click', function() {
        var secretInput = $('#woocommerce_consumer_secret');
        if (secretInput.attr('type') === 'password') {
            secretInput.attr('type', 'text');
            $(this).text('Hide');
        } else {
            secretInput.attr('type', 'password');
            $(this).text('Show');
        }
    });
    
    // Toggle visibility of Loops API Key
    $('#toggleLoopsApiKeyVisibility').on('click', function() {
        var loopsApiKeyInput = $('#loops_api_key');
        if (loopsApiKeyInput.attr('type') === 'password') {
            loopsApiKeyInput.attr('type', 'text');
            $(this).text('Hide');
        } else {
            loopsApiKeyInput.attr('type', 'password');
            $(this).text('Show');
        }
    });
    
    // Toggle visibility of X.AI API Key
    $('#toggleXaiApiKeyVisibility').on('click', function() {
        var xaiApiKeyInput = $('#xai_api_key');
        if (xaiApiKeyInput.attr('type') === 'password') {
            xaiApiKeyInput.attr('type', 'text');
            $(this).text('Hide');
        } else {
            xaiApiKeyInput.attr('type', 'password');
            $(this).text('Show');
        }
    });
    
        // Toggle visibility of Claude API Key
    $('#toggleClaudeApiKeyVisibility').on('click', function() {
        var claudeApiKeyInput = $('#claude_api_key');
        if (claudeApiKeyInput.attr('type') === 'password') {
            claudeApiKeyInput.attr('type', 'text');
            $(this).text('Hide');
        } else {
            claudeApiKeyInput.attr('type', 'password');
            $(this).text('Show');
        }
    });
    
    // Toggle visibility of Brave API Key
    $('#toggleBraveApiKeyVisibility').on('click', function() {
        var braveApiKeyInput = $('#brave_api_key');
        if (braveApiKeyInput.attr('type') === 'password') {
            braveApiKeyInput.attr('type', 'text');
            $(this).text('Hide');
        } else {
            braveApiKeyInput.attr('type', 'password');
            $(this).text('Show');
        }
    });
        
    
const $addIntentButton = $('button[name="mxchat_add_intent"]');

    // Handle the Add Intent form submission
    $('form').on('submit', function(event) {
        if ($addIntentButton.length) {
            // Show loading spinner and text, hide the add intent button on form submission
            $('#mxchat-intent-loading').show();
            $('#mxchat-loading-text-intent').show();
            $addIntentButton.hide();
        }
    });

    // Hide loader and show Add Intent button after form submission completes
    $(document).ajaxComplete(function(event, xhr, settings) {
        if (settings.url.includes('admin-post.php')) {
            $('#mxchat-intent-loading').hide();
            $('#mxchat-loading-text-intent').hide();
            $addIntentButton.show();
        }
    });
    
      // Click the Edit button
    $('.edit-button').on('click', function() {
        var row = $(this).closest('tr');
        row.find('.content-view, .url-view').hide();
        row.find('.content-edit, .url-edit').show();
        row.find('.edit-button').hide();
        row.find('.save-button').show();
    });

    // Click the Save button
    $('.save-button').on('click', function() {
        var button = $(this);
        var row = button.closest('tr');
        var id = button.data('id');
        var newContent = row.find('.content-edit').val();
        var newUrl = row.find('.url-edit').val();

        // Send an AJAX request to save the changes
        $.ajax({
            url: ajaxurl, // ajaxurl is automatically available in WP admin
            type: 'POST',
            data: {
                action: 'mxchat_save_inline_prompt',
                id: id,
                article_content: newContent,
                article_url: newUrl,
                _ajax_nonce: mxchatInlineEdit.nonce // Use localized nonce
            },
            success: function(response) {
                if (response.success) {
                    row.find('.content-view').html(newContent.replace(/\n/g, "<br>"));
                    row.find('.url-view a').attr('href', newUrl).text(newUrl);
                    row.find('.content-edit, .url-edit').hide();
                    row.find('.content-view, .url-view').show();
                    row.find('.save-button').hide();
                    row.find('.edit-button').show();
                } else {
                    alert('Error saving content.');
                }
            },
            error: function() {
                alert('An error occurred.');
            }
        });
    });
    

});

jQuery(document).ready(function($) {
    console.log('Activation script loaded within mxchat-admin.js'); // Confirm script is loading

    // Select activation-related elements
    var form = $('#mxchat-activation-form');
    var spinner = $('#mxchat-activation-spinner');
    var submitButton = $('#activate_license_button');
    var licenseStatus = $('#mxchat-license-status');

    // Ensure essential elements exist
    if (form.length === 0 || licenseStatus.length === 0 || submitButton.length === 0) {
        console.error("Essential activation elements are missing from the page.");
        return;
    }

    // Function to handle the response from the activation AJAX request
    function handleActivationResponse(response) {
        spinner.hide(); // Hide the spinner

        if (response.success) {
            // Update UI on successful activation
            licenseStatus.text('Active');
            licenseStatus.removeClass('inactive').addClass('active');

            // Hide the activation form after successful activation
            form.hide();
        } else {
            licenseStatus.text('Inactive');
            alert(response.data || 'Activation failed. Please check your input.');
            submitButton.prop('disabled', false); // Re-enable button on failure
        }
    }

    // Event listener for form submission to activate the license
    form.on('submit', function(event) {
        event.preventDefault(); // Prevent the default form submission
        console.log("Activating license...");

        // Show spinner and disable the submit button to prevent multiple submissions
        spinner.show();
        submitButton.prop('disabled', true);

        // Gather form data
        var formData = {
            action: 'mxchat_activate_license',
            mxchat_pro_email: $('#mxchat_pro_email').val(),
            mxchat_activation_key: $('#mxchat_activation_key').val(),
            security: mxchatAdmin.nonce // Ensure this is localized in PHP
        };

        // Send the AJAX request using jQuery
        $.post(mxchatAdmin.ajax_url, formData, function(response) {
            console.log("Activation response received:", response);
            handleActivationResponse(response);
        }).fail(function() {
            alert('Server error. Please try again.');
            spinner.hide();
            submitButton.prop('disabled', false);
        });
    });
});




```
