s4
changeset 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 | 2199d20249a8 |
children | cd6f0badcff4 |
files | s4-cgi.sh s4-funcs.sh s4-main.js |
diffstat | 3 files changed, 45 insertions(+), 4 deletions(-) [+] |
line diff
1.1 --- a/s4-cgi.sh Wed May 13 07:31:26 2020 +0900 1.2 +++ b/s4-cgi.sh Wed May 13 10:29:09 2020 +0900 1.3 @@ -121,7 +121,7 @@ 1.4 } 1.5 cgi_select_h() { 1.6 # $1=name $2...=hexed-args 1.7 - echo "<select name=\"$1\"${CGI_SELECT_MULTI:+ multiple}>" 1.8 + echo "<select name=\"$1\"${CGI_SELECT_MULTI:+ multiple} id=\"$1\">" 1.9 shift 1.10 for i; do 1.11 echo "<option>`echo \"$i\"|unhexize|htmlescape`</option>"
2.1 --- a/s4-funcs.sh Wed May 13 07:31:26 2020 +0900 2.2 +++ b/s4-funcs.sh Wed May 13 10:29:09 2020 +0900 2.3 @@ -2716,7 +2716,7 @@ 2.4 echo "チーム名に使えない文字を除去しました" | html p 2.5 team=newteam 2.6 fi 2.7 - if [ -z "$team" -o x"$team" = x"なし" ]; then 2.8 + if [ -z "$team" -o x"$team" = x"なし" -o x"$team" = x"TEAM" ]; then 2.9 cat<<-EOF | html p 2.10 有効なチーム名を入力してください。 2.11 カンマだけ、「なし」という名前は使えません。 2.12 @@ -2781,7 +2781,7 @@ 2.13 then 'k' 2.14 ELSE '' 2.15 END || rowid || ',' || gecos NAME, 2.16 - post POST, team TEAM 2.17 + post POST, team _TEAM_ 2.18 FROM user_post up LEFT JOIN teams t 2.19 ON up.name=t.user 2.20 ORDER BY gecos;" 2.21 @@ -2815,6 +2815,8 @@ 2.22 </div><!-- end of $rmteammsg --> 2.23 " 2.24 fi 2.25 + stf=$tmpd/selteam.$$ 2.26 + cgi_select_h selteam "5445414d" $allhexteams > $stf 2.27 b1='<label> <input type="checkbox" name="usel" value="' 2.28 ba='<label class="admin"><input type="checkbox" name="usel" value="' 2.29 br='<span id="reverse" title="Reverse Selection"></span>' 2.30 @@ -2829,7 +2831,8 @@ 2.31 | _m4 -D_TITLE_="spaste(\`$tf')" \ 2.32 -D_SUBTITLE_="チェック後操作ボタン" \ 2.33 -D_FORM_="syscmd(cat)" -D_DUMPTABLE_="" \ 2.34 - $layout/form+dump.m4.html 2.35 + $layout/form+dump.m4.html \ 2.36 + | _m4 -D_TEAM_="spaste(\`$stf')" 2.37 <p>下でチェックした人を対象として:</p> 2.38 <div class="foldtabs"> 2.39 `cgi_radio rm addteam 'id="cmteam"'`<label
3.1 --- a/s4-main.js Wed May 13 07:31:26 2020 +0900 3.2 +++ b/s4-main.js Wed May 13 10:29:09 2020 +0900 3.3 @@ -9,6 +9,18 @@ 3.4 } 3.5 return list; 3.6 } 3.7 + function nthChildOf(parent, n, elem) { // Return Nth child of type ELEM 3.8 + // N begins with 1 3.9 + var i=0; 3.10 + var le = elem.toLowerCase(); 3.11 + for (var c of parent.childNodes) { 3.12 + if (!c.tagName) continue; 3.13 + if (c.tagName.toLowerCase() == le) { 3.14 + if (++i >= n) return c; 3.15 + } 3.16 + } 3.17 + return null; 3.18 + } 3.19 function insertRedirect(e) { 3.20 var articleId, textarea = document.getElementById("text"); 3.21 var p = e.target, checked = p.checked; 3.22 @@ -80,6 +92,7 @@ 3.23 } 3.24 var emailbtn = document.getElementById("email"); 3.25 emailbtn.addEventListener("click", function(ev){ 3.26 + // Enlarge box and Select user's checkbox 3.27 if (!ev.target.checked) return; 3.28 var x = collectElementsByAttr("div", "class", "foldtabs"); 3.29 if (x && x[0] && x[0].style) { 3.30 @@ -96,6 +109,31 @@ 3.31 } 3.32 } 3.33 }, null); 3.34 + var teamsel = document.getElementById("selteam"); 3.35 + if (teamsel) { 3.36 + var usel, p, team; 3.37 + // Select all members of the team 3.38 + teamsel.addEventListener("change", function(ev) { 3.39 + var teamname = teamsel.value, 3.40 + selected = new RegExp('\\b'+teamname+"($|,)"); 3.41 + usel = collectElementsByAttr("input", "name", "usel"); 3.42 + if (!usel) return; 3.43 + for (u of usel) { 3.44 + p = u.parentNode; // should be label 3.45 + if (!p) continue; 3.46 + if (teamname == "TEAM") { // Reset all checks 3.47 + u.checked = false; // when "TEAM" is selected 3.48 + } else { 3.49 + p = p.parentNode.parentNode;// should be tr 3.50 + team = nthChildOf(p, 3, "td") 3.51 + if (team && team.textContent 3.52 + && team.textContent.match(selected)) { 3.53 + u.checked = true; 3.54 + } 3.55 + } 3.56 + } 3.57 + }, null); 3.58 + } 3.59 } 3.60 function init() { 3.61 initGrpAction();