Online Workflow-Based Document Routing System

Online Workflow-Based Document Routing System

Step 1: Define Document and Workflow

Current Routing Order:

${workflowState.content}

`; // Add event listeners to the newly created buttons document.getElementById('approveBtn')?.addEventListener('click', handleApproval); document.getElementById('rejectBtn')?.addEventListener('click', handleRejection); } else { actionPanelEl.innerHTML = `

No action required from you at this time. Waiting for ${currentUser}.

`; } }; /** * Handles the approval action. */ const handleApproval = () => { const approver = workflowState.approvers[workflowState.currentApproverIndex]; logAction(`Approved by ${approver}.`); if (workflowState.currentApproverIndex === workflowState.approvers.length - 1) { workflowState.status = 'approved'; } else { workflowState.currentApproverIndex++; } renderTrackingView(); renderActionPanel(); }; /** * Handles the rejection action. */ const handleRejection = () => { const approver = workflowState.approvers[workflowState.currentApproverIndex]; logAction(`Rejected by ${approver}.`); workflowState.status = 'rejected'; renderTrackingView(); renderActionPanel(); }; /** * Logs an action with a timestamp. * @param {string} message - The log message. */ const logAction = (message) => { const timestamp = new Date().toLocaleString('en-US'); workflowState.log.push({ message, timestamp }); }; /** * Generates and downloads a PDF summary of the workflow. */ const generatePdf = () => { // Ensure the required library is available if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') { console.error("jsPDF library is not loaded."); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); // Document Title doc.setFontSize(18); doc.text('Workflow Summary', 14, 22); // Document Details doc.setFontSize(12); doc.text(`Title: ${workflowState.title}`, 14, 32); doc.text(`Final Status: ${workflowState.status.charAt(0).toUpperCase() + workflowState.status.slice(1)}`, 14, 40); // Document Content doc.setFontSize(14); doc.text('Document Content:', 14, 55); doc.setFontSize(10); const contentLines = doc.splitTextToSize(workflowState.content, 180); doc.text(contentLines, 14, 62); // Action Log using autoTable const tableBody = workflowState.log.map(entry => [entry.timestamp, entry.message]); doc.autoTable({ startY: 80 + (contentLines.length * 4), head: [['Date & Time', 'Action']], body: tableBody, theme: 'striped', headStyles: { fillColor: [41, 128, 185] }, }); doc.save(`workflow-summary-${workflowState.title.replace(/\s+/g, '-')}.pdf`); }; // --- EVENT LISTENERS --- if (addApproverBtn) { addApproverBtn.addEventListener('click', addApprover); } if (approverNameEl) { approverNameEl.addEventListener('keypress', (e) => { if (e.key === 'Enter') addApprover(); }); } if (startRoutingBtn) { startRoutingBtn.addEventListener('click', startRouting); } if (userSelectorEl) { userSelectorEl.addEventListener('change', renderActionPanel); } if (downloadPdfBtn) { downloadPdfBtn.addEventListener('click', generatePdf); } if (prevBtn) { prevBtn.addEventListener('click', () => changeTab(currentTab - 1)); } if (nextBtn) { nextBtn.addEventListener('click', () => changeTab(currentTab + 1)); } // --- INITIALIZATION --- renderApproversList(); updateNavButtons(); });
Scroll to Top