Files
TasGrid/test-embed.html
T
tcardoza ec67fb89ca
CI / build (push) Has been skipped
CI / deploy (push) Successful in 1m8s
embed improved
2026-03-26 11:59:50 -05:00

763 lines
33 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TasGrid Parent App Simulator</title>
<style>
body {
font-family: system-ui;
padding: 20px;
background: #f4f4f5;
max-width: 1200px;
margin: 0 auto;
}
.container {
display: flex;
gap: 20px;
margin-top: 20px;
}
.iframe-container {
flex: 1;
border: 1px solid #ddd;
background: white;
border-radius: 8px;
overflow: hidden;
display: flex;
flex-direction: column;
height: 600px;
}
.controls {
background: white;
padding: 20px;
border-radius: 8px;
border: 1px solid #ddd;
margin-bottom: 20px;
}
.login-form {
display: grid;
gap: 10px;
max-width: 400px;
}
.login-form input {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
.login-form button {
padding: 10px;
background: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-weight: bold;
}
.login-form button:hover {
background: #0056b3;
}
.status {
margin-top: 10px;
padding: 10px;
border-radius: 4px;
display: none;
}
.status.success {
background: #d4edda;
color: #155724;
display: block;
}
.status.error {
background: #f8d7da;
color: #721c24;
display: block;
}
iframe {
border: none;
width: 100%;
height: 100%;
}
button.send-manual {
padding: 8px 16px;
cursor: pointer;
margin-top: 10px;
}
input.manual-token {
padding: 8px;
width: 100%;
box-sizing: border-box;
}
h1 {
margin-top: 0;
}
.sdk-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 14px;
margin-bottom: 10px;
}
.sdk-card {
border: 1px solid #e5e7eb;
border-radius: 10px;
padding: 14px;
background: #fafafa;
}
.sdk-card h4 {
margin: 0 0 10px;
font-size: 14px;
}
.sdk-card p {
margin: 0 0 10px;
font-size: 12px;
color: #666;
line-height: 1.5;
}
.sdk-stack {
display: grid;
gap: 8px;
}
.sdk-stack input,
.sdk-stack textarea,
.sdk-stack select {
width: 100%;
padding: 8px 10px;
border: 1px solid #d1d5db;
border-radius: 6px;
font: inherit;
box-sizing: border-box;
background: white;
}
.sdk-stack textarea {
min-height: 74px;
resize: vertical;
}
.sdk-inline {
display: flex;
gap: 8px;
align-items: center;
flex-wrap: wrap;
}
.sdk-inline label {
font-size: 12px;
color: #444;
}
.sdk-meta {
margin-top: 10px;
font-size: 12px;
color: #555;
line-height: 1.5;
}
.sdk-actions {
display: flex;
gap: 8px;
flex-wrap: wrap;
margin-top: 8px;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/pocketbase/dist/pocketbase.umd.js"></script>
</head>
<body>
<h1>TasGrid Parent App Simulator</h1>
<div class="controls">
<div id="env-settings" style="margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid #eee;">
<p style="font-size: 13px; color: #666; margin-top: 0;"><strong>Target Environment:</strong></p>
<label style="margin-right: 15px; cursor: pointer;">
<input type="radio" name="envToggle" value="https://tasgrid.ccllc.pro" onchange="updateEnv()">
Production (tasgrid.ccllc.pro)
</label>
<label style="cursor: pointer;">
<input type="radio" name="envToggle" value="http://localhost:4001" checked onchange="updateEnv()">
Localhost:4001
</label>
</div>
<div id="login-section">
<h3>Login to Parent Application</h3>
<p>This simulates the parent application authenticating with the shared backend.</p>
<div class="login-form">
<input type="email" id="email" placeholder="Email" value="">
<input type="password" id="password" placeholder="Password" value="">
<button onclick="login()">Login & Sync Iframes</button>
</div>
<div id="status" class="status"></div>
</div>
<div id="manual-section" style="margin-top: 30px; border-top: 1px solid #eee; padding-top: 20px;">
<p style="font-size: 13px; color: #666;"><strong>Test Deep Linking:</strong></p>
<div style="display: flex; gap: 10px; margin-bottom: 10px;">
<input type="text" id="note-id-input" style="flex: 1; padding: 8px;"
placeholder="Paste Note ID here...">
<button onclick="loadSpecificNote()" style="padding: 8px 16px; cursor: pointer;">Load Note</button>
</div>
<p style="font-size: 13px; color: #666; margin-top: 20px;"><strong>Test Headless SDK (Current
Creation Model):</strong></p>
<div class="sdk-grid">
<div class="sdk-card">
<h4>Task Creation</h4>
<p>Creates a task with normalized tags, structured sharing refs, and optional `#note` linkage, then verifies the task is anchored by personal-context refs instead of the legacy direct user link.</p>
<div class="sdk-stack">
<input type="text" id="sdk-task-title" placeholder="Task title">
<input type="text" id="sdk-task-tags"
placeholder="Tags CSV, e.g. sdk_test,#sdk-workspace,@Shared Bucket">
<textarea id="sdk-task-share-modes"
placeholder="Optional share mode overrides, one per line. Example:&#10;#sdk-workspace=collaborative&#10;@shared bucket=handoff"></textarea>
<div class="sdk-inline">
<input type="number" id="sdk-task-priority" min="1" max="10" value="8"
style="max-width: 90px;" title="Priority">
<input type="number" id="sdk-task-urgency" min="1" max="10" value="4"
style="max-width: 90px;" title="Urgency">
<input type="number" id="sdk-task-size" min="0" max="10" value="3"
style="max-width: 90px;" title="Size">
</div>
<textarea id="sdk-task-content"
placeholder="Task content HTML or plain text">This task was created by a sister app using the current TasGrid SDK flow.</textarea>
</div>
<div class="sdk-actions">
<button onclick="createTaskViaSDK()"
style="padding: 8px 16px; cursor: pointer; background: #6f42c1; color: white; border: none; border-radius: 4px; font-weight: bold;">Create
Task via SDK</button>
</div>
<div class="sdk-meta" id="sdk-task-meta">Last created task: none</div>
</div>
<div class="sdk-card">
<h4>Note Creation</h4>
<p>Creates a canonical-key note and can fully link tasks into the note workspace the new way.</p>
<div class="sdk-stack">
<input type="text" id="sdk-note-title" placeholder="Note title">
<input type="text" id="sdk-note-key" placeholder="Optional note key override">
<input type="text" id="sdk-note-tags" placeholder="Tags CSV, e.g. sdk_test">
<textarea id="sdk-note-content"
placeholder="Note HTML content">&lt;p&gt;This note was created by the updated TasGrid SDK.&lt;/p&gt;</textarea>
<input type="text" id="sdk-note-task-ids"
placeholder="Task IDs CSV to fully link into this note workspace">
<div class="sdk-inline">
<label>Share mode
<select id="sdk-note-share-mode">
<option value="collaborative" selected>collaborative</option>
<option value="handoff">handoff</option>
</select>
</label>
<label>Visibility
<select id="sdk-note-private">
<option value="false" selected>public</option>
<option value="true">private</option>
</select>
</label>
<label style="display: flex; align-items: center; gap: 6px;">
<input type="checkbox" id="sdk-note-link-tasks" checked>
Link tasks via SDK
</label>
</div>
</div>
<div class="sdk-actions">
<button onclick="createNoteViaSDK()"
style="padding: 8px 16px; cursor: pointer; background: #fd7e14; color: white; border: none; border-radius: 4px; font-weight: bold;">Create
Note via SDK</button>
<button onclick="createLinkedWorkspaceScenario()"
style="padding: 8px 16px; cursor: pointer; background: #0f766e; color: white; border: none; border-radius: 4px; font-weight: bold;">Create
Task + Linked Note</button>
</div>
<div class="sdk-meta" id="sdk-note-meta">Last created note: none</div>
</div>
<div class="sdk-card">
<h4>Link Existing Tasks</h4>
<p>Calls the SDK's direct note-link helper so you can test current workspace linking without creating a new note.</p>
<div class="sdk-stack">
<input type="text" id="sdk-link-note-id" placeholder="Target note ID">
<input type="text" id="sdk-link-task-ids" placeholder="Task IDs CSV to link">
</div>
<div class="sdk-actions">
<button onclick="linkExistingTasksViaSDK()"
style="padding: 8px 16px; cursor: pointer; background: #2563eb; color: white; border: none; border-radius: 4px; font-weight: bold;">Link
Tasks to Note</button>
<button onclick="loadLastCreatedNote()" style="padding: 8px 16px; cursor: pointer;">Load Last
Note Embed</button>
</div>
<div class="sdk-meta" id="sdk-link-meta">Ready to link existing records.</div>
</div>
</div>
<p style="font-size: 13px; color: #666; margin-top: 20px;"><strong>Manual Auth:</strong></p>
<input type="text" id="token" class="manual-token" placeholder="Paste PB Token here...">
<button class="send-manual" onclick="sendAuthFromInput()">Send Manual Token</button>
</div>
<div id="docs-section" style="margin-top: 30px; border-top: 1px solid #eee; padding-top: 20px;">
<details>
<summary style="cursor: pointer; font-weight: bold; color: #007bff;">Developer Integration Guide
</summary>
<div style="font-size: 14px; line-height: 1.6; margin-top: 15px;">
<p><strong>1. Available Routes:</strong></p>
<ul>
<li><code>/embed/notes</code>: Renders the full notepad/editor.</li>
<li><code>/embed/notes?noteId=XXX</code>: Renders a specific note directly.</li>
<li><code>/embed/quick-add</code>: Renders a standalone task creation form.</li>
</ul>
<p><strong>2. Programmatic Creation (TasGrid SDK):</strong></p>
<p>The recommended way to create entries is using the <code>tasgrid-sdk.js</code> module. This
now applies TasGrid's current normalized creation rules, including canonical note keys,
structured <code>labelTags</code>/<code>shareRefs</code>/<code>noteRefs</code>, owner-context
tagging, and note-linked task metadata.
</p>
<p><em>Setup:</em></p>
<pre
style="background: #f8f9fa; padding: 15px; border-radius: 4px; border: 1px solid #e9ecef; overflow-x: auto; font-size: 12px;">
import { createTasgridTask, createTasgridNote } from 'https://tasgrid.ccllc.pro/tasgrid-sdk.js';</pre>
<div style="border-left: 4px solid #6f42c1; padding-left: 15px; margin: 20px 0;">
<p><strong>A. Creating a TASK:</strong></p>
<p style="font-size: 12px; color: #666; margin-top: -10px;">Use this for items that need status,
priority, and automated due date calculation.</p>
<pre
style="background: #f8f9fa; padding: 15px; border-radius: 4px; border: 1px solid #e9ecef; overflow-x: auto; font-size: 12px;">
const task = await createTasgridTask(pb, {
title: "Urgent Task",
urgency: 10, // Automated: 10=Today, 5=Next Week, 1=Six Months
priority: 8, // 1-10
size: 3, // Default: 3 (1 hour). Range 0-10.
tags: ["external", "@Shared Bucket", "#project-brief"],
shareModeByTag: {
"@shared bucket": "handoff",
"#project-brief": "collaborative"
},
owner: "USER_ID" // Optional: target personal-context owner, not a direct task.user link
});</pre>
</div>
<div style="border-left: 4px solid #fd7e14; padding-left: 15px; margin: 20px 0;">
<p><strong>B. Creating a NOTE:</strong></p>
<p style="font-size: 12px; color: #666; margin-top: -10px;">Use this for long-form content or
documentation without a deadline.</p>
<pre
style="background: #f8f9fa; padding: 15px; border-radius: 4px; border: 1px solid #e9ecef; overflow-x: auto; font-size: 12px;">
const note = await createTasgridNote(pb, {
title: "Project Brief",
content: "&lt;p&gt;HTML content here...&lt;/p&gt;",
tags: ["documentation"],
noteShareMode: "collaborative",
isPrivate: false,
tasks: [] // Optional: Task IDs to store and fully link into the note workspace
});</pre>
</div>
<p><strong>3. Authentication Protocol:</strong></p>
<p>The parent application must send a <code>postMessage</code> to the iframe immediately after the
iframe loads (or whenever auth state changes). Since iframes reset their internal state on
navigation,
you should always sync auth on the <code>onload</code> event.</p>
<p><em>Example using vanilla JS:</em></p>
<pre
style="background: #f8f9fa; padding: 15px; border-radius: 4px; border: 1px solid #e9ecef; overflow-x: auto; font-size: 12px;">
// 1. Define sync function
function syncAuth(iframe) {
iframe.contentWindow.postMessage({
type: "TASGRID_AUTH",
token: pb.authStore.token,
user: pb.authStore.model
}, "*");
}
// 2. Attach to iframe (either in HTML or via JS)
// &lt;iframe onload="syncAuth(this)" src="..."&gt;&lt;/iframe&gt;
</pre>
<p><strong>4. Responsiveness:</strong></p>
<p>Both routes are designed to be fluid. Ensure your iframe container has defined dimensions; the
content will expand to fill it.</p>
</div>
</details>
</div>
</div>
<div class="container">
<div class="iframe-container">
<div
style="padding: 10px; background: #eee; border-bottom: 1px solid #ddd; font-weight: bold; font-size: 12px; display: flex; justify-content: space-between;">
<span>Notes Embed</span>
<code style="font-size: 10px;">/embed/notes</code>
</div>
<iframe id="notes-iframe" onload="syncAuthOnLoad(this)"></iframe>
</div>
<div class="iframe-container">
<div
style="padding: 10px; background: #eee; border-bottom: 1px solid #ddd; font-weight: bold; font-size: 12px; display: flex; justify-content: space-between;">
<span>Quick Add Embed</span>
<code style="font-size: 10px;">/embed/quick-add</code>
</div>
<iframe id="quick-add-iframe" onload="syncAuthOnLoad(this)"></iframe>
</div>
</div>
<script>
const pb = new PocketBase('https://pocketbase.ccllc.pro');
const statusEl = document.getElementById('status');
let ENV_URL = 'http://localhost:4001';
let lastCreatedTaskId = '';
let lastCreatedNoteId = '';
function setStatus(kind, message) {
statusEl.className = kind ? `status ${kind}` : 'status';
statusEl.textContent = message;
statusEl.style.display = 'block';
}
function parseCsvInput(id) {
return (document.getElementById(id)?.value || '')
.split(',')
.map(value => value.trim())
.filter(Boolean);
}
function parseShareModeOverrides(id) {
const lines = (document.getElementById(id)?.value || '')
.split(/\r?\n/)
.map(line => line.trim())
.filter(Boolean);
const result = {};
for (const line of lines) {
const separatorIndex = line.indexOf('=');
if (separatorIndex === -1) continue;
const key = line.slice(0, separatorIndex).trim().toLowerCase();
const value = line.slice(separatorIndex + 1).trim().toLowerCase();
if (!key || (value !== 'collaborative' && value !== 'handoff')) continue;
result[key] = value;
}
return result;
}
function refreshSdkMeta() {
document.getElementById('sdk-task-meta').textContent = lastCreatedTaskId
? `Last created task: ${lastCreatedTaskId}`
: 'Last created task: none';
document.getElementById('sdk-note-meta').textContent = lastCreatedNoteId
? `Last created note: ${lastCreatedNoteId}`
: 'Last created note: none';
document.getElementById('sdk-link-meta').textContent = [
lastCreatedTaskId ? `task ${lastCreatedTaskId}` : null,
lastCreatedNoteId ? `note ${lastCreatedNoteId}` : null
].filter(Boolean).join(' | ') || 'Ready to link existing records.';
}
async function loadSdkModule() {
return await import(`${ENV_URL}/tasgrid-sdk.js`);
}
function fillLinkingFields() {
if (lastCreatedTaskId && !document.getElementById('sdk-note-task-ids').value.trim()) {
document.getElementById('sdk-note-task-ids').value = lastCreatedTaskId;
}
if (lastCreatedTaskId && !document.getElementById('sdk-link-task-ids').value.trim()) {
document.getElementById('sdk-link-task-ids').value = lastCreatedTaskId;
}
if (lastCreatedNoteId && !document.getElementById('sdk-link-note-id').value.trim()) {
document.getElementById('sdk-link-note-id').value = lastCreatedNoteId;
}
}
function loadLastCreatedNote() {
if (!lastCreatedNoteId) {
alert('Create a note first.');
return;
}
document.getElementById('note-id-input').value = lastCreatedNoteId;
loadSpecificNote();
}
async function inspectTaskContextState(taskId) {
const record = await pb.collection('TasGrid').getOne(taskId, {
fields: 'id,user,shareRefs,noteRefs,tags,labelTags',
requestKey: null
});
const legacyUser = record.user && (typeof record.user === 'string' ? record.user : record.user.id);
const shareRefCount = Array.isArray(record.shareRefs) ? record.shareRefs.length : 0;
const noteRefCount = Array.isArray(record.noteRefs) ? record.noteRefs.length : 0;
return {
legacyUser: legacyUser || null,
shareRefCount,
noteRefCount,
tags: Array.isArray(record.tags) ? record.tags : []
};
}
function updateEnv() {
const selected = document.querySelector('input[name="envToggle"]:checked').value;
ENV_URL = selected;
// Reload iframes with new base URL
const notesIframe = document.getElementById('notes-iframe');
const noteId = document.getElementById('note-id-input')?.value.trim();
if (noteId) {
notesIframe.src = `${ENV_URL}/embed/notes?noteId=${noteId}`;
} else {
notesIframe.src = `${ENV_URL}/embed/notes`;
}
document.getElementById('quick-add-iframe').src = `${ENV_URL}/embed/quick-add`;
console.log(`Switched target environment to: ${ENV_URL}`);
}
// Initialize iframes on load
window.addEventListener('DOMContentLoaded', () => {
updateEnv();
});
function syncAuthOnLoad(iframe) {
console.log(`Iframe ${iframe.id} loaded, checking auth sync...`);
if (pb.authStore.isValid) {
console.log(`Syncing existing auth to ${iframe.id}`);
sendAuth(pb.authStore.token, pb.authStore.model);
}
}
function loadSpecificNote() {
const id = document.getElementById('note-id-input').value.trim();
const iframe = document.getElementById('notes-iframe');
if (id) {
iframe.src = `${ENV_URL}/embed/notes?noteId=${id}`;
} else {
iframe.src = `${ENV_URL}/embed/notes`;
}
}
async function createTaskViaSDK() {
const title = document.getElementById('sdk-task-title').value.trim() || 'SDK Generated Task';
if (!pb.authStore.isValid) {
alert("Please log in first before creating a task via SDK.");
return;
}
setStatus('', 'Importing SDK and creating task...');
try {
const { createTasgridTask, TASGRID_SDK_SIGNATURE } = await loadSdkModule();
const priority = parseInt(document.getElementById('sdk-task-priority').value || '8', 10);
const urgency = parseInt(document.getElementById('sdk-task-urgency').value || '4', 10);
const size = parseInt(document.getElementById('sdk-task-size').value || '3', 10);
const tags = parseCsvInput('sdk-task-tags');
const shareModeByTag = parseShareModeOverrides('sdk-task-share-modes');
const record = await createTasgridTask(pb, {
title: title,
priority: Number.isFinite(priority) ? priority : 8,
urgency: Number.isFinite(urgency) ? urgency : 4,
size: Number.isFinite(size) ? size : 3,
tags: tags,
shareModeByTag,
content: document.getElementById('sdk-task-content').value || ""
});
lastCreatedTaskId = record.id;
fillLinkingFields();
refreshSdkMeta();
const inspection = await inspectTaskContextState(record.id);
const legacyText = inspection.legacyUser ? `legacy user mirror still present: ${inspection.legacyUser}` : 'no legacy task.user link';
setStatus('success', `Task created successfully via SDK ${TASGRID_SDK_SIGNATURE || '(unknown signature)'} (ID: ${record.id}). shareRefs=${inspection.shareRefCount}, noteRefs=${inspection.noteRefCount}, ${legacyText}.`);
} catch (err) {
setStatus('error', 'Failed to create task via SDK: ' + err.message);
}
}
async function createNoteViaSDK() {
const title = document.getElementById('sdk-note-title').value.trim() || 'SDK Generated Note';
if (!pb.authStore.isValid) {
alert("Please log in first before creating a note via SDK.");
return;
}
setStatus('', 'Importing SDK and creating note...');
try {
const { createTasgridNote, TASGRID_SDK_SIGNATURE } = await loadSdkModule();
const taskIds = parseCsvInput('sdk-note-task-ids');
const record = await createTasgridNote(pb, {
title: title,
key: document.getElementById('sdk-note-key').value.trim() || undefined,
content: document.getElementById('sdk-note-content').value || "",
tags: parseCsvInput('sdk-note-tags'),
noteShareMode: document.getElementById('sdk-note-share-mode').value,
isPrivate: document.getElementById('sdk-note-private').value === 'true',
tasks: taskIds,
linkTasks: document.getElementById('sdk-note-link-tasks').checked
});
lastCreatedNoteId = record.id;
document.getElementById('note-id-input').value = record.id;
fillLinkingFields();
refreshSdkMeta();
loadSpecificNote();
setStatus('success', `Note created successfully via SDK ${TASGRID_SDK_SIGNATURE || '(unknown signature)'} (ID: ${record.id}). The notes iframe was pointed at the new note.`);
} catch (err) {
setStatus('error', 'Failed to create note via SDK: ' + err.message);
}
}
async function linkExistingTasksViaSDK() {
const noteId = document.getElementById('sdk-link-note-id').value.trim();
const taskIds = parseCsvInput('sdk-link-task-ids');
if (!pb.authStore.isValid) {
alert("Please log in first before linking tasks via SDK.");
return;
}
if (!noteId || taskIds.length === 0) {
alert("Provide both a target note ID and at least one task ID.");
return;
}
setStatus('', 'Importing SDK and linking tasks to note...');
try {
const { linkTasgridTasksToNote, TASGRID_SDK_SIGNATURE } = await loadSdkModule();
const records = await linkTasgridTasksToNote(pb, noteId, taskIds);
lastCreatedNoteId = noteId;
fillLinkingFields();
refreshSdkMeta();
const inspection = await inspectTaskContextState(taskIds[0]);
setStatus('success', `Linked ${records.length} task(s) to note ${noteId} via SDK ${TASGRID_SDK_SIGNATURE || '(unknown signature)'}. First task now has shareRefs=${inspection.shareRefCount} and noteRefs=${inspection.noteRefCount}.`);
} catch (err) {
setStatus('error', 'Failed to link tasks via SDK: ' + err.message);
}
}
async function createLinkedWorkspaceScenario() {
if (!pb.authStore.isValid) {
alert("Please log in first before creating linked workspace data.");
return;
}
setStatus('', 'Creating a task and linked note scenario via the SDK...');
try {
const { createTasgridTask, createTasgridNote, TASGRID_SDK_SIGNATURE } = await loadSdkModule();
const timestamp = new Date().toISOString().replace(/[^\d]/g, '').slice(0, 12);
const workspaceTag = `#sdk-workspace-${timestamp}`;
const taskRecord = await createTasgridTask(pb, {
title: `SDK Workspace Task ${timestamp}`,
priority: 8,
urgency: 4,
size: 3,
tags: ['sdk_test', workspaceTag],
shareModeByTag: {
[workspaceTag.toLowerCase()]: 'collaborative'
},
content: 'Workspace task created by the test simulator.'
});
const noteRecord = await createTasgridNote(pb, {
title: `SDK Workspace Note ${timestamp}`,
tags: ['sdk_test'],
content: `<p>Workspace note for task <code>${taskRecord.id}</code>.</p>`,
noteShareMode: 'collaborative',
isPrivate: false,
tasks: [taskRecord.id],
linkTasks: true
});
lastCreatedTaskId = taskRecord.id;
lastCreatedNoteId = noteRecord.id;
document.getElementById('note-id-input').value = noteRecord.id;
document.getElementById('sdk-note-task-ids').value = taskRecord.id;
fillLinkingFields();
refreshSdkMeta();
loadSpecificNote();
const inspection = await inspectTaskContextState(taskRecord.id);
const legacyText = inspection.legacyUser ? `legacy user mirror still present: ${inspection.legacyUser}` : 'no legacy task.user link';
setStatus('success', `Created linked workspace scenario via SDK ${TASGRID_SDK_SIGNATURE || '(unknown signature)'}. Task ${taskRecord.id} and note ${noteRecord.id} were created, loaded into the embed, and verified with shareRefs=${inspection.shareRefCount}, noteRefs=${inspection.noteRefCount}, ${legacyText}.`);
} catch (err) {
setStatus('error', 'Failed to create linked workspace scenario: ' + err.message);
}
}
async function login() {
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
setStatus('', 'Logging in...');
try {
const authData = await pb.collection('users').authWithPassword(email, password);
setStatus('success', `Logged in as ${authData.record.email}! Syncing iframes...`);
// Automatically send auth to iframes
sendAuth(pb.authStore.token, authData.record);
} catch (err) {
setStatus('error', 'Login failed: ' + err.message);
}
}
function sendAuthFromInput() {
const token = document.getElementById('token').value;
if (!token) {
alert("Please enter a token first");
return;
}
sendAuth(token, null);
}
function sendAuth(token, user) {
const payload = {
type: "TASGRID_AUTH",
token: token,
user: user
};
const notesIframe = document.getElementById('notes-iframe').contentWindow;
const quickAddIframe = document.getElementById('quick-add-iframe').contentWindow;
console.log("Sending auth to iframes...", payload);
notesIframe.postMessage(payload, "*");
quickAddIframe.postMessage(payload, "*");
}
// Handle case where user refreshed but is still logged in to the parent
window.addEventListener('load', () => {
if (pb.authStore.isValid && pb.authStore.model) {
document.getElementById('email').value = pb.authStore.model.email || "";
setStatus('success', 'Session restored. Click login or send manual token to sync.');
}
refreshSdkMeta();
});
</script>
</body>
</html>