forked from llaske/sugarizer
-
Notifications
You must be signed in to change notification settings - Fork 53
/
database.js
72 lines (70 loc) · 1.78 KB
/
database.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Database handling for the Abecedarium game
// Load all database files
Abcd.loadDatabase = function(callback) {
var jsonFiles = [
"database/db_url.json",
"database/db_meta.json",
"database/db_themes.json",
"database/db_collections.json",
"database/db_en.json",
"database/db_en_letters.json",
"database/db_fr.json",
"database/db_fr_letters.json",
"database/db_es.json",
"database/db_es_letters.json"
];
var count = 0;
var error = false;
var initDatabase = function(url, value) {
var index = -1;
for (var j = 0 ; j < jsonFiles.length ; j++) {
if (jsonFiles[j] == url) {
index = j;
break;
}
}
if (index == 0) {
Abcd.context.database = value;
} else if (index == 1) {
Abcd.entries = value;
} else if (index == 2) {
Abcd.themes = value;
} else if (index == 3) {
Abcd.collections = value;
} else if (index == 4) {
Abcd.enTexts = value;
} else if (index == 5) {
Abcd.enLetters = value;
} else if (index == 6) {
Abcd.frTexts = value;
Abcd.texts = Abcd.frTexts;
} else if (index == 7) {
Abcd.frLetters = value;
Abcd.letters = Abcd.frLetters;
} else if (index == 8) {
Abcd.esTexts = value;
} else if (index == 9) {
Abcd.esLetters = value;
}
}
for (var i = 0 ; i < jsonFiles.length ; i++) {
var ajax = new enyo.Ajax({method: "GET",handleAs: "json"});
ajax.url = jsonFiles[i];
ajax.response(function(inSender, inResponse) {
initDatabase(inSender.url, inResponse);
if (++count == jsonFiles.length) {
if (error) { Abcd.context.database = null; }
callback(error);
}
});
ajax.error(function(inResponse) {
console.log("Error loading database");
error = true;
if (++count == jsonFiles.length) {
if (error) { Abcd.context.database = null; }
callback(error);
}
});
ajax.go();
}
}