comparison s4-main.js @ 1035:e8f73df7ed5d draft

Add "sort by uid" button to blog table
author HIROSE Yuuji <yuuji@gentei.org>
date Wed, 06 Mar 2024 09:37:52 +0900
parents 1ffaa8b2b1bf
children 9c392ddb4d8a
comparison
equal deleted inserted replaced
1034:17e21e7dcfaa 1035:e8f73df7ed5d
892 } else { 892 } else {
893 getTextContentCSV_1(e); 893 getTextContentCSV_1(e);
894 } 894 }
895 } 895 }
896 function initBlogs() { 896 function initBlogs() {
897 // Auto-complete #xxxx 897 // (1)Auto-complete #xxxx, (2)Prepare sort
898
899 // (1)Complete #xxxx
898 let i, check = collectElementsByAttr("input", "name", "notifyto"); 900 let i, check = collectElementsByAttr("input", "name", "notifyto");
901 let blogheadtd = document.querySelector("table.bloghead tr td");
899 if (check) 902 if (check)
900 for (i of check) { 903 for (i of check) {
901 i.addEventListener("click", insertRedirect, false); 904 i.addEventListener("click", insertRedirect, false);
902 } 905 }
903 registInsertDirect(document.querySelectorAll("a[href]")); 906 registInsertDirect(document.querySelectorAll("a[href]"));
922 b.parentNode.appendChild(i); 925 b.parentNode.appendChild(i);
923 } 926 }
924 i = document.getElementById("reload"); 927 i = document.getElementById("reload");
925 if (i) i.addEventListener("click", ajaxPost, false); 928 if (i) i.addEventListener("click", ajaxPost, false);
926 // Add CSV download button 929 // Add CSV download button
927 let td = document.querySelector("table.bloghead tr td"); 930 if (blogheadtd) {
928 if (td) {
929 let btn = document.createElement("button"); 931 let btn = document.createElement("button");
930 btn.innerText = "CSVget"; 932 btn.innerText = "CSVget";
931 btn.type = "button"; 933 btn.type = "button";
932 btn.accessKey = "g"; 934 btn.accessKey = "g";
933 btn.title = `Shortcut: G 935 btn.title = `Shortcut: G
934 見えている書き込みをCSVで取得します 936 見えている書き込みをCSVで取得します
935 全件表示されていることを確認してから利用して下さい。 937 全件表示されていることを確認してから利用して下さい。
936 Excelで利用する場合は Ctrl を押しながらクリックして下さい。 938 Excelで利用する場合は Ctrl を押しながらクリックして下さい。
937 Get seen TEXT content as CSV.`; 939 Get seen TEXT content as CSV.`;
938 btn.addEventListener("click", getTextContentCSV, false); 940 btn.addEventListener("click", getTextContentCSV, false);
939 let artlink = td.querySelector('a[accesskey="f"]'); 941 let artlink = blogheadtd.querySelector('a[accesskey="f"]');
940 let spacer = document.createElement("span"); 942 let spacer = document.createElement("span");
941 if (artlink) { 943 if (artlink) {
942 spacer.innerText = "|"; 944 spacer.innerText = "|";
943 artlink.insertAdjacentElement('beforebegin', btn); 945 artlink.insertAdjacentElement('beforebegin', btn);
944 artlink.insertAdjacentElement('beforebegin', spacer); 946 artlink.insertAdjacentElement('beforebegin', spacer);
945 } else { 947 } else {
946 spacer.innerText = " "; 948 spacer.innerText = " ";
947 td.appendChild(spacer); 949 blogheadtd.appendChild(spacer);
948 td.appendChild(btn); 950 blogheadtd.appendChild(btn);
949 } 951 }
950 } 952 }
951 } 953 }
952 for (i of document.querySelectorAll('input[type="file"]')) { 954 for (i of document.querySelectorAll('input[type="file"]')) {
953 i.addEventListener('change', (e) => { 955 i.addEventListener('change', (e) => {
958 i.addEventListener('click', toggleAuthorVisibility, false); 960 i.addEventListener('click', toggleAuthorVisibility, false);
959 } 961 }
960 // Hack article_m links 962 // Hack article_m links
961 registPjaxViewers(document.querySelectorAll("a[href]")); 963 registPjaxViewers(document.querySelectorAll("a[href]"));
962 atMarkView(document); 964 atMarkView(document);
965 /*****************************************************************/
966 //(2) Prepare sort
967 let warn = document.querySelector("tr.warn span.warn");
968 if (blogheadtd && warn==null) {
969 let umode = "UserSORT", amode = "ArticleSort";
970 let sbtn = document.createElement("button");
971 sbtn.textContent = umode;
972 sbtn.type = 'button';
973 let spacer = document.createElement("span");
974 spacer.textContent = " ";
975 let hide = document.getElementById("hideauth");
976 if (hide) {
977 hide.insertAdjacentElement('afterend', sbtn);
978 hide.insertAdjacentElement('afterend', spacer);
979 } else {
980 blogheadtd.appendChild(spacer);
981 blogheadtd.appendChild(sbtn);
982 }
983 function compareRowsByUid(a, b) {
984 if (a.key1 < b.key1) return -1;
985 if (a.key1 > b.key1) return 1;
986 if (a.key2 < b.key2) return -1;
987 if (a.key2 > b.key2) return 1;
988 return 0;
989 }
990 function compareRowsByAid(a, b) {
991 if (a.key2 < b.key2) return -1;
992 if (a.key2 > b.key2) return 1;
993 return 0;
994 }
995 sbtn.addEventListener("click", (e)=>{
996 let uidsort = (sbtn.textContent.indexOf(umode) >= 0);
997 let rows = [], elm,
998 tbl = document.querySelector("table.blog_replies");
999 for (let tr of tbl.rows) {
1000 elm = {};
1001 elm.tr = tr;
1002 elm.key1 = tr.querySelector("a.author").title; // userid
1003 tr.innerHTML.match(/<a href="(#[0-9]+)">\1</); // ArticleID
1004 elm.key2 = RegExp.$1;
1005 rows.push(elm);
1006 }
1007 rows.sort(uidsort ? compareRowsByUid : compareRowsByAid);
1008 for (let r of rows) tbl.appendChild(r.tr);
1009 sbtn.textContent = uidsort ? amode : umode;
1010 });
1011 }
963 } 1012 }
964 function initGrpAction() { 1013 function initGrpAction() {
965 var rev = document.getElementById("reverse"); 1014 var rev = document.getElementById("reverse");
966 if (!rev) return; // Is not grpAction page 1015 if (!rev) return; // Is not grpAction page
967 if (rev.tagName.match(/span/i)) { 1016 if (rev.tagName.match(/span/i)) {

yatex.org