(slug, submissions)
| 2216 | } |
| 2217 | |
| 2218 | function exportSubmissionsToCsv(slug, submissions) { |
| 2219 | if (!Array.isArray(submissions) || !submissions.length) { |
| 2220 | showToast(t('admin_portal_no_submissions_export')); |
| 2221 | return; |
| 2222 | } |
| 2223 | |
| 2224 | const header = [ |
| 2225 | 'Created', |
| 2226 | 'Folder', |
| 2227 | 'SubmittedBy', |
| 2228 | 'IP', |
| 2229 | 'SubmissionRef', |
| 2230 | 'Name', |
| 2231 | 'Email', |
| 2232 | 'Reference', |
| 2233 | 'Notes', |
| 2234 | 'Downloads' |
| 2235 | ]; |
| 2236 | |
| 2237 | const lines = []; |
| 2238 | lines.push(header.map(csvEscape).join(',')); |
| 2239 | |
| 2240 | submissions.forEach(sub => { |
| 2241 | const row = normalizeSubmissionForCsv(sub); |
| 2242 | const cols = [ |
| 2243 | row.created, |
| 2244 | row.folder, |
| 2245 | row.submittedBy, |
| 2246 | row.ip, |
| 2247 | row.submissionRef, |
| 2248 | row.name, |
| 2249 | row.email, |
| 2250 | row.reference, |
| 2251 | row.notes, |
| 2252 | row.downloadsSummary |
| 2253 | ]; |
| 2254 | lines.push(cols.map(csvEscape).join(',')); |
| 2255 | }); |
| 2256 | |
| 2257 | const csv = lines.join('\r\n'); |
| 2258 | const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' }); |
| 2259 | const url = URL.createObjectURL(blob); |
| 2260 | |
| 2261 | const a = document.createElement('a'); |
| 2262 | a.href = url; |
| 2263 | a.download = (slug || 'portal') + '-submissions.csv'; |
| 2264 | |
| 2265 | document.body.appendChild(a); |
| 2266 | a.click(); |
| 2267 | document.body.removeChild(a); |
| 2268 | |
| 2269 | setTimeout(() => { |
| 2270 | URL.revokeObjectURL(url); |
| 2271 | }, 0); |
| 2272 | } |
| 2273 | |
| 2274 | function attachPortalSubmissionsUI() { |
| 2275 | const body = document.getElementById('clientPortalsBody'); |
no test coverage detected