PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 2.4.6
MxChat – AI Chatbot & Content Generation for WordPress v2.4.6
3.2.21 3.2.20 3.2.19 3.2.18 3.2.17 3.2.16 3.2.15 3.2.14 3.2.12 3.2.13 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 3.2.6 3.2.5 3.2.4 3.2.3 3.2.2 3.2.1 2.0.3 2.0.4 2.0.5 2.0.6 All 152 releases
← All changes | js/content-selector.js +108 -316 3.2.72.4.6 View file →
@@ -8,14 +8,8 @@
8 8 const $pagination = $('.mxchat-kb-pagination');
9 9 const $processButton = $('#mxchat-kb-process-selected');
10 10 const $selectAll = $('#mxchat-kb-select-all');
11 11 const $selectionCount = $('.mxchat-kb-selection-count');
12 - const $acfPdfExtractCheckbox = $('#mxchat-kb-acf-pdf-extract');
13 -
14 - // Restore last-used ACF→PDF extract preference from the server-localized default.
15 - if (typeof mxchatSelector !== 'undefined' && mxchatSelector.acfPdfExtractDefault) {
16 - $acfPdfExtractCheckbox.prop('checked', true);
17 - }
18 12
19 13 // Filter elements
20 14 const $searchInput = $('#mxchat-kb-content-search');1
21 15 const $typeFilter = $('#mxchat-kb-content-type-filter');
@@ -43,76 +37,53 @@
43 37 // Handle import option box clicks (for non-WordPress options)
44 38 $('.mxchat-import-box').on('click', function() {
45 39 const $box = $(this);
46 40 const option = $box.data('option');
47 -
41 +
48 42 // Skip if this is the WordPress option (it has its own handler)
49 43 if (option === 'wordpress') {
50 44 return;
51 45 }
52 -
46 +
53 47 // Update active state
54 48 $('.mxchat-import-box').removeClass('active');
55 49 $box.addClass('active');
56 -
50 +
57 51 // Hide all input areas
58 - $('#mxchat-url-input-area, #mxchat-content-input-area, #mxchat-pdf-upload-area').hide();
59 -
60 - // Hide sitemap-specific sections (but NOT for sitemap option - let detection logic handle it)
61 - if (option !== 'sitemap') {
62 - $('#mxchat-detected-sitemaps, #mxchat-no-sitemaps, #mxchat-sitemaps-loading').hide();
63 - }
64 -
52 + $('#mxchat-url-input-area, #mxchat-content-input-area').hide();
53 +
65 54 // Handle different import options
66 55 switch (option) {
67 - case 'pdf-url':
56 + case 'pdf':
68 57 case 'sitemap':
69 58 case 'url':
70 59 // Show URL input area with appropriate placeholder
71 60 $('#mxchat-url-input-area').show();
72 61 $('#sitemap_url').attr('placeholder', $box.data('placeholder'));
73 - $('#import_type').val(option === 'pdf-url' ? 'pdf' : option);
74 -
62 + $('#import_type').val(option);
63 +
75 64 // UPDATED: Add or update bot_id hidden field for URL forms
76 65 updateBotIdInForm('#mxchat-url-form');
77 -
66 +
78 67 // Update the description text based on the import type
79 68 let descriptionText = '';
80 - if (option === 'pdf-url') {
69 + if (option === 'pdf') {
81 70 descriptionText = 'Import a PDF document by entering its URL above. PDFs are processed via cron job. If processing does not start, you can manually process batch 5 pages at a time.';
82 71 } else if (option === 'sitemap') {
83 72 descriptionText = 'Enter a content-specific sub-sitemap URL, not the sitemap index. Sitemaps are processed via cron job. If processing does not start, you can manually process batch 5 pages at a time.';
84 - // Re-show sitemap sections if they were previously loaded
85 - const $sitemapsList = $('#mxchat-sitemaps-list');
86 - if ($sitemapsList.children().length > 0) {
87 - // Sitemaps were already loaded, just show the container
88 - $('#mxchat-detected-sitemaps').show();
89 - } else if ($('#mxchat-no-sitemaps').data('was-shown')) {
90 - // No sitemaps message was shown before
91 - $('#mxchat-no-sitemaps').show();
92 - }
93 - // Note: If neither condition is true, initSitemapDetection will show loading state
94 73 } else if (option === 'url') {
95 74 descriptionText = 'Import content from any webpage by entering its URL.';
96 75 }
97 76 $('#url-description-text').text(descriptionText);
98 77 break;
99 -
78 +
100 79 case 'content':
101 80 // Show content input area
102 81 $('#mxchat-content-input-area').show();
103 -
82 +
104 83 // UPDATED: Add or update bot_id hidden field for content forms
105 84 updateBotIdInForm('#mxchat-content-form');
106 85 break;
107 -
108 - case 'pdf-upload':
109 - // Show PDF file upload area
110 - $('#mxchat-pdf-upload-area').show();
111 -
112 - // Add or update bot_id hidden field for PDF upload form
113 - updateBotIdInForm('#mxchat-pdf-upload-form');
114 - break;
115 86 }
116 87 });
117 88
118 89 // Helper function to add/update bot_id hidden field in forms
@@ -146,9 +117,9 @@
146 117 const data = {
147 118 action: 'mxchat_get_content_list',
148 119 nonce: mxchatSelector.nonce,
149 120 page: currentPage,
150 - per_page: 100,
121 + per_page: 50,
151 122 search: $searchInput.val(),
152 123 post_type: $typeFilter.val(),
153 124 post_status: $statusFilter.val(),
154 125 processed_filter: $processedFilter.val()
@@ -213,22 +184,18 @@
213 184
214 185 // Render content items
215 186 function renderContentItems(items) {
216 187 let html = '';
217 -
188 +
218 189 items.forEach(function(item) {
219 190 const isSelected = selectedItems.has(item.id);
220 191 const isProcessed = item.already_processed;
221 - const chunkCount = item.chunk_count || 0;
222 -
223 - // Updated badge text - include chunk count if > 1
224 - let badgeText = 'Not In Knowledge Base';
225 - if (isProcessed) {
226 - badgeText = chunkCount > 1 ? `In Knowledge Base (${chunkCount} chunks)` : 'In Knowledge Base';
227 - }
192 +
193 + // Updated badge text
194 + const badgeText = isProcessed ? 'In Knowledge Base' : 'Not In Knowledge Base';
228 195 const badgeClass = isProcessed ? 'mxchat-kb-processed-badge' : 'mxchat-kb-unprocessed-badge';
229 -
230 -
196 +
197 +
231 198 html += `
232 199 <div class="mxchat-kb-content-item ${isProcessed ? 'processed' : ''}" data-id="${item.id}">
233 200 <div class="mxchat-kb-content-checkbox">
234 201 <input type="checkbox" id="content-${item.id}" ${isSelected ? 'checked' : ''}>
@@ -248,9 +215,9 @@
248 215 </div>
249 216 </div>
250 217 `;
251 218 });
252 -
219 +
253 220 $contentList.html(html);
254 221
255 222 // Add event listeners for checkboxes using delegation for better performance
256 223 $contentList.off('change', 'input[type="checkbox"]').on('change', 'input[type="checkbox"]', function() {
@@ -323,36 +290,18 @@
323 290 function updateSelection() {
324 291 const selectedCount = selectedItems.size;
325 292 $selectionCount.text(selectedCount + ' ' + (selectedCount === 1 ? 'selected' : 'selected'));
326 293 $('.mxchat-kb-selected-count').text('(' + selectedCount + ')');
327 -
328 - // Show/hide clear all selections link
329 - let $clearAllLink = $('.mxchat-kb-clear-all-selections');
330 - if (selectedCount > 0) {
331 - if ($clearAllLink.length === 0) {
332 - $clearAllLink = $('<a href="#" class="mxchat-kb-clear-all-selections" style="margin-left: 10px; font-size: 12px; color: var(--mxch-error, #dc2626);">Clear all</a>');
333 - $selectionCount.after($clearAllLink);
334 - $clearAllLink.on('click', function(e) {
335 - e.preventDefault();
336 - selectedItems.clear();
337 - $('.mxchat-kb-content-item input[type="checkbox"]').prop('checked', false);
338 - updateSelection();
339 - });
340 - }
341 - $clearAllLink.show();
342 - } else {
343 - $clearAllLink.hide();
344 - }
345 -
294 +
346 295 // Determine if any selected items are already processed
347 296 const hasProcessedItems = Array.from(selectedItems).some(id => {
348 297 const item = allItems.find(item => item.id === id);
349 298 return item && item.already_processed;
350 299 });
351 -
300 +
352 301 if (selectedCount > 0) {
353 302 $processButton.prop('disabled', false);
354 -
303 +
355 304 // Update button text based on selection
356 305 if (hasProcessedItems && selectedCount === 1) {
357 306 $processButton.text('Update Selected Content (1)').addClass('update-mode');
358 307 } else if (hasProcessedItems && selectedCount > 1) {
@@ -364,9 +313,9 @@
364 313 $processButton.prop('disabled', true);
365 314 $processButton.text('Process Selected Content').removeClass('update-mode mixed-mode');
366 315 $('.mxchat-kb-selected-count').text('(0)');
367 316 }
368 -
317 +
369 318 updateSelectAllState();
370 319 }
371 320
372 321 // Update "Select All" checkbox state
@@ -454,13 +403,9 @@
454 403
455 404 // UPDATED: Get current bot_id for WordPress content processing
456 405 const currentBotId = $('#mxchat-bot-selector').val();
457 406
458 - // Flag to track if processing should be aborted
459 - let abortProcessing = false;
460 - let currentXHR = null;
461 -
462 - // Create a modal to show progress with stop button
407 + // Create a modal to show progress
463 408 const $progressModal = $('<div class="mxchat-kb-processing-overlay">' +
464 409 '<div class="mxchat-kb-processing-content">' +
465 410 '<h3>Processing Content</h3>' +
466 411 '<p class="mxchat-kb-processing-status">Processing 1 of ' + totalToProcess + '...</p>' +
@@ -465,65 +410,46 @@
465 410 '<h3>Processing Content</h3>' +
466 411 '<p class="mxchat-kb-processing-status">Processing 1 of ' + totalToProcess + '...</p>' +
467 412 '<div class="mxchat-kb-progress-bar"><div class="mxchat-kb-progress-fill" style="width: 0%"></div></div>' +
468 413 '<p class="mxchat-kb-current-item"></p>' +
469 - '<button type="button" class="mxchat-kb-stop-processing mxch-btn mxch-btn-secondary" style="margin-top: 15px;">' +
470 - '<span class="dashicons dashicons-controls-pause" style="margin-right: 5px;"></span>Stop Processing</button>' +
471 414 '</div>' +
472 415 '</div>');
473 -
416 +
474 417 $('body').append($progressModal);
475 -
476 - // Handle stop button click
477 - $progressModal.find('.mxchat-kb-stop-processing').on('click', function() {
478 - abortProcessing = true;
479 - $(this).prop('disabled', true).html('<span class="dashicons dashicons-update spin" style="margin-right: 5px;"></span>Stopping...');
480 - if (currentXHR) {
481 - currentXHR.abort();
482 - }
483 - });
484 418
485 419 // Process posts one by one
486 420 function processNext(index) {
487 - // Check if processing was aborted
488 - if (abortProcessing) {
489 - finishProcessing(true); // Pass true to indicate abort
490 - return;
491 - }
492 -
493 421 if (index >= selectedPostIds.length) {
494 422 // All done
495 423 finishProcessing();
496 424 return;
497 425 }
498 -
426 +
499 427 const postId = selectedPostIds[index];
500 428 const percent = Math.round((index / totalToProcess) * 100);
501 429 const item = allItems.find(item => item.id === postId);
502 430 const isUpdate = item && item.already_processed;
503 -
431 +
504 432 // Update progress UI
505 433 $progressModal.find('.mxchat-kb-processing-status')
506 434 .text((isUpdate ? 'Updating' : 'Processing') + ' ' + (index + 1) + ' of ' + totalToProcess + '...');
507 435 $progressModal.find('.mxchat-kb-progress-fill').css('width', percent + '%');
508 -
436 +
509 437 // UPDATED: Prepare AJAX data with bot_id
510 - const extractAcfPdfs = $acfPdfExtractCheckbox.prop('checked') ? 1 : 0;
511 438 const ajaxData = {
512 439 action: 'mxchat_process_selected_content',
513 440 nonce: mxchatSelector.nonce,
514 441 post_ids: [postId],
515 - is_update: isUpdate,
516 - extract_acf_pdfs: extractAcfPdfs
442 + is_update: isUpdate
517 443 };
518 -
444 +
519 445 // Add bot_id if multi-bot is active and not default
520 446 if (currentBotId && currentBotId !== 'default') {
521 447 ajaxData.bot_id = currentBotId;
522 448 }
523 -
524 - // Make AJAX request for this post (store reference for potential abort)
525 - currentXHR = $.ajax({
449 +
450 + // Make AJAX request for this post
451 + $.ajax({
526 452 url: mxchatSelector.ajaxurl,
527 453 method: 'POST',
528 454 data: ajaxData,
529 455 dataType: 'json',
@@ -542,15 +468,10 @@
542 468 title: response.data.title || ('ID: ' + postId)
543 469 });
544 470 }
545 471
546 - let successText = 'Successfully ' + (isUpdate ? 'updated' : 'processed') + ': ' + response.data.title;
547 - const pdfCount = parseInt(response.data.pdf_extracted_count, 10) || 0;
548 - if (pdfCount > 0) {
549 - const suffixTpl = (mxchatSelector.i18n && mxchatSelector.i18n.pdfExtractedSuffix) || ' (%d PDF(s) extracted)';
550 - successText += suffixTpl.replace('%d', pdfCount);
551 - }
552 - $progressModal.find('.mxchat-kb-current-item').text(successText);
472 + $progressModal.find('.mxchat-kb-current-item')
473 + .text('Successfully ' + (isUpdate ? 'updated' : 'processed') + ': ' + response.data.title);
553 474 } else {
554 475 failed++;
555 476 results.failed.push({
556 477 id: postId,
@@ -584,32 +505,23 @@
584 505 });
585 506 }
586 507
587 508 // Function to finish processing and show results
588 - function finishProcessing(wasAborted) {
509 + function finishProcessing() {
589 510 // Remove progress modal
590 511 $progressModal.remove();
591 -
512 +
592 513 // Determine notification type based on results
593 514 let notificationClass = 'success';
594 - if (wasAborted) {
595 - notificationClass = processed > 0 || updated > 0 ? 'warning' : 'info';
596 - } else if (failed > 0) {
515 + if (failed > 0) {
597 516 notificationClass = processed > 0 || updated > 0 ? 'warning' : 'error';
598 517 }
599 -
518 +
600 519 // Create summary message
601 - let resultHTML = '<div class="mxchat-kb-notification ' + notificationClass + '">' +
520 + let resultHTML = '<div class="mxchat-kb-notification ' + notificationClass + '">' +
602 521 '<h4>';
603 -
604 - if (wasAborted) {
605 - resultHTML += 'Processing stopped. ';
606 - if (processed > 0 || updated > 0) {
607 - resultHTML += 'Completed ' + (processed + updated) + ' of ' + totalToProcess + ' items before stopping';
608 - } else {
609 - resultHTML += 'No items were processed before stopping';
610 - }
611 - } else if (processed > 0 && updated > 0) {
522 +
523 + if (processed > 0 && updated > 0) {
612 524 resultHTML += 'Processed ' + processed + ' new items and updated ' + updated + ' existing items';
613 525 } else if (processed > 0) {
614 526 resultHTML += 'Processed ' + processed + ' items successfully';
615 527 } else if (updated > 0) {
@@ -616,10 +528,10 @@
616 528 resultHTML += 'Updated ' + updated + ' items successfully';
617 529 } else {
618 530 resultHTML += 'No items were processed successfully';
619 531 }
620 -
621 - if (failed > 0 && !wasAborted) {
532 +
533 + if (failed > 0) {
622 534 resultHTML += ' with ' + failed + ' failures';
623 535 }
624 536
625 537 resultHTML += '</h4>';
@@ -649,20 +561,21 @@
649 561 $button.prop('disabled', false)
650 562 .text('Process Selected Content')
651 563 .removeClass('update-mode mixed-mode');
652 564 $('.mxchat-kb-selected-count').text('(0)');
653 -
565 +
654 566 // Only reload if there were successful operations
655 567 if (processed > 0 || updated > 0) {
656 - // Refresh the knowledge base table with properly grouped entries
657 - if (typeof window.refreshKnowledgeBaseTable === 'function') {
658 - window.refreshKnowledgeBaseTable();
659 - }
660 -
661 - // Reload content list to update "already processed" status
568 + // Reload after delay
662 569 setTimeout(function() {
663 - loadContent();
664 - }, 1000);
570 + // Reload the knowledge base table - if this function exists
571 + if (typeof reloadKnowledgeBaseTable === 'function') {
572 + reloadKnowledgeBaseTable();
573 + } else {
574 + // Fallback: reload content list instead of full page reload
575 + loadContent();
576 + }
577 + }, 3000);
665 578 }
666 579 }
667 580
668 581 // Start processing the first post
@@ -672,150 +585,91 @@
672 585 // Initialize - Set WordPress as the active option by default
673 586 $('.mxchat-import-box[data-option="wordpress"]').addClass('active');
674 587 });
675 588
676 -// Navigation functionality for Knowledge Base page
589 +// Tab switching functionality - Keep this separate
677 590 jQuery(document).ready(function($) {
678 -
679 - // Hook into the new navigation system using .mxch-nav-link
680 - $(document).on('click', '.mxch-nav-link[data-target], .mxch-mobile-nav-link[data-target]', function() {
681 - var target = $(this).data('target');
682 -
683 - // Initialize Pinecone functionality when Pinecone section is activated
684 - if (target === 'pinecone') {
685 - setTimeout(function() {
686 - if (typeof initPineconeFeatures === 'function') {
687 - initPineconeFeatures();
688 - }
689 - }, 100);
591 +
592 +// Tab switching functionality
593 +// Modified tab switching to check for Pinecone changes
594 +$('.mxchat-kb-tab-button').on('click', function() {
595 + var tabId = $(this).data('tab');
596 + var $button = $(this);
597 +
598 + // Switch tabs immediately for all tabs
599 + $('.mxchat-kb-tab-button').removeClass('active');
600 + $('.mxchat-kb-tab-content').removeClass('active');
601 + $button.addClass('active');
602 + $('#mxchat-kb-tab-' + tabId).addClass('active');
603 +
604 + // Check if Pinecone was changed and we're going to import tab
605 + if (tabId === 'import' && sessionStorage.getItem('mxchat_pinecone_changed') === 'true') {
606 + sessionStorage.removeItem('mxchat_pinecone_changed');
607 +
608 + // Show refresh notice
609 + var $knowledgeCard = $('#mxchat-kb-tab-import .mxchat-card').eq(1);
610 + if ($knowledgeCard.length > 0 && $knowledgeCard.find('.notice-warning').length === 0) {
611 + var refreshNotice = $('<div class="notice notice-warning" style="margin: 15px 0; padding: 10px 15px;">' +
612 + '<p style="margin: 0;">' +
613 + '<span class="dashicons dashicons-info" style="color: #f0ad4e; margin-right: 5px;"></span>' +
614 + 'Database settings have changed. ' +
615 + '<a href="#" onclick="location.reload(); return false;" style="font-weight: bold;">Click here to refresh</a> to see the updated knowledge base.' +
616 + '</p></div>');
617 +
618 + $knowledgeCard.prepend(refreshNotice);
690 619 }
691 -
692 - // Initialize OpenAI Vector Store functionality when Vector Store section is activated
693 - if (target === 'openai-vectorstore') {
694 - setTimeout(function() {
695 - if (typeof initVectorStoreFeatures === 'function') {
696 - initVectorStoreFeatures();
697 - }
698 - }, 100);
699 - }
700 -
701 - // Check if Pinecone was changed and we're going to import section
702 - if (target === 'import' && sessionStorage.getItem('mxchat_pinecone_changed') === 'true') {
703 - sessionStorage.removeItem('mxchat_pinecone_changed');
704 -
705 - // Show refresh notice
706 - var $knowledgeCard = $('#import .mxch-card').eq(1);
707 - if ($knowledgeCard.length > 0 && $knowledgeCard.find('.notice-warning').length === 0) {
708 - var refreshNotice = $('<div class="notice notice-warning" style="margin: 15px 0; padding: 10px 15px;">' +
709 - '<p style="margin: 0;">' +
710 - '<span class="dashicons dashicons-info" style="color: #f0ad4e; margin-right: 5px;"></span>' +
711 - 'Database settings have changed. ' +
712 - '<a href="#" onclick="location.reload(); return false;" style="font-weight: bold;">Click here to refresh</a> to see the updated knowledge base.' +
713 - '</p></div>');
714 -
715 - $knowledgeCard.prepend(refreshNotice);
716 - }
717 - }
718 - });
719 -
720 - // Also check on page load if we're already on one of these sections
721 - setTimeout(function() {
722 - if ($('#pinecone').is(':visible') || $('#pinecone.active').length > 0) {
723 - if (typeof initPineconeFeatures === 'function') {
724 - initPineconeFeatures();
725 - }
726 - }
727 -
728 - if ($('#openai-vectorstore').is(':visible') || $('#openai-vectorstore.active').length > 0) {
729 - if (typeof initVectorStoreFeatures === 'function') {
730 - initVectorStoreFeatures();
731 - }
732 - }
733 - }, 200);
620 + }
621 +
622 + // Initialize Pinecone functionality when Pinecone tab is activated
623 + if (tabId === 'pinecone') {
624 + setTimeout(function() {
625 + initPineconeFeatures();
626 + }, 100);
627 + }
734 628 });
735 629
736 -// Pinecone and Vector Store functionality - global functions
737 -var initPineconeFeatures, initVectorStoreFeatures;
738 630
739 -(function($) {
740 -
741 - // Helper function to update sidebar badge when integration is toggled
742 - function updateSidebarBadge(section, isActive) {
743 - // Find the nav item for this section (both desktop and mobile)
744 - var $desktopNavItem = $('.mxch-nav-item[data-section="' + section + '"] .mxch-nav-link');
745 - var $mobileNavItem = $('.mxch-mobile-nav-link[data-target="' + section + '"]');
746 -
747 - // Remove existing badge if any
748 - $desktopNavItem.find('.mxch-active-badge').remove();
749 - $mobileNavItem.find('.mxch-active-badge').remove();
750 -
751 - // Add badge if active
752 - if (isActive) {
753 - var badgeHtml = '<span class="mxch-nav-link-badge mxch-active-badge">Active</span>';
754 - $desktopNavItem.append(badgeHtml);
755 - $mobileNavItem.append(badgeHtml);
756 - }
757 - }
758 -
759 631 // Pinecone functionality
760 - initPineconeFeatures = function() {
761 - // Check for either old or new section ID
762 - if ($('#pinecone').length === 0 && $('#mxchat-kb-tab-pinecone').length === 0) {
632 + function initPineconeFeatures() {
633 + //console.log('Initializing Pinecone features...');
634 +
635 + if ($('#mxchat-kb-tab-pinecone').length === 0) {
763 636 return;
764 637 }
765 -
638 +
766 639 initPineconeToggle();
767 640 initPineconeConnectionTest();
768 641 checkPineconeCompatibility();
769 - };
770 -
642 + }
643 +
771 644 function initPineconeToggle() {
772 645 // Remove any existing handlers to prevent duplicates
773 - var $toggleInput = $('input[name="mxchat_pinecone_addon_options[mxchat_use_pinecone]"]');
774 - $toggleInput.off('change.pineconeToggle');
775 -
776 - // Ensure the success notice exists in the settings div (add if not present)
777 - // Check for both the JS-added class and any existing PHP-rendered success notice
778 - var settingsDiv = $('.mxchat-pinecone-settings');
779 - if (settingsDiv.length > 0 && settingsDiv.find('.mxch-notice-success').length === 0) {
780 - var successNotice = $('<div class="mxch-notice mxch-notice-success mxchat-pinecone-enabled-notice" style="margin-bottom: 20px; display: none;">' +
781 - '<svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>' +
782 - '<span>Pinecone is enabled. All new knowledge base content will be stored in Pinecone.</span>' +
783 - '</div>');
784 - settingsDiv.prepend(successNotice);
785 - }
786 -
646 + $('input[name="mxchat_pinecone_addon_options[mxchat_use_pinecone]"]').off('change.pineconeToggle');
647 +
787 648 // Add the toggle handler for UI only (auto-save will handle the actual saving)
788 - $toggleInput.on('change.pineconeToggle', function() {
649 + $('input[name="mxchat_pinecone_addon_options[mxchat_use_pinecone]"]').on('change.pineconeToggle', function() {
789 650 var $checkbox = $(this);
790 651 var isChecked = $checkbox.is(':checked');
791 652 var settingsDiv = $('.mxchat-pinecone-settings');
792 - var enabledNotice = settingsDiv.find('.mxchat-pinecone-enabled-notice, .mxch-notice-success');
793 -
653 +
654 + //console.log('Pinecone toggle changed to:', isChecked);
655 +
794 656 // Update the UI immediately
795 657 if (isChecked) {
796 658 settingsDiv.slideDown(300);
797 - enabledNotice.slideDown(300);
798 659 } else {
799 - enabledNotice.slideUp(300);
800 660 settingsDiv.slideUp(300);
801 661 }
802 -
803 - // Update sidebar badge for Pinecone
804 - updateSidebarBadge('pinecone', isChecked);
805 662 });
806 -
663 +
807 664 // Set initial state based on current checkbox value
808 665 var currentToggle = $('input[name="mxchat_pinecone_addon_options[mxchat_use_pinecone]"]');
809 666 if (currentToggle.length > 0) {
810 667 var settingsDiv = $('.mxchat-pinecone-settings');
811 - var enabledNotice = settingsDiv.find('.mxchat-pinecone-enabled-notice, .mxch-notice-success');
812 668 if (currentToggle.is(':checked')) {
813 669 settingsDiv.show();
814 - enabledNotice.show();
815 670 } else {
816 671 settingsDiv.hide();
817 - enabledNotice.hide();
818 672 }
819 673 }
820 674 }
821 675
@@ -912,68 +766,6 @@
912 766 }
913 767 });
914 768 }
915 769 }
916 -
917 - // ============================================
918 - // OpenAI Vector Store functionality
919 - // ============================================
920 - initVectorStoreFeatures = function() {
921 - if ($('#openai-vectorstore').length === 0) {
922 - return;
923 - }
924 -
925 - initVectorStoreToggle();
926 - };
927 -
928 - function initVectorStoreToggle() {
929 - // Remove any existing handlers to prevent duplicates
930 - var $toggleInput = $('input[name="mxchat_openai_vectorstore_options[mxchat_use_openai_vectorstore]"]');
931 - $toggleInput.off('change.vectorstoreToggle');
932 -
933 - // Ensure the success notice exists in the settings div (add if not present)
934 - // Check for both the JS-added class and any existing PHP-rendered success notice
935 - var settingsDiv = $('.mxchat-vectorstore-settings');
936 - if (settingsDiv.length > 0 && settingsDiv.find('.mxch-notice-success').length === 0) {
937 - var successNotice = $('<div class="mxch-notice mxch-notice-success mxchat-vectorstore-enabled-notice" style="margin-bottom: 20px; display: none;">' +
938 - '<svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>' +
939 - '<span>OpenAI Vector Store is enabled. Queries will search your Vector Store for relevant content.</span>' +
940 - '</div>');
941 - settingsDiv.prepend(successNotice);
942 - }
943 -
944 - // Add the toggle handler for UI only (form submit will handle the actual saving)
945 - $toggleInput.on('change.vectorstoreToggle', function() {
946 - var $checkbox = $(this);
947 - var isChecked = $checkbox.is(':checked');
948 - var settingsDiv = $('.mxchat-vectorstore-settings');
949 - var enabledNotice = settingsDiv.find('.mxchat-vectorstore-enabled-notice, .mxch-notice-success');
950 -
951 - // Update the UI immediately
952 - if (isChecked) {
953 - settingsDiv.slideDown(300);
954 - enabledNotice.slideDown(300);
955 - } else {
956 - enabledNotice.slideUp(300);
957 - settingsDiv.slideUp(300);
958 - }
959 -
960 - // Update sidebar badge for OpenAI Vector Store
961 - updateSidebarBadge('openai-vectorstore', isChecked);
962 - });
963 -
964 - // Set initial state based on current checkbox value
965 - var currentToggle = $('input[name="mxchat_openai_vectorstore_options[mxchat_use_openai_vectorstore]"]');
966 - if (currentToggle.length > 0) {
967 - var settingsDiv = $('.mxchat-vectorstore-settings');
968 - var enabledNotice = settingsDiv.find('.mxchat-vectorstore-enabled-notice, .mxch-notice-success');
969 - if (currentToggle.is(':checked')) {
970 - settingsDiv.show();
971 - enabledNotice.show();
972 - } else {
973 - settingsDiv.hide();
974 - enabledNotice.hide();
975 - }
976 - }
977 - }
978 -
979 -})(jQuery);
770 +
771 +});