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 wrap: on
line diff
--- a/s4-cgi.sh	Wed May 13 07:31:26 2020 +0900
+++ b/s4-cgi.sh	Wed May 13 10:29:09 2020 +0900
@@ -121,7 +121,7 @@
 }
 cgi_select_h() {
   # $1=name $2...=hexed-args
-  echo "<select name=\"$1\"${CGI_SELECT_MULTI:+ multiple}>"
+  echo "<select name=\"$1\"${CGI_SELECT_MULTI:+ multiple} id=\"$1\">"
   shift
   for i; do
     echo "<option>`echo \"$i\"|unhexize|htmlescape`</option>"
--- a/s4-funcs.sh	Wed May 13 07:31:26 2020 +0900
+++ b/s4-funcs.sh	Wed May 13 10:29:09 2020 +0900
@@ -2716,7 +2716,7 @@
 	echo "チーム名に使えない文字を除去しました" | html p
 	team=newteam
       fi
-      if [ -z "$team" -o x"$team" = x"なし" ]; then
+      if [ -z "$team" -o x"$team" = x"なし" -o x"$team" = x"TEAM" ]; then
 	cat<<-EOF | html p
 	有効なチーム名を入力してください。
 	カンマだけ、「なし」という名前は使えません。
@@ -2781,7 +2781,7 @@
 	      then 'k'
 	  ELSE ''
 	  END || rowid || ',' || gecos NAME,
-	  post POST, team TEAM
+	  post POST, team _TEAM_
 	FROM user_post up LEFT JOIN teams t
 	ON up.name=t.user
 	ORDER BY gecos;"
@@ -2815,6 +2815,8 @@
 </div><!-- end of $rmteammsg -->
 "
   fi
+  stf=$tmpd/selteam.$$
+  cgi_select_h selteam "5445414d" $allhexteams > $stf
   b1='<label> <input type="checkbox" name="usel" value="'
   ba='<label class="admin"><input type="checkbox" name="usel" value="'
   br='<span id="reverse" title="Reverse Selection"></span>'
@@ -2829,7 +2831,8 @@
 	| _m4 -D_TITLE_="spaste(\`$tf')" \
 	      -D_SUBTITLE_="チェック後操作ボタン" \
 	      -D_FORM_="syscmd(cat)" -D_DUMPTABLE_="" \
-	      $layout/form+dump.m4.html
+	      $layout/form+dump.m4.html \
+	| _m4 -D_TEAM_="spaste(\`$stf')"
 <p>下でチェックした人を対象として:</p>
 <div class="foldtabs">
 `cgi_radio rm addteam 'id="cmteam"'`<label
--- 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();

yatex.org