source: tmcsimulator/trunk/webapps/EInotebook/scripts/LoadEvents.js @ 361

Revision 361, 5.2 KB checked in by jdalbey, 7 years ago (diff)

modify CADClient AssignedIncidents?.java to fix defect #142. Also fix minor typos in full_script_2016.xml

Line 
1var xmlDoc;
2function loadJSON(inFile, callback)
3{
4    var xobj = new XMLHttpRequest();
5    // Assume XML unless filename ends with .json
6    if (inFile.endsWith(".json"))
7    {
8        xobj.overrideMimeType("application/json");
9    }
10    xobj.open('GET', inFile, true);
11    xobj.onreadystatechange = function()
12    {
13        if (xobj.readyState == 4 && xobj.status == "200")
14        {
15            callback(xobj.responseText);
16        }
17    };
18    // We want ajax to ignore any cached responses
19    xobj.setRequestHeader('If-Modified-Since', 'Sat, 01 Jan 2000 01:01:01 GMT')
20    xobj.send(null);
21}
22
23// Parse the entire Incident XML Script file
24// Extract the Incidents and Events and create lists of each
25function parseXml(response)
26{
27    // Create a parser and grab the high level tag we're interested in
28    var parser = new DOMParser();
29    xmlDoc = parser.parseFromString(response,"text/xml");
30    var eventTags = xmlDoc.getElementsByTagName("SCRIPT_EVENT");
31
32    // Process each SCRIPT_EVENT tag
33    for (var i = 0; i < eventTags.length; i++)
34    {
35        var currEvt = eventTags[i];
36        // local variable declarations
37        var timeFields; var evtTime; var incidentNum; var cadProp; var telProp;
38        var proparray = new Array();
39        var evalarray = new Array();
40        // Process all the children of one event
41        for (var child = 1; child < currEvt.childNodes.length; child++)
42        {
43            // Ignore undefined nodes
44            if (currEvt.childNodes[child].localName != undefined)
45            {
46                // Determine the tag type and dispatch it for further processing
47                switch(currEvt.childNodes[child].localName)
48                {
49                    case "TIME_INDEX": 
50                        timeFields = currEvt.childNodes[child].textContent.split(":"); 
51                        evtTime = new Time(Number(timeFields[0]), Number(timeFields[1]), Number(timeFields[2]));
52                        break;
53                    case "INCIDENT":
54                        incidentNum = Number(currEvt.childNodes[child].attributes["LogNum"].value); 
55                        break;
56                    case "GENERAL_INFO":  break;
57                    case "CAD_DATA": 
58                        var caddata = parseCAD(currEvt.childNodes[child]); 
59                        if (caddata.length > 0)
60                        {
61                            cadProp = new Property("CHP CAD", caddata ); 
62                            proparray.push(cadProp);
63                        }
64                        break;
65                    case "TELEPHONE": 
66                        telProp = new Evaluation("Telephone Conversation", 
67                                 parseTelephone(currEvt.childNodes[child]) ); 
68                        evalarray.push(telProp);
69                        break;
70                    case "CHP_RADIO": 
71                        var chpradio = parseCHPradio(currEvt.childNodes[child]); 
72                        if (chpradio.length > 0)
73                        {
74                            cadProp = new Property("CHP RADIO", chpradio ); 
75                            proparray.push(cadProp);
76                        }
77                        break;
78                    case "TMT_RADIO":  break;
79                    case "MAINTENANCE_RADIO": break;
80                    // case *_EVALUATION: break;
81
82                }
83            }
84        }
85        //console.log(evtTime.format(), incidentNum, proparray.length, evalarray.length);
86        if (incidentNum != undefined)
87        {
88          events.add(new Event(evtTime, incidents.get(incidentNum), new Properties(proparray), 
89                new Evaluations(evalarray)) );
90        }
91    }
92
93}
94function parseCAD(element)
95{
96    var result = new Array();
97    var details = element.getElementsByTagName("DETAIL");
98    if (details.length > 0)
99    {
100        for (detail in details)
101        {
102            if (details[detail].textContent != undefined)
103            {               
104                result.push("Detail:");
105                result.push(details[detail].textContent);
106            }
107        }
108    }
109    return result;
110}
111function parseTelephone(element)
112{
113    var result = new Array();
114    for (var child = 1; child < element.childNodes.length; child++)
115    {
116        if (element.childNodes[child].localName != undefined)
117        {
118            if (element.childNodes[child].localName == "INSTRUCTOR")
119            {
120                result.push(element.childNodes[child].attributes["Role"].value);
121            }
122            else
123            {
124                result.push(element.childNodes[child].localName);   
125            }
126            result.push(element.childNodes[child].textContent);
127        }
128    }
129    return result;
130}
131function parseCHPradio(element)
132{
133    var result = new Array();
134    var dialog = element.getElementsByTagName("LINE");
135    if (dialog.length > 0)
136    {
137        for (line in dialog)
138        {
139            if (dialog[line].textContent != undefined)
140            {               
141                result.push(dialog[line].attributes["Role"].value);
142                result.push(dialog[line].textContent);
143            }
144        }
145    }
146    return result;
147}
148
149// MAIN
150loadJSON("full_script.xml", parseXml)
151// Note: the script has the Media Log event removed
152
Note: See TracBrowser for help on using the repository browser.