-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDataLoader.js
67 lines (61 loc) · 1.89 KB
/
DataLoader.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
/**
* Functions for loading the data, as well as loading the schema and pages
* information.
*
* @author Yaron Koren
*/
function DataLoader() {
}
/**
* This should probably go elsewhere.
*/
function getConnectorPropertyBetweenCategories( mainCategory, secondaryCategory ) {
// Find the connector between these two categories - if there's more
// than one, we'll just take the first one, though that shouldn't
// ever happen.
for ( var fieldName in gDataSchema[secondaryCategory]['fields']) {
var field = gDataSchema[secondaryCategory]['fields'][fieldName];
if ( field.hasOwnProperty('connectedCategory')) {
if ( field['connectedCategory'] == mainCategory ) {
return fieldName;
}
}
}
return null;
}
DataLoader.isDateType = function( typeName ) {
return ( typeName == 'Date' || typeName == 'Start time' || typeName == 'End time' );
}
DataLoader.getAppSettingsAndSchema = function() {
// Preliminary check that JS data file exists and is accesible.
if ( typeof generalSettings === 'undefined' ) {
displayMainText('<h1>Error!</h1><h2>Could not find data file migaData.js. Either you are offline, or this file has not been created yet.</h2>');
return;
}
var curURL = getURLPath();
for ( appName in generalSettings ) {
if ( appName == '_general' ) {
continue;
}
var appSettings = generalSettings[appName];
if ( appSettings.hasOwnProperty('URL') && appSettings['URL'] == curURL ) {
gAppSettings = appSettings;
gAppSettings['Name'] = appName;
gDataSchema = schemas[appName];
gPagesInfo = pages[appName];
break;
}
}
// If there were no matches, use the first app
if ( gAppSettings == null ) {
for ( appName in generalSettings ) {
if ( appName == '_general' ) continue;
var appSettings = generalSettings[appName];
gAppSettings = appSettings;
gAppSettings['Name'] = appName;
gDataSchema = schemas[appName];
gPagesInfo = pages[appName];
break;
}
}
}