source: tmcsimulator/trunk/webapps/common/js/fileutils.js @ 551

Revision 551, 1.4 KB checked in by jdalbey, 6 years ago (diff)

Multi-file commit to implement saving evaluation ratings from einotebook to a log file and merging with unified log. Also fix defect #212. cgi-bin/saveEvals.py cgi-bin/saveRatingsToLog.py common/js/displayutils.js common/js/fileutils.js common/js/revision_number.dat common/unifiedlog.css dynamicdata/CADcomments.log dynamicdata/caddetails.csv dynamicdata cms_messages.json dynamicdata/har_messages.json dynamicdata highway_status.json dynamicdata/ratings.csv dynamicdata/unifiedlog.csv dynamicdata/unifiedlog_final.csv einotebook/roles/index.html einotebook roles/roles.js einotebook/script/index.html einotebook/script scrollframe.js einotebook/scripts/Evaluation.js einotebook/scripts/Event.js mergelogs.bash unifiedlogdisplay.html unifiedlogmonitor.html

Line 
1// Load the dynamic json file for highways, etc.
2// Ref: https://codepen.io/KryptoniteDove/post/load-json-file-locally-using-pure-javascript
3function loadJSON(inFile, callback)
4{
5    var xobj = new XMLHttpRequest();
6    // Assume XML unless filename ends with .json
7    if (inFile.endsWith(".json"))
8    {
9        xobj.overrideMimeType("application/json");
10    }
11    if (inFile.endsWith(".csv"))
12    {
13        xobj.overrideMimeType("text/csv");
14    }
15    xobj.open('GET', inFile, true);
16    xobj.onreadystatechange = function()
17    {
18        if (xobj.readyState == 4 && xobj.status == "200")
19        {
20            callback(xobj.responseText);
21        }
22    };
23    // We want ajax to ignore any cached responses
24    xobj.setRequestHeader('If-Modified-Since', 'Sat, 01 Jan 2000 01:01:01 GMT')
25    xobj.send(null);
26}
27
28/* Retrieve URL parameters passed to a web page
29   @return a dictionary of key/value pairs
30*/
31function getQueryParms()
32{
33    var items = {};
34    var query = window.location.search.substring(1);
35    var parms = query.split("&");
36    // Examine each parameter
37    for (var i = 0, max = parms.length; i < max; i++)
38    {
39        // check for trailing & with no param
40        if (parms[i] === "") 
41            continue; // skip it
42
43        var param = parms[i].split("=");
44        // If it's valid add it to dictionary
45        items[decodeURIComponent(param[0])] = decodeURIComponent(param[1] || "");
46    }
47    return items
48}
Note: See TracBrowser for help on using the repository browser.