Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: sitescripts/reports/static/reports.js

Issue 8625042: Reports - user usefullness (Closed)
Left Patch Set: Reports - user usefulness Created Oct. 19, 2012, 12:54 p.m.
Right Patch Set: Reports - user usefulness Created Oct. 29, 2012, 12:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « sitescripts/reports/static/lib/reportsview.js ('k') | sitescripts/reports/template/digest.html » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 { 44 {
45 for (var i = 0; i < radio.length; i++) 45 for (var i = 0; i < radio.length; i++)
46 radio[i].addEventListener("click", listener, false); 46 radio[i].addEventListener("click", listener, false);
47 } 47 }
48 48
49 function getCheckedRadio(radio) 49 function getCheckedRadio(radio)
50 { 50 {
51 for (var i = 0; i < radio.length; i++) 51 for (var i = 0; i < radio.length; i++)
52 { 52 {
53 if (radio[i].checked) 53 if (radio[i].checked)
54 return radio[i] 54 return radio[i];
Wladimir Palant 2012/10/23 05:23:28 Semicolon missing here.
55 } 55 }
56 return undefined; 56 return undefined;
57 } 57 }
58 58
59 function saveSecret(guid, secret) 59 function saveSecret(guid, secret)
60 { 60 {
61 var secrets = localStorage.secrets; 61 var secrets = localStorage.secrets;
62 if (secrets) 62 if (secrets)
63 secrets = JSON.parse(secrets); 63 secrets = JSON.parse(secrets);
64 else 64 else
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 'Enter new status:' + notifyBox + '<br />' + 105 'Enter new status:' + notifyBox + '<br />' +
106 '<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' + 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' +
108 '</p>' + 108 '</p>' +
109 '<div>' + 109 '<div>' +
110 '<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>' +
111 '<button id="removeTemplateButton" type="button" onclick="removeTemplate ();">Remove template</button>' + 111 '<button id="removeTemplateButton" type="button" onclick="removeTemplate ();">Remove template</button>' +
112 '<input type="submit" value="Change status"/>' + 112 '<input type="submit" value="Change status"/>' +
113 '</div>' + 113 '</div>' +
114 '</form>'; 114 '</form>';
115 var radios = document.getElementById("updateForm").elements.usefulness;
115 document.getElementById("templatesField").addEventListener("change", functio n() 116 document.getElementById("templatesField").addEventListener("change", functio n()
116 { 117 {
117 if (this.selectedIndex > 0) 118 if (this.selectedIndex > 0)
118 { 119 {
119 » var template = this.options[this.selectedIndex].value.split("|"); 120 » var template = this.options[this.selectedIndex].value.split("\1");
Wladimir Palant 2012/10/23 05:23:28 .split("|", 2) please - just in case. However, it
120 var displayText = template[template.length - 1]; 121 var displayText = template[template.length - 1];
121 if (template.length > 1) 122 if (template.length > 1)
122 setRadio(document.getElementById("updateForm").elements.usefulness, te mplate[0]); 123 setRadio(radios, template[0]);
123 document.getElementById("statusField").value = displayText; 124 document.getElementById("statusField").value = displayText;
124 var notifyField = document.getElementById("notify"); 125 var notifyField = document.getElementById("notify");
125 if (notifyField) 126 if (notifyField)
126 notifyField.checked = true; 127 notifyField.checked = true;
127 updateTemplateButtons(); 128 updateTemplateButtons();
128 } 129 }
129 }, false); 130 }, false);
130 131
131 var statusField = document.getElementById("statusField"); 132 var statusField = document.getElementById("statusField");
132 statusField.value = status; 133 statusField.value = status;
133 134
134 var usefulness = document.getElementById("usefulnessCell").getAttribute("val ue"); 135 var usefulness = 0;
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; 136 var usefulnessCell = document.getElementById("usefulnessCell");
Andrey Novikov 2012/10/23 14:15:29 Done.
137 if (usefulnessCell)
138 usefulness = usefulnessCell.getAttribute("value");
136 setRadio(radios, usefulness); 139 setRadio(radios, usefulness);
137 setRadioListener(radios, updateTemplates); 140 setRadioListener(radios, updateTemplates);
138 141
139 updateTemplates(); 142 updateTemplates();
140 statusField.focus(); 143 statusField.focus();
141 } 144 }
142 } 145 }
143 146
144 function updateTemplates() 147 function updateTemplates()
145 { 148 {
146 var templatesField = document.getElementById("templatesField"); 149 var templatesField = document.getElementById("templatesField");
147 while (templatesField.options.length > 1) 150 while (templatesField.options.length > 1)
148 templatesField.remove(1); 151 templatesField.remove(1);
149 for (var i = 0; i < templates.length; i++) 152 for (var i = 0; i < templates.length; i++)
150 { 153 {
151 var template = templates[i].split("|"); 154 var template = templates[i].split("\1");
152 var displayText = template[template.length - 1]; 155 var displayText = template[template.length - 1];
153 if (displayText.length > 150) 156 if (displayText.length > 150)
154 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);
155 if (template.length > 1) 158 if (template.length > 1)
156 { 159 {
157 usefulnessText = template[0] > 0 ? "useful" : template[0] < 0 ? "useless" : "neutral"; 160 usefulnessText = template[0] > 0 ? "useful" : template[0] < 0 ? "useless" : null;
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; 161 if (usefulnessText != null)
159 } 162 displayText = "[" + usefulnessText + "] " + displayText;
163 }
160 templatesField.add(new Option(displayText, templates[i], false, false), null ); 164 templatesField.add(new Option(displayText, templates[i], false, false), null );
161 } 165 }
162 updateTemplateButtons(); 166 updateTemplateButtons();
163 } 167 }
164 168
165 function updateTemplateButtons() 169 function updateTemplateButtons()
166 { 170 {
167 var currentText = document.getElementById("statusField").value; 171 var currentText = document.getElementById("statusField").value;
168 var usefulnessValue = "0"; 172 var usefulnessValue = "0";
169 var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").e lements.usefulness); 173 var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").e lements.usefulness);
170 if (usefulnessButton) 174 if (usefulnessButton)
171 usefulnessValue = usefulnessButton.value; 175 usefulnessValue = usefulnessButton.value;
172 176
173 var options = document.getElementById("templatesField").options; 177 var options = document.getElementById("templatesField").options;
174 for (var i = 1; i < options.length; i++) 178 for (var i = 1; i < options.length; i++)
175 { 179 {
176 var template = options[i].value.split("|"); 180 var template = options[i].value.split("\1");
177 var text = template[template.length - 1]; 181 var text = template[template.length - 1];
178 var usefulness = template.length > 1 ? template[0] : "0"; 182 var usefulness = template.length > 1 ? template[0] : "0";
179 183
180 if (text == currentText && usefulness == usefulnessValue) 184 if (text == currentText && usefulness == usefulnessValue)
181 { 185 {
182 document.getElementById("templatesField").selectedIndex = i; 186 document.getElementById("templatesField").selectedIndex = i;
183 document.getElementById("addTemplateButton").style.display = "none"; 187 document.getElementById("addTemplateButton").style.display = "none";
184 document.getElementById("removeTemplateButton").style.display = ""; 188 document.getElementById("removeTemplateButton").style.display = "";
185 return; 189 return;
186 } 190 }
187 } 191 }
188 192
189 document.getElementById("templatesField").selectedIndex = 0; 193 document.getElementById("templatesField").selectedIndex = 0;
190 document.getElementById("addTemplateButton").disabled = !/\S/.test(currentText ) || currentText == "unknown"; 194 document.getElementById("addTemplateButton").disabled = !/\S/.test(currentText ) || currentText == "unknown";
191 document.getElementById("addTemplateButton").style.display = ""; 195 document.getElementById("addTemplateButton").style.display = "";
192 document.getElementById("removeTemplateButton").style.display = "none"; 196 document.getElementById("removeTemplateButton").style.display = "none";
193 } 197 }
194 198
195 function addTemplate() 199 function addTemplate()
196 { 200 {
197 var usefulnessValue = "0"; 201 var usefulnessValue = "0";
198 var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").e lements.usefulness); 202 var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").e lements.usefulness);
199 if (usefulnessButton) 203 if (usefulnessButton)
200 usefulnessValue = usefulnessButton.value; 204 usefulnessValue = usefulnessButton.value;
201 205
202 var value = usefulnessValue + "|" + document.getElementById("statusField").va lue; 206 var value = usefulnessValue + "\1" + document.getElementById("statusField").v alue;
203 templates.push(value); 207 templates.push(value);
204 templates.sort(); 208 templates.sort();
Wladimir Palant 2012/10/23 05:23:28 Note that the result of this sort will be: useless
205 localStorage.templates = templates.join("\0"); 209 localStorage.templates = templates.join("\0");
206 updateTemplates(); 210 updateTemplates();
207 } 211 }
208 212
209 function removeTemplate() 213 function removeTemplate()
210 { 214 {
211 var currentText = document.getElementById("statusField").value; 215 var currentText = document.getElementById("statusField").value;
212 var usefulnessValue = "0"; 216 var usefulnessValue = "0";
213 var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").e lements.usefulness); 217 var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").e lements.usefulness);
214 if (usefulnessButton) 218 if (usefulnessButton)
215 usefulnessValue = usefulnessButton.value; 219 usefulnessValue = usefulnessButton.value;
216 for (var i = 0; i < templates.length; i++) 220 for (var i = 0; i < templates.length; i++)
217 { 221 {
218 var template = templates[i].split("|"); 222 var template = templates[i].split("\1");
219 var text = template[template.length - 1]; 223 var text = template[template.length - 1];
220 var usefulness = template.length > 1 ? template[0] : "0"; 224 var usefulness = template.length > 1 ? template[0] : "0";
221 if (text == currentText && usefulness == usefulnessValue) 225 if (text == currentText && usefulness == usefulnessValue)
222 templates.splice(i--, 1); 226 templates.splice(i--, 1);
223 } 227 }
224 localStorage.templates = templates.join("\0"); 228 localStorage.templates = templates.join("\0");
225 updateTemplates(); 229 updateTemplates();
226 } 230 }
227 231
228 function selectTab(tab) 232 function selectTab(tab)
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 var spans = nodes[j].getElementsByTagName("span"); 390 var spans = nodes[j].getElementsByTagName("span");
387 for (var k = 0; k < spans.length; k++) 391 for (var k = 0; k < spans.length; k++)
388 if (spans[k].hasAttribute("title")) 392 if (spans[k].hasAttribute("title"))
389 spans[k].setAttribute("title", toLocalDate(spans[k].getAttribute("titl e"))); 393 spans[k].setAttribute("title", toLocalDate(spans[k].getAttribute("titl e")));
390 } 394 }
391 } 395 }
392 } 396 }
393 397
394 window.addEventListener("DOMContentLoaded", initTables, false); 398 window.addEventListener("DOMContentLoaded", initTables, false);
395 window.addEventListener("DOMContentLoaded", changeDates, false); 399 window.addEventListener("DOMContentLoaded", changeDates, false);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld