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
81
82
83
84
85
86
87
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href='https://fonts.googleapis.com/css?family=Noto+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>
function addPending(albumName) {
function makeElement(name) {
return $('<li>' + name + ' (<a href="javascript:void(0)">edit</a>)</li>');
}
var element = makeElement(albumName);
$(element).find('a').click(function() {
var input =
$('<input type="text" value="'+albumName+'" autofocus="true">');
setTimeout(function() {
var position = input[0].value.length;
input[0].setSelectionRange(position, position);
}, 0);
$(this).replaceWith(input);
});
$('#pending-container').append(element);
}
function addPermanentAlbum(albumName) {
function makeElement(name) {
return $('<li>' + name + '</li>');
}
$('#album-container').append(makeElement(albumName));
}
function fetchAlbums() {
$.ajax({
url: "/api/albums",
success: function(data) {
$('#pending-error').empty();
$('#pending-container').empty();
$('#album-container').empty();
console.log('Got albums:');
console.log(data);
data.forEach(function (album) {
if (album.pending) {
addPending(album.name, album.pending);
} else {
addPermanentAlbum(album.name);
}
console.log('Added album ' + album.name);
});
},
error: function(unused, unusedStatus, error) {
$('#pending-container').empty();
$('#pending-error').html(
'<p><b>Error</b> fetching pending albums: ' + error);
}
});
}
$(document).ready(function() {
fetchAlbums();
var request = {
from: { name: 'x', pending: true },
to: { name: 'y', pending: false }
};
console.log('rename request: ', request);
$.ajax({
url: '/api/rename',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(request),
success: function(data) { console.log('Rename succes: ', data); },
error: function(unused, unusedStatus, error) { console.log('Rename failure: ' + error); }
});
});
</script>
</head>
<body>
<h1>Pending Photos</h1>
<span id="pending-error"></span>
<ul id="pending-container"></ul>
<h1>Albums</h1>
<ul id="album-container"></ul>
</body>
</html>
|