Gate Studio frontend by workspace and isolate browser catalog state
This commit is contained in:
@@ -19,10 +19,10 @@ const I18N_DICTIONARY = {
|
||||
poster_mode_label: "ডিসপ্লে মোড (Display Mode):",
|
||||
mode_single_btn: "🎯 ১টি প্রোডাক্ট হিরো ৩ডি স্টেজ",
|
||||
mode_multi_btn: "🔲 মাল্টি-প্রোডাক্ট গ্রিড ভিউ (৩-৪টি প্রোডাক্ট)",
|
||||
trends_label: "🔥 গুগল ট্রেন্ডিং সার্চ (Google Trends 1-Click Load):",
|
||||
trends_badge: "Realtime BD Trends",
|
||||
trends_label: "🛍️ আপনার catalog থেকে বাছুন:",
|
||||
trends_badge: "Workspace catalog",
|
||||
product_input_label: "প্রডাক্ট লিংক বা নাম (Product Link or Name):",
|
||||
open_catalog_btn: "🛍️ GT ক্যাটালগ লিস্ট (560+)",
|
||||
open_catalog_btn: "🛍️ আপনার catalog",
|
||||
product_input_ph: "e.g. Silk Saree, Smartwatch, Pure Honey, Sneaker or Skincare",
|
||||
product_price_label: "মূল্য ও অফার (Price & Discount):",
|
||||
product_price_ph: "e.g. ৳ ১,০৬০ (৳ ১,৪৭০) 28% OFF",
|
||||
@@ -220,10 +220,10 @@ const I18N_DICTIONARY = {
|
||||
poster_mode_label: "Display Mode:",
|
||||
mode_single_btn: "🎯 1 Product Hero 3D Stage",
|
||||
mode_multi_btn: "🔲 Multi-Product Grid View (3-4 Products)",
|
||||
trends_label: "🔥 Google Trending Searches (Google Trends 1-Click Load):",
|
||||
trends_badge: "Realtime BD Trends",
|
||||
trends_label: "🛍️ Choose from your catalog:",
|
||||
trends_badge: "Workspace catalog",
|
||||
product_input_label: "Product Link or Name:",
|
||||
open_catalog_btn: "🛍️ GT Catalog List (560+)",
|
||||
open_catalog_btn: "🛍️ Your catalog",
|
||||
product_input_ph: "e.g. Silk Saree, Smartwatch, Pure Honey, Sneaker or Skincare",
|
||||
product_price_label: "Price & Discount Offer:",
|
||||
product_price_ph: "e.g. ৳ 1,060 (৳ 1,470) 28% OFF",
|
||||
@@ -465,7 +465,17 @@ window.applyLanguage = function(lang) {
|
||||
if (typeof renderHistory === 'function') renderHistory();
|
||||
};
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.addEventListener('aura-studio-ready', () => {
|
||||
const brandSelect = document.getElementById('brandWatermarkSelect');
|
||||
if (brandSelect) brandSelect.replaceChildren(new Option(window.AuraStudio.workspace.name || window.AuraStudio.workspace.tenant, 'workspace'));
|
||||
const storeContext = document.getElementById('inboxStoreContext');
|
||||
if (storeContext) storeContext.value = window.AuraStudio.workspace.name || window.AuraStudio.workspace.tenant;
|
||||
['productInput', 'productPrice', 'customBadgeInput', 'ugcProductName', 'ugcTargetAudience', 'gridMainHeadlineInput'].forEach(id => {
|
||||
const field = document.getElementById(id); if (field) field.value = '';
|
||||
});
|
||||
for (let slot = 1; slot <= 4; slot++) {
|
||||
['slotTitle', 'slotPrice', 'slotBadge'].forEach(prefix => { const field = document.getElementById(prefix + slot); if (field) field.value = ''; });
|
||||
}
|
||||
initNavigation();
|
||||
initSettings();
|
||||
initCatalogBrowser();
|
||||
@@ -552,9 +562,9 @@ function initSettings() {
|
||||
const statusMsg = document.getElementById('settingsStatusMsg');
|
||||
|
||||
// Load saved settings
|
||||
const savedKey = localStorage.getItem('opal_gemini_api_key') || '';
|
||||
const savedModel = localStorage.getItem('opal_selected_model') || 'gemini-2.0-flash';
|
||||
const savedN8n = localStorage.getItem('opal_n8n_webhook') || 'https://n8n.auraajenticai.cloud/webhook/gt-auto-post';
|
||||
const savedKey = window.AuraStudio.local.getItem('opal_gemini_api_key') || '';
|
||||
const savedModel = window.AuraStudio.local.getItem('opal_selected_model') || 'gemini-2.0-flash';
|
||||
const savedN8n = window.AuraStudio.local.getItem('opal_n8n_webhook') || '';
|
||||
|
||||
if (apiKeyInput) apiKeyInput.value = savedKey;
|
||||
if (modelSelect) modelSelect.value = savedModel;
|
||||
@@ -567,11 +577,11 @@ function initSettings() {
|
||||
const n8nUrl = n8nWebhookInput ? n8nWebhookInput.value.trim() : '';
|
||||
|
||||
if (n8nUrl) {
|
||||
localStorage.setItem('opal_n8n_webhook', n8nUrl);
|
||||
window.AuraStudio.local.setItem('opal_n8n_webhook', n8nUrl);
|
||||
}
|
||||
|
||||
if (!key) {
|
||||
localStorage.setItem('opal_selected_model', model);
|
||||
window.AuraStudio.local.setItem('opal_selected_model', model);
|
||||
statusMsg.classList.remove('hidden');
|
||||
statusMsg.style.color = '#10B981';
|
||||
statusMsg.textContent = '✅ Settings saved (Offline templates active).';
|
||||
@@ -585,8 +595,8 @@ function initSettings() {
|
||||
try {
|
||||
const res = await callGeminiApi(key, model, "Respond with: 'Aura Studio Connected successfully!'");
|
||||
if (res) {
|
||||
localStorage.setItem('opal_gemini_api_key', key);
|
||||
localStorage.setItem('opal_selected_model', model);
|
||||
window.AuraStudio.local.setItem('opal_gemini_api_key', key);
|
||||
window.AuraStudio.local.setItem('opal_selected_model', model);
|
||||
statusMsg.style.color = '#10B981';
|
||||
statusMsg.textContent = `✅ Verified & Active: ${res.trim()}`;
|
||||
}
|
||||
@@ -606,7 +616,7 @@ function getCachedPromptResult(cacheKey) {
|
||||
return GEMINI_CACHE.get(cacheKey);
|
||||
}
|
||||
try {
|
||||
const stored = sessionStorage.getItem(`opal_cache_${cacheKey}`);
|
||||
const stored = window.AuraStudio.session.getItem(`opal_cache_${cacheKey}`);
|
||||
if (stored) {
|
||||
const parsed = JSON.parse(stored);
|
||||
if (Date.now() - parsed.ts < 1000 * 60 * 60 * 2) { // 2 hour cache
|
||||
@@ -621,7 +631,7 @@ function getCachedPromptResult(cacheKey) {
|
||||
function setCachedPromptResult(cacheKey, data) {
|
||||
GEMINI_CACHE.set(cacheKey, data);
|
||||
try {
|
||||
sessionStorage.setItem(`opal_cache_${cacheKey}`, JSON.stringify({ ts: Date.now(), data }));
|
||||
window.AuraStudio.session.setItem(`opal_cache_${cacheKey}`, JSON.stringify({ ts: Date.now(), data }));
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
@@ -638,7 +648,7 @@ async function callGeminiApi(apiKey, model, prompt, retries = 2) {
|
||||
}
|
||||
|
||||
const modelHierarchy = [
|
||||
model || localStorage.getItem('opal_selected_model') || 'gemini-2.0-flash',
|
||||
model || window.AuraStudio.local.getItem('opal_selected_model') || 'gemini-2.0-flash',
|
||||
'gemini-1.5-flash',
|
||||
'gemma-2-27b-it'
|
||||
];
|
||||
@@ -1012,7 +1022,7 @@ function initMiniAppsHub() {
|
||||
}
|
||||
|
||||
function getCustomMiniApps() {
|
||||
return JSON.parse(localStorage.getItem('opal_custom_apps') || '[]');
|
||||
return JSON.parse(window.AuraStudio.local.getItem('opal_custom_apps') || '[]');
|
||||
}
|
||||
|
||||
function renderMiniApps() {
|
||||
@@ -1105,7 +1115,7 @@ function initMiniAppBuilder() {
|
||||
|
||||
const existing = getCustomMiniApps();
|
||||
existing.unshift(newApp);
|
||||
localStorage.setItem('opal_custom_apps', JSON.stringify(existing));
|
||||
window.AuraStudio.local.setItem('opal_custom_apps', JSON.stringify(existing));
|
||||
|
||||
statusMsg.classList.remove('hidden');
|
||||
statusMsg.style.color = '#10B981';
|
||||
@@ -1193,7 +1203,7 @@ window.closeAppRunner = function() {
|
||||
};
|
||||
|
||||
// Handle Mini-App Execution
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.addEventListener('aura-studio-ready', () => {
|
||||
const execBtn = document.getElementById('runnerExecuteBtn');
|
||||
if (execBtn) {
|
||||
execBtn.addEventListener('click', async () => {
|
||||
@@ -1212,7 +1222,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const inputs = document.querySelectorAll('.runner-input');
|
||||
const selectedBrandKey = document.getElementById('brandWatermarkSelect')?.value || 'glamourstouch';
|
||||
const activeBrand = getBrandProfile(selectedBrandKey);
|
||||
const cleanPhone = (activeBrand.footerHotline || '01712-426871').replace(/\D/g, '');
|
||||
const cleanPhone = (activeBrand.footerHotline || '').replace(/\D/g, '');
|
||||
const dynamicWaLink = `https://wa.me/88${cleanPhone}`;
|
||||
|
||||
let prompt = currentRunningApp.promptTemplate || 'Generate helpful response for the user.';
|
||||
@@ -1231,8 +1241,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
prompt = prompt.replace(/{{wa_link}}/g, dynamicWaLink);
|
||||
prompt = prompt.replace(/https:\/\/wa\.me\/8801712426871/g, dynamicWaLink);
|
||||
|
||||
const apiKey = localStorage.getItem('opal_gemini_api_key') || '';
|
||||
const model = currentRunningApp.model || localStorage.getItem('opal_selected_model') || 'gemini-2.0-flash';
|
||||
const apiKey = window.AuraStudio.local.getItem('opal_gemini_api_key') || '';
|
||||
const model = currentRunningApp.model || window.AuraStudio.local.getItem('opal_selected_model') || 'gemini-2.0-flash';
|
||||
|
||||
try {
|
||||
let output = '';
|
||||
@@ -1705,9 +1715,9 @@ function initPosterLab() {
|
||||
shareWhatsAppBtn.addEventListener('click', () => {
|
||||
const selectedBrand = document.getElementById('brandWatermarkSelect')?.value || 'glamourstouch';
|
||||
const activeBrand = getBrandProfile(selectedBrand);
|
||||
const cleanPhone = (activeBrand.footerHotline || '01712-426871').replace(/\D/g, '');
|
||||
const cleanPhone = (activeBrand.footerHotline || '').replace(/\D/g, '');
|
||||
const pTitle = productInput.value.trim() || 'Authentic Product';
|
||||
const text = encodeURIComponent(`✨ Hello! I want to order: ${pTitle}\nWebsite: https://${activeBrand.footerSite || 'glamourstouch.com'}\nHotline: ${activeBrand.footerHotline}`);
|
||||
const text = encodeURIComponent(`✨ Hello! I want to order: ${pTitle}\nWebsite: https://${activeBrand.footerSite || ''}\nHotline: ${activeBrand.footerHotline}`);
|
||||
window.open(`https://wa.me/88${cleanPhone}?text=${text}`, '_blank');
|
||||
});
|
||||
|
||||
@@ -1717,7 +1727,7 @@ function initPosterLab() {
|
||||
|
||||
if (autoPostN8nBtn) {
|
||||
autoPostN8nBtn.addEventListener('click', async () => {
|
||||
const webhookUrl = localStorage.getItem('opal_n8n_webhook');
|
||||
const webhookUrl = window.AuraStudio.local.getItem('opal_n8n_webhook');
|
||||
if (!webhookUrl) {
|
||||
alert('⚠️ Please configure n8n Webhook URL in Settings first!');
|
||||
switchToTab('tabSettings');
|
||||
@@ -1732,7 +1742,7 @@ function initPosterLab() {
|
||||
try {
|
||||
const selectedBrand = document.getElementById('brandWatermarkSelect')?.value || 'glamourstouch';
|
||||
const activeBrand = getBrandProfile(selectedBrand);
|
||||
const cleanPhone = (activeBrand.footerHotline || '01712-426871').replace(/\D/g, '');
|
||||
const cleanPhone = (activeBrand.footerHotline || '').replace(/\D/g, '');
|
||||
const pTitle = productInput.value.trim() || 'Authentic Product';
|
||||
const pPrice = productPrice.value.trim() || '৳ ১,০৬০';
|
||||
const posterDataUrl = posterCanvas.toDataURL('image/jpeg', 0.92);
|
||||
@@ -1774,100 +1784,17 @@ function initPosterLab() {
|
||||
|
||||
// --- Dynamic Brand Profiles & Tenant Sync Engine ---
|
||||
const DEFAULT_BRAND_PROFILES = {
|
||||
glamourstouch: {
|
||||
id: 'glamourstouch',
|
||||
headerTitle: "✨ GLAMOUR'S TOUCH ✨",
|
||||
headerSub: '100% AUTHENTIC KOREAN COSMETICS • DERMATOLOGIST TESTED',
|
||||
badgeL1: '🌿 Pure & Safe Care',
|
||||
badgeL2: '🛡️ Authentic Seal',
|
||||
footerSite: 'glamourstouch.com',
|
||||
footerHotline: '01712-426871',
|
||||
theme: 'obsidian_gold',
|
||||
category: 'cosmetics'
|
||||
},
|
||||
panjabi: {
|
||||
id: 'panjabi',
|
||||
headerTitle: '👑 AURA HERITAGE PANJABI 👑',
|
||||
headerSub: 'ROYAL DESIGNER PANJABI & KABLI SUITS • 100% PURE COTTON & SILK',
|
||||
badgeL1: '🧵 100% Pre-Shrunk Weave',
|
||||
badgeL2: '✨ Size Trial Available',
|
||||
footerSite: 'panjabi.auraajenticai.cloud',
|
||||
footerHotline: '01712-426871',
|
||||
theme: 'obsidian_gold',
|
||||
category: 'panjabi'
|
||||
},
|
||||
snehalata: {
|
||||
id: 'snehalata',
|
||||
headerTitle: '🌸 SNEHALATA AURA 🌸',
|
||||
headerSub: 'PREMIUM LUXURY FASHION, SAREE & LIFESTYLE • 100% AUTHENTIC',
|
||||
badgeL1: '👗 Pure Fabric Weave',
|
||||
badgeL2: '✨ Size Trial Guarantee',
|
||||
footerSite: 'snehalata.com',
|
||||
footerHotline: '01712-426871',
|
||||
theme: 'rose_quartz',
|
||||
category: 'fashion'
|
||||
},
|
||||
techvolt: {
|
||||
id: 'techvolt',
|
||||
headerTitle: '⚡ TECHVOLT GADGETS ⚡',
|
||||
headerSub: 'OFFICIAL WARRANTY • SMART ELECTRONICS & AUDIO ACCESSORIES',
|
||||
badgeL1: '🔋 High Battery Life',
|
||||
badgeL2: '🛡️ 1 Year Warranty',
|
||||
footerSite: 'techvolt.auraajenticai.cloud',
|
||||
footerHotline: '01712-426871',
|
||||
theme: 'cyber_neon',
|
||||
category: 'electronics'
|
||||
},
|
||||
organic: {
|
||||
id: 'organic',
|
||||
headerTitle: '🍯 PRANON ORGANIC 🍯',
|
||||
headerSub: '100% PURE NATURAL HONEY & UNADULTERATED ORGANIC FOODS',
|
||||
badgeL1: '🌿 100% Lab Tested',
|
||||
badgeL2: '🛡️ Double Money Back',
|
||||
footerSite: 'organic.auraajenticai.cloud',
|
||||
footerHotline: '01712-426871',
|
||||
theme: 'botanical_eco',
|
||||
category: 'organic'
|
||||
},
|
||||
sneakerlab: {
|
||||
id: 'sneakerlab',
|
||||
headerTitle: '👟 SNEAKERLAB BD 👟',
|
||||
headerSub: 'PREMIUM STREETWEAR & GENUINE LEATHER FOOTWEAR',
|
||||
badgeL1: '👟 Memory Foam Cushion',
|
||||
badgeL2: '✨ Doorstep Fitting',
|
||||
footerSite: 'sneakers.auraajenticai.cloud',
|
||||
footerHotline: '01712-426871',
|
||||
theme: 'obsidian_gold',
|
||||
category: 'sneakerlab'
|
||||
},
|
||||
royale: {
|
||||
id: 'royale',
|
||||
headerTitle: '💎 AURA ROYALE 💎',
|
||||
headerSub: 'LUXURY JEWELRY, WATCHES & 24-HOUR SIGNATURE PERFUMES',
|
||||
badgeL1: '💎 24h Projection',
|
||||
badgeL2: '👑 Pure Luxury Finish',
|
||||
footerSite: 'royale.auraajenticai.cloud',
|
||||
footerHotline: '01712-426871',
|
||||
theme: 'obsidian_gold',
|
||||
category: 'royale'
|
||||
},
|
||||
custom: {
|
||||
id: 'custom',
|
||||
headerTitle: '🛍️ UNIVERSAL MERCHANT 🛍️',
|
||||
headerSub: '100% ORIGINAL AUTHENTIC • CASH ON DELIVERY BANGLADESH',
|
||||
badgeL1: '⭐ Premium Quality',
|
||||
badgeL2: '🛡️ 100% Original',
|
||||
footerSite: 'auraajenticai.cloud',
|
||||
footerHotline: '01712-426871',
|
||||
theme: 'obsidian_gold',
|
||||
category: 'general'
|
||||
workspace: {
|
||||
id: 'workspace', headerTitle: window.AuraStudio.workspace.name || window.AuraStudio.workspace.tenant,
|
||||
headerSub: '', badgeL1: '', badgeL2: '', footerSite: '', footerHotline: '',
|
||||
theme: 'obsidian_gold', category: 'general'
|
||||
}
|
||||
};
|
||||
|
||||
function getDynamicBrandProfiles() {
|
||||
let customMap = {};
|
||||
try {
|
||||
const saved = localStorage.getItem('opal_custom_brands');
|
||||
const saved = window.AuraStudio.local.getItem('opal_custom_brands');
|
||||
if (saved) customMap = JSON.parse(saved);
|
||||
} catch (e) {}
|
||||
return Object.assign({}, DEFAULT_BRAND_PROFILES, customMap);
|
||||
@@ -1875,7 +1802,7 @@ function getDynamicBrandProfiles() {
|
||||
|
||||
function getBrandProfile(brandKey) {
|
||||
const all = getDynamicBrandProfiles();
|
||||
return all[brandKey] || all.glamourstouch;
|
||||
return all[brandKey] || all.workspace;
|
||||
}
|
||||
|
||||
// Universal Dynamic Product Resolver
|
||||
@@ -6206,7 +6133,8 @@ window.loadCgiIntoPosterLab = function(promptId) {
|
||||
}
|
||||
};
|
||||
|
||||
async function drawWhatsAppQrOnCanvas(ctx, x, y, size, hotline = '01712-426871') {
|
||||
async function drawWhatsAppQrOnCanvas(ctx, x, y, size, hotline = '') {
|
||||
if (!String(hotline).replace(/\D/g, '')) return;
|
||||
ctx.fillStyle = '#FFFFFF';
|
||||
roundRect(ctx, x - 4, y - 4, size + 8, size + 8, 10);
|
||||
ctx.fill();
|
||||
@@ -6266,12 +6194,12 @@ function initInboxAI() {
|
||||
generateBtn.addEventListener('click', async () => {
|
||||
const query = customerMsgInput.value.trim();
|
||||
const storeInfo = storeContextInput.value.trim();
|
||||
const apiKey = localStorage.getItem('opal_gemini_api_key') || '';
|
||||
const model = localStorage.getItem('opal_selected_model') || 'gemini-2.0-flash';
|
||||
const apiKey = window.AuraStudio.local.getItem('opal_gemini_api_key') || '';
|
||||
const model = window.AuraStudio.local.getItem('opal_selected_model') || 'gemini-2.0-flash';
|
||||
|
||||
const selectedBrand = document.getElementById('brandWatermarkSelect')?.value || 'glamourstouch';
|
||||
const activeBrand = getBrandProfile(selectedBrand);
|
||||
const cleanPhone = (activeBrand.footerHotline || '01712-426871').replace(/\D/g, '');
|
||||
const cleanPhone = (activeBrand.footerHotline || '').replace(/\D/g, '');
|
||||
const dynamicWaLink = `https://wa.me/88${cleanPhone}`;
|
||||
|
||||
if (!query) {
|
||||
@@ -6331,7 +6259,7 @@ function initHistory() {
|
||||
function renderHistory() {
|
||||
if (!historyContainer) return;
|
||||
const dict = I18N_DICTIONARY[window.currentLang] || I18N_DICTIONARY.bn;
|
||||
const list = JSON.parse(localStorage.getItem('opal_history') || '[]');
|
||||
const list = JSON.parse(window.AuraStudio.local.getItem('opal_history') || '[]');
|
||||
if (list.length === 0) {
|
||||
historyContainer.innerHTML = `
|
||||
<div class="empty-state">
|
||||
@@ -6358,7 +6286,7 @@ function initHistory() {
|
||||
|
||||
if (clearBtn) {
|
||||
clearBtn.addEventListener('click', () => {
|
||||
localStorage.removeItem('opal_history');
|
||||
window.AuraStudio.local.removeItem('opal_history');
|
||||
renderHistory();
|
||||
});
|
||||
}
|
||||
@@ -6367,9 +6295,9 @@ function initHistory() {
|
||||
}
|
||||
|
||||
function saveGenerationToHistory(item) {
|
||||
const list = JSON.parse(localStorage.getItem('opal_history') || '[]');
|
||||
const list = JSON.parse(window.AuraStudio.local.getItem('opal_history') || '[]');
|
||||
list.unshift(item);
|
||||
localStorage.setItem('opal_history', JSON.stringify(list.slice(0, 30)));
|
||||
window.AuraStudio.local.setItem('opal_history', JSON.stringify(list.slice(0, 30)));
|
||||
}
|
||||
|
||||
// --- 7. Google Flow & Omni UGC Video Ads Studio (Google Veo 3.1) ---
|
||||
@@ -6541,8 +6469,8 @@ function initUgcStudio() {
|
||||
const preset = UGC_PRESET_LIBRARY[selectedUgcPreset] || UGC_PRESET_LIBRARY.unhinged_review;
|
||||
|
||||
try {
|
||||
const apiKey = localStorage.getItem('opal_gemini_api_key') || '';
|
||||
const model = localStorage.getItem('opal_selected_model') || 'gemini-2.0-flash';
|
||||
const apiKey = window.AuraStudio.local.getItem('opal_gemini_api_key') || '';
|
||||
const model = window.AuraStudio.local.getItem('opal_selected_model') || 'gemini-2.0-flash';
|
||||
|
||||
let masterPrompt = '';
|
||||
let timelineShots = [];
|
||||
@@ -6661,7 +6589,7 @@ Generate:
|
||||
|
||||
// --- Universal Multi-Store Catalog & Client URL Sync Engine ---
|
||||
window.ALL_STORES = {};
|
||||
window.activeStoreId = 'glamourstouch';
|
||||
window.activeStoreId = null;
|
||||
window.GT_CATALOG = [];
|
||||
let selectedCatalogBrand = 'all';
|
||||
|
||||
@@ -6689,36 +6617,29 @@ async function initCatalogBrowser() {
|
||||
const productInput = document.getElementById('productInput');
|
||||
const autocompleteList = document.getElementById('productAutocompleteList');
|
||||
|
||||
// 1. Initialize Master Store: Glamour's Touch (563 Products)
|
||||
try {
|
||||
const res = await fetch('gt_full_catalog.json');
|
||||
if (res.ok) {
|
||||
window.GT_CATALOG = await res.json();
|
||||
window.ALL_STORES['glamourstouch'] = {
|
||||
id: 'glamourstouch',
|
||||
name: "Glamour's Touch",
|
||||
icon: '✨',
|
||||
domain: 'glamourstouch.com',
|
||||
url: 'https://glamourstouch.com',
|
||||
category: 'cosmetics',
|
||||
badge: 'KOREAN COSMETICS',
|
||||
count: window.GT_CATALOG.length,
|
||||
products: window.GT_CATALOG,
|
||||
isMaster: true
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Could not load gt_full_catalog.json:', e);
|
||||
}
|
||||
|
||||
const htmlText = window.AuraStudio.escapeText;
|
||||
const apiUrl = window.AuraStudio.apiUrl;
|
||||
// Load only the authenticated workspace catalog; no global merchant fallback.
|
||||
// 2. Load Synced Stores from backend API
|
||||
await loadSyncedStoresFromBackend();
|
||||
window.activeStoreId = Object.keys(window.ALL_STORES)[0] || null;
|
||||
const shortcuts = document.getElementById('trendingPosterChips');
|
||||
if (shortcuts) {
|
||||
shortcuts.replaceChildren();
|
||||
Object.values(window.ALL_STORES).flatMap(item => item.products || []).slice(0, 7).forEach(product => {
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button'; button.className = 'pill-btn'; button.textContent = product.title;
|
||||
button.addEventListener('click', () => window.applyCatalogProductToPoster(product.id));
|
||||
shortcuts.appendChild(button);
|
||||
});
|
||||
}
|
||||
|
||||
async function loadSyncedStoresFromBackend() {
|
||||
try {
|
||||
const res = await fetch('/api/get-synced-stores');
|
||||
if (res.ok) {
|
||||
const res = await fetch(apiUrl('/api/get-synced-stores'), { cache: 'no-store' });
|
||||
{
|
||||
const data = await res.json();
|
||||
if (!res.ok || data.success !== true) throw new Error(data.error || 'Catalog load হয়নি।');
|
||||
if (data && Array.isArray(data.stores)) {
|
||||
data.stores.forEach(s => {
|
||||
let catEmoji = '🛍️';
|
||||
@@ -6746,7 +6667,7 @@ async function initCatalogBrowser() {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Could not load synced stores:', e);
|
||||
if (storeSyncStatusMsg) { storeSyncStatusMsg.classList.remove('hidden'); storeSyncStatusMsg.textContent = e.message || 'Catalog load হয়নি।'; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6760,8 +6681,8 @@ async function initCatalogBrowser() {
|
||||
const st = window.ALL_STORES[k];
|
||||
const isActive = k === window.activeStoreId;
|
||||
html += `
|
||||
<button type="button" class="store-chip-btn ${isActive ? 'active' : ''}" data-store-id="${st.id}">
|
||||
<span>${st.icon || '🛍️'}</span> ${st.name} (${st.count || st.products.length})
|
||||
<button type="button" class="store-chip-btn ${isActive ? 'active' : ''}" data-store-id="${htmlText(st.id)}">
|
||||
<span>${htmlText(st.icon || '🛍️')}</span> ${htmlText(st.name)} (${st.count || st.products.length})
|
||||
</button>
|
||||
`;
|
||||
});
|
||||
@@ -6812,7 +6733,13 @@ async function initCatalogBrowser() {
|
||||
// Update Store Banner
|
||||
function updateStoreBanner() {
|
||||
const cur = window.ALL_STORES[window.activeStoreId];
|
||||
if (!cur) return;
|
||||
if (!cur) {
|
||||
if (activeStoreTitle) activeStoreTitle.textContent = window.AuraStudio.workspace.name || window.AuraStudio.workspace.tenant;
|
||||
if (activeStoreBadge) activeStoreBadge.textContent = 'CATALOG';
|
||||
if (activeStoreUrlLink) { activeStoreUrlLink.removeAttribute('href'); activeStoreUrlLink.textContent = ''; }
|
||||
if (deleteCurrentStoreBtn) deleteCurrentStoreBtn.classList.add('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
if (activeStoreIcon) activeStoreIcon.textContent = cur.icon || '🛍️';
|
||||
if (activeStoreTitle) activeStoreTitle.textContent = `${cur.name} (${cur.domain})`;
|
||||
@@ -6839,13 +6766,16 @@ async function initCatalogBrowser() {
|
||||
|
||||
if (confirm(`আপনি কি "${cur.name}" স্টোর বক্স এবং এর সব প্রডাক্ট মুছে ফেলতে চান?`)) {
|
||||
try {
|
||||
await fetch('/api/delete-synced-store', {
|
||||
const response = await fetch(apiUrl('/api/delete-synced-store'), {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ storeId: cur.id })
|
||||
});
|
||||
const result = await response.json();
|
||||
if (!response.ok || result.success !== true) throw new Error(result.error || 'Store মুছে ফেলা হয়নি।');
|
||||
delete window.ALL_STORES[cur.id];
|
||||
switchActiveStore('glamourstouch');
|
||||
window.activeStoreId = Object.keys(window.ALL_STORES)[0] || null;
|
||||
renderStoreSwitcher(); updateStoreBanner(); renderBrandFilterChips(); renderCatalogGrid();
|
||||
} catch (e) {
|
||||
alert('Error deleting store: ' + e.message);
|
||||
}
|
||||
@@ -6879,7 +6809,7 @@ async function initCatalogBrowser() {
|
||||
startStoreSyncBtn.disabled = true;
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/sync-store', {
|
||||
const res = await fetch(apiUrl('/api/sync-store'), {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
@@ -6986,7 +6916,7 @@ async function initCatalogBrowser() {
|
||||
return;
|
||||
}
|
||||
|
||||
const brandCounts = {};
|
||||
const brandCounts = Object.create(null);
|
||||
cur.products.forEach(p => {
|
||||
const b = p.brand || cur.name || 'Brand';
|
||||
brandCounts[b] = (brandCounts[b] || 0) + 1;
|
||||
@@ -6999,7 +6929,7 @@ async function initCatalogBrowser() {
|
||||
let html = `<button class="filter-chip ${selectedCatalogBrand === 'all' ? 'active' : ''}" data-brand="all">🔥 All Brands (${cur.products.length})</button>`;
|
||||
|
||||
topBrands.forEach(b => {
|
||||
html += `<button class="filter-chip ${selectedCatalogBrand.toLowerCase() === b.toLowerCase() ? 'active' : ''}" data-brand="${b}">${b} (${brandCounts[b]})</button>`;
|
||||
html += `<button class="filter-chip ${selectedCatalogBrand.toLowerCase() === b.toLowerCase() ? 'active' : ''}" data-brand="${htmlText(b)}">${htmlText(b)} (${brandCounts[b]})</button>`;
|
||||
});
|
||||
|
||||
brandChipsContainer.innerHTML = html;
|
||||
@@ -7018,7 +6948,14 @@ async function initCatalogBrowser() {
|
||||
function renderCatalogGrid() {
|
||||
if (!catalogGridContainer) return;
|
||||
const cur = window.ALL_STORES[window.activeStoreId];
|
||||
if (!cur) return;
|
||||
if (!cur) {
|
||||
catalogGridContainer.replaceChildren();
|
||||
const empty = document.createElement('p');
|
||||
empty.textContent = 'এই workspace-এ catalog এখনও যোগ করা হয়নি। নিজের store connect বা URL দিয়ে sync করুন।';
|
||||
catalogGridContainer.appendChild(empty);
|
||||
if (catalogCountText) catalogCountText.textContent = '0 products';
|
||||
return;
|
||||
}
|
||||
|
||||
const dict = I18N_DICTIONARY[window.currentLang] || I18N_DICTIONARY.bn;
|
||||
const query = (catalogSearchInput ? catalogSearchInput.value : '').toLowerCase().trim();
|
||||
@@ -7036,9 +6973,9 @@ async function initCatalogBrowser() {
|
||||
|
||||
if (catalogCountText) {
|
||||
if (window.currentLang === 'en') {
|
||||
catalogCountText.textContent = `${cur.name} — ${filtered.length} authentic products found (Total ${cur.products.length})`;
|
||||
catalogCountText.textContent = `${cur.name} — ${filtered.length} products found (Total ${cur.products.length})`;
|
||||
} else {
|
||||
catalogCountText.textContent = `${cur.name} — ${filtered.length}টি আসল প্রোডাক্ট পাওয়া গেছে (মোট ${cur.products.length}টি)`;
|
||||
catalogCountText.textContent = `${cur.name} — ${filtered.length}টি প্রোডাক্ট পাওয়া গেছে (মোট ${cur.products.length}টি)`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7055,20 +6992,20 @@ async function initCatalogBrowser() {
|
||||
const displayList = filtered.slice(0, 150);
|
||||
catalogGridContainer.innerHTML = displayList.map(p => `
|
||||
<div class="catalog-item-card">
|
||||
<img class="catalog-item-img" src="${p.image || '/assets/products/cosmetics_3d_cgi.jpg'}" alt="${p.title}" loading="lazy" onerror="this.src='/assets/products/cosmetics_3d_cgi.jpg'">
|
||||
<img class="catalog-item-img" src="${htmlText(p.image || '/assets/products/cosmetics_3d_cgi.jpg')}" alt="${htmlText(p.title)}" loading="lazy" onerror="this.src='/assets/products/cosmetics_3d_cgi.jpg'">
|
||||
<div style="flex:1;">
|
||||
<span style="font-size:10px; font-weight:800; color:#C084FC; text-transform:uppercase; letter-spacing:0.5px;">${p.brand || cur.name}</span>
|
||||
<h4 class="catalog-item-title" title="${p.title}">${p.title}</h4>
|
||||
<span style="font-size:10px; font-weight:800; color:#C084FC; text-transform:uppercase; letter-spacing:0.5px;">${htmlText(p.brand || cur.name)}</span>
|
||||
<h4 class="catalog-item-title" title="${htmlText(p.title)}">${htmlText(p.title)}</h4>
|
||||
<div class="catalog-item-price-row">
|
||||
<span class="catalog-item-price">${p.price}</span>
|
||||
<span class="catalog-item-reg-price">${p.regularPrice}</span>
|
||||
<span class="catalog-item-price">${htmlText(p.price)}</span>
|
||||
<span class="catalog-item-reg-price">${htmlText(p.regularPrice)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="catalog-item-actions">
|
||||
<button type="button" class="btn-catalog-copy" onclick="window.copyCatalogProductInfo('${p.id}')">
|
||||
<button type="button" class="btn-catalog-copy" onclick="window.copyCatalogProductInfo(decodeURIComponent('${encodeURIComponent(String(p.id)).replace(/'/g, '%27')}'))">
|
||||
${dict.btn_catalog_copy || '📋 কপি'}
|
||||
</button>
|
||||
<button type="button" class="btn-catalog-use" onclick="window.applyCatalogProductToPoster('${p.id}')">
|
||||
<button type="button" class="btn-catalog-use" onclick="window.applyCatalogProductToPoster(decodeURIComponent('${encodeURIComponent(String(p.id)).replace(/'/g, '%27')}'))">
|
||||
${dict.btn_catalog_use || '⚡ ৩ডি পোস্টার'}
|
||||
</button>
|
||||
</div>
|
||||
@@ -7092,7 +7029,7 @@ async function initCatalogBrowser() {
|
||||
}
|
||||
|
||||
if (!p) return;
|
||||
const text = `✨ ${p.title}\n🏷️ ব্র্যান্ড / স্টোর: ${p.brand || storeObj.name}\n💰 অফার মূল্য: ${p.price} (রেগুলার ${p.regularPrice})\n🛡️ ১০০% আসল ও প্রিমিয়াম কোয়ালিটি নিশ্চিত\n🔗 লিংক: ${p.link || storeObj.url}\n📸 ইমেজ: ${p.image}`;
|
||||
const text = `✨ ${p.title}\n🏷️ ব্র্যান্ড / স্টোর: ${p.brand || storeObj.name}\n💰 মূল্য: ${p.price}${p.regularPrice ? ' (রেগুলার ' + p.regularPrice + ')' : ''}\n🔗 লিংক: ${p.link || storeObj.url}\n📸 ইমেজ: ${p.image}`;
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
alert(`✅ "${p.title}"-এর সম্পূর্ণ তথ্য কপি হয়েছে!`);
|
||||
}).catch(() => {
|
||||
@@ -7131,33 +7068,26 @@ async function initCatalogBrowser() {
|
||||
const clearBtn = document.getElementById('clearPhotoBtn');
|
||||
|
||||
if (pInput) pInput.value = p.title;
|
||||
if (pPrice) pPrice.value = `${p.price} (${p.regularPrice}) 20% OFF`;
|
||||
if (pBadge) pBadge.value = `🛡️ 100% Authentic ${p.brand || storeObj.name}`;
|
||||
if (pPrice) pPrice.value = [p.price, p.regularPrice ? '(' + p.regularPrice + ')' : ''].filter(Boolean).join(' ');
|
||||
if (pBadge) pBadge.value = '';
|
||||
|
||||
if (pBrand) {
|
||||
if (storeObj.id === 'glamourstouch') {
|
||||
pBrand.value = 'glamourstouch';
|
||||
} else if (storeObj.category && pBrand.querySelector(`option[value="${storeObj.category}"]`)) {
|
||||
pBrand.value = storeObj.category;
|
||||
} else {
|
||||
pBrand.value = 'custom';
|
||||
}
|
||||
}
|
||||
if (pBrand) pBrand.value = 'workspace';
|
||||
|
||||
if (photoImg && photoBox && p.image) {
|
||||
photoImg.src = p.image;
|
||||
photoBox.classList.remove('hidden');
|
||||
if (clearBtn) clearBtn.classList.remove('hidden');
|
||||
} else if (photoImg && photoBox) {
|
||||
photoImg.removeAttribute('src');
|
||||
photoBox.classList.add('hidden');
|
||||
if (clearBtn) clearBtn.classList.add('hidden');
|
||||
}
|
||||
|
||||
window.closeCatalogModal();
|
||||
if (autocompleteList) autocompleteList.classList.add('hidden');
|
||||
switchToTab('tabPosterLab');
|
||||
|
||||
setTimeout(() => {
|
||||
const genBtn = document.getElementById('generatePosterBtn');
|
||||
if (genBtn) genBtn.click();
|
||||
}, 250);
|
||||
// Product selection fills the form; rendering remains an explicit user action.
|
||||
};
|
||||
|
||||
// 8. Live Autocomplete on #productInput across all active stores
|
||||
@@ -7185,16 +7115,16 @@ async function initCatalogBrowser() {
|
||||
|
||||
const dict = I18N_DICTIONARY[window.currentLang] || I18N_DICTIONARY.bn;
|
||||
autocompleteList.innerHTML = matches.map(p => `
|
||||
<div class="autocomplete-item" onclick="window.applyCatalogProductToPoster('${p.id}')">
|
||||
<img class="autocomplete-thumb" src="${p.image || '/assets/products/cosmetics_3d_cgi.jpg'}" alt="${p.title}" onerror="this.src='/assets/products/cosmetics_3d_cgi.jpg'">
|
||||
<div class="autocomplete-item" onclick="window.applyCatalogProductToPoster(decodeURIComponent('${encodeURIComponent(String(p.id)).replace(/'/g, '%27')}'))">
|
||||
<img class="autocomplete-thumb" src="${htmlText(p.image || '/assets/products/cosmetics_3d_cgi.jpg')}" alt="${htmlText(p.title)}" onerror="this.src='/assets/products/cosmetics_3d_cgi.jpg'">
|
||||
<div class="autocomplete-info">
|
||||
<div class="autocomplete-title">${p.title}</div>
|
||||
<div class="autocomplete-title">${htmlText(p.title)}</div>
|
||||
<div class="autocomplete-meta">
|
||||
<span class="autocomplete-brand">${p.brand || p.storeName || "Authentic"}</span>
|
||||
<span class="autocomplete-price">${p.price}</span>
|
||||
<span class="autocomplete-brand">${htmlText(p.brand || p.storeName || "Authentic")}</span>
|
||||
<span class="autocomplete-price">${htmlText(p.price)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="autocomplete-copy-btn" onclick="event.stopPropagation(); window.copyCatalogProductInfo('${p.id}');">
|
||||
<button type="button" class="autocomplete-copy-btn" onclick="event.stopPropagation(); window.copyCatalogProductInfo(decodeURIComponent('${encodeURIComponent(String(p.id)).replace(/'/g, '%27')}'));">
|
||||
${dict.btn_catalog_copy || '📋 কপি'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user