Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 13 matching lines...) Expand all Loading... | |
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) | 32 function setRadio(radio, value) |
33 { | 33 { |
34 for (i = 0; i < radio.length; i++) | 34 for (var i = 0; i < radio.length; i++) |
35 { | 35 { |
36 if (radio[i].value == value) | 36 if (radio[i].value == value) |
37 radio[i].checked = true; | 37 radio[i].checked = true; |
38 else | 38 else |
39 radio[i].checked = false; | 39 radio[i].checked = false; |
40 } | 40 } |
41 } | |
42 | |
43 function setRadioListener(radio, listener) | |
44 { | |
45 for (var i = 0; i < radio.length; i++) | |
46 radio[i].addEventListener("click", listener, false); | |
47 } | |
48 | |
49 function getCheckedRadio(radio) | |
50 { | |
51 for (var i = 0; i < radio.length; i++) | |
52 { | |
53 if (radio[i].checked) | |
54 return radio[i]; | |
55 } | |
56 return undefined; | |
41 } | 57 } |
42 | 58 |
43 function saveSecret(guid, secret) | 59 function saveSecret(guid, secret) |
44 { | 60 { |
45 var secrets = localStorage.secrets; | 61 var secrets = localStorage.secrets; |
46 if (secrets) | 62 if (secrets) |
47 secrets = JSON.parse(secrets); | 63 secrets = JSON.parse(secrets); |
48 else | 64 else |
49 secrets = {}; | 65 secrets = {}; |
50 secrets[guid] = {value: secret, expiration: new Date().getTime() + 1000*60*60* 24*30}; | 66 secrets[guid] = {value: secret, expiration: new Date().getTime() + 1000*60*60* 24*30}; |
51 localStorage.secrets = JSON.stringify(secrets); | 67 localStorage.secrets = JSON.stringify(secrets); |
52 } | 68 } |
53 | 69 |
54 function setSecret(guid, secret) | 70 function setSecret(guid, secret) |
55 { | 71 { |
56 saveSecret(guid, secret); | 72 saveSecret(guid, secret); |
57 | 73 |
58 var status = ""; | 74 var status = ""; |
59 var statusCell = document.getElementById("statusCell"); | 75 var statusCell = document.getElementById("statusCell"); |
60 if (statusCell) | 76 if (statusCell) |
61 status = statusCell.textContent; | 77 status = statusCell.textContent; |
62 | 78 |
63 var utility = "0"; | |
64 var utilityCell = document.getElementById("utilityCell"); | |
65 | |
66 var div = document.createElement("div"); | 79 var div = document.createElement("div"); |
67 div.className = "updateLink" | 80 div.className = "updateLink" |
68 var link = document.createElement("a"); | 81 var link = document.createElement("a"); |
69 link.setAttribute("href", "javascript:void(0);"); | 82 link.setAttribute("href", "javascript:void(0);"); |
70 link.textContent = "Update status" | 83 link.textContent = "Update status" |
71 div.appendChild(link); | 84 div.appendChild(link); |
72 | 85 |
73 if (statusCell) | 86 if (statusCell) |
74 statusCell.appendChild(div); | 87 statusCell.appendChild(div); |
75 else | 88 else |
76 document.body.insertBefore(div, document.body.firstChild); | 89 document.body.insertBefore(div, document.body.firstChild); |
77 | 90 |
78 link.onclick = function() | 91 link.onclick = function() |
79 { | 92 { |
80 var notifyBox = ""; | 93 var notifyBox = ""; |
81 var utilityRadios = ""; | |
82 if (document.getElementById("emailCell")) | 94 if (document.getElementById("emailCell")) |
83 { | |
84 notifyBox = '<span id="notifyField"><input type="checkbox" id="notify" nam e="notify" value="1" /> <label for="notify">Notify user</label></span>'; | 95 notifyBox = '<span id="notifyField"><input type="checkbox" id="notify" nam e="notify" value="1" /> <label for="notify">Notify user</label></span>'; |
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'; | 96 |
Wladimir Palant
2012/10/18 15:41:24
Not "harmful" but "useless". And it is "useful", n
Andrey Novikov
2012/10/18 15:51:29
Done.
| |
86 } | |
87 | |
88 div.innerHTML = '<form id="updateForm" action="/updateReport" method="POST"> ' + | 97 div.innerHTML = '<form id="updateForm" action="/updateReport" method="POST"> ' + |
89 '<input type="hidden" name="secret" value="' + escapeHTML(secret) + '" />' + | 98 '<input type="hidden" name="secret" value="' + escapeHTML(secret) + '" />' + |
90 '<input type="hidden" name="guid" value="' + escapeHTML(guid) + '" />' + | 99 '<input type="hidden" name="guid" value="' + escapeHTML(guid) + '" />' + |
91 '<p>' + | 100 '<p>' + |
92 'Status templates: <br />' + | 101 'Status templates: <br />' + |
93 '<select id="templatesField"><option value="" selected="selected" disabl ed="true">(select one)</option></select>' + | 102 '<select id="templatesField"><option value="" selected="selected" disabl ed="true">(select one)</option></select>' + |
94 '</p>' + | 103 '</p>' + |
95 '<p>' + | 104 '<p>' + |
96 'Enter new status:' + notifyBox + '<br />' + | 105 'Enter new status:' + notifyBox + '<br />' + |
97 '<textarea id="statusField" name="status" oninput="updateTemplateButtons ();"></textarea>' + | 106 '<textarea id="statusField" name="status" oninput="updateTemplateButtons ();"></textarea>' + |
98 » utilityRadios + | 107 '<br />Usefulness: <input type="radio" name="usefulness" value="0" check ed="checked" /> not established <input type="radio" name="usefulness" value="1" /> useful <input type="radio" name="usefulness" value="-1" /> useless' + |
99 '</p>' + | 108 '</p>' + |
100 '<div>' + | 109 '<div>' + |
101 '<button id="addTemplateButton" type="button" onclick="addTemplate();">A dd as template</button>' + | 110 '<button id="addTemplateButton" type="button" onclick="addTemplate();">A dd as template</button>' + |
102 '<button id="removeTemplateButton" type="button" onclick="removeTemplate ();">Remove template</button>' + | 111 '<button id="removeTemplateButton" type="button" onclick="removeTemplate ();">Remove template</button>' + |
103 '<input type="submit" value="Change status"/>' + | 112 '<input type="submit" value="Change status"/>' + |
104 '</div>' + | 113 '</div>' + |
105 '</form>'; | 114 '</form>'; |
115 var radios = document.getElementById("updateForm").elements.usefulness; | |
106 document.getElementById("templatesField").addEventListener("change", functio n() | 116 document.getElementById("templatesField").addEventListener("change", functio n() |
107 { | 117 { |
108 if (this.selectedIndex > 0) | 118 if (this.selectedIndex > 0) |
109 { | 119 { |
110 document.getElementById("statusField").value = this.options[this.selecte dIndex].value; | 120 » var template = this.options[this.selectedIndex].value.split("\1"); |
121 var displayText = template[template.length - 1]; | |
122 if (template.length > 1) | |
123 setRadio(radios, template[0]); | |
124 document.getElementById("statusField").value = displayText; | |
111 var notifyField = document.getElementById("notify"); | 125 var notifyField = document.getElementById("notify"); |
112 if (notifyField) | 126 if (notifyField) |
113 notifyField.checked = true; | 127 notifyField.checked = true; |
114 updateTemplateButtons(); | 128 updateTemplateButtons(); |
115 } | 129 } |
116 }, false); | 130 }, false); |
131 | |
117 var statusField = document.getElementById("statusField"); | 132 var statusField = document.getElementById("statusField"); |
118 statusField.value = status; | 133 statusField.value = status; |
119 if (utilityCell) | 134 |
120 { | 135 var usefulness = 0; |
121 utility = utilityCell.getAttribute("value"); | 136 var usefulnessCell = document.getElementById("usefulnessCell"); |
122 setRadio(document.getElementById("updateForm").elements.utility, utility); | 137 if (usefulnessCell) |
123 } | 138 usefulness = usefulnessCell.getAttribute("value"); |
139 setRadio(radios, usefulness); | |
140 setRadioListener(radios, updateTemplates); | |
124 | 141 |
125 updateTemplates(); | 142 updateTemplates(); |
126 statusField.focus(); | 143 statusField.focus(); |
127 } | 144 } |
128 } | 145 } |
129 | 146 |
130 function updateTemplates() | 147 function updateTemplates() |
131 { | 148 { |
132 var templatesField = document.getElementById("templatesField"); | 149 var templatesField = document.getElementById("templatesField"); |
133 while (templatesField.options.length > 1) | 150 while (templatesField.options.length > 1) |
134 templatesField.remove(1); | 151 templatesField.remove(1); |
135 for (var i = 0; i < templates.length; i++) | 152 for (var i = 0; i < templates.length; i++) |
136 { | 153 { |
137 var displayText = templates[i]; | 154 var template = templates[i].split("\1"); |
155 var displayText = template[template.length - 1]; | |
138 if (displayText.length > 150) | 156 if (displayText.length > 150) |
139 displayText = displayText.substr(0, 75) + "..." + displayText.substr(displ ayText.length - 75, displayText.length); | 157 displayText = displayText.substr(0, 75) + "..." + displayText.substr(displ ayText.length - 75, displayText.length); |
158 if (template.length > 1) | |
159 { | |
160 usefulnessText = template[0] > 0 ? "useful" : template[0] < 0 ? "useless" : null; | |
161 if (usefulnessText != null) | |
162 displayText = "[" + usefulnessText + "] " + displayText; | |
163 } | |
140 templatesField.add(new Option(displayText, templates[i], false, false), null ); | 164 templatesField.add(new Option(displayText, templates[i], false, false), null ); |
141 } | 165 } |
142 updateTemplateButtons(); | 166 updateTemplateButtons(); |
143 } | 167 } |
144 | 168 |
145 function updateTemplateButtons() | 169 function updateTemplateButtons() |
146 { | 170 { |
147 var currentText = document.getElementById("statusField").value; | 171 var currentText = document.getElementById("statusField").value; |
172 var usefulnessValue = "0"; | |
173 var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").e lements.usefulness); | |
174 if (usefulnessButton) | |
175 usefulnessValue = usefulnessButton.value; | |
176 | |
148 var options = document.getElementById("templatesField").options; | 177 var options = document.getElementById("templatesField").options; |
149 for (var i = 1; i < options.length; i++) | 178 for (var i = 1; i < options.length; i++) |
150 { | 179 { |
151 if (options[i].value == currentText) | 180 var template = options[i].value.split("\1"); |
181 var text = template[template.length - 1]; | |
182 var usefulness = template.length > 1 ? template[0] : "0"; | |
183 | |
184 if (text == currentText && usefulness == usefulnessValue) | |
152 { | 185 { |
153 document.getElementById("templatesField").selectedIndex = i; | 186 document.getElementById("templatesField").selectedIndex = i; |
154 document.getElementById("addTemplateButton").style.display = "none"; | 187 document.getElementById("addTemplateButton").style.display = "none"; |
155 document.getElementById("removeTemplateButton").style.display = ""; | 188 document.getElementById("removeTemplateButton").style.display = ""; |
156 return; | 189 return; |
157 } | 190 } |
158 } | 191 } |
159 | 192 |
160 document.getElementById("templatesField").selectedIndex = 0; | 193 document.getElementById("templatesField").selectedIndex = 0; |
161 document.getElementById("addTemplateButton").disabled = !/\S/.test(currentText ) || currentText == "unknown"; | 194 document.getElementById("addTemplateButton").disabled = !/\S/.test(currentText ) || currentText == "unknown"; |
162 document.getElementById("addTemplateButton").style.display = ""; | 195 document.getElementById("addTemplateButton").style.display = ""; |
163 document.getElementById("removeTemplateButton").style.display = "none"; | 196 document.getElementById("removeTemplateButton").style.display = "none"; |
164 } | 197 } |
165 | 198 |
166 function addTemplate() | 199 function addTemplate() |
167 { | 200 { |
168 templates.push(document.getElementById("statusField").value); | 201 var usefulnessValue = "0"; |
202 var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").e lements.usefulness); | |
203 if (usefulnessButton) | |
204 usefulnessValue = usefulnessButton.value; | |
205 | |
206 var value = usefulnessValue + "\1" + document.getElementById("statusField").v alue; | |
207 templates.push(value); | |
169 templates.sort(); | 208 templates.sort(); |
170 localStorage.templates = templates.join("\0"); | 209 localStorage.templates = templates.join("\0"); |
171 updateTemplates(); | 210 updateTemplates(); |
172 } | 211 } |
173 | 212 |
174 function removeTemplate() | 213 function removeTemplate() |
175 { | 214 { |
176 var currentText = document.getElementById("statusField").value; | 215 var currentText = document.getElementById("statusField").value; |
216 var usefulnessValue = "0"; | |
217 var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").e lements.usefulness); | |
218 if (usefulnessButton) | |
219 usefulnessValue = usefulnessButton.value; | |
177 for (var i = 0; i < templates.length; i++) | 220 for (var i = 0; i < templates.length; i++) |
178 if (templates[i] == currentText) | 221 { |
222 var template = templates[i].split("\1"); | |
223 var text = template[template.length - 1]; | |
224 var usefulness = template.length > 1 ? template[0] : "0"; | |
225 if (text == currentText && usefulness == usefulnessValue) | |
179 templates.splice(i--, 1); | 226 templates.splice(i--, 1); |
227 } | |
180 localStorage.templates = templates.join("\0"); | 228 localStorage.templates = templates.join("\0"); |
181 updateTemplates(); | 229 updateTemplates(); |
182 } | 230 } |
183 | 231 |
184 function selectTab(tab) | 232 function selectTab(tab) |
185 { | 233 { |
186 document.documentElement.setAttribute("selectedTab", tab); | 234 document.documentElement.setAttribute("selectedTab", tab); |
187 window.location.replace(window.location.href.replace(/#.*|$/, "#tab=" + tab)); | 235 window.location.replace(window.location.href.replace(/#.*|$/, "#tab=" + tab)); |
188 } | 236 } |
189 | 237 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 var spans = nodes[j].getElementsByTagName("span"); | 390 var spans = nodes[j].getElementsByTagName("span"); |
343 for (var k = 0; k < spans.length; k++) | 391 for (var k = 0; k < spans.length; k++) |
344 if (spans[k].hasAttribute("title")) | 392 if (spans[k].hasAttribute("title")) |
345 spans[k].setAttribute("title", toLocalDate(spans[k].getAttribute("titl e"))); | 393 spans[k].setAttribute("title", toLocalDate(spans[k].getAttribute("titl e"))); |
346 } | 394 } |
347 } | 395 } |
348 } | 396 } |
349 | 397 |
350 window.addEventListener("DOMContentLoaded", initTables, false); | 398 window.addEventListener("DOMContentLoaded", initTables, false); |
351 window.addEventListener("DOMContentLoaded", changeDates, false); | 399 window.addEventListener("DOMContentLoaded", changeDates, false); |
LEFT | RIGHT |