From 60d99e4d35568b3fb76eb26f0284236b4cd602c3 Mon Sep 17 00:00:00 2001 From: lowercasename Date: Thu, 2 Jan 2020 20:24:55 +1100 Subject: Export as ICS functionality --- views/event.handlebars | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'views/event.handlebars') diff --git a/views/event.handlebars b/views/event.handlebars index 4d0cf28..70c4018 100755 --- a/views/event.handlebars +++ b/views/event.handlebars @@ -45,6 +45,9 @@ Add to Google Calendar + {{#if eventHasHost}}
  • @@ -375,6 +378,29 @@ }) $(document).ready(function() { + // From https://davidwalsh.name/javascript-download + function downloadFile(data, fileName, type="text/plain") { + // Create an invisible A element + const a = document.createElement("a"); + a.style.display = "none"; + document.body.appendChild(a); + + // Set the HREF to a Blob representation of the data to be downloaded + a.href = window.URL.createObjectURL( + new Blob([data], { type }) + ); + + // Use download attribute to set set desired file name + a.setAttribute("download", fileName); + + // Trigger the download by simulating click + a.click(); + + // Cleanup + window.URL.revokeObjectURL(a.href); + document.body.removeChild(a); + } + $.uploadPreview({ input_field: "#image-upload", preview_box: "#image-preview", @@ -394,6 +420,12 @@ {{/if}} new ClipboardJS('#copyEventLink'); autosize($('textarea')); + $("#exportICS").click(function(){ + let eventID = $(this).attr('data-event-id'); + $.get('/exportevent/' + eventID, function(response) { + downloadFile(response, eventID + '.ics'); + }) + }) $("#copyEventLink").click(function(){ $(this).html(' Copied!'); setTimeout(function(){ $("#copyEventLink").html(' Copy');}, 5000); -- cgit v1.2.3