-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedule-ics-button.js
More file actions
70 lines (65 loc) · 1.96 KB
/
schedule-ics-button.js
File metadata and controls
70 lines (65 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Handle ICS and CSV export button clicks
jQuery(document).ready(function ($) {
// Handle clicks on ICS export buttons
$(document).on("click", ".dust-ics-export-btn", function () {
var $btn = $(this);
var originalText = $btn.text();
var eventName = $btn.data("event") || "";
$btn.prop("disabled", true).text("Generating...");
$.ajax({
url: dust_events_ajax.ajax_url,
type: "POST",
data: {
action: "export_schedule_ics",
nonce: dust_events_ajax.nonce,
event_name: eventName,
},
xhrFields: {
responseType: "blob",
},
success: function (data) {
var blob = new Blob([data], { type: "text/calendar" });
var url = window.URL.createObjectURL(blob);
var a = document.createElement("a");
a.href = url;
a.download = "schedule.ics";
a.click();
window.URL.revokeObjectURL(url);
},
complete: function () {
$btn.prop("disabled", false).text(originalText);
},
});
});
// Handle clicks on CSV export buttons
$(document).on("click", ".dust-csv-export-btn", function () {
var $btn = $(this);
var originalText = $btn.text();
var eventName = $btn.data("event") || "";
$btn.prop("disabled", true).text("Generating...");
$.ajax({
url: dust_events_ajax.ajax_url,
type: "POST",
data: {
action: "export_schedule_csv",
nonce: dust_events_ajax.nonce,
event_name: eventName,
},
xhrFields: {
responseType: "blob",
},
success: function (data) {
var blob = new Blob([data], { type: "text/csv" });
var url = window.URL.createObjectURL(blob);
var a = document.createElement("a");
a.href = url;
a.download = "schedule.csv";
a.click();
window.URL.revokeObjectURL(url);
},
complete: function () {
$btn.prop("disabled", false).text(originalText);
},
});
});
});