-
Notifications
You must be signed in to change notification settings - Fork 3
/
csv.html
65 lines (60 loc) · 2.32 KB
/
csv.html
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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<title>CloudSponge Basic Installation</title>
<!-- you can delete everything above this comment, it's just here to make the helper pretty. -->
<script src="//api.cloudsponge.com/widget/localhost-only.js"></script>
<script type="text/javascript">
cloudsponge.init({
// implement custom logic for the afterSubmitContacts callback
// https://www.cloudsponge.com/developer/contact-picker/javascript-callbacks/after-submit-contacts/
afterSubmitContacts: function(contacts, source, owner) {
// create the header row for the csv file
var csvStr = "First Name,Last Name,Email\n";
// loop through the selected contacts and construct a CSV file
for (var contact of contacts) {
// https://www.cloudsponge.com/developer/contact-picker/data-structure/
csvStr += contact.first_name + ',' + contact.last_name + ',' + contact.email[0].address + '\n';
}
// inspired by: https://stackoverflow.com/questions/17564103/using-javascript-to-download-file-as-a-csv-file
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csvStr);
hiddenElement.target = '_blank';
hiddenElement.download = 'contacts.csv';
hiddenElement.click();
},
// Override default CloudSponge text for the contact picker submit button
// https://www.cloudsponge.com/developer/contact-picker/options/locale-data/
localeData: {
GET_CONTACTS: "Download CSV File"
}
});
</script>
</head>
<body>
<div class="container" style="text-align: center;">
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<a class="cloudsponge-launch">Add from Address Book</a><br />
</div>
</body>
</html>