// Projects view — CRUD list styled like a Jira projects page.
const ProjectsView = {
async render(container) {
container.innerHTML = `
Projects
Manage your projects and their structure
${id ? 'Edit project' : 'Create project'}
`);
modal.querySelector('#f-cancel').addEventListener('click', UI.closeModal);
modal.querySelector('#f-save').addEventListener('click', async () => {
const name = modal.querySelector('#f-name').value.trim();
if (!name) return UI.toast('Name is required', true);
const payload = {
name,
note: modal.querySelector('#f-note').value.trim(),
struc: modal.querySelector('#f-struc').value.trim()
};
try {
if (id) await API.updateProject(id, payload);
else await API.createProject(payload);
UI.closeModal();
UI.toast(id ? 'Project updated' : 'Project created');
this.load();
} catch (e) { UI.toast(e.message, true); }
});
},
async remove(id) {
if (!confirm('Delete this project? Tickets linked to it will be unlinked.')) return;
try {
await API.deleteProject(id);
UI.toast('Project deleted');
this.load();
} catch (e) { UI.toast(e.message, true); }
}
};