Mercurial > hgrepos > hgweb.cgi > s4
diff s4-main.js @ 675:9c54908814be
Team selection in GrpAction anabled with js
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Wed, 13 May 2020 10:29:09 +0900 |
parents | 42bf03cb3712 |
children | cd6f0badcff4 |
line wrap: on
line diff
--- a/s4-main.js Wed May 13 07:31:26 2020 +0900 +++ b/s4-main.js Wed May 13 10:29:09 2020 +0900 @@ -9,6 +9,18 @@ } return list; } + function nthChildOf(parent, n, elem) { // Return Nth child of type ELEM + // N begins with 1 + var i=0; + var le = elem.toLowerCase(); + for (var c of parent.childNodes) { + if (!c.tagName) continue; + if (c.tagName.toLowerCase() == le) { + if (++i >= n) return c; + } + } + return null; + } function insertRedirect(e) { var articleId, textarea = document.getElementById("text"); var p = e.target, checked = p.checked; @@ -80,6 +92,7 @@ } var emailbtn = document.getElementById("email"); emailbtn.addEventListener("click", function(ev){ + // Enlarge box and Select user's checkbox if (!ev.target.checked) return; var x = collectElementsByAttr("div", "class", "foldtabs"); if (x && x[0] && x[0].style) { @@ -96,6 +109,31 @@ } } }, null); + var teamsel = document.getElementById("selteam"); + if (teamsel) { + var usel, p, team; + // Select all members of the team + teamsel.addEventListener("change", function(ev) { + var teamname = teamsel.value, + selected = new RegExp('\\b'+teamname+"($|,)"); + usel = collectElementsByAttr("input", "name", "usel"); + if (!usel) return; + for (u of usel) { + p = u.parentNode; // should be label + if (!p) continue; + if (teamname == "TEAM") { // Reset all checks + u.checked = false; // when "TEAM" is selected + } else { + p = p.parentNode.parentNode;// should be tr + team = nthChildOf(p, 3, "td") + if (team && team.textContent + && team.textContent.match(selected)) { + u.checked = true; + } + } + } + }, null); + } } function init() { initGrpAction();