X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Fweb%2Ftabsort;h=5031a988382acf63c15cf7f736cb710bce77c379;hp=db7ac2b48cdd5468e5ccab0fe553719e18c23a38;hb=ea3cffe854b1c540bc68cd2218fdb2be732197fa;hpb=a3a663b2720733e0b0d28d97e66e14bb8d48de32 diff --git a/yarrg/web/tabsort b/yarrg/web/tabsort index db7ac2b..5031a98 100644 --- a/yarrg/web/tabsort +++ b/yarrg/web/tabsort @@ -40,6 +40,7 @@ $table => 'ts_table' $sortkeys => 'ts_sortkeys' $throw => undef $tbrow => undef +$rowclass => undef $cols @@ -53,7 +54,9 @@ $cols <&| script &> -% my $sortfn= "ts_sort__$table"; +% print $m->content(); + +% my $sortfn= "ts_s_$table"; function <% $sortfn %>(compar) { debug('sorting compar='+compar); var table= document.getElementById('<% $table %>'); @@ -90,6 +93,14 @@ function <% $sortfn %>(compar) { debug('final row '+rowix+' [[ '+row+' ]]'); } newrows.sort(compar); +% if (defined $rowclass) { + for (var rowix=0; rowix < newrows.length; rowix++) { + var row= newrows[rowix]; + var classname= '<% $rowclass %>'+(rowix % 2); + debug('fix row '+rowix+' class '+classname); + row.className= classname; + } +% } newrows= newrows.concat(finalrows); for (var rowix=0; rowix < newrows.length; rowix++) { var row= newrows[rowix]; @@ -104,9 +115,9 @@ function <% $sortfn %>(compar) { % my $thhtml= ''; % next if $col->{NoSort}; -% my $mapfn= "ts_compar${cix}_map__$table"; -function <% $mapfn %>(rowelement) { - var rowid = rowelement.id; +% my $mapfn= "ts_${cix}m_$table"; +function <% $mapfn %>(re) { + var rowid = re.id; % if ($col->{SortKey}) { return <% $col->{SortKey} %>; % } else { @@ -119,24 +130,25 @@ function <% $mapfn %>(rowelement) { % } } -% my $comparefn= "ts_compar${cix}_cmp0__$table"; +% my $comparefn= "ts_${cix}c0_$table"; function <% $comparefn %>(a,b) { - var a_key = <% $mapfn %>(a); - var b_key = <% $mapfn %>(b); + var ak = <% $mapfn %>(a); + var bk = <% $mapfn %>(b); % if ($col->{Numeric}) { - return a_key - b_key + return ak - bk % } else { - if (a_key < b_key) return -1; - if (a_key > b_key) return +1; + if (ak < bk) return -1; + if (ak > bk) return +1; return 0; % } } % foreach my $reverse (qw(1 0)) { -% my $tcomparefn= "ts_compar${cix}_cmp${reverse}__$table"; +% my $tcomparefn= "ts_${cix}c${reverse}_$table"; % if ($reverse) { % next unless $col->{DoReverse}; function <% $tcomparefn %>(a,b) { return -<% $comparefn %>(a,b); } + % } % $thhtml .= "". % ($reverse ? '∨' : '∧'). ''; @@ -154,9 +166,12 @@ function ts_onload__<% $table %>() { debug('thlist='+thlist); debug('thlist.item(2)=' + thlist.item(2)); for (var cix in ts_add_heads) { + if (!ts_add_heads.hasOwnProperty(cix)) continue; var ah = ts_add_heads[cix]; debug('appending to cix='+cix+' ah='+ah); thlist.item(cix).innerHTML += ah; } } + +register_onload(ts_onload__<% $table %>);