/** * HVAC REST API Event Submission System * Achieves 100% field control by bypassing TEC Community Events limitations * Uses TEC REST API to submit events with ALL WordPress fields including excerpt */ (function($) { 'use strict'; const HVACRestEventSubmission = { // REST API endpoints apiEndpoint: '/wp-json/tribe/events/v1/events', eventId: null, // Will be set if editing /** * Initialize the REST API submission system */ init: function() { console.log('[HVAC REST] Initializing REST API Event Submission System'); // Check if we're in edit mode if (window.hvacEditEventId) { this.eventId = window.hvacEditEventId; console.log('[HVAC REST] Edit mode - Event ID:', this.eventId); } // Enhance existing form or create new submission handler this.attachSubmitHandler(); this.enhanceFormFields(); // If editing, load existing excerpt if (this.eventId) { this.loadExistingExcerpt(); } }, /** * Enhance form with additional fields not supported by TEC frontend */ enhanceFormFields: function() { // Add excerpt field if not present if (!$('#event_excerpt').length && $('#tribe-community-events').length) { const excerptHTML = `

Event Summary

Brief summary for search results and previews (excerpt)

`; // Insert after description section $('.tribe-section-content').first().parent().after(excerptHTML); console.log('[HVAC REST] Added excerpt field to form'); } }, /** * Initialize form enhancement without overriding TEC submission * * Uses WordPress filter hooks for TEC integration instead of JavaScript overrides. * This prevents "Security check failed" errors by maintaining TEC's native security flow. */ attachSubmitHandler: function() { console.log('[HVAC REST] TEC form enhancement initialized - using WordPress filter hooks for integration'); // Enhance form with additional UI improvements without intercepting submission this.enhanceFormUI(); }, /** * Enhance form UI without intercepting submission * * Provides visual feedback and validation while preserving TEC native functionality */ enhanceFormUI: function() { const $form = $('#tribe-community-events form'); if (!$form.length) { console.log('[HVAC REST] TEC form not found for UI enhancement'); return; } // Add visual feedback for form submission (without prevention) $form.on('submit', function() { console.log('[HVAC REST] Form submitted - TEC handling natively with WordPress filters'); }); // Enhance excerpt field if present const $excerptField = $form.find('[name="excerpt"]'); if ($excerptField.length) { $excerptField.attr('placeholder', 'Brief event description...'); } // Add form validation helpers (non-blocking) this.addFormValidationHelpers($form); }, /** * Add non-blocking form validation helpers */ addFormValidationHelpers: function($form) { // Add visual feedback for required fields $form.find('input[required], textarea[required]').on('blur', function() { const $field = $(this); if (!$field.val().trim()) { $field.addClass('hvac-field-warning'); } else { $field.removeClass('hvac-field-warning'); } }); // Add CSS for validation styling if (!$('style#hvac-form-validation').length) { $('