create note api added
This commit is contained in:
+71
-3
@@ -124,6 +124,19 @@
|
||||
<div id="status" class="status"></div>
|
||||
</div>
|
||||
|
||||
<div id="api-section" style="margin-top: 30px; border-top: 1px solid #eee; padding-top: 20px;">
|
||||
<h3>Note Creation API</h3>
|
||||
<div style="display: flex; gap: 10px; align-items: center;">
|
||||
<button class="send-manual" onclick="createNote()"
|
||||
style="margin-top: 0; background: #28a745; color: white; border: none; border-radius: 4px; padding: 10px 15px; font-weight: bold; cursor: pointer;">Create
|
||||
Sample Note</button>
|
||||
<div id="api-status" style="font-size: 12px; color: #666;"></div>
|
||||
</div>
|
||||
<div id="api-result"
|
||||
style="margin-top: 10px; font-family: monospace; font-size: 11px; background: #eee; padding: 10px; border-radius: 4px; display: none; word-break: break-all;">
|
||||
</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;">Or send a token manually:</p>
|
||||
<input type="text" id="token" class="manual-token" placeholder="Paste PB Token here...">
|
||||
@@ -152,9 +165,28 @@ iframe.contentWindow.postMessage({
|
||||
user: { /* optional PB user record */ }
|
||||
}, "*");</pre>
|
||||
|
||||
<p><strong>3. 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>
|
||||
<p><strong>4. Note Creation API (TASGRID_CREATE_NOTE):</strong></p>
|
||||
<p>Trigger note creation from the parent app. TasGrid will respond with
|
||||
<code>TASGRID_NOTE_CREATED</code>.</p>
|
||||
<pre
|
||||
style="background: #f8f9fa; padding: 15px; border-radius: 4px; border: 1px solid #e9ecef; overflow-x: auto;">
|
||||
// Request
|
||||
iframe.contentWindow.postMessage({
|
||||
type: "TASGRID_CREATE_NOTE",
|
||||
note: {
|
||||
title: "Project Alpha",
|
||||
content: "Initial requirements...",
|
||||
tags: ["Project", "2024"],
|
||||
isPrivate: false
|
||||
}
|
||||
}, "*");
|
||||
|
||||
// Response Listener
|
||||
window.addEventListener("message", (event) => {
|
||||
if (event.data.type === "TASGRID_NOTE_CREATED") {
|
||||
console.log("New Note ID:", event.data.noteId);
|
||||
}
|
||||
});</pre>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
@@ -230,6 +262,42 @@ iframe.contentWindow.postMessage({
|
||||
quickAddIframe.postMessage(payload, "*");
|
||||
}
|
||||
|
||||
async function createNote() {
|
||||
const apiStatus = document.getElementById('api-status');
|
||||
const apiResult = document.getElementById('api-result');
|
||||
|
||||
apiStatus.textContent = "Sending creation request...";
|
||||
apiResult.style.display = 'none';
|
||||
|
||||
const payload = {
|
||||
type: "TASGRID_CREATE_NOTE",
|
||||
note: {
|
||||
title: "Test Note from Parent " + new Date().toLocaleTimeString(),
|
||||
content: "This note was created automatically via the postMessage API.",
|
||||
tags: ["API-TEST", "SISTER-APP"],
|
||||
isPrivate: false
|
||||
}
|
||||
};
|
||||
|
||||
// We can send to either iframe since EmbedAuthWrapper handles it globally for all embedded views
|
||||
document.getElementById('notes-iframe').contentWindow.postMessage(payload, "*");
|
||||
}
|
||||
|
||||
// Listen for responses
|
||||
window.addEventListener("message", (event) => {
|
||||
const { data } = event;
|
||||
console.log("Parent received message:", data);
|
||||
|
||||
if (data.type === "TASGRID_NOTE_CREATED") {
|
||||
const apiStatus = document.getElementById('api-status');
|
||||
const apiResult = document.getElementById('api-result');
|
||||
|
||||
apiStatus.innerHTML = `<span style="color: green; font-weight: bold;">Note Created! ID: ${data.noteId}</span>`;
|
||||
apiResult.textContent = JSON.stringify(data, null, 2);
|
||||
apiResult.style.display = 'block';
|
||||
}
|
||||
});
|
||||
|
||||
// Handle case where user refreshed but is still logged in to the parent
|
||||
window.addEventListener('load', () => {
|
||||
if (pb.authStore.isValid && pb.authStore.model) {
|
||||
|
||||
Reference in New Issue
Block a user