48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/tdriver/report/report_javascript.rb', line 48
def self.get_table_sorting_java_script
java_script="
function TSorter(){
var table = Object;
var trs = Array;
var ths = Array;
var curSortCol = Object;
var prevSortCol = '3';
var sortType = Object;
function get(){}
function getCell(index){
return trs[index].cells[curSortCol]
}
this.init = function(tableName)
{
table = document.getElementById(tableName);
ths = table.getElementsByTagName(\"th\");
for(var i = 0; i < ths.length ; i++)
{
ths[i].onclick = function()
{
sort(this);
}
}
return true;
};
function sort(oTH)
{
curSortCol = oTH.cellIndex;
sortType = oTH.abbr;
trs = table.tBodies[0].getElementsByTagName(\"tr\");
setGet(sortType)
for(var j=0; j<trs.length; j++)
{
if(trs[j].className == 'detail_row')
{
closeDetails(j+2);
}
}
// if already sorted just reverse
if(prevSortCol == curSortCol)
{
oTH.className = (oTH.className != 'ascend' ? 'ascend' : 'descend' );
reverseTable();
}
// not sorted - call quicksort
else
{
oTH.className = 'ascend';
if(ths[prevSortCol].className != 'exc_cell'){ths[prevSortCol].className = '';}
quicksort(0, trs.length);
}
prevSortCol = curSortCol;
}
function setGet(sortType)
{
switch(sortType)
{
case \"link_column\":
get = function(index){
return parseFloat(getCell(index).firstChild.firstChild.nodeValue);
};
break;
default:
get = function(index){ return parseInt(getCell(index).firstChild.nodeValue);};
break;
};
}
function exchange(i, j)
{
if(i == j+1) {
table.tBodies[0].insertBefore(trs[i], trs[j]);
} else if(j == i+1) {
table.tBodies[0].insertBefore(trs[j], trs[i]);
} else {
var tmpNode = table.tBodies[0].replaceChild(trs[i], trs[j]);
if(typeof(trs[i]) == \"undefined\") {
table.appendChild(tmpNode);
} else {
table.tBodies[0].insertBefore(tmpNode, trs[i]);
}
}
}
function reverseTable()
{
for(var i = 1; i<trs.length; i++)
{
table.tBodies[0].insertBefore(trs[i], trs[0]);
}
}
function quicksort(lo, hi)
{
if(hi <= lo+1) return;
if((hi - lo) == 2) {
if(get(hi-1) > get(lo)) exchange(hi-1, lo);
return;
}
var i = lo + 1;
var j = hi - 1;
if(get(lo) > get(i)) exchange(i, lo);
if(get(j) > get(lo)) exchange(lo, j);
if(get(lo) > get(i)) exchange(i, lo);
var pivot = get(lo);
while(true) {
j--;
while(pivot > get(j)) j--;
i++;
while(get(i) > pivot) i++;
if(j <= i) break;
exchange(i, j);
}
exchange(lo, j);
if((j-lo) < (hi-j)) {
quicksort(lo, j);
quicksort(j+1, hi);
} else {
quicksort(j+1, hi);
quicksort(lo, j);
}
}
}"
java_script
end
|