Samaira Travels
Loading...
Loading data...
let allData = [];/* LOAD DATA */function loadData() { google.script.run .withSuccessHandler(function(result) { allData = result.rows; createCategoryFilter(); displayData(allData); }) .withFailureHandler(function(error) { document.getElementById("content").innerHTML = "
Unable to load data.
"; console.error(error); }) .getSheetData();}/* CREATE CATEGORY FILTER */function createCategoryFilter() { const select = document.getElementById("categoryFilter"); const categories = []; allData.forEach(row => { const category = row["Category"]; if ( category && !categories.includes(category) ) { categories.push(category); } }); categories.sort(); categories.forEach(category => { const option = document.createElement("option"); option.value = category; option.textContent = category; select.appendChild(option); });}/* DISPLAY DATA */function displayData(data) { const container = document.getElementById("content"); const resultInfo = document.getElementById("resultInfo"); resultInfo.textContent = data.length + " results found"; if (!data.length) { container.innerHTML = "
No results found.
"; retu; } let html = "
"; data.forEach(row => { html += createCard(row); }); html += "
"; container.innerHTML = html;}/* CREATE CARD */function createCard(row) { const category = row["Category"] || ""; /* * Change "Name" if your * main title column has * another name. */ const title = row["Name"] || row["Hotel"] || row["Package"] || row["Service"] || "Travel Service"; let html = `
${escapeHTML(category)}
${escapeHTML(title)}
`; Object.keys(row).forEach(key => { if ( key === "Category" || key === "Name" || key === "Hotel" || key === "Package" || key === "Service" ) { retu; } if (!row[key]) { retu; } html += `
${escapeHTML(key)}: ${escapeHTML(row[key])}
`; }); html += `
`; retu html;}/* SEARCH + FILTER */function filterData() { const search = document .getElementById("searchBox") .value .toLowerCase(); const category = document .getElementById("categoryFilter") .value; const filtered = allData.filter(row => { const text = Object.values(row) .join(" ") .toLowerCase(); const matchesSearch = text.includes(search); const matchesCategory = !category || row["Category"] === category; retu ( matchesSearch && matchesCategory ); }); displayData(filtered);}/* SECURITY */function escapeHTML(value) { retu String(value) .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'");}/* INITIAL LOAD */loadData();/* * AUTOMATIC UPDATE * * Refresh data every 60 seconds. */setInterval(function() { loadData();}, 60000);