diff --git a/static/js/src/app/groups.js b/static/js/src/app/groups.js index 1bb63ef5..1960e0c8 100644 --- a/static/js/src/app/groups.js +++ b/static/js/src/app/groups.js @@ -241,12 +241,16 @@ function load() { escapeHtml(group.name), escapeHtml(group.num_targets), moment(group.modified_date).format('MMMM Do YYYY, h:mm:ss a'), - "
\ -
" + "
\ + \ + \ +
" ]) }) groupTable.rows.add(groupRows).draw() @@ -294,3 +298,33 @@ $(document).ready(function () { }); $("#csv-template").click(downloadCSVTemplate) }); + +// Exports group contents as a CSV file +function exportGroupAsCSV(groupId, groupName) { + var exportHTML = $("#exportGroupButton"+groupId).html() + var filename = groupName + '.csv' + var groupDetails = api.groupId.get(groupId) + if (!groupDetails) { + return + } + $("#exportGroupButton"+groupId).html('') + var csvString = Papa.unparse(groupDetails.responseJSON.targets, { + 'escapeFormulae': true + }) + + var csvData = new Blob([csvString], { + type: 'text/csv;charset=utf-8;' + }); + if (navigator.msSaveBlob) { + navigator.msSaveBlob(csvData, filename); + } else { + var csvURL = window.URL.createObjectURL(csvData); + var dlLink = document.createElement('a'); + dlLink.href = csvURL; + dlLink.setAttribute('download', filename) + document.body.appendChild(dlLink) + dlLink.click(); + document.body.removeChild(dlLink) + } + $("#exportGroupButton"+groupId).html(exportHTML) +} \ No newline at end of file