chiark / gitweb /
New onload arrangments; make tabsort take script argument
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 26 Aug 2009 01:46:27 +0000 (02:46 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 26 Aug 2009 01:46:57 +0000 (02:46 +0100)
yarrg/TODO
yarrg/web/lookup
yarrg/web/qtextstring
yarrg/web/query_age
yarrg/web/query_commod
yarrg/web/routetrade
yarrg/web/tabsort

index 8a2208830f793b95c4042088cd34fb18429d2e47..e6d969e91648011f9866514d17651030c043e397 100644 (file)
@@ -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
index 1453a372145ee2989261f757481aee295e052fb1..4dbd7558e68a8161ad3394f669bb54d5d161c4b8 100755 (executable)
@@ -127,6 +127,15 @@ body {
 tr.datarow0 { background: #ffffff; }
 tr.datarow1 { background: #e3e3e3; }
 </style>
+<&| script &>
+  function register_onload(f) {
+    var previous_onload= window.onload;
+    window.onload= function() {
+      if (previous_onload) previous_onload();
+      f();
+    };
+  }
+</&script>
 </head><body>
 
 <a href="<% $m->current_comp()->name() |u %>">YARRG</a> -
index 16aa372bd6794caad89992d6d7b2f2a976d519c2..84564df55205125a2bbad3deac5611b256167582 100644 (file)
@@ -87,7 +87,7 @@ function ts_Ready() {
   ts_request= false;
   ts_Request();
 }
-window.onload= ts_Needed;
+register_onload(ts_Needed);
 </&script>
 
 <input type="text" <% $m->content %>
index 88bc7ea16b73fa686bb30628761a725c4bd242c3..a02187eae01d1b85988382f3e82bc538c6ba010f 100644 (file)
@@ -85,29 +85,13 @@ $sth->execute();
 % }
 </table>
 
-<& tabsort, table => 'ts_table', rowclass => 'datarow', cols => [
-       {}, {},
-       { DoReverse => 1,
-         Numeric => 1,
-         SortKey => "da_ages[rowid]" }]
-  &>
-
-<p>
-Time since this page loaded:
-<span id="cid_loaded">(not known; times above not updating)</span>
-
-<form action="lookup" method="get">
-<input type=submit name=submit value="Reload">
-<& "lookup:formhidden", ours => sub { 0; } &>
-</form>
-
+<& SELF:dataages, id2age => \%da_ages, elemidprefix => "'c'+" &>
 <%method dataages>
 <%args>
   $id2age
   $elemidprefix => ''
 </%args>
 <&| 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);
 </&>
 </%method>
 
-<& 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) %>;
+</&tabsort>
 
-  function all_onload() {
-    ts_onload__ts_table();
-    da_Refresh();
-  }
-  window.onload= all_onload;
-</&script>
+<p>
+Time since this page loaded:
+<span id="cid_loaded">(not known; times above not updating)</span>
+
+<form action="lookup" method="get">
+<input type=submit name=submit value="Reload">
+<& "lookup:formhidden", ours => sub { 0; } &>
+</form>
 
 <%init>
 use POSIX;
index 34b1347f20f5034315a1821d535cd6de40f8f8e2..3c2049ca3a509af276a9c28b9c59dbdf463667f5 100644 (file)
@@ -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}) {
 %      }
 </table>
 
-<& 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";
+</&tabsort>
 
 <%perl>
 }
 </%perl>
-
-<&| script &>
-  function all_onload() {
-<% $onloads %>
-  }
-  window.onload= all_onload;
-</&>
index 80fc2b13d5e8cf78f5ba1c61d0310e5de0280318..ce91b48726c40f4a59da3f5d8ad40f2204fb1e12 100644 (file)
@@ -542,15 +542,10 @@ $addcols->({ Total => 0, DoReverse => 1 }, qw(
 % }
 </table>
 
-<& 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;
-</&script>
+</&tabsort>
 
 <input type=submit name=update value="Update">
 
index 444bfb56b15f6e1b01e6e2ff74a29c1140209bb8..e114319a0254f4780bfcaa6071093d39f016f23f 100644 (file)
@@ -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 %>);
 </&>