Mercurial > hgrepos > hgweb.cgi > s4
diff s4-blog.sh @ 889:5843755e3b30
The beginning of AJAX operations
Frozen/Running can be toggled by ajax button
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Thu, 24 Dec 2020 19:42:58 +0900 |
parents | 4c02a9f862d7 |
children | bc52f605f41d |
line wrap: on
line diff
--- a/s4-blog.sh Tue Dec 22 10:58:03 2020 +0900 +++ b/s4-blog.sh Thu Dec 24 19:42:58 2020 +0900 @@ -1292,6 +1292,47 @@ dumptable html blog 'ctime title heading' "$cond" ) +blog_setval() { + # $1=GRProwID $2=key $3=value + # RETURN VALUE(JSON): + # {code: EXIT_CODE, message: MESSAGE} + # This function will be called via ajax control of fetch() suite, + # so we need to return JSON text string and exit directly. + rid=`numericalize $1` + blogowner=`getvalbyid blog owner "$rid"` + contenttype "application/json; charset=utf-8"; echo + if ! isgroup "$blogowner"; then + msg="グループのみの操作です"; code=1 + elif ! isgrpowner "$user" "$blogowner"; then + msg="グループ管理者のみの操作です"; code=2 + else # With full permission + blogid=`query "SELECT id FROM blog WHERE rowid=$rid;"` + dbsetbyid blog "$blogid" "$2" "$3" + code=0 + fi + # echo "{\"code\": $code, \"message\": \"foo\"}"; exit + newval=`getvalbyid blog "$2" "$1"` + alert="${msg:+, \"alert\": \"$msg\"}" + cat <<-EOF + {"code": $code, "$2": "`echo "$newval"|sed 's/"/\\\\"/g'`"$alert} + EOF + exit +} + +blog_setfrozen() { + # $1=GRProwID $2=val={ "frozen" | "" } + case "$2" in + [Ff]) state="frozen" ;; + *) state="" ;; + esac + err getvalbyid-blog-$1= `getvalbyid blog state "$1"` + case `getvalbyid blog state "$1"` in + [Ff][Rr]*) newval="" ;; + *) newval="frozen" ;; + esac + blog_setval "$1" state $newval +} + blog_addentry() { # $1=GRProwID(if it is a group) grprowid=`numericalize $1`