-
Notifications
You must be signed in to change notification settings - Fork 1
/
ColorStatus.js
32 lines (28 loc) · 1.26 KB
/
ColorStatus.js
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
(function () {
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.OnPostRender = [AddColorCode];
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
// This library requires that you have a column containing the values in the colors array
// see screenshot in this repository, JsLinkForColorStatus.jpg
function AddColorCode(inCtx) {
var colors = ["Red", "Yellow", "Green"]
var contrastingText = {"red": "white", "yellow": "black", "green": "white"}
var officialShade = {"red": "#DC143C", "yellow": "#FFFF33", "green": "#008000"}
for (var i = 0; i < inCtx.ListData.Row.length; ++i) {
var listItem = inCtx.ListData.Row[i];
var iid = GenerateIIDForListItem(inCtx, listItem);
var row = document.getElementById(iid);
if (row != null) {
for (var i_cell=0; i_cell < row.cells.length; ++i_cell) {
if(colors.indexOf(row.cells[i_cell].innerHTML) > -1) {
rowColor = row.cells[i_cell].innerHTML.toLowerCase()
row.cells[i_cell].style.backgroundColor = officialShade[rowColor.toLowerCase()];
row.cells[i_cell].style.color = contrastingText[rowColor.toLowerCase()];
}
}
}
inCtx.skipNextAnimation = true;
}
}