This repository has been archived by the owner on Feb 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
update.js
54 lines (50 loc) · 1.8 KB
/
update.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
;(function() {
//we update server data if it's obsolete or here since more than 2 days
var update = leiminauts.lastServerDataUpdate < leiminauts.lastSpreadsheetUpdate;
if (!update)
update = (new Date().getTime() - leiminauts.lastServerDataUpdate) > (1000*60*60*24*2);
if (update) {
if ( $('.data-update-button').length ) {
$('.data-update-button').attr('disabled', 'disabled');
}
var sheets = {
steam: "0AuPP-DBESPOedF9hckdzMWVhc2c3Rkk1R2RTa1pUdWc",
dev : "0AuPP-DBESPOedHBBU1FCcWl2ZTZDSUdwM0JPcW0wV2c",
conso: "0AuPP-DBESPOedHJTeGo4QUZsY0hiUThaRWg1eUJrZFE"
};
var sheetsKey = _(sheets).keys();
var updateDataFromSheet = function(sheet, dataz, tabletop) {
var characters = JSON.stringify(tabletop.sheets('Characters').all());
var skills = JSON.stringify(tabletop.sheets('Skills').all());
var upgrades = JSON.stringify(tabletop.sheets('Upgrades').all());
var scaling = JSON.stringify(tabletop.sheets('Scaling').all());
var data = {sheet: sheet, characters: characters, skills: skills, upgrades: upgrades, scaling: scaling};
$.ajax({
type: 'POST',
url: '../../../data/update.php',
data: data,
complete: onSheetDataUpdated
});
};
var notifyUser = function(text) {
text = text || '';
if ( $('.data-updated-notice').length ) {
$('.data-updated-notice').html(text);
}
};
var onSheetDataUpdated = _.after(sheetsKey.length, function() { notifyUser("The <a href=\"/\">Nautsbuilder</a>'s data is now up-to-date!"); });
notifyUser("Updating data...");
var updateSheet = function(sheet) {
Tabletop.init({
key: sheets[sheet],
debug: true,
callback: function(dataz, tabletop) {
updateDataFromSheet(sheet, dataz, tabletop);
}
});
};
for (var i = sheetsKey.length - 1; i >= 0; i--) {
updateSheet(sheetsKey[i]);
}
}
})();