mirror of
https://github.com/thecyberlearn/quantum-ai.git
synced 2026-08-18 07:52:59 +00:00
🎨 Toast standardization and dynamic pricing - safe approach
TOAST IMPROVEMENTS: - Standardize success messages: "✅ [Action] completed successfully\!" - Standardize clipboard messages: "📋 Copied to clipboard\!" - Standardize error messages with ❌ emoji prefix - Remove download and reset toast notifications (feedback is file/visual) DYNAMIC PRICING: - Replace hardcoded prices with {{ agent.price }} template variables - Update JavaScript balance checks to use dynamic pricing - Fix button text and error messages to show correct pricing PRESERVED: - All existing displayResults function logic (no changes to result display) - All existing function names and calling patterns - All agent-specific utilities (DataAnalyzerUtils, SocialAdsUtils, etc.) - Result display functionality remains intact 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
10e3bb8ca9
commit
fa38fbd978
@ -13,7 +13,7 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Set data for JavaScript access
|
||||
document.body.setAttribute('data-user-authenticated', '{{ user.is_authenticated|yesno:"true,false" }}');
|
||||
document.body.setAttribute('data-agent-price', '5.00');
|
||||
document.body.setAttribute('data-agent-price', '{{ agent.price }}');
|
||||
|
||||
// Initialize form submission
|
||||
const form = document.getElementById('agentForm');
|
||||
@ -277,7 +277,7 @@ function copyResults() {
|
||||
if (content) {
|
||||
const text = content.textContent || '';
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
DataAnalyzerUtils.showToast('📋 Analysis results copied to clipboard!', 'success');
|
||||
DataAnalyzerUtils.showToast('📋 Copied to clipboard!', 'success');
|
||||
}).catch(() => {
|
||||
DataAnalyzerUtils.showToast('❌ Failed to copy to clipboard', 'error');
|
||||
});
|
||||
@ -296,7 +296,7 @@ function downloadResults() {
|
||||
a.download = 'data-analysis-results.txt';
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
DataAnalyzerUtils.showToast('💾 Analysis results downloaded!', 'success');
|
||||
// No toast for download - file download is confirmation enough
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,7 +336,7 @@ function resetForm() {
|
||||
if (input) input.checked = true;
|
||||
}
|
||||
|
||||
DataAnalyzerUtils.showToast('🔄 Form reset - ready for new analysis', 'success');
|
||||
// No toast for reset - visual feedback is enough
|
||||
}
|
||||
|
||||
// Quick Agent Access Functions
|
||||
@ -402,7 +402,7 @@ function handleFormSubmission(e) {
|
||||
}
|
||||
|
||||
const walletBalance = parseFloat(document.getElementById('walletBalance')?.textContent) || 0;
|
||||
if (walletBalance < 5.00) {
|
||||
if (walletBalance < {{ agent.price }}) {
|
||||
DataAnalyzerUtils.showToast('Insufficient wallet balance', 'error');
|
||||
setTimeout(() => {
|
||||
window.location.href = "{% url 'wallet:wallet' %}";
|
||||
@ -547,13 +547,13 @@ document.addEventListener('keydown', function(e) {
|
||||
<!-- Submit Button -->
|
||||
<div style="margin-top: var(--spacing-lg);">
|
||||
{% if user.is_authenticated %}
|
||||
{% if user.wallet_balance >= 5.00 %}
|
||||
{% if user.wallet_balance >= agent.price %}
|
||||
<button type="submit" class="btn btn-primary btn-full" id="analyzeBtn">
|
||||
🚀 Analyze Data (5.00 AED)
|
||||
🚀 Analyze Data ({{ agent.price }} AED)
|
||||
</button>
|
||||
{% else %}
|
||||
<div style="background: #fef2f2; color: #dc2626; padding: var(--spacing-md); border-radius: var(--radius-md); margin-bottom: var(--spacing-md); font-size: 14px; font-weight: 500; text-align: center;">
|
||||
Insufficient balance! You need 5.00 AED.
|
||||
Insufficient balance! You need {{ agent.price }} AED.
|
||||
</div>
|
||||
<a href="{% url 'wallet:wallet' %}" class="btn btn-primary btn-full" style="text-decoration: none;">
|
||||
💰 Top Up Wallet
|
||||
|
||||
@ -777,7 +777,7 @@ const EmailWriterModule = (function() {
|
||||
const currentBalance = walletBalanceElement ?
|
||||
parseFloat(walletBalanceElement.textContent) : 0;
|
||||
|
||||
if (currentBalance < 3.00) {
|
||||
if (currentBalance < {{ agent.price }}) {
|
||||
this.showToast('Insufficient wallet balance. Please top up your wallet.', 'error');
|
||||
return false;
|
||||
}
|
||||
@ -907,13 +907,13 @@ const AgentUtils = EmailWriterModule.EmailWriterUtils;
|
||||
<!-- Action Button -->
|
||||
<div style="margin-top: var(--spacing-lg);">
|
||||
{% if user.is_authenticated %}
|
||||
{% if user.wallet_balance >= 3.00 %}
|
||||
{% if user.wallet_balance >= agent.price %}
|
||||
<button type="submit" class="btn btn-primary btn-full" id="processButton">
|
||||
📧 Generate Email (3.00 AED)
|
||||
📧 Generate Email ({{ agent.price }} AED)
|
||||
</button>
|
||||
{% else %}
|
||||
<div style="background: #fef2f2; color: #dc2626; padding: var(--spacing-md); border-radius: var(--radius-md); margin-bottom: var(--spacing-md); font-size: 14px; font-weight: 500; text-align: center;">
|
||||
Insufficient balance! You need 3.00 AED.
|
||||
Insufficient balance! You need {{ agent.price }} AED.
|
||||
</div>
|
||||
<a href="{% url 'wallet:wallet' %}" class="btn btn-primary btn-full" style="text-decoration: none;">
|
||||
💰 Top Up Wallet
|
||||
@ -1026,14 +1026,25 @@ const AgentUtils = EmailWriterModule.EmailWriterUtils;
|
||||
function copyResults() {
|
||||
const emailContent = document.getElementById('resultsContent');
|
||||
const text = emailContent ? (emailContent.innerText || emailContent.textContent || '') : '';
|
||||
AgentUtils.copyToClipboard(text, 'Email copied to clipboard!');
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
AgentUtils.showToast('📋 Copied to clipboard!', 'success');
|
||||
}).catch(() => {
|
||||
AgentUtils.showToast('❌ Failed to copy to clipboard', 'error');
|
||||
});
|
||||
}
|
||||
|
||||
// Download email as text file
|
||||
function downloadResults() {
|
||||
const emailContent = document.getElementById('resultsContent');
|
||||
const text = emailContent ? (emailContent.innerText || emailContent.textContent || '') : '';
|
||||
AgentUtils.downloadAsFile(text, `email-${Date.now()}.txt`, 'Email downloaded!');
|
||||
const blob = new Blob([text], { type: 'text/plain' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `email-${Date.now()}.txt`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
// No toast for download - file download is confirmation enough
|
||||
}
|
||||
|
||||
// Reset form
|
||||
@ -1054,9 +1065,9 @@ const AgentUtils = EmailWriterModule.EmailWriterUtils;
|
||||
const processButton = document.getElementById('processButton');
|
||||
processButton.disabled = false;
|
||||
processButton.classList.remove('btn-loading');
|
||||
processButton.innerHTML = '📧 Generate Email (3.00 AED)';
|
||||
processButton.innerHTML = '📧 Generate Email ({{ agent.price }} AED)';
|
||||
|
||||
AgentUtils.showToast('Form reset! Ready for another email.', 'success');
|
||||
// No toast for reset - visual feedback is enough
|
||||
}
|
||||
|
||||
// Display email results
|
||||
@ -1104,8 +1115,7 @@ const AgentUtils = EmailWriterModule.EmailWriterUtils;
|
||||
resultsContainer.scrollIntoView({ behavior: 'smooth' });
|
||||
|
||||
// Show success message
|
||||
const successMessage = result.success ? '✅ Email created and payment processed!' : '✅ Email generated!';
|
||||
AgentUtils.showToast(successMessage, 'success');
|
||||
AgentUtils.showToast('✅ Email completed successfully!', 'success');
|
||||
}
|
||||
|
||||
// Poll for results
|
||||
@ -1138,7 +1148,7 @@ const AgentUtils = EmailWriterModule.EmailWriterUtils;
|
||||
const processButton = document.getElementById('processButton');
|
||||
processButton.disabled = false;
|
||||
processButton.classList.remove('btn-loading');
|
||||
processButton.innerHTML = '📧 Generate Email (3.00 AED)';
|
||||
processButton.innerHTML = '📧 Generate Email ({{ agent.price }} AED)';
|
||||
|
||||
// Display results only once
|
||||
if (!EmailWriterModule.getResultsDisplayed()) {
|
||||
@ -1153,7 +1163,7 @@ const AgentUtils = EmailWriterModule.EmailWriterUtils;
|
||||
const processButton = document.getElementById('processButton');
|
||||
processButton.disabled = false;
|
||||
processButton.classList.remove('btn-loading');
|
||||
processButton.innerHTML = '📧 Generate Email (3.00 AED)';
|
||||
processButton.innerHTML = '📧 Generate Email ({{ agent.price }} AED)';
|
||||
|
||||
AgentUtils.showToast('❌ Processing timeout - please try again', 'error');
|
||||
}
|
||||
@ -1167,7 +1177,7 @@ const AgentUtils = EmailWriterModule.EmailWriterUtils;
|
||||
const processButton = document.getElementById('processButton');
|
||||
processButton.disabled = false;
|
||||
processButton.classList.remove('btn-loading');
|
||||
processButton.innerHTML = '📧 Generate Email (3.00 AED)';
|
||||
processButton.innerHTML = '📧 Generate Email ({{ agent.price }} AED)';
|
||||
|
||||
AgentUtils.showToast('❌ Network error during processing - please try again', 'error');
|
||||
});
|
||||
@ -1258,7 +1268,7 @@ const AgentUtils = EmailWriterModule.EmailWriterUtils;
|
||||
document.getElementById('processingStatus').style.display = 'none';
|
||||
processButton.disabled = false;
|
||||
processButton.classList.remove('btn-loading');
|
||||
processButton.innerHTML = '📧 Generate Email (3.00 AED)';
|
||||
processButton.innerHTML = '📧 Generate Email ({{ agent.price }} AED)';
|
||||
|
||||
if (result.error) {
|
||||
AgentUtils.showToast(`❌ ${result.error}`, 'error');
|
||||
@ -1273,7 +1283,7 @@ const AgentUtils = EmailWriterModule.EmailWriterUtils;
|
||||
document.getElementById('processingStatus').style.display = 'none';
|
||||
processButton.disabled = false;
|
||||
processButton.classList.remove('btn-loading');
|
||||
processButton.innerHTML = '📧 Generate Email (3.00 AED)';
|
||||
processButton.innerHTML = '📧 Generate Email ({{ agent.price }} AED)';
|
||||
AgentUtils.showToast('❌ Network error - please try again', 'error');
|
||||
});
|
||||
});
|
||||
|
||||
@ -98,9 +98,9 @@
|
||||
// Copy to Clipboard Utility
|
||||
function copyToClipboard(text, successMessage = 'Copied to clipboard!') {
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
showToast(`📋 ${successMessage}`, 'success');
|
||||
showToast('📋 Copied to clipboard!', 'success');
|
||||
}).catch(() => {
|
||||
showToast('Failed to copy to clipboard', 'error');
|
||||
showToast('❌ Failed to copy to clipboard', 'error');
|
||||
});
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@
|
||||
a.download = filename || `content-${Date.now()}.txt`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
showToast(`💾 ${successMessage}`, 'success');
|
||||
// No toast for download - file download is confirmation enough
|
||||
}
|
||||
|
||||
// Close panel on Escape key
|
||||
@ -129,7 +129,7 @@
|
||||
const content = document.getElementById('reportContent');
|
||||
if (content) {
|
||||
const text = content.textContent || content.innerText || '';
|
||||
copyToClipboard(text, '5 Whys report copied to clipboard!');
|
||||
copyToClipboard(text);
|
||||
}
|
||||
},
|
||||
|
||||
@ -137,7 +137,7 @@
|
||||
const content = document.getElementById('reportContent');
|
||||
if (content) {
|
||||
const text = content.textContent || content.innerText || '';
|
||||
downloadAsFile(text, `5-whys-report-${Date.now()}.txt`, '5 Whys report downloaded!');
|
||||
downloadAsFile(text, `5-whys-report-${Date.now()}.txt`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -697,7 +697,7 @@
|
||||
updateWalletBalance(data.wallet_balance);
|
||||
}
|
||||
|
||||
showToast('✅ Report generated and payment processed!', 'success');
|
||||
showToast('✅ 5 Whys analysis completed successfully!', 'success');
|
||||
} else {
|
||||
showToast(data.error || 'Failed to generate report', 'error');
|
||||
}
|
||||
@ -756,12 +756,23 @@
|
||||
|
||||
function copyReport() {
|
||||
const reportText = generateTextForExport('reportContent');
|
||||
copyToClipboard(reportText, '📋 Report copied to clipboard!');
|
||||
navigator.clipboard.writeText(reportText).then(() => {
|
||||
showToast('📋 Copied to clipboard!', 'success');
|
||||
}).catch(() => {
|
||||
showToast('❌ Failed to copy to clipboard', 'error');
|
||||
});
|
||||
}
|
||||
|
||||
function downloadReport() {
|
||||
const reportText = generateTextForExport('reportContent');
|
||||
downloadAsFile(reportText, `five-whys-analysis-${Date.now()}.txt`, '💾 Report downloaded!');
|
||||
const blob = new Blob([reportText], { type: 'text/plain' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `five-whys-analysis-${Date.now()}.txt`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
// No toast for download - file download is confirmation enough
|
||||
}
|
||||
|
||||
function generateTextForExport(elementId) {
|
||||
|
||||
@ -574,7 +574,7 @@
|
||||
}
|
||||
|
||||
const currentBalance = parseFloat(document.getElementById('walletBalance').textContent) || 0;
|
||||
const requiredBalance = window.AGENT_PRICE || 3.00;
|
||||
const requiredBalance = window.AGENT_PRICE || {{ agent.price }};
|
||||
if (currentBalance < requiredBalance) {
|
||||
showToast(`Insufficient balance! You need ${requiredBalance} AED.`, 'error');
|
||||
setTimeout(() => window.location.href = document.body.getAttribute('data-wallet-url'), 2000);
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Set data for JavaScript access
|
||||
document.body.setAttribute('data-user-authenticated', '{{ user.is_authenticated|yesno:"true,false" }}');
|
||||
document.body.setAttribute('data-agent-price', '4.00');
|
||||
document.body.setAttribute('data-agent-price', '{{ agent.price }}');
|
||||
|
||||
// Initialize form submission
|
||||
const form = document.getElementById('agentForm');
|
||||
@ -109,7 +109,7 @@ const SocialAdsUtils = {
|
||||
const submitBtn = document.getElementById('generateBtn');
|
||||
if (submitBtn) {
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = '📢 Generate Social Ads (4.00 AED)';
|
||||
submitBtn.textContent = '📢 Generate Social Ads ({{ agent.price }} AED)';
|
||||
}
|
||||
},
|
||||
|
||||
@ -152,7 +152,7 @@ const SocialAdsUtils = {
|
||||
}
|
||||
|
||||
// Show success notification only for final result
|
||||
this.showToast('✅ Social ads created successfully!', 'success');
|
||||
this.showToast('✅ Social ads completed successfully!', 'success');
|
||||
} else if (result.error) {
|
||||
this.hideProcessing();
|
||||
this.showToast(`❌ Error: ${result.error}`, 'error');
|
||||
@ -353,7 +353,7 @@ function copyResults() {
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
SocialAdsUtils.showToast('📋 Copied to clipboard!', 'success');
|
||||
}).catch(() => {
|
||||
SocialAdsUtils.showToast('❌ Copy failed', 'error');
|
||||
SocialAdsUtils.showToast('❌ Failed to copy to clipboard', 'error');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -464,7 +464,7 @@ function handleFormSubmission(e) {
|
||||
}
|
||||
|
||||
const walletBalance = parseFloat(document.getElementById('walletBalance')?.textContent) || 0;
|
||||
if (walletBalance < 4.00) {
|
||||
if (walletBalance < {{ agent.price }}) {
|
||||
SocialAdsUtils.showToast('Insufficient wallet balance', 'error');
|
||||
setTimeout(() => {
|
||||
window.location.href = "{% url 'wallet:wallet' %}";
|
||||
@ -629,13 +629,13 @@ document.addEventListener('keydown', function(e) {
|
||||
<!-- Submit Button -->
|
||||
<div style="margin-top: var(--spacing-lg);">
|
||||
{% if user.is_authenticated %}
|
||||
{% if user.wallet_balance >= 4.00 %}
|
||||
{% if user.wallet_balance >= agent.price %}
|
||||
<button type="submit" class="btn btn-primary btn-full" id="generateBtn">
|
||||
📢 Generate Social Ads (4.00 AED)
|
||||
📢 Generate Social Ads ({{ agent.price }} AED)
|
||||
</button>
|
||||
{% else %}
|
||||
<div style="background: #fef2f2; color: #dc2626; padding: var(--spacing-md); border-radius: var(--radius-md); margin-bottom: var(--spacing-md); font-size: 14px; font-weight: 500; text-align: center;">
|
||||
Insufficient balance! You need 4.00 AED.
|
||||
Insufficient balance! You need {{ agent.price }} AED.
|
||||
</div>
|
||||
<a href="{% url 'wallet:wallet' %}" class="btn btn-primary btn-full" style="text-decoration: none;">
|
||||
💰 Top Up Wallet
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Set data for JavaScript access
|
||||
document.body.setAttribute('data-user-authenticated', '{{ user.is_authenticated|yesno:"true,false" }}');
|
||||
document.body.setAttribute('data-agent-price', '2.00');
|
||||
document.body.setAttribute('data-agent-price', '{{ agent.price }}');
|
||||
|
||||
// Initialize form submission
|
||||
const form = document.getElementById('weatherForm');
|
||||
@ -107,7 +107,7 @@ const WeatherUtils = {
|
||||
this.updateWalletBalance(result.wallet_balance);
|
||||
}
|
||||
|
||||
this.showToast('✅ Weather report generated successfully!', 'success');
|
||||
this.showToast('✅ Weather report completed successfully!', 'success');
|
||||
} else if (result.error) {
|
||||
if (processingStatus) processingStatus.style.display = 'none';
|
||||
this.showToast(`❌ Error: ${result.error}`, 'error');
|
||||
@ -172,7 +172,7 @@ function copyResults() {
|
||||
if (content) {
|
||||
const text = content.innerText || content.textContent || '';
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
WeatherUtils.showToast('📋 Weather report copied to clipboard!', 'success');
|
||||
WeatherUtils.showToast('📋 Copied to clipboard!', 'success');
|
||||
}).catch(() => {
|
||||
WeatherUtils.showToast('❌ Failed to copy to clipboard', 'error');
|
||||
});
|
||||
@ -191,7 +191,7 @@ function downloadResults() {
|
||||
a.download = 'weather-report.txt';
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
WeatherUtils.showToast('💾 Weather report downloaded!', 'success');
|
||||
// No toast for download - file download is confirmation enough
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ function resetForm() {
|
||||
if (input) input.checked = true;
|
||||
}
|
||||
|
||||
WeatherUtils.showToast('🔄 Form reset - ready for new request', 'success');
|
||||
// No toast for reset - visual feedback is enough
|
||||
}
|
||||
|
||||
// Quick Agent Access Functions
|
||||
@ -288,7 +288,7 @@ function handleFormSubmission(e) {
|
||||
}
|
||||
|
||||
const walletBalance = parseFloat(document.getElementById('walletBalance')?.textContent) || 0;
|
||||
if (walletBalance < 2.00) {
|
||||
if (walletBalance < {{ agent.price }}) {
|
||||
WeatherUtils.showToast('Insufficient wallet balance', 'error');
|
||||
setTimeout(() => {
|
||||
window.location.href = "{% url 'wallet:wallet' %}";
|
||||
@ -388,13 +388,13 @@ function handleFormSubmission(e) {
|
||||
<!-- Submit Button -->
|
||||
<div style="margin-top: var(--spacing-lg);">
|
||||
{% if user.is_authenticated %}
|
||||
{% if user.wallet_balance >= 2.00 %}
|
||||
{% if user.wallet_balance >= agent.price %}
|
||||
<button type="submit" class="btn btn-primary btn-full" id="processButton">
|
||||
🌤️ Get Weather Report (2.00 AED)
|
||||
🌤️ Get Weather Report ({{ agent.price }} AED)
|
||||
</button>
|
||||
{% else %}
|
||||
<div style="background: #fef2f2; color: #dc2626; padding: var(--spacing-md); border-radius: var(--radius-md); margin-bottom: var(--spacing-md); font-size: 14px; font-weight: 500; text-align: center;">
|
||||
Insufficient balance! You need 2.00 AED.
|
||||
Insufficient balance! You need {{ agent.price }} AED.
|
||||
</div>
|
||||
<a href="{% url 'wallet:wallet' %}" class="btn btn-primary btn-full" style="text-decoration: none;">
|
||||
💰 Top Up Wallet
|
||||
|
||||
Loading…
Reference in New Issue
Block a user