From 767e625796d67e5f5cc94d7e1949b1389f753764 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 26 Aug 2009 02:46:27 +0100 Subject: [PATCH] New onload arrangments; make tabsort take script argument --- yarrg/TODO | 2 -- yarrg/web/lookup | 9 +++++++++ yarrg/web/qtextstring | 2 +- yarrg/web/query_age | 44 +++++++++++++++++------------------------- yarrg/web/query_commod | 15 ++------------ yarrg/web/routetrade | 9 ++------- yarrg/web/tabsort | 4 ++++ 7 files changed, 36 insertions(+), 49 deletions(-) diff --git a/yarrg/TODO b/yarrg/TODO index 8a22088..e6d969e 100644 --- a/yarrg/TODO +++ b/yarrg/TODO @@ -23,8 +23,6 @@ commodity mass/volume in live database WEBSITE ------- -onload thing broken, need proper framework - dropdowns are broken sometimes initial/final stocks feature diff --git a/yarrg/web/lookup b/yarrg/web/lookup index 1453a37..4dbd755 100755 --- a/yarrg/web/lookup +++ b/yarrg/web/lookup @@ -127,6 +127,15 @@ body { tr.datarow0 { background: #ffffff; } tr.datarow1 { background: #e3e3e3; } +<&| script &> + function register_onload(f) { + var previous_onload= window.onload; + window.onload= function() { + if (previous_onload) previous_onload(); + f(); + }; + } + YARRG - diff --git a/yarrg/web/qtextstring b/yarrg/web/qtextstring index 16aa372..84564df 100644 --- a/yarrg/web/qtextstring +++ b/yarrg/web/qtextstring @@ -87,7 +87,7 @@ function ts_Ready() { ts_request= false; ts_Request(); } -window.onload= ts_Needed; +register_onload(ts_Needed); content %> diff --git a/yarrg/web/query_age b/yarrg/web/query_age index 88bc7ea..a02187e 100644 --- a/yarrg/web/query_age +++ b/yarrg/web/query_age @@ -85,29 +85,13 @@ $sth->execute(); % } -<& tabsort, table => 'ts_table', rowclass => 'datarow', cols => [ - {}, {}, - { DoReverse => 1, - Numeric => 1, - SortKey => "da_ages[rowid]" }] - &> - -

-Time since this page loaded: -(not known; times above not updating) - -

- -<& "lookup:formhidden", ours => sub { 0; } &> -
- +<& SELF:dataages, id2age => \%da_ages, elemidprefix => "'c'+" &> <%method dataages> <%args> $id2age $elemidprefix => '' <&| script &> - da_ages= <% to_json_protecttags($id2age) %>; function da_Refresh() { var now= Date.now(); debug('updating now='+now); @@ -119,21 +103,29 @@ Time since this page loaded: el.innerHTML= newhtml; } } + da_ages= <% to_json_protecttags($id2age) %>; window.setInterval(da_Refresh, 10000); + register_onload(da_Refresh); -<& SELF:dataages, id2age => \%da_ages, elemidprefix => "'c'+" &> - -<&| script &> +<&| tabsort, table => 'ts_table', rowclass => 'datarow', cols => [ + {}, {}, + { DoReverse => 1, + Numeric => 1, + SortKey => "da_ages[rowid]" }] + &> ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>; + - function all_onload() { - ts_onload__ts_table(); - da_Refresh(); - } - window.onload= all_onload; - +

+Time since this page loaded: +(not known; times above not updating) + +

+ +<& "lookup:formhidden", ours => sub { 0; } &> +
<%init> use POSIX; diff --git a/yarrg/web/query_commod b/yarrg/web/query_commod index 34b1347..3c2049c 100644 --- a/yarrg/web/query_commod +++ b/yarrg/web/query_commod @@ -89,8 +89,6 @@ $someresults->(); #---------- actually compute the results and print them ---------- -my $onloads= ""; - foreach my $bs (split /_/, $ARGS{BuySell}) { $bs =~ m/^(buy|sell)$/ or die; $bs= $1; @@ -197,7 +195,7 @@ foreach my $bs (split /_/, $ARGS{BuySell}) { % } -<& tabsort, table => "${bs}_table", sortkeys => "${bs}_sortkeys", +<&| tabsort, table => "${bs}_table", sortkeys => "${bs}_sortkeys", throw => "${bs}_table_thr", rowclass => 'datarow', cols => [ {}, {}, { DoReverse => 1 }, @@ -207,22 +205,13 @@ foreach my $bs (split /_/, $ARGS{BuySell}) { { DoReverse => 1, Numeric => 1 }, { DoReverse => 1, Numeric => 1 }, ] &> -<&| script &> <% $bs %>_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>; function ts_Pricemap_<% $bs %>(price) { if (price=='-') { return <% $bs eq 'buy' ? '-1' : '99999999' %>; } return price; } - -% $onloads .= " ts_onload__${bs}_table();\n"; + <%perl> } - -<&| script &> - function all_onload() { -<% $onloads %> - } - window.onload= all_onload; - diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 80fc2b1..ce91b48 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -542,15 +542,10 @@ $addcols->({ Total => 0, DoReverse => 1 }, qw( % } -<& tabsort, cols => \@cols, table => 'trades', rowclass => 'datarow', +<&| tabsort, cols => \@cols, table => 'trades', rowclass => 'datarow', throw => 'trades_sort', tbrow => 'trades_total' &> -<&| script &> ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>; - function all_onload() { - ts_onload__trades(); - } - window.onload= all_onload; - + diff --git a/yarrg/web/tabsort b/yarrg/web/tabsort index 444bfb5..e114319 100644 --- a/yarrg/web/tabsort +++ b/yarrg/web/tabsort @@ -54,6 +54,8 @@ $cols <&| script &> +% print $m->content(); + % my $sortfn= "ts_sort__$table"; function <% $sortfn %>(compar) { debug('sorting compar='+compar); @@ -168,4 +170,6 @@ function ts_onload__<% $table %>() { thlist.item(cix).innerHTML += ah; } } + +register_onload(ts_onload__<% $table %>); -- 2.30.2