953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
|
** t Sort by text
** n Sort numerically
** k Sort by the data-sortkey property
** x This column is not sortable
**
** Capital letters mean sort in reverse order.
** If there are fewer characters in zColumnTypes[] than their are columns,
** the all extra columns assume type "t" (text).
**
** The third parameter is the column that was initially sorted (using 1-based
** column numbers, like SQL). Make this value 0 if none of the columns are
** initially sorted. Make the value negative if the column is initially sorted
** in reverse order.
**
** Clicking on the same column header twice in a row inverts the sort.
*/
void output_table_sorting_javascript(
const char *zTableId, /* ID of table to sort */
const char *zColumnTypes, /* String for column types */
int iInitSort /* Initially sorted column. Leftmost is 1. 0 for NONE */
){
@ <script>
@ function SortableTable(tableEl,columnTypes,initSort){
@ this.tbody = tableEl.getElementsByTagName('tbody');
@ this.columnTypes = columnTypes;
@ this.sort = function (cell) {
@ var column = cell.cellIndex;
@ var sortFn;
@ switch( cell.sortType ){
@ case "N": case "n": sortFn = this.sortNumeric; break;
@ case "T": case "t": sortFn = this.sortText; break;
@ case "K": case "k": sortFn = this.sortKey; break;
@ default: return;
@ }
@ this.sortIndex = column;
@ var newRows = new Array();
@ for (j = 0; j < this.tbody[0].rows.length; j++) {
@ newRows[j] = this.tbody[0].rows[j];
@ }
@ if( this.sortIndex==Math.abs(this.prevColumn)-1 ){
@ newRows.reverse();
@ this.prevColumn = -this.prevColumn;
@ }else{
@ newRows.sort(sortFn);
@ this.prevColumn = this.sortIndex+1;
@ if( cell.sortType>="A" && cell.sortType<="Z" ){
@ newRows.reverse();
@ }
@ }
@ for (i=0;i<newRows.length;i++) {
@ this.tbody[0].appendChild(newRows[i]);
@ }
@ this.setHdrIcons();
@ }
@ this.setHdrIcons = function() {
|
|
>
>
>
|
>
>
>
>
|
>
>
>
>
|
>
>
>
>
<
<
<
|
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
|
** t Sort by text
** n Sort numerically
** k Sort by the data-sortkey property
** x This column is not sortable
**
** Capital letters mean sort in reverse order.
** If there are fewer characters in zColumnTypes[] than their are columns,
** then all extra columns assume type "t" (text).
**
** The third parameter is the column that was initially sorted (using 1-based
** column numbers, like SQL). Make this value 0 if none of the columns are
** initially sorted. Make the value negative if the column is initially sorted
** in reverse order.
**
** Clicking on the same column header twice in a row inverts the sort.
*/
void output_table_sorting_javascript(
const char *zTableId, /* ID of table to sort */
const char *zColumnTypes, /* String for column types */
int iInitSort /* Initially sorted column. Leftmost is 1. 0 for NONE */
){
@ <script>
@ function SortableTable(tableEl,columnTypes,initSort){
@ this.tbody = tableEl.getElementsByTagName('tbody');
@ this.columnTypes = columnTypes;
@ var ncols = tableEl.rows[0].cells.length;
@ for(var i = columnTypes.length; i<=ncols; i++){this.columnTypes += 't';}
@ this.sort = function (cell) {
@ var column = cell.cellIndex;
@ var sortFn;
@ switch( cell.sortType ){
if( strchr(zColumnTypes,'n') ){
@ case "n": sortFn = this.sortNumeric; break;
}
if( strchr(zColumnTypes,'N') ){
@ case "N": sortFn = this.sortReverseNumeric; break;
}
@ case "t": sortFn = this.sortText; break;
if( strchr(zColumnTypes,'T') ){
@ case "T": sortFn = this.sortReverseText; break;
}
if( strchr(zColumnTypes,'k') ){
@ case "k": sortFn = this.sortKey; break;
}
if( strchr(zColumnTypes,'K') ){
@ case "K": sortFn = this.sortReverseKey; break;
}
@ default: return;
@ }
@ this.sortIndex = column;
@ var newRows = new Array();
@ for (j = 0; j < this.tbody[0].rows.length; j++) {
@ newRows[j] = this.tbody[0].rows[j];
@ }
@ if( this.sortIndex==Math.abs(this.prevColumn)-1 ){
@ newRows.reverse();
@ this.prevColumn = -this.prevColumn;
@ }else{
@ newRows.sort(sortFn);
@ this.prevColumn = this.sortIndex+1;
@ }
@ for (i=0;i<newRows.length;i++) {
@ this.tbody[0].appendChild(newRows[i]);
@ }
@ this.setHdrIcons();
@ }
@ this.setHdrIcons = function() {
|
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
|
@ hdrCell.className = clsName;
@ }
@ }
@ this.sortText = function(a,b) {
@ var i = thisObject.sortIndex;
@ aa = a.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
@ bb = b.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
@ if(aa==bb) return a.rowIndex-b.rowIndex;
@ if(aa<bb) return -1;
@ return 1;
@ }
@ this.sortNumeric = function(a,b) {
@ var i = thisObject.sortIndex;
@ aa = parseFloat(a.cells[i].textContent);
@ if (isNaN(aa)) aa = 0;
@ bb = parseFloat(b.cells[i].textContent);
@ if (isNaN(bb)) bb = 0;
@ if(aa==bb) return a.rowIndex-b.rowIndex;
@ return aa-bb;
@ }
@ this.sortKey = function(a,b) {
@ var i = thisObject.sortIndex;
@ aa = a.cells[i].getAttribute("data-sortkey");
@ bb = b.cells[i].getAttribute("data-sortkey");
@ if(aa==bb) return a.rowIndex-b.rowIndex;
@ if(aa<bb) return -1;
@ return 1;
@ }
@ var x = tableEl.getElementsByTagName('thead');
@ if(!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length>0)){
@ return;
@ }
@ if(x && x[0].rows && x[0].rows.length > 0) {
@ this.hdrRow = x[0].rows[0];
@ } else {
|
>
>
>
>
>
>
>
>
|
>
|
|
>
>
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
>
|
>
>
>
>
>
>
>
>
|
>
|
|
>
|
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
|
@ hdrCell.className = clsName;
@ }
@ }
@ this.sortText = function(a,b) {
@ var i = thisObject.sortIndex;
@ aa = a.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
@ bb = b.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
@ if(aa<bb) return -1;
@ if(aa==bb) return a.rowIndex-b.rowIndex;
@ return 1;
@ }
if( strchr(zColumnTypes,'T') ){
@ this.sortReverseText = function(a,b) {
@ var i = thisObject.sortIndex;
@ aa = a.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
@ bb = b.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
@ if(aa<bb) return +1;
@ if(aa==bb) return a.rowIndex-b.rowIndex;
@ return -1;
@ }
}
if( strchr(zColumnTypes,'n') ){
@ this.sortNumeric = function(a,b) {
@ var i = thisObject.sortIndex;
@ aa = parseFloat(a.cells[i].textContent);
@ if (isNaN(aa)) aa = 0;
@ bb = parseFloat(b.cells[i].textContent);
@ if (isNaN(bb)) bb = 0;
@ if(aa==bb) return a.rowIndex-b.rowIndex;
@ return aa-bb;
@ }
}
if( strchr(zColumnTypes,'N') ){
@ this.sortReverseNumeric = function(a,b) {
@ var i = thisObject.sortIndex;
@ aa = parseFloat(a.cells[i].textContent);
@ if (isNaN(aa)) aa = 0;
@ bb = parseFloat(b.cells[i].textContent);
@ if (isNaN(bb)) bb = 0;
@ if(aa==bb) return a.rowIndex-b.rowIndex;
@ return bb-aa;
@ }
}
if( strchr(zColumnTypes,'k') ){
@ this.sortKey = function(a,b) {
@ var i = thisObject.sortIndex;
@ aa = a.cells[i].getAttribute("data-sortkey");
@ bb = b.cells[i].getAttribute("data-sortkey");
@ if(aa<bb) return -1;
@ if(aa==bb) return a.rowIndex-b.rowIndex;
@ return 1;
@ }
}
if( strchr(zColumnTypes,'K') ){
@ this.sortReverseKey = function(a,b) {
@ var i = thisObject.sortIndex;
@ aa = a.cells[i].getAttribute("data-sortkey");
@ bb = b.cells[i].getAttribute("data-sortkey");
@ if(aa<bb) return +1;
@ if(aa==bb) return a.rowIndex-b.rowIndex;
@ return -1;
@ }
}
@ var x = tableEl.getElementsByTagName('thead');
@ if(!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length>0)){
@ return;
@ }
@ if(x && x[0].rows && x[0].rows.length > 0) {
@ this.hdrRow = x[0].rows[0];
@ } else {
|
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
|
zDir = !strcmp("ASC",zDir) ? "ASC" : "DESC";
zSql = mprintf("SELECT * FROM (%s) ORDER BY %d %s", zSql, nField, zDir);
}
}
count = 0;
if( !tabs ){
struct GenerateHTML sState;
db_multi_exec("PRAGMA empty_result_callbacks=ON");
style_submenu_element("Raw", "Raw",
"rptview?tablist=1&%h", PD("QUERY_STRING",""));
if( g.perm.Admin
|| (g.perm.TktFmt && g.zLogin && fossil_strcmp(g.zLogin,zOwner)==0) ){
style_submenu_element("Edit", "Edit", "rptedit?rn=%d", rn);
|
|
|
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
|
zDir = !strcmp("ASC",zDir) ? "ASC" : "DESC";
zSql = mprintf("SELECT * FROM (%s) ORDER BY %d %s", zSql, nField, zDir);
}
}
count = 0;
if( !tabs ){
struct GenerateHTML sState = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
db_multi_exec("PRAGMA empty_result_callbacks=ON");
style_submenu_element("Raw", "Raw",
"rptview?tablist=1&%h", PD("QUERY_STRING",""));
if( g.perm.Admin
|| (g.perm.TktFmt && g.zLogin && fossil_strcmp(g.zLogin,zOwner)==0) ){
style_submenu_element("Edit", "Edit", "rptedit?rn=%d", rn);
|