+
+
+ {% if messages %}
+ {% for message in messages %}
+
+ {{ message }}
+
+ {% endfor %}
+ {% endif %}
+
+
+
+
+
📢 Social Ads Generator
+
+
+
+
+
+
+
📢
+
Creating Social Ads...
+
Generating engaging ad content...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+{% endblock %}
+
+{% block extra_js %}
+
-
-
\ No newline at end of file
+ }
+
+ // Download social ads as text file
+ function downloadSocialAds() {
+ const adText = generateAdText();
+ const blob = new Blob([adText], { type: 'text/plain' });
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement('a');
+ a.href = url;
+ a.download = 'social-ads-' + Date.now() + '.txt';
+ a.click();
+ URL.revokeObjectURL(url);
+ showToast('💾 Social ads downloaded!', 'success');
+ }
+
+ // Generate ad text for copy/download
+ function generateAdText() {
+ const content = document.querySelector('#adContent');
+ if (content) {
+ return content.textContent || content.innerText || '';
+ }
+ return 'No ad content available';
+ }
+
+ // Reset form for creating another ad
+ function resetForm() {
+ document.getElementById('socialAdsForm').reset();
+ document.getElementById('adResults').style.display = 'none';
+ document.getElementById('processingStatus').style.display = 'none';
+ document.getElementById('processButton').disabled = false;
+ document.getElementById('processButton').innerHTML = '📢 Generate Social Ads (7.00 AED)';
+ showToast('Form reset! Ready for another ad campaign.', 'success');
+ }
+
+ // Simple toast notification
+ function showToast(message, type = 'info') {
+ const toast = document.createElement('div');
+ toast.style.cssText = `
+ position: fixed;
+ top: 20px;
+ right: 20px;
+ padding: 12px 20px;
+ border-radius: 8px;
+ color: white;
+ font-weight: 600;
+ z-index: 1000;
+ ${type === 'success' ? 'background: #10b981;' : 'background: #ef4444;'}
+ `;
+ toast.textContent = message;
+ document.body.appendChild(toast);
+
+ setTimeout(() => {
+ toast.remove();
+ }, 3000);
+ }
+
+ // Update wallet balance display
+ function updateWalletBalance(newBalance) {
+ const balanceElements = document.querySelectorAll('[data-wallet-balance]');
+ balanceElements.forEach(element => {
+ element.textContent = `${newBalance.toFixed(2)} AED`;
+ });
+ window.currentWalletBalance = newBalance;
+ }
+
+ // Display social ads results
+ function displayResults(result) {
+ const resultsContainer = document.getElementById('adResults');
+ const contentContainer = document.getElementById('adContent');
+
+ if (result.success && result.status === 'completed') {
+ contentContainer.textContent = result.content || result.ad_copy_content || result.output_text || 'Social ads generated successfully!';
+ resultsContainer.style.display = 'block';
+
+ // Update wallet balance if provided
+ if (result.wallet_balance !== undefined) {
+ updateWalletBalance(result.wallet_balance);
+ }
+
+ showToast('✅ Social ads created and payment processed!', 'success');
+ } else {
+ showToast('❌ Failed to generate ads - no charge applied', 'error');
+ }
+ }
+
+ // Poll for results
+ function pollForResults(requestId) {
+ let pollCount = 0;
+ const maxPolls = 30; // 30 seconds maximum
+
+ const pollInterval = setInterval(() => {
+ pollCount++;
+
+ fetch(`/agents/social-ads-generator/status/${requestId}/`)
+ .then(response => response.json())
+ .then(result => {
+ if (result.status === 'completed' || result.status === 'failed') {
+ clearInterval(pollInterval);
+ document.getElementById('processingStatus').style.display = 'none';
+ document.getElementById('processButton').disabled = false;
+ document.getElementById('processButton').innerHTML = '📢 Generate Social Ads (7.00 AED)';
+
+ displayResults(result);
+ } else if (pollCount >= maxPolls) {
+ clearInterval(pollInterval);
+ document.getElementById('processingStatus').style.display = 'none';
+ document.getElementById('processButton').disabled = false;
+ document.getElementById('processButton').innerHTML = '📢 Generate Social Ads (7.00 AED)';
+ showToast('❌ Processing timeout - please try again', 'error');
+ }
+ })
+ .catch(error => {
+ console.error('Error polling results:', error);
+ if (pollCount >= maxPolls) {
+ clearInterval(pollInterval);
+ document.getElementById('processingStatus').style.display = 'none';
+ document.getElementById('processButton').disabled = false;
+ document.getElementById('processButton').innerHTML = '📢 Generate Social Ads (7.00 AED)';
+ showToast('❌ Network error - please try again', 'error');
+ }
+ });
+ }, 1000);
+ }
+
+ // Handle form submission
+ document.getElementById('socialAdsForm').addEventListener('submit', function(e) {
+ e.preventDefault();
+
+ if (!isFormValid()) {
+ showToast('Please fill in all required fields', 'error');
+ return;
+ }
+
+ // Check user authentication
+ {% if not user.is_authenticated %}
+ window.location.href = "{% url 'authentication:login' %}";
+ return;
+ {% endif %}
+
+ // Check wallet balance
+ const balance = {{ user.wallet_balance|default:0 }};
+ if (balance < 7.00) {
+ showToast('Insufficient balance! You need 7.00 AED.', 'error');
+ setTimeout(() => {
+ window.location.href = "{% url 'core:wallet' %}";
+ }, 2000);
+ return;
+ }
+
+ // Show processing status with steps
+ document.getElementById('processingStatus').style.display = 'block';
+ document.getElementById('processButton').disabled = true;
+ document.getElementById('processButton').innerHTML = '⏳ Processing...';
+ document.getElementById('adResults').style.display = 'none';
+
+ const steps = [
+ 'Analyzing product information...',
+ 'Understanding target platforms...',
+ 'Crafting engaging headlines...',
+ 'Writing compelling copy...',
+ 'Optimizing for each platform...'
+ ];
+
+ let currentStep = 0;
+ const stepInterval = setInterval(() => {
+ if (currentStep < steps.length) {
+ document.getElementById('statusText').textContent = steps[currentStep];
+ currentStep++;
+ } else {
+ clearInterval(stepInterval);
+ }
+ }, 800);
+
+ // Submit form via AJAX
+ const formData = new FormData(this);
+
+ fetch(window.location.href, {
+ method: 'POST',
+ body: formData,
+ headers: {
+ 'X-Requested-With': 'XMLHttpRequest'
+ }
+ })
+ .then(response => response.json())
+ .then(result => {
+ clearInterval(stepInterval);
+ if (result.success && result.request_id) {
+ // Start polling for results
+ pollForResults(result.request_id);
+ } else {
+ // Handle immediate response
+ document.getElementById('processingStatus').style.display = 'none';
+ document.getElementById('processButton').disabled = false;
+ document.getElementById('processButton').innerHTML = '📢 Generate Social Ads (7.00 AED)';
+
+ if (result.error) {
+ showToast(`❌ ${result.error}`, 'error');
+ } else {
+ displayResults(result);
+ }
+ }
+ })
+ .catch(error => {
+ clearInterval(stepInterval);
+ console.error('Error:', error);
+ document.getElementById('processingStatus').style.display = 'none';
+ document.getElementById('processButton').disabled = false;
+ document.getElementById('processButton').innerHTML = '📢 Generate Social Ads (7.00 AED)';
+ showToast('❌ Network error - please try again', 'error');
+ });
+ });
+
+{% endblock %}
\ No newline at end of file
diff --git a/weather_reporter/templates/weather_reporter/detail.html b/weather_reporter/templates/weather_reporter/detail.html
index 0bcf561..d38b323 100644
--- a/weather_reporter/templates/weather_reporter/detail.html
+++ b/weather_reporter/templates/weather_reporter/detail.html
@@ -1,1141 +1,673 @@
+{% extends 'base.html' %}
{% load static %}
-
-
-
-
-
-
Weather Reporter Agent - NetCop AI Hub
-
-
-
-
-
-