// Asana offline clone — authenticated app SPA.
// History-based routing under /app/*; all data via the local /api.
(function () {
"use strict";
var ME = null; // {user, workspace, workspaces, role}
var PROJECTS = [];
var UNREAD = 0;
var SELECTED = {}; // task_id -> true (bulk selection)
var FILTERS = {}; // current list filters
var SIDEBAR_COLLAPSED = false;
var SIDEBAR_OPEN = false;
var root = document.getElementById("app");
// ---------------- helpers ----------------
function esc(s) {
return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) {
return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c];
});
}
function el(html) {
var t = document.createElement("template");
t.innerHTML = html.trim();
return t.content.firstElementChild;
}
async function api(path, opts) {
opts = opts || {};
var init = { credentials: "same-origin", method: opts.method || "GET", headers: {} };
if (opts.body !== undefined && !(opts.body instanceof FormData)) {
init.headers["Content-Type"] = "application/json";
init.body = JSON.stringify(opts.body);
} else if (opts.body instanceof FormData) {
init.body = opts.body;
}
var res = await fetch("/api" + path, init);
if (res.status === 401) { location.assign("/-/login"); throw new Error("unauthorized"); }
var data = null;
try { data = await res.json(); } catch (e) { data = {}; }
if (!res.ok) {
var msg = (data && data.error && data.error.message) ||
(data && data.message) || "Something went wrong.";
var err = new Error(msg); err.status = res.status; err.code = data && data.error && data.error.code;
throw err;
}
return data;
}
function toast(msg, isError) {
var box = document.querySelector(".toasts") || document.body.appendChild(el('
'));
var t = el('' + esc(msg) + "
");
box.appendChild(t);
setTimeout(function () { t.remove(); }, 3400);
}
function avatar(name, color, initials, small) {
return '' + esc(initials || "?") + " ";
}
function fmtDate(iso) {
if (!iso) return "";
var d = new Date(iso + "T00:00:00");
return d.toLocaleDateString(undefined, { month: "short", day: "numeric" });
}
function dueClass(iso, completed) {
if (!iso || completed) return "";
var today = new Date(); today.setHours(0, 0, 0, 0);
var d = new Date(iso + "T00:00:00");
if (d < today) return " overdue";
if (d.getTime() === today.getTime()) return " today";
return "";
}
function ago(ts) {
var s = Math.max(1, Math.floor(Date.now() / 1000 - ts));
if (s < 60) return s + "s ago";
if (s < 3600) return Math.floor(s / 60) + "m ago";
if (s < 86400) return Math.floor(s / 3600) + "h ago";
return Math.floor(s / 86400) + "d ago";
}
function greeting() {
var h = new Date().getHours();
return h < 12 ? "Good morning" : h < 18 ? "Good afternoon" : "Good evening";
}
// ---------------- routing ----------------
function nav(path) { history.pushState({}, "", path); route(); }
window.addEventListener("popstate", route);
document.addEventListener("click", function (ev) {
var a = ev.target.closest("a[data-nav]");
if (a) { ev.preventDefault(); nav(a.getAttribute("href")); }
});
function route() {
closePane();
var p = location.pathname.replace(/\/+$/, "") || "/app/home";
var m;
var activeMode = document.querySelector(".mode-button.active");
if (activeMode && activeMode.dataset.mode !== currentMode()) shell("");
if (p === "/app" || p === "/app/home") return viewHome();
if ((m = p.match(/^\/app\/agents(?:\/(\w+))?$/))) return viewAgents(m[1] || "overview");
if ((m = p.match(/^\/app\/strategy(?:\/(\w+))?$/))) return viewStrategy(m[1] || "overview");
if ((m = p.match(/^\/app\/knowledge(?:\/(\w+))?$/))) return viewKnowledge(m[1] || "overview");
if ((m = p.match(/^\/app\/people(?:\/(\w+))?$/))) return viewPeople(m[1] || "directory");
if (p === "/app/more") return viewMore();
if (p === "/app/tasks") return viewMyTasks();
if (p === "/app/tasks/upcoming") return viewMyTasks("upcoming");
if (p === "/app/tasks/overdue") return viewMyTasks("overdue");
if (p === "/app/projects") return viewProjects();
if ((m = p.match(/^\/app\/project\/([^/]+)(?:\/(\w+))?$/))) return viewProject(m[1], m[2] || null);
if (p === "/app/search") return viewSearch(new URLSearchParams(location.search).get("q") || "");
if (p === "/app/inbox") return viewInbox();
if (p === "/app/portfolios") return viewPortfolios();
if ((m = p.match(/^\/app\/portfolio\/([^/]+)$/))) return viewPortfolio(m[1]);
if (p === "/app/goals") return viewGoals();
if (p === "/app/activity") return viewActivity();
if (p === "/app/settings") return viewSettings(new URLSearchParams(location.search).get("tab") || "profile");
if (p === "/app/admin") return viewAdmin();
if (p === "/app/invite") return viewInvite();
if (p === "/app/billing") return viewBilling();
if (p === "/app/trash") return viewTrash();
if (p === "/app/help") return viewHelp();
return viewNotFound(p);
}
// ---------------- shell ----------------
var APP_ICON_PATHS = {
work: "M24.5068 -.0001C28.649-.0001 32.0068 3.3578 32.0068 7.4999c0 3.0004-1.7622 5.5866-4.308 6.7851-.6802.3202-1.192.9621-1.192 1.7139s.512 1.3937 1.192 1.714c2.546 1.1987 4.308 3.7865 4.308 6.7871 0 4.142-3.3578 7.5-7.5 7.5-3.0064-.0002-5.5986-1.7696-6.7942-4.3238-.3145-.6716-.9479-1.1762-1.6896-1.1762-.7476 0-1.3846.5126-1.6961 1.1922-1.184 2.5836-3.7919 4.378-6.8201 4.378-4.1419-.0002-7.5-3.358-7.5-7.5.0003-2.9876 1.7479-5.5663 4.2763-6.7718.6974-.3325 1.2237-.9918 1.2237-1.7644s-.5263-1.4318-1.2236-1.7642C1.7548 13.0646.0068 10.4875.0068 7.4999.0068 3.3579 3.365.0002 7.5068-.0001c3.0008 0 5.5887 1.7628 6.7874 4.309.32.6796.9614 1.191 1.7126 1.191s1.3927-.5114 1.7127-1.191C18.9182 1.7627 21.5062.0001 24.5068-.0001ZM16.0068 9.4999c-.7512 0-1.3926.5113-1.7127 1.1909-.7376 1.5662-2.0012 2.8346-3.5636 3.5792-.6974.3323-1.2237.9915-1.2237 1.764s.5264 1.4318 1.2238 1.7643c1.5395.7339 2.7889 1.9772 3.531 3.5123.3284.6794.9742 1.1894 1.7289 1.1894.7608 0 1.4103-.5182 1.736-1.2058.7436-1.5704 2.0164-2.8406 3.5885-3.5812.6802-.3204 1.1918-.9623 1.1918-1.7141s-.5116-1.3938-1.1918-1.714c-1.5768-.7426-2.8528-2.0175-3.5954-3.5941-.3202-.6795-.9616-1.1909-1.7128-1.1909Z",
agents: "M13.0073 4.0898C13.0022.4564 17.1674-1.3675 19.604 1.2011l11.2715 11.8867c.7245.7641 1.1316 1.8012 1.1318 2.8818v.0997c-.0001 1.0806-.4073 2.1176-1.1318 2.8818L19.6421 30.7978c-2.4323 2.5651-6.5919.7526-6.5977-2.875l-.0117-7.6826c-.001-.6849-.5564-1.2401-1.2412-1.2403-.3384 0-.6623.1386-.8965.3828l-4.2314 4.416C4.2098 26.3593.0194 24.5544.0161 20.9355L.0073 11.0839c-.0028-3.6254 4.198-5.449 6.6524-2.8877l4.2392 4.4248c.2322.2422.5532.3789.8887.3789.6807 0 1.2323-.5518 1.2314-1.2324l-.0117-7.6777Z",
strategy: "M19.535 3.417C18.752 2.217 17.431 1.5 16 1.5c-1.431 0-2.752.716-3.534 1.916L.696 21.443c-.866 1.326-.933 2.949-.179 4.342C1.268 27.172 2.656 28 4.23 28h23.539c1.574 0 2.962-.828 3.713-2.215.754-1.393.688-3.016-.179-4.342L19.535 3.417Z",
knowledge: "M19.0054.0012c.5516-.0276 1.0019.4242 1.0019.9777v9.9233c0 .6222.562 1.0948 1.1592.9248 3.4919-.9944 6.0419-3.4111 9.8418-3.7844.5495-.0538.999.3998.999.9532v18.0381c-.0001.5534-.4497.9963-.999 1.053-4.1964.4333-6.7155 3.4839-11.002 3.9087-.5495.0544-.9989-.3998-.999-.9532v-6.0245c0-.5751-.4845-1.0354-1.0547-.9698-6.3185.7273-10.2016 4.6063-16.9433 4.9636-.5515.0292-1.0019-.4223-1.002-.9757V6.0286c0-.5295.4132-.9651.9385-1.0217C7.8044 4.2694 12.0132.3505 19.0054.0012Z",
people: "M16.0073 0c4.9706 0 9 4.0294 9 9 0 3.3202-1.799 6.2184-4.4744 7.7781-.3161.1842-.5256.5148-.5256.8806 0 .4521.3154.8408.7522.9573 5.886 1.5708 10.3368 5.9833 11.2252 11.3913.1791 1.0905-.7336 1.9927-1.8388 1.9927H1.8687c-1.1052 0-2.018-.9022-1.8388-1.9927.8884-5.4079 5.3393-9.8205 11.2252-11.3912.4368-.1166.7522-.5053.7522-.9574 0-.3658-.2095-.6964-.5256-.8806C8.8062 15.2184 7.0073 12.3202 7.0073 9c0-4.9706 4.0294-9 9-9Z",
more: "M16 13c1.7 0 3 1.3 3 3s-1.3 3-3 3-3-1.3-3-3 1.3-3 3-3ZM3 13c1.7 0 3 1.3 3 3s-1.3 3-3 3-3-1.3-3-3 1.3-3 3-3Zm26 0c1.7 0 3 1.3 3 3s-1.3 3-3 3-3-1.3-3-3 1.3-3 3-3Z",
home: "M31.6 12.2 17.8 2.6c-1.1-.8-2.6-.8-3.7 0L.4 12.2c-.5.3-.6.9-.3 1.4s.9.6 1.4.3L4 12.1v10.8c0 3.9 3.2 7.1 7.1 7.1H21c3.9 0 7.1-3.2 7.1-7.1V12.1l2.4 1.7c.1.2.3.2.5.2.3 0 .6-.2.8-.4.3-.5.2-1.1-.2-1.4ZM26 22.9c0 2.8-2.3 5-5 5h-9.9c-2.8 0-5-2.3-5-5V10.7l9.4-6.5c.4-.3.9-.3 1.3 0l9.3 6.5-.1 12.2Z",
tasks: "M29.1 20.9M16 32C7.2 32 0 24.8 0 16S7.2 0 16 0s16 7.2 16 16-7.2 16-16 16Zm0-30C8.3 2 2 8.3 2 16s6.3 14 14 14 14-6.3 14-14S23.7 2 16 2Zm-3.1 20.6c-.3 0-.5-.1-.7-.3l-3.9-3.9c-.3-.4-.3-1 0-1.4s1-.4 1.4 0l3.1 3.1 8.6-8.6c.4-.4 1-.4 1.4 0s.4 1 0 1.4l-9.4 9.4c0 .2-.2.4-.5.4Z",
inbox: "M26 12c3.3137 0 6-2.6863 6-6s-2.6863-6-6-6-6 2.6863-6 6 2.6863 6 6 6Zm3.97 8.635C28.718 19.523 28 17.924 28 16.249V15c0-.552-.448-1-1-1s-1 .448-1 1v1.249c0 2.246.962 4.389 2.641 5.881.367.326.462.849.239 1.303-.167.339-.582.567-1.03.567H4.151c-.449 0-.863-.228-1.03-.568-.224-.453-.128-.977.239-1.302C5.038 20.638 6.001 18.495 6.001 16.249V12c0-2.706 1.063-5.24 2.994-7.136 1.931-1.896 4.489-2.921 7.194-2.862.701.012 1.4.102 2.077.266.536.128 1.077-.2 1.207-.737.129-.537-.2-1.077-.737-1.207A12.1 12.1 0 0 0 16.225.003C12.961-.049 9.91 1.164 7.594 3.438 5.277 5.713 4.001 8.754 4.001 12.001v4.249c0 1.675-.718 3.273-1.97 4.386-1.047.932-1.33 2.411-.704 3.682.504 1.023 1.613 1.684 2.824 1.684h23.698c1.211 0 2.32-.661 2.824-1.683.626-1.271.344-2.75-.704-3.682ZM19.733 28H20.896C19.963 29.817 18.081 31 16 31s-3.963-1.183-4.896-3h8.629Z",
projects: "M10 13.5c.8 0 1.5.7 1.5 1.5s-.7 1.5-1.5 1.5-1.5-.7-1.5-1.5.7-1.5 1.5-1.5ZM23 14h-8c-.6 0-1 .4-1 1s.4 1 1 1h8c.6 0 1-.4 1-1s-.4-1-1-1Zm0 6h-8c-.6 0-1 .4-1 1s.4 1 1 1h8c.6 0 1-.4 1-1s-.4-1-1-1Zm-13-.5c.8 0 1.5.7 1.5 1.5s-.7 1.5-1.5 1.5-1.5-.7-1.5-1.5.7-1.5 1.5-1.5ZM24 2h-2.2C21.4.8 20.3 0 19 0h-6c-1.3 0-2.4.8-2.8 2H8C4.7 2 2 4.7 2 8v18c0 3.3 2.7 6 6 6h16c3.3 0 6-2.7 6-6V8c0-3.3-2.7-6-6-6ZM13 2h6c.6 0 1 .4 1 1v2c0 .6-.4 1-1 1h-6c-.6 0-1-.4-1-1V3c0-.6.4-1 1-1Zm15 24c0 2.2-1.8 4-4 4H8c-2.2 0-4-1.8-4-4V8c0-2.2 1.8-4 4-4h2v1c0 1.7 1.3 3 3 3h6c1.7 0 3-1.3 3-3V4h2v22Z",
portfolios: "M29 8c1.6569 0 3 1.3431 3 3v14c0 2.7614-2.2386 5-5 5H5c-2.7614 0-5-2.2386-5-5V5c0-1.6569 1.3431-3 3-3h9.2c.3693 0 .7086.2036.8824.5294l2.0705 3.8824C15.6743 7.3894 16.6921 8 17.8 8H29Zm1 3v14c0 1.6569-1.3431 3-3 3H5c-1.6569 0-3-1.3431-3-3V10h27c.5523 0 1 .4477 1 1ZM13.7999 8c-.1522-.203-.29-.419-.4117-.6471L11.6 4H3c-.5523 0-1 .4477-1 1v3h11.7999Z"
};
function appIcon(name, small) {
return ' ';
}
function projectMark() {
return ' ';
}
function currentMode() {
var path = location.pathname;
if (path.indexOf("/app/agents") === 0) return "agents";
if (path.indexOf("/app/strategy") === 0 || path === "/app/goals" || path.indexOf("/app/portfolio") === 0) return "strategy";
if (path.indexOf("/app/knowledge") === 0) return "knowledge";
if (path.indexOf("/app/people") === 0 || path === "/app/invite") return "people";
if (path === "/app/more" || /^\/app\/(settings|admin|billing|trash)/.test(path)) return "more";
return "work";
}
function modeSidebar(mode, projItems) {
if (mode === "work") {
return '' + sideItem("/app/home", appIcon("home"), "Home") +
sideItem("/app/inbox", appIcon("inbox"), "Inbox", UNREAD) +
'
' +
sideItem("/app/tasks", appIcon("tasks"), "My tasks") +
sideItem("/app/projects", appIcon("projects"), "Projects") +
sideItem("/app/portfolios", appIcon("portfolios"), "Portfolios") +
'
';
}
var links = {
agents: [["/app/agents", "agents", "Overview"], ["/app/agents/library", "projects", "Agent library"], ["/app/agents/activity", "strategy", "Agent activity"]],
strategy: [["/app/strategy", "strategy", "Overview"], ["/app/goals", "strategy", "Goals"], ["/app/portfolios", "portfolios", "Portfolios"], ["/app/strategy/reporting", "strategy", "Reporting"]],
knowledge: [["/app/knowledge", "knowledge", "Overview"], ["/app/knowledge/collections", "projects", "Collections"], ["/app/knowledge/templates", "portfolios", "Templates"]],
people: [["/app/people", "people", "Directory"], ["/app/people/teams", "projects", "Teams"], ["/app/invite", "people", "Invite people"]],
more: [["/app/more", "more", "Overview"], ["/app/settings", "people", "My settings"], ["/app/admin", "projects", "Workspace settings"], ["/app/billing", "portfolios", "Billing"], ["/app/trash", "inbox", "Trash"]],
}[mode];
return '' + links.map(function (item) {
return sideItem(item[0], appIcon(item[1]), item[2]);
}).join("") + '
' +
({ agents: "Build and monitor AI teammates.", strategy: "Connect goals to execution.", knowledge: "Find shared team knowledge.", people: "Manage people and teams.", more: "Workspace tools and settings." }[mode]) + '
';
}
function shell(contentHtml) {
var projItems = PROJECTS.slice(0, 1).map(function (p) {
return '' +
projectMark() +
'Team schedule ';
}).join("");
var wsOptions = (ME.workspaces || []).map(function (w, index) {
return '" +
(index ? "Demo Workspace " + (index + 1) : "Demo Workspace") + " ";
}).join("");
var mode = currentMode();
var modeTitle = { work: "Work", agents: "Agents", strategy: "Strategy", knowledge: "Knowledge", people: "People", more: "More" }[mode];
var modeButtons = [["work", "/app/home", "Work"], ["agents", "/app/agents", "Agents"],
["strategy", "/app/strategy", "Strategy"], ["knowledge", "/app/knowledge", "Knowledge"],
["people", "/app/people", "People"], ["more", "/app/more", "More"]].map(function (item) {
return '' +
appIcon(item[0]) + ' ' + item[2] + ' ';
}).join("");
root.innerHTML =
'' +
'' +
'Create ' +
'' +
' ' +
" " +
'";
document.getElementById("hamb").onclick = function () {
var sb = document.getElementById("sidebar");
if (window.innerWidth <= 860) {
SIDEBAR_OPEN = !SIDEBAR_OPEN;
sb.classList.toggle("open", SIDEBAR_OPEN);
} else {
SIDEBAR_COLLAPSED = !SIDEBAR_COLLAPSED;
sb.classList.toggle("collapsed", SIDEBAR_COLLAPSED);
}
this.setAttribute("aria-expanded", String(window.innerWidth <= 860 ? SIDEBAR_OPEN : !SIDEBAR_COLLAPSED));
};
document.getElementById("create-btn").onclick = openCreateMenu;
document.getElementById("assistant-btn").onclick = openAssistant;
var sideAdd = document.getElementById("side-add-project");
if (sideAdd) sideAdd.onclick = function () { openProjectModal(); };
document.getElementById("workspace-title").onclick = openWorkspaceSwitcher;
document.getElementById("ws-switch").onchange = async function () {
await api("/workspace/switch", { method: "POST", body: { workspace_id: this.value } });
await loadMe(); nav("/app/home");
};
var gs = document.getElementById("global-search");
gs.addEventListener("keydown", function (ev) {
if (ev.key === "Enter" && gs.value.trim()) nav("/app/search?q=" + encodeURIComponent(gs.value.trim()));
});
document.getElementById("me-menu").onclick = openMeMenu;
document.getElementById("help-menu").onclick = openHelpMenu;
document.getElementById("trial-info").onclick = function () { nav("/app/billing"); };
highlightSide();
}
function sideItem(href, icon, label, badge) {
return '' + icon + " " +
esc(label) + (badge ? '' + badge + " " : "") + " ";
}
function highlightSide() {
document.querySelectorAll(".side-item").forEach(function (a) {
a.classList.toggle("active", a.getAttribute("href") === location.pathname);
});
}
function setPage(html) {
if (!document.getElementById("page")) shell("");
var page = document.getElementById("page");
page.className = "page" + (arguments[1] ? " " + arguments[1] : "");
page.innerHTML = html;
highlightSide();
}
function loadingPage() { setPage(''); }
function openMeMenu() {
openModal('' +
'');
document.querySelectorAll("[data-go]").forEach(function (b) {
b.onclick = function () { closeModal(); nav(b.dataset.go); };
});
document.getElementById("logout-btn").onclick = async function () {
await api("/auth/logout", { method: "POST" });
location.assign("/-/login");
};
document.getElementById("profile-workspace").onclick = function () { closeModal(); openWorkspaceSwitcher(); };
document.getElementById("profile-help").onclick = function () { closeModal(); openHelpMenu(); };
}
function openHelpMenu() {
openModal('How can we help? Get help without leaving your current work.
' +
'' +
'
');
document.querySelectorAll("[data-help-go]").forEach(function (button) {
button.onclick = function () { closeModal(); nav(button.dataset.helpGo); };
});
document.getElementById("help-shortcuts").onclick = function () {
document.getElementById("help-result").textContent = "Press / to search, Tab to move, and Esc to close a dialog.";
};
document.getElementById("help-support").onclick = function () {
document.getElementById("help-result").textContent = "Support is available inside this local demo; no message was sent.";
};
}
function openAssistant() {
openModal('Local assistant ' +
'Get help with this synthetic Demo Workspace. Nothing is sent outside this device.
' +
'' +
'Summarize my tasks ' +
'Show active projects ' +
'Open help
' +
'
');
document.querySelectorAll("[data-assistant]").forEach(function (button) {
button.onclick = function () {
if (button.dataset.assistant === "help") { closeModal(); nav("/app/help"); return; }
document.getElementById("assistant-answer").textContent = button.dataset.assistant === "tasks" ?
"Your local task list is ready on Home and My tasks." :
PROJECTS.length + " active local projects are available in Demo Workspace.";
};
});
}
function openWorkspaceSwitcher() {
openModal('Demo Workspace Switch between local synthetic workspaces.
' +
'Workspace ' +
'' + document.getElementById("ws-switch").innerHTML + '
' +
'Cancel ' +
'Open workspace
');
document.getElementById("modal-ws-cancel").onclick = closeModal;
document.getElementById("modal-ws-open").onclick = async function () {
await api("/workspace/switch", { method: "POST", body: {
workspace_id: document.getElementById("modal-ws-switch").value,
} });
closeModal(); await loadMe(); nav("/app/home");
};
}
function openCreateMenu() {
openModal('Create ' +
'Task ' +
'Project ' +
'Portfolio ' +
'Goal ' +
'Workspace
');
document.getElementById("cm-task").onclick = function () { closeModal(); openTaskModal(); };
document.getElementById("cm-project").onclick = function () { closeModal(); openProjectModal(); };
document.getElementById("cm-portfolio").onclick = function () { closeModal(); openPortfolioModal(); };
document.getElementById("cm-goal").onclick = function () { closeModal(); openGoalModal(); };
document.getElementById("cm-workspace").onclick = function () { closeModal(); openWorkspaceModal(); };
}
// ---------------- modals ----------------
function openModal(inner) {
closeModal();
var b = el('");
b.addEventListener("mousedown", function (ev) { if (ev.target === b) closeModal(); });
document.body.appendChild(b);
document.addEventListener("keydown", escClose);
var f = b.querySelector("input,select,textarea,button");
if (f) f.focus();
}
function escClose(ev) { if (ev.key === "Escape") { closeModal(); closePane(); } }
document.addEventListener("keydown", escClose);
function closeModal() {
var b = document.querySelector(".modal-backdrop");
if (b) b.remove();
}
var COLORS = ["#4573d2", "#f06a6a", "#5da283", "#f1bd6c", "#796eff", "#aa62e3", "#f9838c", "#6d6e6f"];
function colorRow(sel) {
return '' + COLORS.map(function (c) {
return ' ';
}).join("") + "
";
}
function wireColorRow(box) {
box.querySelectorAll(".color-swatch").forEach(function (s) {
s.onclick = function () {
box.querySelectorAll(".color-swatch").forEach(function (x) { x.classList.remove("on"); });
s.classList.add("on");
};
});
}
function pickedColor() {
var s = document.querySelector(".color-swatch.on");
return s ? s.dataset.color : COLORS[0];
}
async function memberOptions(sel, suppliedMembers) {
var members = suppliedMembers || (await api("/members")).members;
return 'Unassigned ' + members.map(function (m) {
return '" +
esc(m.display_name) + " ";
}).join("");
}
async function openTaskModal(presetProject, presetSection) {
var opts = await memberOptions(ME.user.user_id);
var projOpts = 'No project ' + PROJECTS.map(function (p) {
return '" + esc(p.name) + " ";
}).join("");
openModal('New task ' +
'Task name
' +
'Project ' + projOpts + "
" +
'Assignee ' + opts + "
" +
'Due date
' +
'Priority None Low Medium High
' +
'Description
' +
'
' +
'Cancel ' +
'Create task
');
document.getElementById("nt-cancel").onclick = closeModal;
document.getElementById("nt-create").onclick = async function () {
var name = document.getElementById("nt-name").value.trim();
var errEl = document.getElementById("nt-err");
if (!name) { errEl.textContent = "Task name is required."; errEl.hidden = false; return; }
try {
await api("/tasks", { method: "POST", body: {
name: name,
project_id: document.getElementById("nt-project").value || null,
section_id: presetSection || null,
assignee_user_id: document.getElementById("nt-assignee").value || null,
due_date: document.getElementById("nt-due").value || null,
priority: document.getElementById("nt-priority").value || null,
notes: document.getElementById("nt-notes").value,
} });
closeModal(); toast("Task created"); route();
} catch (e) { errEl.textContent = e.message; errEl.hidden = false; }
};
}
async function openProjectModal(portfolioId) {
var tpls = (await api("/templates")).templates.map(function (t) {
return '' + esc(t.name) + " ";
}).join("");
openModal('New project ' +
'Project name
' +
'Template ' + tpls + "
" +
'Default view List Board Calendar Timeline
' +
'Color ' + colorRow(COLORS[0]) + "
" +
'
' +
'Cancel ' +
'Create project
');
wireColorRow(document.querySelector(".modal"));
document.getElementById("np-cancel").onclick = closeModal;
document.getElementById("np-create").onclick = async function () {
var name = document.getElementById("np-name").value.trim();
var errEl = document.getElementById("np-err");
if (!name) { errEl.textContent = "Project name is required."; errEl.hidden = false; return; }
try {
var r = await api("/projects", { method: "POST", body: {
name: name, template: document.getElementById("np-template").value,
view: document.getElementById("np-view").value, color: pickedColor(),
portfolio_id: portfolioId || null,
} });
closeModal(); await loadProjects(); toast("Project created");
nav("/app/project/" + r.project_id);
} catch (e) { errEl.textContent = e.message; errEl.hidden = false; }
};
}
function openPortfolioModal() {
openModal('New portfolio ' +
'Portfolio name
' +
'Color ' + colorRow("#796eff") + "
" +
'
' +
'Cancel ' +
'Create portfolio
');
wireColorRow(document.querySelector(".modal"));
document.getElementById("npf-cancel").onclick = closeModal;
document.getElementById("npf-create").onclick = async function () {
var name = document.getElementById("npf-name").value.trim();
var errEl = document.getElementById("npf-err");
if (!name) { errEl.textContent = "Portfolio name is required."; errEl.hidden = false; return; }
try {
await api("/portfolios", { method: "POST", body: { name: name, color: pickedColor() } });
closeModal(); toast("Portfolio created"); nav("/app/portfolios");
} catch (e) { errEl.textContent = e.message; errEl.hidden = false; }
};
}
function openGoalModal() {
openModal('New goal ' +
'Goal name
' +
'Time period FY26 Q3 FY26 Q4 FY26
' +
'
' +
'Cancel ' +
'Create goal
');
document.getElementById("ng-cancel").onclick = closeModal;
document.getElementById("ng-create").onclick = async function () {
var name = document.getElementById("ng-name").value.trim();
var errEl = document.getElementById("ng-err");
if (!name) { errEl.textContent = "Goal name is required."; errEl.hidden = false; return; }
try {
await api("/goals", { method: "POST", body: { name: name, time_period: document.getElementById("ng-period").value } });
closeModal(); toast("Goal created"); nav("/app/goals");
} catch (e) { errEl.textContent = e.message; errEl.hidden = false; }
};
}
function openWorkspaceModal() {
openModal('New workspace ' +
'Workspace name
' +
'
' +
'Cancel ' +
'Create workspace
');
document.getElementById("nw-cancel").onclick = closeModal;
document.getElementById("nw-create").onclick = async function () {
var name = document.getElementById("nw-name").value.trim();
var errEl = document.getElementById("nw-err");
if (!name) { errEl.textContent = "Workspace name is required."; errEl.hidden = false; return; }
try {
await api("/workspaces", { method: "POST", body: { name: name } });
closeModal(); await loadMe(); toast("Workspace created — you are now in it");
nav("/app/home");
} catch (e) { errEl.textContent = e.message; errEl.hidden = false; }
};
}
// ---------------- task pane ----------------
function closePane() {
var p = document.querySelector(".task-pane"); if (p) p.remove();
var b = document.querySelector(".pane-backdrop"); if (b) b.remove();
}
async function openTask(taskId) {
closePane();
document.body.appendChild(el('
'));
document.querySelector(".pane-backdrop").onclick = closePane;
var pane = el('');
document.body.appendChild(pane);
var data;
try { data = await api("/tasks/" + taskId); }
catch (e) { pane.innerHTML = '
Task not found '; return; }
renderTaskPane(pane, data);
}
async function renderTaskPane(pane, data) {
var t = data.task;
var canEdit = !data.project || ["editor", "admin"].indexOf(data.project.current_user_access) >= 0;
var mopts = await memberOptions(t.assignee_user_id, data.eligible_assignees);
var comments = data.comments.map(function (cm) {
var mine = cm.author_user_id === ME.user.user_id;
return '";
}).join("") || 'No comments yet.
';
var subtasks = data.subtasks.map(function (st) {
return '✓ ' + esc(st.name) + " " +
(st.due_date ? '' + fmtDate(st.due_date) + " " : "") + "
";
}).join("");
var deps = data.dependencies.map(function (dp) {
return '⛓ Blocked by ' + esc(dp.name) + ' ✕
';
}).join("");
var blocking = data.blocking.map(function (dp) {
return '⛔ Blocking ' + esc(dp.name) + "
";
}).join("");
var atts = data.attachments.map(function (a) {
return '";
}).join("");
var acts = data.activity.map(function (a) {
return '' + esc(a.display_name) + " " + esc(a.verb) + " · " + ago(a.created_at) + "
";
}).join("");
pane.innerHTML =
'' +
'' +
(t.completed ? "✓ Completed" : "○ Mark complete") + " " +
' ' +
'🗑 ' +
'✕
' +
'' +
'
' + esc(t.name) + " " +
(data.project ? '
" : "") +
'
Assignee ' + mopts + "
" +
'
Start date
' +
'
Due date
' +
'
Priority ' +
["", "Low", "Medium", "High"].map(function (p) {
return '" + (p || "None") + " ";
}).join("") + "
" +
'
Status ' +
[["", "None"], ["On track", "On track"], ["At risk", "At risk"], ["Off track", "Off track"]].map(function (s) {
return '" + s[1] + " ";
}).join("") + "
" +
'
Description
' +
'
" +
'
Subtasks
' + subtasks +
'
+ Add subtask
' +
'
Dependencies
' + (deps + blocking || '
None.
') +
'
+ Add dependency
' +
'
Attachments
' + (atts || '
No attachments.
') +
'
📎 Attach file
' +
'
Comments
' + comments +
'' +
'
' +
'
Activity
' + (acts || '
No activity.
') +
"
";
if (!canEdit) {
pane.setAttribute("data-read-only", "true");
pane.querySelectorAll("button,select,input,textarea").forEach(function (control) { control.disabled = true; });
pane.querySelector("#tp-close").disabled = false;
pane.querySelector("#tp-name").setAttribute("contenteditable", "false");
var notice = el('You have read-only access to this private project.
');
pane.querySelector(".pane-body").prepend(notice);
}
var tid = t.task_id;
async function patch(body, refresh) {
try {
await api("/tasks/" + tid, { method: "PATCH", body: body });
if (refresh !== false) { route(); }
} catch (e) {
if (e.code === "blocked") {
if (confirm(e.message + " Complete it anyway?")) {
await api("/tasks/" + tid, { method: "PATCH", body: Object.assign({ force: true }, body) });
route(); return;
}
} else { toast(e.message, true); }
}
openTask(tid);
}
pane.querySelector("#tp-close").onclick = closePane;
pane.querySelector("#tp-complete").onclick = function () { patch({ completed: t.completed ? 0 : 1 }); };
pane.querySelector("#tp-delete").onclick = async function () {
if (!confirm("Delete this task? It moves to trash and can be restored.")) return;
await api("/tasks/" + tid, { method: "DELETE" });
closePane(); toast("Task moved to trash"); route();
};
pane.querySelector("#tp-name").addEventListener("blur", function () {
var name = this.textContent.trim();
if (name && name !== t.name) patch({ name: name }, false);
});
pane.querySelector("#tp-assignee").onchange = function () { patch({ assignee_user_id: this.value || null }); };
pane.querySelector("#tp-start").onchange = function () { patch({ start_date: this.value || null }); };
pane.querySelector("#tp-due").onchange = function () { patch({ due_date: this.value || null }); };
pane.querySelector("#tp-priority").onchange = function () { patch({ priority: this.value || null }); };
pane.querySelector("#tp-status").onchange = function () { patch({ task_status: this.value || null }); };
pane.querySelector("#tp-notes").addEventListener("blur", function () {
if (this.value !== t.notes) patch({ notes: this.value }, false);
});
pane.querySelector("#tp-addsub").onclick = async function () {
var name = prompt("Subtask name");
if (!name || !name.trim()) return;
await api("/tasks", { method: "POST", body: { name: name.trim(), parent_task_id: tid } });
openTask(tid);
};
pane.querySelector("#tp-adddep").onclick = async function () {
var q = prompt("Type part of the blocking task's name");
if (!q) return;
var res = await api("/search?q=" + encodeURIComponent(q.trim()));
var cand = res.tasks.filter(function (x) { return x.task_id !== tid; })[0];
if (!cand) { toast("No matching task found", true); return; }
if (!confirm('Add "' + cand.name + '" as a dependency?')) return;
try {
await api("/tasks/" + tid + "/dependencies", { method: "POST", body: { depends_on_task_id: cand.task_id } });
openTask(tid);
} catch (e) { toast(e.message, true); }
};
pane.querySelectorAll("[data-deldep]").forEach(function (b) {
b.onclick = async function () {
await api("/tasks/" + tid + "/dependencies/" + b.dataset.deldep, { method: "DELETE" });
openTask(tid);
};
});
pane.querySelectorAll("[data-subdone]").forEach(function (b) {
b.onclick = async function () {
await api("/tasks/" + b.dataset.subdone, { method: "PATCH", body: { completed: b.classList.contains("on") ? 0 : 1 } });
openTask(tid);
};
});
pane.querySelectorAll("[data-opentask]").forEach(function (a) {
a.onclick = function (ev) { ev.preventDefault(); openTask(a.dataset.opentask); };
});
pane.querySelector("#tp-file").onchange = async function () {
if (!this.files.length) return;
var fd = new FormData(); fd.append("file", this.files[0]);
try {
await api("/tasks/" + tid + "/attachments", { method: "POST", body: fd });
toast("Attachment uploaded"); openTask(tid);
} catch (e) { toast(e.message, true); }
};
pane.querySelector("#tp-comment-send").onclick = async function () {
var body = pane.querySelector("#tp-comment").value.trim();
if (!body) return;
await api("/tasks/" + tid + "/comments", { method: "POST", body: { body: body } });
openTask(tid);
};
pane.querySelectorAll("[data-editc]").forEach(function (b) {
b.onclick = async function () {
var nb = prompt("Edit comment");
if (nb === null || !nb.trim()) return;
await api("/comments/" + b.dataset.editc, { method: "PATCH", body: { body: nb.trim() } });
openTask(tid);
};
});
pane.querySelectorAll("[data-delc]").forEach(function (b) {
b.onclick = async function () {
if (!confirm("Delete this comment?")) return;
await api("/comments/" + b.dataset.delc, { method: "DELETE" });
openTask(tid);
};
});
}
// ---------------- shared task rendering ----------------
function taskRowHtml(t, withSelect) {
var canEdit = t.current_user_access !== "viewer";
return '' +
(withSelect && canEdit ? ' ' : "") +
(canEdit ? '✓ ' :
'✓ ') +
'' + esc(t.name) + " " +
'' +
(t.subtask_count ? '↳' + t.subtask_count + " " : "") +
(t.comment_count ? '💬' + t.comment_count + " " : "") +
(t.attachment_count ? "📎 " : "") +
(t.priority ? '' + esc(t.priority) + " " : "") +
(t.task_status ? '' + esc(t.task_status) + " " : "") +
(t.due_date ? '' + fmtDate(t.due_date) + " " : "") +
(t.assignee_name ? avatar(t.assignee_name, t.assignee_color, t.assignee_initials, true) : "") +
"
";
}
function wireTaskRows(scope) {
scope.querySelectorAll("[data-task]").forEach(function (r) {
r.addEventListener("click", function (ev) {
if (ev.target.closest("[data-done],[data-select]")) return;
openTask(r.dataset.task);
});
});
scope.querySelectorAll("[data-done]").forEach(function (b) {
b.onclick = async function () {
try {
await api("/tasks/" + b.dataset.done, { method: "PATCH", body: { completed: b.classList.contains("on") ? 0 : 1 } });
route();
} catch (e) {
if (e.code === "blocked" && confirm(e.message + " Complete it anyway?")) {
await api("/tasks/" + b.dataset.done, { method: "PATCH", body: { completed: 1, force: true } });
route();
} else if (e.code !== "blocked") { toast(e.message, true); }
}
};
});
scope.querySelectorAll("[data-select]").forEach(function (cb) {
cb.onchange = function () {
if (cb.checked) SELECTED[cb.dataset.select] = true; else delete SELECTED[cb.dataset.select];
updateBulkBar();
};
});
}
function bulkBarHtml() {
var n = Object.keys(SELECTED).length;
return '' +
'' + n + " selected " +
'Complete ' +
'Assign to me ' +
'Set due date… ' +
'Delete ' +
'Clear
';
}
function updateBulkBar() {
var bar = document.getElementById("bulkbar");
if (!bar) return;
var n = Object.keys(SELECTED).length;
bar.hidden = !n;
var c = document.getElementById("bulk-count");
if (c) c.textContent = n;
}
function wireBulkBar() {
var bar = document.getElementById("bulkbar");
if (!bar) return;
async function run(action, extra) {
var ids = Object.keys(SELECTED);
if (!ids.length) return;
var body = Object.assign({ task_ids: ids, action: action }, extra || {});
try {
var r = await api("/tasks/bulk", { method: "POST", body: body });
SELECTED = {};
toast(r.changed + " tasks updated"); route();
} catch (e) {
if (action === "complete" && e.code === "blocked" && confirm(e.message + " Complete them anyway?")) {
body.force = true;
var forced = await api("/tasks/bulk", { method: "POST", body: body });
SELECTED = {};
toast(forced.changed + " tasks completed with dependency override"); route();
} else { toast(e.message, true); }
}
}
document.getElementById("bulk-complete").onclick = function () { run("complete"); };
document.getElementById("bulk-assign").onclick = function () { run("assign", { assignee_user_id: ME.user.user_id }); };
document.getElementById("bulk-due").onclick = function () {
var v = prompt("Due date (YYYY-MM-DD)");
if (v) run("set_due_date", { due_date: v });
};
document.getElementById("bulk-delete").onclick = function () {
if (confirm("Move selected tasks to trash?")) run("delete");
};
document.getElementById("bulk-clear").onclick = function () { SELECTED = {}; route(); };
}
function filterBarHtml() {
return '' +
'Incomplete ' +
'Just my tasks ' +
'Priority: all ' +
["High", "Medium", "Low"].map(function (p) {
return '" + p + " ";
}).join("") + " " +
'Sort: manual ' +
[["due_date", "Due date"], ["alphabetical", "Alphabetical"], ["created", "Newest"]].map(function (s) {
return 'Sort: " + s[1] + " ";
}).join("") + " " +
'☆ Save view ' +
'
';
}
function wireFilterBar() {
var q = function () { route(); };
var b;
if ((b = document.getElementById("f-incomplete"))) b.onclick = function () {
FILTERS.completed = FILTERS.completed === "0" ? undefined : "0"; q();
};
if ((b = document.getElementById("f-mine"))) b.onclick = function () {
FILTERS.assignee = FILTERS.assignee ? undefined : ME.user.user_id; q();
};
if ((b = document.getElementById("f-priority"))) b.onchange = function () {
FILTERS.priority = this.value || undefined; q();
};
if ((b = document.getElementById("f-sort"))) b.onchange = function () {
FILTERS.sort = this.value === "manual" ? undefined : this.value; q();
};
if ((b = document.getElementById("f-save"))) b.onclick = async function () {
var name = prompt("Name this view");
if (!name || !name.trim()) return;
await api("/views", { method: "POST", body: { name: name.trim(), query: Object.assign({ path: location.pathname }, FILTERS) } });
toast("View saved — find it on Home");
};
}
function filterQuery() {
var qp = new URLSearchParams();
Object.keys(FILTERS).forEach(function (k) { if (FILTERS[k]) qp.set(k, FILTERS[k]); });
var s = qp.toString();
return s ? "?" + s : "";
}
// ---------------- views ----------------
async function viewHome() {
loadingPage();
var mt, views, members;
try {
mt = await api("/my-tasks");
views = await api("/views");
members = await api("/members");
} catch (e) { return; }
var completedCount = mt.tasks.filter(function (task) { return !!task.completed; }).length;
var collaboratorCount = Math.max(0, members.members.length - 1);
var today = new Date().toLocaleDateString("en-US", {
weekday: "long", month: "long", day: "numeric",
});
var projectRows = PROJECTS.slice(0, 1).map(function (p) {
return '' +
'☷ ' +
'' + esc(p.name) + ' ' +
p.task_count + (p.task_count === 1 ? ' active task' : ' active tasks') +
' › ';
}).join("");
var learnCards = [
["3 min", "Getting started", "Learn the basics and see how Asana helps you get work done.", "learn-tasks", "rocket"],
["5 min read", "Manage student organizations", "Learn how to organize meetings, events, and projects.", "learn-team", "education"],
["15 min", "Manage projects in Asana", "Plan, organize, and manage your projects effectively.", "learn-projects", "calendar"],
["5 min read", "Avoid silos with multi-homing", "Keep work visible across useful local projects.", "learn-workflow", "workflow"],
].map(function (card, index) {
return '' +
'' +
' ' +
'' + card[0] + ' ' + card[1] +
' ' + card[2] +
' ';
}).join("");
setPage('' +
'
' +
'
' +
'
QA ' +
'
▣ ' +
'
••• ' +
'
' +
'Upcoming ' +
'Overdue ' +
'Completed ' +
'
' +
'
' +
'
' +
'
' +
'
' +
'+ Create project ' +
(projectRows || '
No projects yet.
') + '
' +
'
' +
'
' +
'
' +
'
' +
'
', "home-page");
function renderHomeTasks(kind) {
var iso = new Date().toISOString().slice(0, 10);
var tasks = mt.tasks.filter(function (task) {
if (kind === "completed") return Boolean(task.completed);
if (task.completed) return false;
if (kind === "overdue") return Boolean(task.due_date && task.due_date < iso);
return true;
}).slice(0, 2);
var panel = document.getElementById("home-task-panel");
var homeRows = tasks.map(function (task) {
return '' +
'✓ ' +
'' + esc(task.name) + ' Demo ' +
'' + (task.due_date ? fmtDate(task.due_date) : 'This week') + '
';
}).join("");
panel.innerHTML = '+ Create task ' +
'' + (homeRows || '
You\'re all caught up No ' +
kind + ' tasks in this local workspace.
') + '
';
wireTaskRows(panel);
document.getElementById("home-add-task").onclick = function () { openTaskModal(); };
}
renderHomeTasks("upcoming");
document.querySelectorAll("[data-home-tab]").forEach(function (tab) {
tab.onclick = function () {
document.querySelectorAll("[data-home-tab]").forEach(function (item) {
var selected = item === tab;
item.classList.toggle("active", selected);
item.setAttribute("aria-selected", String(selected));
});
renderHomeTasks(tab.dataset.homeTab);
};
});
document.getElementById("home-new-project").onclick = function () { openProjectModal(); };
document.getElementById("home-project-view").onclick = function () { openHomeOptions("project-view"); };
document.getElementById("home-project-options").onclick = function () { openHomeOptions("projects"); };
document.getElementById("home-customize").onclick = openCustomizeHome;
document.getElementById("home-timeframe").onclick = function () { toast("My week selected"); };
document.getElementById("home-tasks-stat").onclick = function () { nav("/app/tasks"); };
document.getElementById("home-collaborators").onclick = function () { nav("/app/invite"); };
document.getElementById("home-task-options").onclick = function () { openSavedViews(views.views); };
document.querySelectorAll("[data-learn]").forEach(function (card) {
card.onclick = function () { openLearnDetail(card.dataset.learn); };
});
document.querySelectorAll("[data-widget]").forEach(function (button) {
button.onclick = function () { openHomeOptions(button.dataset.widget); };
});
document.querySelectorAll(".widget-rows button,.people-grid button,.focus-steps button").forEach(function (button) {
button.onclick = function () { openWidgetDetail(button); };
});
}
function openHomeOptions(kind) {
var config = {
"project-view": ["Project view", "Choose which projects appear on Home.", [["Recent projects", "/app/projects"], ["All projects", "/app/projects"]]],
projects: ["Project options", "Open or create projects from Home.", [["Open projects", "/app/projects"], ["Create project", "create-project"]]],
assigned: ["Assigned task options", "Review tasks you have delegated.", [["Open My tasks", "/app/tasks"], ["Customize Home", "customize"]]],
people: ["People options", "See teammates and team activity.", [["Open People", "/app/people"], ["Browse teams", "/app/people/teams"]]],
focus: ["Focus options", "Connect this week’s priorities to strategy.", [["Open Strategy", "/app/strategy"], ["Customize Home", "customize"]]],
}[kind];
var actions = config[2].map(function (item) {
return '' + esc(item[0]) + ' ';
}).join("");
openModal('' + config[0] + ' ' + config[1] + '
' + actions + '
');
document.querySelectorAll("[data-home-option]").forEach(function (button) {
button.onclick = function () {
var target = button.dataset.homeOption;
closeModal();
if (target === "create-project") openProjectModal();
else if (target === "customize") openCustomizeHome();
else nav(target);
};
});
}
function openWidgetDetail(button) {
var title = button.querySelector("strong");
var widget = button.closest(".home-assigned") ? "assigned" : button.closest(".home-people") ? "people" : "focus";
var target = widget === "assigned" ? "/app/tasks" : widget === "people" ? "/app/people" : "/app/strategy";
openModal('' + esc(title ? title.textContent : "Home item") + ' Review this item in its related workspace area.
' +
'Close Open related work
');
document.getElementById("widget-close").onclick = closeModal;
document.getElementById("widget-open").onclick = function () { closeModal(); nav(target); };
}
function openCustomizeHome() {
openModal('Customize Home Choose a comfortable local layout for this device.
' +
'Comfortable ' +
'Compact ' +
'Reset
' +
'
');
document.querySelectorAll("[data-density]").forEach(function (button) {
button.onclick = function () {
document.body.dataset.homeDensity = button.dataset.density;
localStorage.setItem("asana-home-density", button.dataset.density);
document.getElementById("customize-result").textContent = "Home layout updated locally.";
};
});
}
function openAchievements() {
openModal('Local achievements ' +
'
✓ Home explorer Opened your synthetic workspace.
' +
'
◇ Project starter Create a local project to continue.
' +
'
');
}
function openSavedViews(savedViews) {
var rows = savedViews.map(function (view) {
var query = JSON.parse(view.query_json || "{}");
return '☆ " + esc(view.name) + ' ';
}).join("");
openModal('My tasks Open My tasks or one of your locally saved views.
' +
(rows || 'No saved views yet.
') +
'Open My tasks
');
document.getElementById("open-my-tasks").onclick = function () { closeModal(); nav("/app/tasks"); };
document.querySelectorAll("[data-saved-view]").forEach(function (button) {
button.onclick = function () {
var query = JSON.parse(button.dataset.savedView);
FILTERS = {};
["completed", "assignee", "priority", "sort"].forEach(function (key) {
if (query[key]) FILTERS[key] = query[key];
});
closeModal(); nav(query.path || "/app/tasks");
};
});
}
function openLearnDetail(topic) {
var detail = {
"learn-tasks": ["Get started with My tasks", "Use Upcoming, Overdue, and Completed to keep your local day clear."],
"learn-projects": ["Build your first project", "Create a project, choose a local template, and assign synthetic work."],
"learn-team": ["Collaborate with your team", "Invite synthetic teammates and keep comments attached to local tasks."],
"learn-workflow": ["Try a useful workflow", "Open Projects to create a deterministic local workflow."],
}[topic];
openModal('' + esc(detail[0]) + ' ' + esc(detail[1]) + '
' +
'Close ' +
'Open related work
');
document.getElementById("learn-close").onclick = closeModal;
document.getElementById("learn-open").onclick = function () {
closeModal(); nav(topic === "learn-tasks" ? "/app/tasks" : "/app/projects");
};
}
async function viewMyTasks(dueState) {
loadingPage();
var data;
var query = new URLSearchParams(filterQuery().replace(/^\?/, ""));
var today = new Date();
var iso = today.toISOString().slice(0, 10);
if (dueState === "upcoming") query.set("due_after", iso);
if (dueState === "overdue") {
today.setDate(today.getDate() - 1);
query.set("due_before", today.toISOString().slice(0, 10));
query.set("completed", "0");
}
try { data = await api("/my-tasks" + (query.toString() ? "?" + query : "")); } catch (e) { return; }
var rows = data.tasks.map(function (t) { return taskRowHtml(t, true); }).join("");
setPage('' + avatar(ME.user.display_name, ME.user.avatar_color, ME.user.initials) +
"
" + (dueState === "upcoming" ? "Upcoming" : dueState === "overdue" ? "Overdue" : "My tasks") +
" " + filterBarHtml() + bulkBarHtml() +
'' + (rows ||
'
✅
No tasks match Change the filters or create a task.
') +
"
" +
'+ Add task
');
wireFilterBar(); wireBulkBar(); wireTaskRows(document.getElementById("page"));
document.getElementById("mt-add").onclick = function () { openTaskModal(); };
}
async function viewProjects() {
var cards = PROJECTS.map(function (p) {
return '' +
'
≡ ' +
'
' + esc(p.name) + ' ' + p.task_count + ' tasks
';
}).join("");
setPage('
Projects ' +
'Create project ' +
'' + (cards || '
No projects yet ') + '
');
document.getElementById("projects-create").onclick = openProjectModal;
document.querySelectorAll("[data-navcard]").forEach(function (card) {
card.onclick = function () { nav(card.dataset.navcard); };
});
}
async function viewAgents(section) {
var body;
if (section === "library") {
var saved = await api("/agents");
var savedCards = saved.agents.map(function (agent) {
return '✦ ' + esc(agent.name) + ' ' +
'
' + esc(agent.instructions) + '
Draft by ' + esc(agent.creator_name) + ' ' +
'
Delete draft ';
}).join("");
body = '
Agent library Create agent ' +
'Choose an agent pattern for repeatable work in this workspace.
' +
'
✦ Project status agent Summarize progress, risks, and next steps.
' +
'
↳ Work intake agent Organize requests and route new work.
' +
'
◎ Campaign agent Coordinate briefs, reviews, and launches.
' + savedCards + '
';
} else if (section === "activity") {
var activityDrafts = await api("/agents");
var activityRows = activityDrafts.agents.map(function (agent) {
return '✦ ' + esc(agent.name) +
' Draft saved locally by ' + esc(agent.creator_name) +
'.
' + ago(agent.modified_at) + ' ';
}).join("");
body = '
Agent activity ' +
'Saved agent drafts in this workspace. Agents do not run automatically.
' +
'Local draft activity ' +
(activityRows || '
No agent drafts have been saved yet.
') + '
';
} else {
body = '✦ AGENTS
AI teammates for your team’s work Create, manage, and monitor agents without mixing them into your Inbox.
' +
'Explore the agent library Start from a role designed for common workflows.
Browse agents → ' +
'
Review agent activity See agent drafts saved in this workspace.
View activity → ' +
'
Create an agent Define a role and the work it should support.
Get started → ';
}
setPage(body, "mode-page");
document.querySelectorAll("[data-go]").forEach(function (button) { button.onclick = function () { nav(button.dataset.go); }; });
document.querySelectorAll("[data-delete-agent]").forEach(function (button) {
button.onclick = async function () {
if (!confirm("Delete this saved agent draft?")) return;
try {
await api("/agents/" + button.dataset.deleteAgent, { method: "DELETE" });
toast("Agent draft deleted"); route();
} catch (e) { toast(e.message, true); }
};
});
document.querySelectorAll("[data-agent-action]").forEach(function (button) {
button.onclick = function () {
openModal('' + esc(button.dataset.agentAction) + ' Configure this agent for the current local workspace.
' +
'Name
' +
'Instructions
' +
'
' +
'Cancel Save draft
');
document.querySelector("[data-close-modal]").onclick = closeModal;
document.getElementById("agent-save").onclick = async function () {
var name = document.getElementById("agent-name").value.trim();
var instructions = document.getElementById("agent-instructions").value.trim();
var error = document.getElementById("agent-error");
if (!name || !instructions) { error.textContent = "Name and instructions are required."; error.hidden = false; return; }
try {
await api("/agents", { method: "POST", body: { name: name, instructions: instructions } });
closeModal(); toast("Agent draft saved locally"); nav("/app/agents/library");
} catch (e) { error.textContent = e.message; error.hidden = false; }
};
};
});
}
function viewStrategy(section) {
if (section === "reporting") { viewActivity(); return; }
setPage('▲ STRATEGY
' +
'
Connect goals to the work that drives them Move between an overview, goals, portfolios, and reporting from the Strategy sidebar.
' +
'Goals Set measurable outcomes and update progress.
Open goals → ' +
'
Portfolios Monitor related projects in one place.
Open portfolios → ' +
'
Reporting Review workspace activity and delivery signals.
Open reporting → ', "mode-page");
document.querySelectorAll("[data-go]").forEach(function (button) { button.onclick = function () { nav(button.dataset.go); }; });
}
function viewKnowledge(section) {
var cards;
if (section === "collections") {
cards = 'Project playbooks Shared guidance for planning, reviews, and handoffs.
' +
'Team policies Workspace norms and decision records.
' +
'Launch notes Reusable context for upcoming releases.
';
} else if (section === "templates") {
cards = 'Project brief Capture goals, scope, owners, and milestones.
' +
'Meeting notes Record decisions and action items.
' +
'Decision log Keep important choices easy to find.
';
} else {
cards = 'Getting started Learn how work, projects, and goals fit together.
' +
'Collections Browse organized team knowledge.
View collections → ' +
'Templates Create consistent docs and project context.
View templates → ';
}
setPage('
Knowledge Search shared guidance without leaving your workspace.
' +
'
' +
'' + cards + '
', "mode-page");
document.querySelectorAll("[data-go]").forEach(function (button) { button.onclick = function () { nav(button.dataset.go); }; });
document.querySelectorAll("[data-knowledge]").forEach(function (button) {
button.onclick = function () { openModal('' + esc(button.dataset.knowledge) + ' This local knowledge item is ready to use with your team’s work.
'); };
});
document.getElementById("knowledge-search").oninput = function () {
var query = this.value.trim().toLowerCase();
document.querySelectorAll("#knowledge-results .knowledge-card").forEach(function (card) {
card.hidden = Boolean(query && card.textContent.toLowerCase().indexOf(query) < 0);
});
};
}
async function viewPeople(section) {
loadingPage();
var data;
try { data = await api("/members"); } catch (e) { return; }
var memberCards = data.members.map(function (member) {
return '' +
avatar(member.display_name, member.avatar_color, member.initials) + '' + esc(member.display_name) + ' ' + esc(member.email) + '
View profile → ';
}).join("");
var body = section === "teams" ?
'
Teams Invite people ' +
'Organize workspace members around shared work.
' +
'
Product ' + data.members.length + ' members · 2 projects
' +
'
Operations 1 member · 1 project
' +
'
Marketing 1 member · 2 projects
' :
'
People Invite people ' +
'Find teammates, see their workspace details, and move into team views.
Browse teams
' +
'' + memberCards + '
';
setPage(body, "mode-page");
document.getElementById("people-invite").onclick = function () { nav("/app/invite"); };
document.querySelectorAll("[data-go]").forEach(function (button) { button.onclick = function () { nav(button.dataset.go); }; });
document.querySelectorAll("[data-member-name]").forEach(function (button) {
button.onclick = function () { openModal('' + esc(button.dataset.memberName) + ' ' + esc(button.dataset.memberEmail) + '
Workspace member in Demo Workspace.
'); };
});
document.querySelectorAll("[data-team]").forEach(function (button) {
button.onclick = function () { openModal('' + esc(button.dataset.team) + ' Review this team’s members and active work from the local workspace.
'); };
});
var peopleSearch = document.getElementById("people-search");
if (peopleSearch) peopleSearch.oninput = function () {
var query = this.value.trim().toLowerCase();
document.querySelectorAll("#people-directory .people-card").forEach(function (card) {
card.hidden = Boolean(query && card.textContent.toLowerCase().indexOf(query) < 0);
});
};
}
function viewMore() {
setPage('
More Workspace administration and personal settings.
' +
'My settings Profile, notifications, display, and security.
' +
'
Workspace settings Members, roles, and workspace details.
' +
'
Billing Review the local sandbox plan.
' +
'
Trash Restore or permanently remove local work.
', "mode-page");
document.querySelectorAll("[data-go]").forEach(function (button) { button.onclick = function () { nav(button.dataset.go); }; });
}
async function viewInvite() {
var data;
try { data = await api("/members"); } catch (e) { return; }
var members = data.members.map(function (member) {
return '' + avatar(member.display_name, member.avatar_color, member.initials) +
'' + esc(member.display_name) + ' ' +
esc(member.email) + '
';
}).join("");
setPage('
Invite ' +
'
Invite a teammate Invitations stay inside this offline clone.
' +
'
Email address ' +
'
' +
'
Send invite ' +
'
' +
'
Workspace members ' + members + '');
document.getElementById("invite-send").onclick = async function () {
var email = document.getElementById("invite-email").value.trim();
var error = document.getElementById("invite-error");
error.hidden = true;
try {
await api("/invites", { method: "POST", body: { email: email } });
toast("Invite recorded locally"); route();
} catch (e) { error.textContent = e.message; error.hidden = false; }
};
}
async function viewProject(projectId, tab) {
loadingPage();
var meta, tdata;
try {
meta = await api("/projects/" + projectId);
tdata = await api("/projects/" + projectId + "/tasks" + filterQuery());
} catch (e) {
setPage('🔍
Project not found ' +
'
It may have been deleted. Go home
');
return;
}
var p = meta.project;
var canEdit = ["editor", "admin"].indexOf(p.current_user_access) >= 0;
var canAdmin = p.current_user_access === "admin";
tab = tab || p.default_view || "list";
if (p.deleted_at) {
setPage('🗑
' + esc(p.name) + ' is in the trash ' +
'
Restore project
');
document.getElementById("restore-p").onclick = async function () {
await api("/trash/restore", { method: "POST", body: { project_id: p.project_id } });
await loadProjects(); route();
};
return;
}
var tabs = ["overview", "list", "board", "calendar", "timeline", "files"].map(function (tb) {
return '' +
tb.charAt(0).toUpperCase() + tb.slice(1) + " ";
}).join("");
var statusChip = '' +
esc({ on_track: "On track", at_risk: "At risk", off_track: "Off track", on_hold: "On hold", complete: "Complete" }[p.status] || p.status) + " ";
var head = '' +
'≡ ' +
"
" + esc(p.name) + " " +
(canEdit ? '' + (p.starred ? "★" : "☆") + " " : '') +
statusChip +
' ' +
(canAdmin ? 'Share ' : '') +
(canEdit ? '⋯ ' : 'Read only ') + '' +
'' + tabs + "
";
var body = "";
if (tab === "overview") body = projectOverviewHtml(meta);
else if (tab === "board") body = boardHtml(meta, tdata);
else if (tab === "calendar") body = calendarHtml(tdata);
else if (tab === "timeline") body = timelineHtml(tdata);
else if (tab === "files") body = filesHtml(meta, tdata);
else body = filterBarHtml() + bulkBarHtml() + listHtml(meta, tdata);
setPage(head + body);
if (!canEdit) {
var projectPage = document.getElementById("page");
projectPage.querySelectorAll("[data-done],[data-select],[data-add-in],[data-rename-sec],[data-del-sec],#add-section,#import-csv,#add-rule,[data-rule],[data-status],#bulkbar").forEach(function (control) {
control.hidden = true; control.disabled = true;
});
projectPage.querySelectorAll("#ov-desc,#ov-statusnote").forEach(function (control) { control.disabled = true; });
projectPage.querySelectorAll("[draggable]").forEach(function (card) { card.draggable = false; });
}
document.querySelectorAll("[data-tab]").forEach(function (b) {
b.onclick = function () { nav("/app/project/" + projectId + "/" + b.dataset.tab); };
});
var star = document.getElementById("p-star");
if (star) star.onclick = async function () {
await api("/projects/" + projectId, { method: "PATCH", body: { starred: p.starred ? 0 : 1 } });
route();
};
var share = document.getElementById("p-share");
if (share) share.onclick = function () { openShareModal(meta); };
var more = document.getElementById("p-more");
if (more) more.onclick = function () { openProjectMenu(meta); };
if (tab === "list") { wireFilterBar(); wireBulkBar(); }
wireProjectBody(meta, tab);
}
function listHtml(meta, tdata) {
var bySection = {};
tdata.tasks.forEach(function (t) { (bySection[t.section_id] = bySection[t.section_id] || []).push(t); });
var out = '';
meta.sections.forEach(function (s) {
var ts = bySection[s.section_id] || [];
out += '
' + esc(s.name) + ' ' + ts.length + " " +
' ' +
'✎ ' +
'🗑
';
out += ts.map(function (t) { return taskRowHtml(t, true); }).join("");
out += '
+ Add task
';
});
var orphans = bySection[null] || [];
if (orphans.length) out += '
No section
' +
orphans.map(function (t) { return taskRowHtml(t, true); }).join("");
out += "
" +
'+ Add section
';
if (!tdata.tasks.length && !meta.sections.length) {
out = '📋
This project is empty ' +
"
Add a section, then create your first task.
" +
'
+ Add section ';
}
return out;
}
function boardHtml(meta, tdata) {
var bySection = {};
tdata.tasks.forEach(function (t) { (bySection[t.section_id] = bySection[t.section_id] || []).push(t); });
var cols = meta.sections.map(function (s) {
var cards = (bySection[s.section_id] || []).map(function (t) {
return '' +
'
' + esc(t.name) + "
" +
'
' +
(t.priority ? '' + esc(t.priority) + " " : "") +
(t.due_date ? '' + fmtDate(t.due_date) + " " : "") +
(t.assignee_name ? avatar(t.assignee_name, t.assignee_color, t.assignee_initials, true) : "") +
"
";
}).join("");
return '' + esc(s.name) +
'' + (bySection[s.section_id] || []).length + "
" + cards +
'
+ Add task ';
}).join("");
return '' + cols +
'
+ Add section
';
}
function calendarHtml(tdata) {
var now = viewProject._calMonth || new Date();
viewProject._calMonth = now;
var y = now.getFullYear(), mo = now.getMonth();
var first = new Date(y, mo, 1);
var start = new Date(first); start.setDate(1 - ((first.getDay() + 6) % 7)); // Monday start
var byDate = {};
tdata.tasks.forEach(function (t) { if (t.due_date) (byDate[t.due_date] = byDate[t.due_date] || []).push(t); });
var dows = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"].map(function (d) {
return '' + d + "
";
}).join("");
var cells = "";
var today = new Date(); today.setHours(0, 0, 0, 0);
for (var i = 0; i < 42; i++) {
var d = new Date(start); d.setDate(start.getDate() + i);
var iso = d.toISOString().slice(0, 10);
var items = (byDate[iso] || []).map(function (t) {
var proj = PROJECTS.find(function (p) { return p.project_id === t.project_id; });
return '' + esc(t.name) + " ";
}).join("");
cells += '' +
'' + d.getDate() + " " + items + "
";
}
var label = now.toLocaleDateString(undefined, { month: "long", year: "numeric" });
return '‹ ' +
'
' + label + ' › ' +
'Today ' +
'' + dows + cells + "
";
}
function timelineHtml(tdata) {
var sched = tdata.tasks.filter(function (t) { return t.due_date; });
var unsched = tdata.tasks.filter(function (t) { return !t.due_date; });
if (!sched.length) {
return '📅
Nothing scheduled yet ' +
"
Add due dates to tasks to see them on the timeline.
";
}
var min = null, max = null;
sched.forEach(function (t) {
var s = t.start_date || t.due_date, e = t.due_date;
if (!min || s < min) min = s;
if (!max || e > max) max = e;
});
var start = new Date(min + "T00:00:00"); start.setDate(start.getDate() - 2);
var end = new Date(max + "T00:00:00"); end.setDate(end.getDate() + 3);
var days = [];
for (var d = new Date(start); d <= end; d.setDate(d.getDate() + 1)) days.push(new Date(d));
var DAY_W = 48;
var header = days.map(function (d) {
return '' +
d.toLocaleDateString(undefined, { month: "short", day: "numeric" }) + "
";
}).join("");
var depSet = {};
tdata.dependencies.forEach(function (dp) { depSet[dp.task_id] = true; });
var rows = sched.map(function (t) {
var s = new Date((t.start_date || t.due_date) + "T00:00:00");
var e = new Date(t.due_date + "T00:00:00");
var left = Math.round((s - start) / 86400000) * DAY_W;
var width = (Math.round((e - s) / 86400000) + 1) * DAY_W - 6;
var proj = PROJECTS.find(function (p) { return p.project_id === t.project_id; });
return '' + (depSet[t.task_id] ? "⛓ " : "") + esc(t.name) + "
";
}).join("");
return '' +
'
' + header + "
" + rows + "
" +
(unsched.length ? '' + unsched.length + " unscheduled task(s) not shown.
" : "");
}
function filesHtml(meta, tdata) {
return 'Import ' +
"
Upload a CSV with a Name column (optional Notes, Due Date) to add tasks.
" +
'
⬆ Import CSV ' +
'
' +
'' +
'Rules ' +
(meta.rules.map(function (r) {
return '
⚙ ' + esc(r.name) + ' ' + (r.enabled ? "On" : "Off") + " " +
'' +
(r.enabled ? "Turn off" : "Turn on") + "
";
}).join("") || "
No rules yet.
") +
'
+ Add rule ';
}
function projectOverviewHtml(meta) {
var p = meta.project;
var members = meta.members.map(function (m) {
return '' + avatar(m.display_name, m.avatar_color, m.initials) +
'
' + esc(m.display_name) + '
' + esc(m.access) + "
";
}).join("");
return '
Description ' +
'" +
'Status ' +
[["on_track", "On track"], ["at_risk", "At risk"], ["off_track", "Off track"], ["on_hold", "On hold"], ["complete", "Complete"]].map(function (s) {
return '' + s[1] + " ";
}).join("") + "
" +
'
" +
'
Members ' + members + "";
}
function wireProjectBody(meta, tab) {
var page = document.getElementById("page");
wireTaskRows(page);
page.querySelectorAll("[data-add-in]").forEach(function (b) {
b.onclick = function () { openTaskModal(meta.project.project_id, b.dataset.addIn); };
});
var asec = document.getElementById("add-section");
if (asec) asec.onclick = async function () {
var name = prompt("Section name");
if (!name || !name.trim()) return;
await api("/projects/" + meta.project.project_id + "/sections", { method: "POST", body: { name: name.trim() } });
route();
};
page.querySelectorAll("[data-rename-sec]").forEach(function (b) {
b.onclick = async function () {
var name = prompt("Rename section");
if (!name || !name.trim()) return;
await api("/sections/" + b.dataset.renameSec, { method: "PATCH", body: { name: name.trim() } });
route();
};
});
page.querySelectorAll("[data-del-sec]").forEach(function (b) {
b.onclick = async function () {
if (!confirm("Delete this section?")) return;
try { await api("/sections/" + b.dataset.delSec, { method: "DELETE" }); route(); }
catch (e) { toast(e.message, true); }
};
});
// board drag & drop
var dragId = null;
page.querySelectorAll("[data-drag]").forEach(function (c) {
c.addEventListener("dragstart", function () { dragId = c.dataset.drag; });
});
page.querySelectorAll("[data-col]").forEach(function (col) {
col.addEventListener("dragover", function (ev) { ev.preventDefault(); });
col.addEventListener("drop", async function (ev) {
ev.preventDefault();
if (!dragId) return;
await api("/tasks/" + dragId, { method: "PATCH", body: { section_id: col.dataset.col } });
dragId = null; route();
});
});
// calendar nav
var cp = document.getElementById("cal-prev");
if (cp) {
cp.onclick = function () { viewProject._calMonth = shiftMonth(-1); route(); };
document.getElementById("cal-next").onclick = function () { viewProject._calMonth = shiftMonth(1); route(); };
document.getElementById("cal-today").onclick = function () { viewProject._calMonth = new Date(); route(); };
}
function shiftMonth(n) {
var m = viewProject._calMonth || new Date();
return new Date(m.getFullYear(), m.getMonth() + n, 1);
}
// overview
var ov = document.getElementById("ov-desc");
if (ov) {
ov.addEventListener("blur", async function () {
await api("/projects/" + meta.project.project_id, { method: "PATCH", body: { description: ov.value } });
toast("Description saved");
});
page.querySelectorAll("[data-status]").forEach(function (b) {
b.onclick = async function () {
await api("/projects/" + meta.project.project_id, { method: "PATCH", body: { status: b.dataset.status } });
route();
};
});
document.getElementById("ov-statusnote").addEventListener("blur", async function () {
await api("/projects/" + meta.project.project_id, { method: "PATCH", body: { status_note: this.value } });
toast("Status note saved");
});
}
// files tab
var imp = document.getElementById("import-csv");
if (imp) imp.onchange = async function () {
if (!this.files.length) return;
var fd = new FormData(); fd.append("file", this.files[0]);
var errEl = document.getElementById("import-err");
errEl.hidden = true;
try {
var r = await api("/projects/" + meta.project.project_id + "/import", { method: "POST", body: fd });
document.getElementById("import-ok").textContent =
"Imported " + r.imported + " task(s)" + (r.skipped ? ", skipped " + r.skipped + " row(s) without a name." : ".");
} catch (e) { errEl.textContent = e.message; errEl.hidden = false; }
};
var ar = document.getElementById("add-rule");
if (ar) ar.onclick = async function () {
var name = prompt("Rule name (e.g. Move completed tasks to Done)");
if (!name || !name.trim()) return;
await api("/projects/" + meta.project.project_id + "/rules", {
method: "POST", body: { name: name.trim(), trigger: "task_completed", action: "move_to_section:Done" } });
route();
};
page.querySelectorAll("[data-rule]").forEach(function (b) {
b.onclick = async function () {
await api("/rules/" + b.dataset.rule, { method: "PATCH", body: { enabled: b.dataset.en === "1" } });
route();
};
});
}
async function openShareModal(meta) {
var p = meta.project;
var workspace = await api("/members");
var memberships = {};
meta.members.forEach(function (member) { memberships[member.user_id] = member.access; });
var roster = workspace.members.map(function (member) {
var owner = member.user_id === p.owner_user_id;
var access = owner ? "admin" : (memberships[member.user_id] || "");
return '' + avatar(member.display_name, member.avatar_color, member.initials, true) +
'
' + esc(member.display_name) + '
' + esc(member.email) + '
' +
(owner ? '
Owner · admin ' :
'
' +
[["", "No project access"], ["viewer", "Viewer"], ["editor", "Editor"], ["admin", "Admin"]].map(function (option) {
return '' + option[1] + ' ';
}).join("") + ' ') + '
';
}).join("");
openModal('Share ' + esc(p.name) + " " +
'Who has access ' +
[["workspace", "Workspace members"], ["private", "Private to project members"], ["public_link", "Anyone with the local link"]].map(function (m) {
return '" + m[1] + " ";
}).join("") + "
" +
'Project link
' +
"
" +
'Project members Private projects are visible only to these members. Viewers are read-only.
' + roster + '
' +
'Close ' +
'Save
');
function updateLink() {
var publicMode = document.getElementById("sh-mode").value === "public_link";
document.getElementById("sh-link").value = location.origin + (publicMode ? "/share/" : "/app/project/") + p.project_id;
document.getElementById("sh-link-label").textContent = publicMode ? "Public read-only link" : "Signed-in project link";
document.getElementById("sh-disclosure").textContent = publicMode
? "Anyone with this local link can read project and task summaries. Comments, files, members, and workspace data remain private."
: "This link requires sign-in and access to the current workspace and project.";
}
document.getElementById("sh-mode").onchange = updateLink;
updateLink();
document.getElementById("sh-close").onclick = closeModal;
document.getElementById("sh-save").onclick = async function () {
var members = [{ user_id: p.owner_user_id, access: "admin" }];
document.querySelectorAll("[data-project-member]").forEach(function (select) {
if (select.value) members.push({ user_id: select.dataset.projectMember, access: select.value });
});
try {
await api("/projects/" + p.project_id + "/sharing", { method: "PATCH", body: {
share_mode: document.getElementById("sh-mode").value, members: members } });
closeModal(); toast("Sharing and project access updated"); route();
} catch (e) { toast(e.message, true); }
};
}
function openProjectMenu(meta) {
var p = meta.project;
openModal("" + esc(p.name) + " " +
'' +
'Rename ' +
'' + (p.archived ? "Unarchive" : "Archive") + " " +
'Delete
');
document.getElementById("pm-rename").onclick = async function () {
var name = prompt("Project name", p.name);
if (!name || !name.trim()) return;
await api("/projects/" + p.project_id, { method: "PATCH", body: { name: name.trim() } });
closeModal(); await loadProjects(); route();
};
document.getElementById("pm-archive").onclick = async function () {
await api("/projects/" + p.project_id, { method: "PATCH", body: { archived: p.archived ? 0 : 1 } });
closeModal(); await loadProjects(); toast(p.archived ? "Project unarchived" : "Project archived"); route();
};
document.getElementById("pm-delete").onclick = async function () {
if (!confirm("Delete this project? It moves to trash.")) return;
await api("/projects/" + p.project_id, { method: "DELETE" });
closeModal(); await loadProjects(); toast("Project moved to trash"); nav("/app/home");
};
}
async function viewSearch(q) {
loadingPage();
var data;
try { data = await api("/search?q=" + encodeURIComponent(q)); } catch (e) { return; }
var body;
if (!q) {
body = '🔍
Search your workspace Find tasks, projects, and people.
';
} else if (!data.tasks.length && !data.projects.length && !data.people.length) {
body = '🕳
No results for “' + esc(q) + '” ' +
"
Try a different keyword or check the spelling.
";
} else {
body = (data.projects.length ? "Projects " + data.projects.map(function (p) {
return '
' +
' ' + esc(p.name) +
(p.archived ? ' Archived ' : "") + "
";
}).join("") + "
" : "") +
(data.tasks.length ? "Tasks " + data.tasks.map(function (t) { return taskRowHtml(t); }).join("") + "
" : "") +
(data.people.length ? "People " + data.people.map(function (u) {
return '' + avatar(u.display_name, u.avatar_color, u.initials) +
'
' + esc(u.display_name) + "
";
}).join("") : "");
}
setPage("Search " + (q ? 'Results for “' + esc(q) + '”
' : "") + body);
wireTaskRows(document.getElementById("page"));
document.querySelectorAll("[data-navcard]").forEach(function (c) {
c.onclick = function () { nav(c.dataset.navcard); };
});
}
async function viewInbox() {
loadingPage();
var archived = viewInbox._archived ? 1 : 0;
var data;
try { data = await api("/inbox?archived=" + archived); } catch (e) { return; }
var items = data.notifications.map(function (n) {
return '' +
"
" + ({ mention: "💬", comment: "💬", assigned: "👤" }[n.kind] || "🔔") + " " +
'
' + esc(n.text) + '
' + ago(n.created_at) + "
" +
(n.task_id ? '
Open task ' : "") +
"
" +
'
' +
(archived ? '↩ '
: '' + (n.read ? "◌" : "●") + " " +
'🗄 ') +
"
";
}).join("");
setPage("Inbox " +
'Activity ' +
'Archive
' +
(items || '📭
' +
(archived ? "Nothing archived" : "You're all caught up") + " New mentions, assignments, and comments land here.
"));
document.getElementById("ib-act").onclick = function () { viewInbox._archived = false; route(); };
document.getElementById("ib-arch").onclick = function () { viewInbox._archived = true; route(); };
document.querySelectorAll("[data-inbox]").forEach(function (b) {
b.onclick = async function () {
await api("/inbox/" + b.dataset.inbox, { method: "POST" });
await loadUnread(); route();
};
});
document.querySelectorAll("[data-opentask]").forEach(function (b) {
b.onclick = function () { openTask(b.dataset.opentask); };
});
}
async function viewPortfolios() {
loadingPage();
var data;
try { data = await api("/portfolios"); } catch (e) { return; }
var cards = data.portfolios.map(function (pf) {
return '' +
'
🗂 ' +
"
" + esc(pf.name) + ' ' + pf.project_count + " projects
";
}).join("");
setPage('
Portfolios ' +
'+ New portfolio ' +
(cards ? '' + cards + "
"
: '🗂
No portfolios yet Group projects to monitor progress in one place.
' +
'
+ New portfolio '));
var n1 = document.getElementById("pf-new"); if (n1) n1.onclick = openPortfolioModal;
var n2 = document.getElementById("pf-new2"); if (n2) n2.onclick = openPortfolioModal;
document.querySelectorAll("[data-navcard]").forEach(function (c) {
c.onclick = function () { nav(c.dataset.navcard); };
});
}
async function viewPortfolio(pfId) {
loadingPage();
var data;
try { data = await api("/portfolios/" + pfId); } catch (e) {
setPage('
Portfolio not found '); return;
}
var rows = data.projects.map(function (p) {
var pct = p.task_count ? Math.round(100 * p.done_count / p.task_count) : 0;
return '' +
' ' + esc(p.name) + " " +
'' + esc(p.status.replace("_", " ")) + " " +
"" + p.done_count + "/" + p.task_count + ' tasks ';
}).join("");
setPage('🗂 ' +
"
" + esc(data.portfolio.name) + ' ' +
'+ Add project ' +
(rows ? 'Project Status Progress ' + rows + "
"
: '🗂
No projects in this portfolio ' +
'
+ Add project '));
function add() { openProjectModal(pfId); }
var a1 = document.getElementById("pf-addproj"); if (a1) a1.onclick = add;
var a2 = document.getElementById("pf-addproj2"); if (a2) a2.onclick = add;
document.querySelectorAll("[data-navcard]").forEach(function (c) {
c.onclick = function () { nav(c.dataset.navcard); };
});
}
async function viewGoals() {
loadingPage();
var data;
try { data = await api("/goals"); } catch (e) { return; }
var rows = data.goals.map(function (g) {
return '
' + esc(g.name) + " " +
'' + esc(g.status.replace("_", " ")) + " " +
'' + esc(g.time_period) + ' ' +
' ' + avatar(g.owner_name, g.owner_color, g.owner_initials, true) + "" +
'
' +
'
' + g.progress + "% " +
' ' +
'' +
[["on_track", "On track"], ["at_risk", "At risk"], ["off_track", "Off track"], ["achieved", "Achieved"]].map(function (s) {
return '" + s[1] + " ";
}).join("") + "
";
}).join("");
setPage('
Goals ' +
'+ New goal ' +
(rows || '🎯
No goals yet Connect work to measurable objectives.
'));
document.getElementById("goal-new").onclick = openGoalModal;
document.querySelectorAll("[data-goal]").forEach(function (r) {
r.onchange = async function () {
await api("/goals/" + r.dataset.goal, { method: "PATCH", body: { progress: parseInt(r.value, 10) } });
route();
};
});
document.querySelectorAll("[data-goalstatus]").forEach(function (s) {
s.onchange = async function () {
await api("/goals/" + s.dataset.goalstatus, { method: "PATCH", body: { status: s.value } });
route();
};
});
}
async function viewActivity() {
loadingPage();
var data;
try { data = await api("/activity"); } catch (e) { return; }
var items = data.activity.map(function (a) {
return '' + avatar(a.display_name, a.avatar_color, a.initials, true) + " " +
"
" + esc(a.display_name) + " " + esc(a.verb) + " " + esc(a.object_type) +
(a.object_name ? " “" + esc(a.object_name) + "”" : "") + "
" +
'
' + ago(a.created_at) + "
";
}).join("");
setPage("Reporting Workspace activity feed.
" +
(items || ''));
}
async function viewSettings(tab) {
loadingPage();
var u = ME.user;
var tabs = [["profile", "Profile"], ["notifications", "Notifications"], ["display", "Display"], ["security", "Security"]].map(function (t) {
return '' + t[1] + " ";
}).join("");
var body = "";
if (tab === "notifications") {
body = 'Email-style notifications (local only) ' +
[["notify_mentions", "Mentions"], ["notify_status", "Status updates"], ["notify_daily_summary", "Daily summary"]].map(function (n) {
return '
' + n[1] + '
";
}).join("") + "
";
} else if (tab === "display") {
body = 'Display ' +
'
Theme ' +
["light", "dark", "system"].map(function (t) { return "" + t + " "; }).join("") + "
" +
'
Default view ' +
["list", "board", "calendar"].map(function (v) { return "" + v + " "; }).join("") +
"
Dark theme is stored but this demo renders light.
";
} else if (tab === "security") {
var sess = await api("/security/sessions");
body = 'Sessions ' + sess.sessions.map(function (s) {
return '
' + (s.active ? "🟢 Active" : "⚪ Revoked") +
" · created " + ago(s.created_at) + " · last seen " + ago(s.last_seen_at) + "
";
}).join("") +
'
Log out other sessions ' +
'Password Use the reset flow on the login screen to change your password.
' +
'
Reset password ';
} else {
body = 'Profile ' +
'
Full name
' +
'
Role
' +
'
About me
" +
'
Avatar color ' + colorRow(u.avatar_color) + "
" +
'
Save changes
';
}
setPage("Settings " + esc(u.email) + '
' + tabs + "
" + body);
document.querySelectorAll("[data-stab]").forEach(function (b) {
b.onclick = function () { nav("/app/settings?tab=" + b.dataset.stab); };
});
var save = document.getElementById("pr-save");
if (save) {
wireColorRow(document.getElementById("page"));
save.onclick = async function () {
try {
await api("/profile", { method: "PATCH", body: {
display_name: document.getElementById("pr-name").value,
role_title: document.getElementById("pr-role").value,
about_me: document.getElementById("pr-about").value,
avatar_color: pickedColor(),
} });
await loadMe(); toast("Profile saved"); route();
} catch (e) { toast(e.message, true); }
};
}
document.querySelectorAll("[data-notif]").forEach(function (cb) {
cb.onchange = async function () {
var body = {}; body[cb.dataset.notif] = cb.checked ? 1 : 0;
await api("/profile", { method: "PATCH", body: body });
await loadMe(); toast("Preference saved");
};
});
var th = document.getElementById("set-theme");
if (th) {
th.onchange = async function () {
await api("/profile", { method: "PATCH", body: { theme: th.value } });
await loadMe(); toast("Saved");
};
document.getElementById("set-view").onchange = async function () {
await api("/profile", { method: "PATCH", body: { task_default_view: this.value } });
await loadMe(); toast("Saved");
};
}
var slo = document.getElementById("sec-logout-others");
if (slo) slo.onclick = async function () {
var r = await api("/security/logout-others", { method: "POST" });
toast("Revoked " + r.revoked + " other session(s)");
route();
};
}
async function viewAdmin() {
loadingPage();
var data;
try { data = await api("/members"); } catch (e) { return; }
var isAdmin = ME.role === "admin";
var rows = data.members.map(function (m) {
var roleCtl = isAdmin && m.user_id !== ME.user.user_id
? '' +
["member", "admin"].map(function (r) { return "" + r + " "; }).join("") + " "
: '' + esc(m.role) + " ";
return '' + avatar(m.display_name, m.avatar_color, m.initials) +
'
' + esc(m.display_name) + (m.synthetic ? '
Demo teammate ' : "") +
'
' + esc(m.email) + "
" + roleCtl + "
";
}).join("");
var invites = data.invites.map(function (i) {
return '✉ ' + esc(i.email) + ' ' + esc(i.role) + ' ' + esc(i.status) + " (local)
";
}).join("");
setPage("Workspace settings " +
'Workspace name ' +
'
" +
(isAdmin ? '
Save ' : '
Only admins can rename the workspace.
') +
"
" +
'
Members (' + data.members.length + ") " + rows + "" +
'Invite ' +
"
Offline demo: invites are recorded locally — no email is sent.
" +
'
' +
'member admin ' +
'Invite
' +
'
' + invites + "
");
var ws = document.getElementById("ws-save");
if (ws) ws.onclick = async function () {
try {
await api("/workspace", { method: "PATCH", body: { name: document.getElementById("ws-name").value } });
await loadMe(); toast("Workspace renamed"); route();
} catch (e) { toast(e.message, true); }
};
document.getElementById("inv-send").onclick = async function () {
var errEl = document.getElementById("inv-err");
errEl.hidden = true;
try {
await api("/invites", { method: "POST", body: {
email: document.getElementById("inv-email").value,
role: document.getElementById("inv-role").value } });
toast("Invite recorded (local simulation)"); route();
} catch (e) { errEl.textContent = e.message; errEl.hidden = false; }
};
document.querySelectorAll("[data-role]").forEach(function (s) {
s.onchange = async function () {
try {
await api("/members/" + s.dataset.role, { method: "PATCH", body: { role: s.value } });
toast("Role updated"); route();
} catch (e) { toast(e.message, true); route(); }
};
});
}
async function viewBilling() {
loadingPage();
var data;
try { data = await api("/billing"); } catch (e) { return; }
var cards = Object.keys(data.plans).map(function (k) {
var p = data.plans[k];
var current = data.plan === k;
return '" +
"
" + esc(p.label) + (current ? ' Current plan ' : "") + " " +
'
' + (p.monthly_minor ? "$" + (p.monthly_minor / 100).toFixed(2) + " per user / month" : "Free") + "
" +
(!current && p.monthly_minor ? '
Upgrade ' : "") +
"
";
}).join("");
setPage("Billing " +
"Offline demo — payments run against the local sandbox adapter (" + esc(data.payment_adapter) + ").
" +
'' + cards + "
" +
'Sandbox scenario ' +
'
' + data.scenarios.map(function (s) {
return '' + esc(s.label) + " ";
}).join("") + " Choose the simulated outcome before clicking Upgrade.
");
document.querySelectorAll("[data-upgrade]").forEach(function (b) {
b.onclick = async function () {
var scenario = document.getElementById("pay-scenario").value;
try {
var r = await api("/billing/upgrade", { method: "POST", body: { plan: b.dataset.upgrade, scenario: scenario } });
toast("Plan upgraded to " + r.plan + " (simulated)"); await loadMe(); route();
} catch (e) { toast(e.message || "Simulated payment failed", true); }
};
});
}
async function viewTrash() {
loadingPage();
var data;
try { data = await api("/trash"); } catch (e) { return; }
function row(kind, id, name, when) {
return '🗑 ' + esc(name) + ' ' + ago(when) + " " +
' ' +
'Restore ' +
'Delete forever
';
}
var items = data.projects.map(function (p) { return row("project", p.project_id, p.name + " (project)", p.deleted_at); })
.concat(data.tasks.map(function (t) { return row("task", t.task_id, t.name, t.deleted_at); })).join("");
setPage("Trash Deleted items can be restored or removed permanently.
" +
(items || ''));
function body(v) {
var kv = v.split(":");
return kv[0] === "task" ? { task_id: kv[1] } : { project_id: kv[1] };
}
document.querySelectorAll("[data-restore]").forEach(function (b) {
b.onclick = async function () {
await api("/trash/restore", { method: "POST", body: body(b.dataset.restore) });
await loadProjects(); toast("Restored"); route();
};
});
document.querySelectorAll("[data-purge]").forEach(function (b) {
b.onclick = async function () {
if (!confirm("Permanently delete? This cannot be undone.")) return;
await api("/trash/purge", { method: "POST", body: body(b.dataset.purge) });
toast("Deleted forever"); route();
};
});
}
function viewHelp() {
setPage("Help & getting started " +
'Basics ' +
"Create — the + Create button makes tasks, projects, portfolios, goals, and workspaces. " +
"My tasks — everything assigned to you, with filters and bulk actions. " +
"Projects — switch between List, Board, Calendar, and Timeline tabs. " +
"Task pane — click any task to edit fields, subtasks, dependencies, files, and comments. " +
"Search — the top bar searches tasks, projects, and people. " +
'About this demo ' +
"
This is an offline WebsiteBench clone. All data is stored locally in a" +
" site-bound SQLite database. Invites and emails are simulated, and payments use a local sandbox." +
" It is not affiliated with Asana, Inc.
" +
'Support Because this clone runs offline,' +
' there is no live support. Check the resources on the marketing site .
');
}
function viewNotFound(p) {
setPage('🧭
Page not found ' +
"
" + esc(p) + ' does not exist. Go home
');
}
// ---------------- boot ----------------
async function loadMe() {
ME = await api("/me");
await loadProjects();
await loadUnread();
}
async function loadProjects() {
PROJECTS = (await api("/projects")).projects;
if (document.getElementById("sidebar")) shellRefresh();
}
async function loadUnread() {
UNREAD = (await api("/inbox")).unread;
}
function shellRefresh() {
var page = document.getElementById("page");
var content = page ? page.innerHTML : "";
shell(content);
wireTaskRows(document.getElementById("page"));
}
(async function boot() {
try {
await loadMe();
} catch (e) { return; }
shell("");
route();
})();
})();