-
Notifications
You must be signed in to change notification settings - Fork 0
/
photo-tag-ajax.js
57 lines (49 loc) · 1.05 KB
/
photo-tag-ajax.js
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
var SS = (function () {
function Secret(id, text) {
var that = this;
this.id = id;
this.text = text;
this.save = function (callback) {
$.post("/secrets.json", {
secret: {
id: this.id,
text: this.text
}
}, function (response) {
that.id = response.id;
if (callback) {
callback();
}
});
}
};
Secret.all = [];
Secret.fetchAll = function (callback) {
$.getJSON(
"/secrets.json",
function (data) {
Secret.all = [];
_.each(data, function (datum) {
Secret.all.push(new Secret(
datum.id, datum.text));
});
if (callback) {
callback();
}
}
);
};
function SecretsLister(el, secrets) {
this.render = function () {
var ul = $("<ul></ul");
_.each(secrets, function (secret) {
ul.append($("<li></li>").text(secret.text));
});
$(el).html(ul);
};
};
return {
Secret: Secret,
SecretsLister: SecretsLister
};
})();