-
Notifications
You must be signed in to change notification settings - Fork 0
/
artists.html
80 lines (68 loc) · 2.21 KB
/
artists.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.2.min.js"></script>
<script src="airtable.browser.js"></script>
</head>
<body>
<h1>Artists</h1>
<div id="artists"></div>
<hr/>
<button id='create'>Create</button>
<div id="created"></div>
</body>
<script>
var Airtable = require('airtable');
// Get a base ID for an instance of art gallery example
var base = new Airtable({ apiKey: 'keyDUEhF6Gtx76Myx' }).base('appPgm3ltdbRypFvH');
var deleteArtist = function(record) {
record.destroy(function(err) {
if (err) {
console.log('Error destroying ', recordId, err);
} else {
console.log('Destroyed ', record.getId());
$('div[data-record-id="'+record.getId()+'"]').remove();
}
});
};
var loadArtists = function() {
$('#artists').empty();
base('Artists').select({
sort: [
{field: 'Name', direction: 'asc'}
]
}).eachPage(function page(records, fetchNextPage) {
records.forEach(function(record) {
console.log('Retrieved ', record.get('Name'));
var $artistInfo = $('<div>');
$artistInfo.append($('<h3>').text(record.get('Name')));
$artistInfo.append($('<div>').text(record.get('Bio')));
var x = $('<button>').text('Delete').click(function() {
deleteArtist(record);
});
$artistInfo.append(x)
$artistInfo.attr('data-record-id', record.getId());
$('#artists').append($artistInfo);
});
fetchNextPage();
}, function done(error) {
console.log(error);
});
};
$('#create').click(function(){
base('Artists').create({
"Name": "Al Held",
"Bio": "Al Held began his painting career by exhibiting Abstract Expressionist works in New York; he later turned to hard-edged geometric paintings that were ...",
"Genre": [
"American Abstract Expressionism",
"Color Field"
],
"On Display?": true
}, function(err, record) {
if (err) { console.log(err); return; }
loadArtists();
});
});
loadArtists();
</script>
</html>