OLD | NEW |
1 if (typeof localStorage == "undefined") | 1 if (typeof localStorage == "undefined") |
2 window.localStorage = {}; | 2 window.localStorage = {}; |
3 var templates; | 3 var templates; |
4 | 4 |
5 function migrateCookies() | 5 function migrateCookies() |
6 { | 6 { |
7 var cookies = document.cookie.split(/\s*;\s*/); | 7 var cookies = document.cookie.split(/\s*;\s*/); |
8 for (var i = 0; i < cookies.length; i++) | 8 for (var i = 0; i < cookies.length; i++) |
9 { | 9 { |
10 if (/^(.*?)=(.*)/.test(cookies[i])) | 10 if (/^(.*?)=(.*)/.test(cookies[i])) |
(...skipping 11 matching lines...) Expand all Loading... |
22 document.cookie = encodeURIComponent(key) + "=;expires=Thu, 01-Jan-1970
00:00:01 GMT"; | 22 document.cookie = encodeURIComponent(key) + "=;expires=Thu, 01-Jan-1970
00:00:01 GMT"; |
23 } | 23 } |
24 } | 24 } |
25 } | 25 } |
26 | 26 |
27 function escapeHTML(value) | 27 function escapeHTML(value) |
28 { | 28 { |
29 return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"
).replace(/"/g, """); | 29 return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"
).replace(/"/g, """); |
30 } | 30 } |
31 | 31 |
| 32 function setRadio(radio, value) |
| 33 { |
| 34 for (i = 0; i < radio.length; i++) |
| 35 { |
| 36 if (radio[i].value == value) |
| 37 radio[i].checked = true; |
| 38 else |
| 39 radio[i].checked = false; |
| 40 } |
| 41 } |
| 42 |
32 function saveSecret(guid, secret) | 43 function saveSecret(guid, secret) |
33 { | 44 { |
34 var secrets = localStorage.secrets; | 45 var secrets = localStorage.secrets; |
35 if (secrets) | 46 if (secrets) |
36 secrets = JSON.parse(secrets); | 47 secrets = JSON.parse(secrets); |
37 else | 48 else |
38 secrets = {}; | 49 secrets = {}; |
39 secrets[guid] = {value: secret, expiration: new Date().getTime() + 1000*60*60*
24*30}; | 50 secrets[guid] = {value: secret, expiration: new Date().getTime() + 1000*60*60*
24*30}; |
40 localStorage.secrets = JSON.stringify(secrets); | 51 localStorage.secrets = JSON.stringify(secrets); |
41 } | 52 } |
42 | 53 |
43 function setSecret(guid, secret) | 54 function setSecret(guid, secret) |
44 { | 55 { |
45 saveSecret(guid, secret); | 56 saveSecret(guid, secret); |
46 | 57 |
47 var status = ""; | 58 var status = ""; |
48 var statusCell = document.getElementById("statusCell"); | 59 var statusCell = document.getElementById("statusCell"); |
49 if (statusCell) | 60 if (statusCell) |
50 status = statusCell.textContent; | 61 status = statusCell.textContent; |
| 62 |
| 63 var utility = "0"; |
| 64 var utilityCell = document.getElementById("utilityCell"); |
51 | 65 |
52 var div = document.createElement("div"); | 66 var div = document.createElement("div"); |
53 div.className = "updateLink" | 67 div.className = "updateLink" |
54 var link = document.createElement("a"); | 68 var link = document.createElement("a"); |
55 link.setAttribute("href", "javascript:void(0);"); | 69 link.setAttribute("href", "javascript:void(0);"); |
56 link.textContent = "Update status" | 70 link.textContent = "Update status" |
57 div.appendChild(link); | 71 div.appendChild(link); |
58 | 72 |
59 if (statusCell) | 73 if (statusCell) |
60 statusCell.appendChild(div); | 74 statusCell.appendChild(div); |
61 else | 75 else |
62 document.body.insertBefore(div, document.body.firstChild); | 76 document.body.insertBefore(div, document.body.firstChild); |
63 | 77 |
64 link.onclick = function() | 78 link.onclick = function() |
65 { | 79 { |
66 var notifyBox = ""; | 80 var notifyBox = ""; |
| 81 var utilityRadios = ""; |
67 if (document.getElementById("emailCell")) | 82 if (document.getElementById("emailCell")) |
| 83 { |
68 notifyBox = '<span id="notifyField"><input type="checkbox" id="notify" nam
e="notify" value="1" /> <label for="notify">Notify user</label></span>'; | 84 notifyBox = '<span id="notifyField"><input type="checkbox" id="notify" nam
e="notify" value="1" /> <label for="notify">Notify user</label></span>'; |
69 | 85 utilityRadios = '<br />Utility: <input type="radio" name="utility" value="
0" checked="checked" /> not established <input type="radio" name="utility" value
="1" /> usefull <input type="radio" name="utility" value="-1" /> harmful'; |
70 div.innerHTML = '<form action="/updateReport" method="POST">' + | 86 } |
| 87 |
| 88 div.innerHTML = '<form id="updateForm" action="/updateReport" method="POST">
' + |
71 '<input type="hidden" name="secret" value="' + escapeHTML(secret) + '" />'
+ | 89 '<input type="hidden" name="secret" value="' + escapeHTML(secret) + '" />'
+ |
72 '<input type="hidden" name="guid" value="' + escapeHTML(guid) + '" />' + | 90 '<input type="hidden" name="guid" value="' + escapeHTML(guid) + '" />' + |
73 '<p>' + | 91 '<p>' + |
74 'Status templates: <br />' + | 92 'Status templates: <br />' + |
75 '<select id="templatesField"><option value="" selected="selected" disabl
ed="true">(select one)</option></select>' + | 93 '<select id="templatesField"><option value="" selected="selected" disabl
ed="true">(select one)</option></select>' + |
76 '</p>' + | 94 '</p>' + |
77 '<p>' + | 95 '<p>' + |
78 'Enter new status:' + notifyBox + '<br />' + | 96 'Enter new status:' + notifyBox + '<br />' + |
79 '<textarea id="statusField" name="status" oninput="updateTemplateButtons
();"></textarea>' + | 97 '<textarea id="statusField" name="status" oninput="updateTemplateButtons
();"></textarea>' + |
| 98 » utilityRadios + |
80 '</p>' + | 99 '</p>' + |
81 '<div>' + | 100 '<div>' + |
82 '<button id="addTemplateButton" type="button" onclick="addTemplate();">A
dd as template</button>' + | 101 '<button id="addTemplateButton" type="button" onclick="addTemplate();">A
dd as template</button>' + |
83 '<button id="removeTemplateButton" type="button" onclick="removeTemplate
();">Remove template</button>' + | 102 '<button id="removeTemplateButton" type="button" onclick="removeTemplate
();">Remove template</button>' + |
84 '<input type="submit" value="Change status"/>' + | 103 '<input type="submit" value="Change status"/>' + |
85 '</div>' + | 104 '</div>' + |
86 '</form>'; | 105 '</form>'; |
87 document.getElementById("templatesField").addEventListener("change", functio
n() | 106 document.getElementById("templatesField").addEventListener("change", functio
n() |
88 { | 107 { |
89 if (this.selectedIndex > 0) | 108 if (this.selectedIndex > 0) |
90 { | 109 { |
91 document.getElementById("statusField").value = this.options[this.selecte
dIndex].value; | 110 document.getElementById("statusField").value = this.options[this.selecte
dIndex].value; |
92 var notifyField = document.getElementById("notify"); | 111 var notifyField = document.getElementById("notify"); |
93 if (notifyField) | 112 if (notifyField) |
94 notifyField.checked = true; | 113 notifyField.checked = true; |
95 updateTemplateButtons(); | 114 updateTemplateButtons(); |
96 } | 115 } |
97 }, false); | 116 }, false); |
98 var statusField = document.getElementById("statusField"); | 117 var statusField = document.getElementById("statusField"); |
99 statusField.value = status; | 118 statusField.value = status; |
| 119 if (utilityCell) |
| 120 { |
| 121 utility = utilityCell.getAttribute("value"); |
| 122 setRadio(document.getElementById("updateForm").elements.utility, utility); |
| 123 } |
| 124 |
100 updateTemplates(); | 125 updateTemplates(); |
101 statusField.focus(); | 126 statusField.focus(); |
102 } | 127 } |
103 } | 128 } |
104 | 129 |
105 function updateTemplates() | 130 function updateTemplates() |
106 { | 131 { |
107 var templatesField = document.getElementById("templatesField"); | 132 var templatesField = document.getElementById("templatesField"); |
108 while (templatesField.options.length > 1) | 133 while (templatesField.options.length > 1) |
109 templatesField.remove(1); | 134 templatesField.remove(1); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 var spans = nodes[j].getElementsByTagName("span"); | 342 var spans = nodes[j].getElementsByTagName("span"); |
318 for (var k = 0; k < spans.length; k++) | 343 for (var k = 0; k < spans.length; k++) |
319 if (spans[k].hasAttribute("title")) | 344 if (spans[k].hasAttribute("title")) |
320 spans[k].setAttribute("title", toLocalDate(spans[k].getAttribute("titl
e"))); | 345 spans[k].setAttribute("title", toLocalDate(spans[k].getAttribute("titl
e"))); |
321 } | 346 } |
322 } | 347 } |
323 } | 348 } |
324 | 349 |
325 window.addEventListener("DOMContentLoaded", initTables, false); | 350 window.addEventListener("DOMContentLoaded", initTables, false); |
326 window.addEventListener("DOMContentLoaded", changeDates, false); | 351 window.addEventListener("DOMContentLoaded", changeDates, false); |
OLD | NEW |