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

Unified Diff: sitescripts/reports/static/reports.js

Issue 8625042: Reports - user usefullness (Closed)
Patch Set: Reports - user usefulness Created Oct. 19, 2012, 12:54 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sitescripts/reports/static/reports.js
===================================================================
--- a/sitescripts/reports/static/reports.js
+++ b/sitescripts/reports/static/reports.js
@@ -29,6 +29,33 @@
return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
}
+function setRadio(radio, value)
+{
+ for (var i = 0; i < radio.length; i++)
+ {
+ if (radio[i].value == value)
+ radio[i].checked = true;
+ else
+ radio[i].checked = false;
+ }
+}
+
+function setRadioListener(radio, listener)
+{
+ for (var i = 0; i < radio.length; i++)
+ radio[i].addEventListener("click", listener, false);
+}
+
+function getCheckedRadio(radio)
+{
+ for (var i = 0; i < radio.length; i++)
+ {
+ if (radio[i].checked)
+ return radio[i]
Wladimir Palant 2012/10/23 05:23:28 Semicolon missing here.
+ }
+ return undefined;
+}
+
function saveSecret(guid, secret)
{
var secrets = localStorage.secrets;
@@ -48,7 +75,7 @@
var statusCell = document.getElementById("statusCell");
if (statusCell)
status = statusCell.textContent;
-
+
var div = document.createElement("div");
div.className = "updateLink"
var link = document.createElement("a");
@@ -67,7 +94,7 @@
if (document.getElementById("emailCell"))
notifyBox = '<span id="notifyField"><input type="checkbox" id="notify" name="notify" value="1" /> <label for="notify">Notify user</label></span>';
- div.innerHTML = '<form action="/updateReport" method="POST">' +
+ div.innerHTML = '<form id="updateForm" action="/updateReport" method="POST">' +
'<input type="hidden" name="secret" value="' + escapeHTML(secret) + '" />' +
'<input type="hidden" name="guid" value="' + escapeHTML(guid) + '" />' +
'<p>' +
@@ -76,7 +103,8 @@
'</p>' +
'<p>' +
'Enter new status:' + notifyBox + '<br />' +
- '<textarea id="statusField" name="status" oninput="updateTemplateButtons();"></textarea>' +
+ '<textarea id="statusField" name="status" oninput="updateTemplateButtons();"></textarea>' +
+ '<br />Usefulness: <input type="radio" name="usefulness" value="0" checked="checked" /> not established <input type="radio" name="usefulness" value="1" /> useful <input type="radio" name="usefulness" value="-1" /> useless' +
'</p>' +
'<div>' +
'<button id="addTemplateButton" type="button" onclick="addTemplate();">Add as template</button>' +
@@ -88,15 +116,26 @@
{
if (this.selectedIndex > 0)
{
- document.getElementById("statusField").value = this.options[this.selectedIndex].value;
+ var template = this.options[this.selectedIndex].value.split("|");
Wladimir Palant 2012/10/23 05:23:28 .split("|", 2) please - just in case. However, it
+ var displayText = template[template.length - 1];
+ if (template.length > 1)
+ setRadio(document.getElementById("updateForm").elements.usefulness, template[0]);
+ document.getElementById("statusField").value = displayText;
var notifyField = document.getElementById("notify");
if (notifyField)
notifyField.checked = true;
updateTemplateButtons();
}
}, false);
+
var statusField = document.getElementById("statusField");
statusField.value = status;
+
+ var usefulness = document.getElementById("usefulnessCell").getAttribute("value");
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
+ var radios = document.getElementById("updateForm").elements.usefulness;
Andrey Novikov 2012/10/23 14:15:29 Done.
+ setRadio(radios, usefulness);
+ setRadioListener(radios, updateTemplates);
+
updateTemplates();
statusField.focus();
}
@@ -109,9 +148,15 @@
templatesField.remove(1);
for (var i = 0; i < templates.length; i++)
{
- var displayText = templates[i];
+ var template = templates[i].split("|");
+ var displayText = template[template.length - 1];
if (displayText.length > 150)
displayText = displayText.substr(0, 75) + "..." + displayText.substr(displayText.length - 75, displayText.length);
+ if (template.length > 1)
+ {
+ 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.
+ displayText = "[" + usefulnessText + "] " + displayText;
+ }
templatesField.add(new Option(displayText, templates[i], false, false), null);
}
updateTemplateButtons();
@@ -120,10 +165,19 @@
function updateTemplateButtons()
{
var currentText = document.getElementById("statusField").value;
+ var usefulnessValue = "0";
+ var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").elements.usefulness);
+ if (usefulnessButton)
+ usefulnessValue = usefulnessButton.value;
+
var options = document.getElementById("templatesField").options;
for (var i = 1; i < options.length; i++)
{
- if (options[i].value == currentText)
+ var template = options[i].value.split("|");
+ var text = template[template.length - 1];
+ var usefulness = template.length > 1 ? template[0] : "0";
+
+ if (text == currentText && usefulness == usefulnessValue)
{
document.getElementById("templatesField").selectedIndex = i;
document.getElementById("addTemplateButton").style.display = "none";
@@ -140,7 +194,13 @@
function addTemplate()
{
- templates.push(document.getElementById("statusField").value);
+ var usefulnessValue = "0";
+ var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").elements.usefulness);
+ if (usefulnessButton)
+ usefulnessValue = usefulnessButton.value;
+
+ var value = usefulnessValue + "|" + document.getElementById("statusField").value;
+ templates.push(value);
templates.sort();
Wladimir Palant 2012/10/23 05:23:28 Note that the result of this sort will be: useless
localStorage.templates = templates.join("\0");
updateTemplates();
@@ -149,9 +209,18 @@
function removeTemplate()
{
var currentText = document.getElementById("statusField").value;
+ var usefulnessValue = "0";
+ var usefulnessButton = getCheckedRadio(document.getElementById("updateForm").elements.usefulness);
+ if (usefulnessButton)
+ usefulnessValue = usefulnessButton.value;
for (var i = 0; i < templates.length; i++)
- if (templates[i] == currentText)
+ {
+ var template = templates[i].split("|");
+ var text = template[template.length - 1];
+ var usefulness = template.length > 1 ? template[0] : "0";
+ if (text == currentText && usefulness == usefulnessValue)
templates.splice(i--, 1);
+ }
localStorage.templates = templates.join("\0");
updateTemplates();
}

Powered by Google App Engine
This is Rietveld