| 1 | /************* WARNING: THIS IS A GLOBAL VARIABLE. ********************/ |
|---|
| 2 | // Reference to the 'events' array in Events.js |
|---|
| 3 | var events; |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * Sets the events. |
|---|
| 7 | * @param theEvents Reference to the 'events' array in Events.js. |
|---|
| 8 | */ |
|---|
| 9 | function setEvents(theEvents) |
|---|
| 10 | { |
|---|
| 11 | events = theEvents; |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | // Collect all the ratings from the events |
|---|
| 15 | function collectRatings() |
|---|
| 16 | { |
|---|
| 17 | var output = "" |
|---|
| 18 | var ratingCount = 0 |
|---|
| 19 | // Consider each event in the incident script |
|---|
| 20 | for (var evtidx = 0; evtidx < events.length; evtidx++) |
|---|
| 21 | { |
|---|
| 22 | // Does this event have any evaluations? |
|---|
| 23 | if (events[evtidx].evaluations.evaluations.length > 0) |
|---|
| 24 | { |
|---|
| 25 | // Examine each evaluation contained in this event |
|---|
| 26 | for (var rating=0; rating<events[evtidx].evaluations.evaluations.length; rating++ ) |
|---|
| 27 | { |
|---|
| 28 | // Extract the rating assigned to this item |
|---|
| 29 | var item = events[evtidx].evaluations.evaluations[rating]; |
|---|
| 30 | // If it not the default value we want to save it |
|---|
| 31 | if (item.rating > 0) |
|---|
| 32 | { // Build a string for the log in this format: |
|---|
| 33 | //03:01:00, Evaluation, CMS, Poor |
|---|
| 34 | output += events[evtidx].time.format() +", Evaluation, "+item.type + ", " + item.ratingQualities[item.rating] + "\n" |
|---|
| 35 | ratingCount += 1; |
|---|
| 36 | } |
|---|
| 37 | } |
|---|
| 38 | } |
|---|
| 39 | } |
|---|
| 40 | submitRatings(output); |
|---|
| 41 | alert(ratingCount + " rating were saved.") |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | /* This is an alternative way to collect the ratings values by reading them directly from the radio buttons |
|---|
| 45 | function collectRadios() |
|---|
| 46 | { |
|---|
| 47 | var radios = document.getElementsByTagName('input'); |
|---|
| 48 | var count = 0; |
|---|
| 49 | for (var j=0; j<radios.length; j++) |
|---|
| 50 | { |
|---|
| 51 | if (radios[j].type == 'radio') |
|---|
| 52 | { |
|---|
| 53 | count++; |
|---|
| 54 | if (radios[j].checked) |
|---|
| 55 | { |
|---|
| 56 | console.log(radios[j].name + " checked " + radios[j].value) |
|---|
| 57 | } |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | alert("counted " + count + " radios"); |
|---|
| 61 | } |
|---|
| 62 | */ |
|---|
| 63 | |
|---|
| 64 | // Send the string of ratings to the server |
|---|
| 65 | function submitRatings(logString) |
|---|
| 66 | { |
|---|
| 67 | // Using POST to send the data |
|---|
| 68 | var xhr = new XMLHttpRequest(); |
|---|
| 69 | xhr.open("POST", "/cgi-bin/saveRatingsToLog.py", true); |
|---|
| 70 | xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); |
|---|
| 71 | // send the collected data |
|---|
| 72 | xhr.send("msg="+logString); |
|---|
| 73 | } |
|---|