--- reviewpages/scripts/main.js (revision 264)
+++ reviewpages/scripts/main.js (working copy)
@@ -1,23 +1,25 @@
function switch_ok(e) {
if (e.target.checked == true) {
- agree();
+ agree_all();
} else {
- disagree();
+ disagree_all();
}
}
-function agree() {
+function agree_all() {
var inputs=document.getElementsByName("agree_box");
for (var i=0; i<inputs.length; ++i) {
inputs[i].checked=true;
}
+ document.getElementById('cb_0').checked = true;
}
-function disagree() {
+function disagree_all() {
var inputs=document.getElementsByName("agree_box");
for (i=0; i<inputs.length; ++i) {
inputs[i].checked=false;
}
+ document.getElementById('cb_0').checked = false;
}
function agree_clicked(e) {
@@ -27,7 +29,7 @@
} else {
var inputs=document.getElementsByName("agree_box");
var all = true;
- for (var i=1; i<inputs.length; ++i) {
+ for (var i=0; i<inputs.length; ++i) {
if (!inputs[i].checked) {
all = false;
break;
@@ -44,10 +46,77 @@
document.getElementById('bu_'+id).style.display = 'block';
}
+function reset_rep1() {
+ var rep = load_rep();
+ disagree_all();
+ for (var id in rep.c) {
+ clear_comment(id);
+ }
+ delete rep.c;
+ delete rep.a;
+ delete rep.i;
+ save_rep(rep);
+}
+
+function reset_rep2() {
+ deleteCookie('rp_'+reviewID);
+}
+
+/*
+ * Add a static comment to the row of the main table.
+ * Creates the row if there is no one.
+ */
+function add_static_comment(id, comments) { //data=[ time, author, comment, agreed ]
+ comments.sort(function(a,b) { return a[0] > b[0]; });
+
+ var dl = document.getElementById('dl_'+id);
+ if (!dl) {
+ var tr = document.getElementById('item_'+id);
+ if (!tr) {
+ return;
+ }
+ var tbl = document.getElementById('status_table');
+ var tr_c = tbl.insertRow(tr.rowIndex + 1); // TODO: unknown tr!
+ tr_c.id = "ts_"+id;
+ var td_c = tr_c.insertCell(0);
+ td_c.colSpan = 8;
+ dl = document.createElement('DL');
+ dl.className = 'x';
+ dl.id = "dl_"+id;
+ td_c.appendChild(dl);
+ }
+ var comment;
+ var name = getCookie('rp_name');
+ for (var i=0; i<comments.length; ++i) {
+ comment = comments[i];
+ var dt_id = escape_id("dt_"+id+'_'+comment[0]+'_'+escape(comment[1]));
+ if (document.getElementById(dt_id)) {
+ continue;
+ }
+ var dt = document.createElement('DT');
+ dt.id = dt_id;
+ dt.title = new Date(parseInt(comment[0])+1287854282865).toLocaleString();
+ if (id == 0) {
+ dt.innerHTML = comment[3] ? comment[1] + ": Alright" : comment[1];
+ } else {
+ dt.innerHTML = comment[3] ? comment[1]+': Agreed' : comment[1];
+ }
+ dt.className = name == comment[1] ? 'xs' : 'x';
+ dl.appendChild(dt);
+ if (comment[2]) {
+ var dd = document.createElement('DD');
+ if (name == comment[1])
+ dd.className = 'xs';
+ dd.innerHTML = comment[2];
+ dl.appendChild(dd);
+ }
+ }
+}
+
function add_comment(id, comment) {
var ta = document.getElementById('ta_'+id);
document.getElementById('bu_'+id).style.display = "none";
- if (comment != "") {
+ if (comment) {
document.getElementById('lb_'+id).style.borderBottom = '2px dotted blue';
document.getElementById('lb_'+id).title = comment;
} else {
@@ -62,7 +131,9 @@
}
var tbl = document.getElementById('status_table');
- var tr = document.getElementById('item_'+id);
+ var tr = document.getElementById('ts_'+id);
+ if (!tr)
+ tr = document.getElementById('item_'+id);
var tr_c = tbl.insertRow(tr.rowIndex + 1);
tr_c.id = "tr_"+id;
var td_c = tr_c.insertCell(0);
@@ -111,15 +182,56 @@
}
function apply_rep(rep) {
- var id;
if (!rep)
return;
+ var id;
+ if (rep.x) {
+ var comments = {}; // { id: [ [ time, author, comment, agreed ], ... ] }
+ var data, data1;
+ for (var author in rep.x) {
+ data = rep.x[author];
+ for (var time in data) {
+ data1 = data[time];
+ if (data1.c) {
+ for (id in data1.c) {
+ if (!comments[id])
+ comments[id] = [];
+ comments[id].push([
+ time,
+ author,
+ data1.c[id],
+ data1.a && has(data1.a, parseInt(id))]);
+ }
+ }
+ if (data1.a) {
+ var c_id;
+ for (id=0; id<data1.a.length; ++id) {
+ c_id = comments[data1.a[id]];
+ if (!c_id)
+ comments[data1.a[id]] = [[
+ time, author, null, true]];
+ else {
+ for (var c=0; c<c_id.length; ++c) {
+ if (c_id[c][0] == time && c_id[c][1] == author)
+ c_id[c][3] = true;
+ }
+ }
+ }
+ }
+ }
+ }
+ for (id in comments) {
+ add_static_comment(id, comments[id]);
+ }
+ }
+
if (rep.c) for (id in rep.c) {
- add_comment(id, rep.c[''+id]);
+ add_comment(id, rep.c[id]);
}
+
if (rep.a) {
if (has(rep.a, 0)) {
- agree();
+ agree_all();
} else {
for (id=0; id<rep.a.length; ++id) {
document.getElementById('cb_'+rep.a[id]).checked = true;
@@ -137,9 +249,9 @@
rep.a = [];
var id;
- if (inputs[0].checked == true)
+ if (document.getElementById('cb_0').checked == true)
add(rep.a, 0);
- else for (id=1; id<inputs.length; ++id) {
+ else for (id=0; id<inputs.length; ++id) {
if (inputs[id].checked == true)
add(rep.a, parseInt(inputs[id].id.substring(3)));
}
@@ -147,10 +259,13 @@
rep.c = {};
var comments = document.getElementsByName("comment_box");
- for (id=0; id<comments.length; ++id) {
+ for (var c=0; c<comments.length; ++c) {
- rep.c[''+comments[id].id.substring(3)] = comments[id].value;
+ id = comments[c].id.substring(3);
+ rep.c[id] = comments[c].value;
+ if (comments[c].value) {
- document.getElementById('lb_'+id).style.borderBottom = '2px dotted blue';
+ document.getElementById('lb_'+id).style.borderBottom = '2px dotted blue';
- document.getElementById('lb_'+id).title = comments[id].value;
+ document.getElementById('lb_'+id).title = comments[c].value;
+ }
}
return rep;
}
@@ -259,6 +374,8 @@
return text;
if (rep.n)
text += 'Reviewer: '+rep.n+'\n';
+ if (rep.t)
+ text += 'Time: '+new Date(1287854282865+parseInt(rep.t)).toLocaleString()+'\n';
if (rep.d)
text += 'Review id: '+rep.d+'\n';
if (rep.a) {
@@ -289,6 +406,12 @@
}
}
}
+ if (rep.x) {
+ text += 'Has other comments from:\n';
+ var keys = [];
+ for (var i in rep.x) keys.push(i);
+ text += keys.join()+'\n';
+ }
return text;
}
@@ -303,12 +426,12 @@
},
'Apply':
function() {
+ var rep= merge(load_rep(), str_to_rep(
- apply_rep(
- str_to_rep(
document.getElementById('bin_rep_data').value
.replace(/[\r\n]/g, '')
- )
+ ));
+ apply_rep(rep);
- );
+ save_rep(rep);
}
});
var ta = document.createElement('TEXTAREA');