Left: | ||
Right: |
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 (var 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 | |
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] | |
Wladimir Palant
2012/10/23 05:23:28
Semicolon missing here.
| |
55 } | |
56 return undefined; | |
57 } | |
58 | |
32 function saveSecret(guid, secret) | 59 function saveSecret(guid, secret) |
33 { | 60 { |
34 var secrets = localStorage.secrets; | 61 var secrets = localStorage.secrets; |
35 if (secrets) | 62 if (secrets) |
36 secrets = JSON.parse(secrets); | 63 secrets = JSON.parse(secrets); |
37 else | 64 else |
38 secrets = {}; | 65 secrets = {}; |
39 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}; |
40 localStorage.secrets = JSON.stringify(secrets); | 67 localStorage.secrets = JSON.stringify(secrets); |
41 } | 68 } |
42 | 69 |
43 function setSecret(guid, secret) | 70 function setSecret(guid, secret) |
44 { | 71 { |
45 saveSecret(guid, secret); | 72 saveSecret(guid, secret); |
46 | 73 |
47 var status = ""; | 74 var status = ""; |
48 var statusCell = document.getElementById("statusCell"); | 75 var statusCell = document.getElementById("statusCell"); |
49 if (statusCell) | 76 if (statusCell) |
50 status = statusCell.textContent; | 77 status = statusCell.textContent; |
51 | 78 |
52 var div = document.createElement("div"); | 79 var div = document.createElement("div"); |
53 div.className = "updateLink" | 80 div.className = "updateLink" |
54 var link = document.createElement("a"); | 81 var link = document.createElement("a"); |
55 link.setAttribute("href", "javascript:void(0);"); | 82 link.setAttribute("href", "javascript:void(0);"); |
56 link.textContent = "Update status" | 83 link.textContent = "Update status" |
57 div.appendChild(link); | 84 div.appendChild(link); |
58 | 85 |
59 if (statusCell) | 86 if (statusCell) |
60 statusCell.appendChild(div); | 87 statusCell.appendChild(div); |
61 else | 88 else |
62 document.body.insertBefore(div, document.body.firstChild); | 89 document.body.insertBefore(div, document.body.firstChild); |
63 | 90 |
64 link.onclick = function() | 91 link.onclick = function() |
65 { | 92 { |
66 var notifyBox = ""; | 93 var notifyBox = ""; |
67 if (document.getElementById("emailCell")) | 94 if (document.getElementById("emailCell")) |
68 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>'; |
69 | 96 |
70 div.innerHTML = '<form action="/updateReport" method="POST">' + | 97 div.innerHTML = '<form id="updateForm" action="/updateReport" method="POST"> ' + |
71 '<input type="hidden" name="secret" value="' + escapeHTML(secret) + '" />' + | 98 '<input type="hidden" name="secret" value="' + escapeHTML(secret) + '" />' + |
72 '<input type="hidden" name="guid" value="' + escapeHTML(guid) + '" />' + | 99 '<input type="hidden" name="guid" value="' + escapeHTML(guid) + '" />' + |
73 '<p>' + | 100 '<p>' + |
74 'Status templates: <br />' + | 101 'Status templates: <br />' + |
75 '<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>' + |
76 '</p>' + | 103 '</p>' + |
77 '<p>' + | 104 '<p>' + |
78 'Enter new status:' + notifyBox + '<br />' + | 105 'Enter new status:' + notifyBox + '<br />' + |
79 '<textarea id="statusField" name="status" oninput="updateTemplateButtons ();"></textarea>' + | 106 '<textarea id="statusField" name="status" oninput="updateTemplateButtons ();"></textarea>' + |
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' + | |
80 '</p>' + | 108 '</p>' + |
81 '<div>' + | 109 '<div>' + |
82 '<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>' + |
83 '<button id="removeTemplateButton" type="button" onclick="removeTemplate ();">Remove template</button>' + | 111 '<button id="removeTemplateButton" type="button" onclick="removeTemplate ();">Remove template</button>' + |
84 '<input type="submit" value="Change status"/>' + | 112 '<input type="submit" value="Change status"/>' + |
85 '</div>' + | 113 '</div>' + |
86 '</form>'; | 114 '</form>'; |
87 document.getElementById("templatesField").addEventListener("change", functio n() | 115 document.getElementById("templatesField").addEventListener("change", functio n() |
88 { | 116 { |
89 if (this.selectedIndex > 0) | 117 if (this.selectedIndex > 0) |
90 { | 118 { |
91 document.getElementById("statusField").value = this.options[this.selecte dIndex].value; | 119 » var template = this.options[this.selectedIndex].value.split("|"); |
Wladimir Palant
2012/10/23 05:23:28
.split("|", 2) please - just in case. However, it
| |
120 var displayText = template[template.length - 1]; | |
121 if (template.length > 1) | |
122 setRadio(document.getElementById("updateForm").elements.usefulness, te mplate[0]); | |
123 document.getElementById("statusField").value = displayText; | |
92 var notifyField = document.getElementById("notify"); | 124 var notifyField = document.getElementById("notify"); |
93 if (notifyField) | 125 if (notifyField) |
94 notifyField.checked = true; | 126 notifyField.checked = true; |
95 updateTemplateButtons(); | 127 updateTemplateButtons(); |
96 } | 128 } |
97 }, false); | 129 }, false); |
130 | |
98 var statusField = document.getElementById("statusField"); | 131 var statusField = document.getElementById("statusField"); |
99 statusField.value = status; | 132 statusField.value = status; |
133 | |
134 var usefulness = document.getElementById("usefulnessCell").getAttribute("val ue"); | |
Wladimir Palant
2012/10/23 05:23:28
What if there is no usefulnessCell? Note that you
Andrey Novikov
2012/10/23 14:15:29
It's much better to run our one-time all reports u
Wladimir Palant
2012/10/25 15:12:55
I don't really like doing that without a very good
| |
135 var radios = document.getElementById("updateForm").elements.usefulness; | |
Andrey Novikov
2012/10/23 14:15:29
Done.
| |
136 setRadio(radios, usefulness); | |
137 setRadioListener(radios, updateTemplates); | |
138 | |
100 updateTemplates(); | 139 updateTemplates(); |
101 statusField.focus(); | 140 statusField.focus(); |
102 } | 141 } |
103 } | 142 } |
104 | 143 |
105 function updateTemplates() | 144 function updateTemplates() |
106 { | 145 { |
107 var templatesField = document.getElementById("templatesField"); | 146 var templatesField = document.getElementById("templatesField"); |
108 while (templatesField.options.length > 1) | 147 while (templatesField.options.length > 1) |
109 templatesField.remove(1); | 148 templatesField.remove(1); |
110 for (var i = 0; i < templates.length; i++) | 149 for (var i = 0; i < templates.length; i++) |
111 { | 150 { |
112 var displayText = templates[i]; | 151 var template = templates[i].split("|"); |
152 var displayText = template[template.length - 1]; | |
113 if (displayText.length > 150) | 153 if (displayText.length > 150) |
114 displayText = displayText.substr(0, 75) + "..." + displayText.substr(displ ayText.length - 75, displayText.length); | 154 displayText = displayText.substr(0, 75) + "..." + displayText.substr(displ ayText.length - 75, displayText.length); |
155 if (template.length > 1) | |
156 { | |
157 usefulnessText = template[0] > 0 ? "useful" : template[0] < 0 ? "useless" : "neutral"; | |
Wladimir Palant
2012/10/23 05:23:28
I don't think that [neutral] is required - we shou
Andrey Novikov
2012/10/23 14:15:29
Done.
| |
158 displayText = "[" + usefulnessText + "] " + displayText; | |
159 } | |
115 templatesField.add(new Option(displayText, templates[i], false, false), null ); | 160 templatesField.add(new Option(displayText, templates[i], false, false), null ); |
116 } | 161 } |
117 updateTemplateButtons(); | 162 updateTemplateButtons(); |
118 } | 163 } |
119 | 164 |
120 function updateTemplateButtons() | 165 function updateTemplateButtons() |
121 { | 166 { |
122 var currentText = document.getElementById("statusField").value; | 167 var currentText = document.getElementById("statusField").value; |
168 var usefulnessValue = "0"; | |
169 var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").e lements.usefulness); | |
170 if (usefulnessButton) | |
171 usefulnessValue = usefulnessButton.value; | |
172 | |
123 var options = document.getElementById("templatesField").options; | 173 var options = document.getElementById("templatesField").options; |
124 for (var i = 1; i < options.length; i++) | 174 for (var i = 1; i < options.length; i++) |
125 { | 175 { |
126 if (options[i].value == currentText) | 176 var template = options[i].value.split("|"); |
177 var text = template[template.length - 1]; | |
178 var usefulness = template.length > 1 ? template[0] : "0"; | |
179 | |
180 if (text == currentText && usefulness == usefulnessValue) | |
127 { | 181 { |
128 document.getElementById("templatesField").selectedIndex = i; | 182 document.getElementById("templatesField").selectedIndex = i; |
129 document.getElementById("addTemplateButton").style.display = "none"; | 183 document.getElementById("addTemplateButton").style.display = "none"; |
130 document.getElementById("removeTemplateButton").style.display = ""; | 184 document.getElementById("removeTemplateButton").style.display = ""; |
131 return; | 185 return; |
132 } | 186 } |
133 } | 187 } |
134 | 188 |
135 document.getElementById("templatesField").selectedIndex = 0; | 189 document.getElementById("templatesField").selectedIndex = 0; |
136 document.getElementById("addTemplateButton").disabled = !/\S/.test(currentText ) || currentText == "unknown"; | 190 document.getElementById("addTemplateButton").disabled = !/\S/.test(currentText ) || currentText == "unknown"; |
137 document.getElementById("addTemplateButton").style.display = ""; | 191 document.getElementById("addTemplateButton").style.display = ""; |
138 document.getElementById("removeTemplateButton").style.display = "none"; | 192 document.getElementById("removeTemplateButton").style.display = "none"; |
139 } | 193 } |
140 | 194 |
141 function addTemplate() | 195 function addTemplate() |
142 { | 196 { |
143 templates.push(document.getElementById("statusField").value); | 197 var usefulnessValue = "0"; |
198 var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").e lements.usefulness); | |
199 if (usefulnessButton) | |
200 usefulnessValue = usefulnessButton.value; | |
201 | |
202 var value = usefulnessValue + "|" + document.getElementById("statusField").va lue; | |
203 templates.push(value); | |
144 templates.sort(); | 204 templates.sort(); |
Wladimir Palant
2012/10/23 05:23:28
Note that the result of this sort will be: useless
| |
145 localStorage.templates = templates.join("\0"); | 205 localStorage.templates = templates.join("\0"); |
146 updateTemplates(); | 206 updateTemplates(); |
147 } | 207 } |
148 | 208 |
149 function removeTemplate() | 209 function removeTemplate() |
150 { | 210 { |
151 var currentText = document.getElementById("statusField").value; | 211 var currentText = document.getElementById("statusField").value; |
212 var usefulnessValue = "0"; | |
213 var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").e lements.usefulness); | |
214 if (usefulnessButton) | |
215 usefulnessValue = usefulnessButton.value; | |
152 for (var i = 0; i < templates.length; i++) | 216 for (var i = 0; i < templates.length; i++) |
153 if (templates[i] == currentText) | 217 { |
218 var template = templates[i].split("|"); | |
219 var text = template[template.length - 1]; | |
220 var usefulness = template.length > 1 ? template[0] : "0"; | |
221 if (text == currentText && usefulness == usefulnessValue) | |
154 templates.splice(i--, 1); | 222 templates.splice(i--, 1); |
223 } | |
155 localStorage.templates = templates.join("\0"); | 224 localStorage.templates = templates.join("\0"); |
156 updateTemplates(); | 225 updateTemplates(); |
157 } | 226 } |
158 | 227 |
159 function selectTab(tab) | 228 function selectTab(tab) |
160 { | 229 { |
161 document.documentElement.setAttribute("selectedTab", tab); | 230 document.documentElement.setAttribute("selectedTab", tab); |
162 window.location.replace(window.location.href.replace(/#.*|$/, "#tab=" + tab)); | 231 window.location.replace(window.location.href.replace(/#.*|$/, "#tab=" + tab)); |
163 } | 232 } |
164 | 233 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 var spans = nodes[j].getElementsByTagName("span"); | 386 var spans = nodes[j].getElementsByTagName("span"); |
318 for (var k = 0; k < spans.length; k++) | 387 for (var k = 0; k < spans.length; k++) |
319 if (spans[k].hasAttribute("title")) | 388 if (spans[k].hasAttribute("title")) |
320 spans[k].setAttribute("title", toLocalDate(spans[k].getAttribute("titl e"))); | 389 spans[k].setAttribute("title", toLocalDate(spans[k].getAttribute("titl e"))); |
321 } | 390 } |
322 } | 391 } |
323 } | 392 } |
324 | 393 |
325 window.addEventListener("DOMContentLoaded", initTables, false); | 394 window.addEventListener("DOMContentLoaded", initTables, false); |
326 window.addEventListener("DOMContentLoaded", changeDates, false); | 395 window.addEventListener("DOMContentLoaded", changeDates, false); |
OLD | NEW |