forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage-review-requests.js
More file actions
128 lines (113 loc) · 4.54 KB
/
Copy pathmanage-review-requests.js
File metadata and controls
128 lines (113 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
$(document)
.ready(function () {
var form = $("form.review-requests");
var saveButtons = form.find("[name=action][value^='save']");
function updateSaveButtons() {
saveButtons.prop("disabled", form.find("[name$='-action'][value][value!=']")
.length == 0);
}
function setControlDisplay(row) {
var action = row.find("[name$='-action']")
.val();
if (action == "assign") {
row.find(".reviewer-controls")
.show();
row.find(".close-controls")
.hide();
row.find(".assign-action,.close-action")
.hide();
} else if (action == "close") {
row.find(".reviewer-controls")
.hide();
row.find(".close-controls")
.show();
row.find(".assign-action,.close-action")
.hide();
} else {
row.find(".reviewer-controls,.close-controls")
.hide();
row.find(".assign-action,.close-action")
.show();
}
updateSaveButtons();
}
form.find(".assign-action button")
.on("click", function () {
var row = $(this)
.closest(".review-request");
var select = row.find(".reviewer-controls [name$='-reviewer']");
if (!select.val()) {
// collect reviewers already assigned in this session
var reviewerAssigned = {};
select.find("option")
.each(function () {
if (this.value)
reviewerAssigned[this.value] = 0;
});
form.find("[name$='-action'][value='assign']")
.each(function () {
var v = $(this)
.closest(".review-request")
.find("[name$='-reviewer']")
.val();
if (v)
reviewerAssigned[v] += 1;
});
// by default, the select box contains a sorted list, so
// we should be able to select the first, unless that
// person has already been assigned to review in this
// session
var found = null;
var options = select.find("option")
.get();
for (var round = 0; round < 100 && !found; ++round) {
for (var i = 0; i < options.length && !found; ++i) {
var v = options[i].value;
if (!v)
continue;
if (reviewerAssigned[v] == round)
found = v;
}
}
if (found)
select.val(found);
}
row.find("[name$='-action']")
.val("assign");
setControlDisplay(row);
});
form.find(".reviewer-controls .undo")
.on("click", function () {
var row = $(this)
.closest(".review-request");
row.find("[name$='-action']")
.val("");
row.find("[name$='-reviewer']")
.val($(this)
.data("initial"));
setControlDisplay(row);
});
form.find(".close-action button")
.on("click", function () {
var row = $(this)
.closest(".review-request");
row.find("[name$='-action']")
.val("close");
setControlDisplay(row);
});
form.find(".close-controls .undo")
.on("click", function () {
var row = $(this)
.closest(".review-request");
row.find("[name$='-action']")
.val("");
setControlDisplay(row);
});
form.find("[class$='-action']")
.each(function () {
var row = $(this)
.closest(".review-request");
setControlDisplay(row);
});
updateSaveButtons();
});