Convert existing AJAX functions to new framework
[infodrom.org/service.infodrom.org] / src / InfoCon / sprit / list.wml
index c66cbed..8580a12 100644 (file)
@@ -8,6 +8,27 @@
 div#details {
     width: 270px;
 }
+div.bar {
+    background-color: #98c5e5;
+    border-bottom: 1px solid #AAA;
+    font-size: 14px;
+    font-weight: bold;
+}
+div.year {
+    float: left;
+}
+table.spritlog tbody td {
+    border-bottom: 1px solid #CCC;
+}
+table.spritlog thead th {
+    border-bottom: 1px solid #AAA;
+}
+table.spritlog tfoot th {
+    border-top: 1px solid #AAA;
+}
+table.spritlog tbody tr:hover {
+    background-color: yellow;
+}
 </style>
 
 <div id="details" class="popup" style="margin-top: 5px;display:none;">
@@ -40,32 +61,32 @@ div#details {
 &nbsp;&nbsp;&nbsp;
 <input type="submit" onclick="$('#details').hide();return false" value="Abbrechen">
 </div>
-</div>
+ </div>
 </div>
 
 <?php
   $log = new SpritLog();
   $list = $log->distinctYears();
   foreach ($list as $row) {
-    printf('<h3 year="%d" class="bar year">%d</h3>', $row->year, $row->year);
-    printf('<div id="list_%d"></div>', $row->year);
+    echo '<div class="bar">';
+    printf('<div year="%d" class="year">%d</div>', $row->year, $row->year);
+    printf('<div style="float:right;">&euro; %.2f&nbsp;&nbsp;%d km</div>', $row->sum, $row->km);
+    echo '<div style="clear:both;"></div></div>';
+    printf('<div id="list_%d" style="display:none;"></div>', $row->year);
   }
   if (count($list)) {
     $out = <<<EOT
 <script type="text/javascript">
 $(function(){
     load_year({$list[0]->year});
-    $('h3.year').click(function(e){
-       var year = \$(this).attr('year');
-       load_year(year);
-    });
+    $('div.bar').click(toggle_year);
 });
 </script>
 EOT;
 echo $out;
   }
 ?>
-
+<div style="height:10px;"></div>
 </page>
 <protect><script text="text/javascript">
 var sprit_machine = <?=intval($_POST['machine'])?>;
@@ -81,23 +102,27 @@ function log_new()
 
 function log_save()
 {
-    ajax_request('savelog', $('#details input').serialize(),
-          function(data){
-              load_year(data.year);
-              $('#details').hide();
-          });
+    $.invoke('SpritLog/Add', $('#details input').serialize(), function(data){
+       load_year(data.year);
+       $('#details').hide();
+    });
+
     return false;
 }
 
+function toggle_year(event)
+{
+    var year = $(this).find('div.year').attr('year');
+
+    if ($('div#list_'+year).is(':visible'))
+       $('div#list_'+year).hide();
+    else
+       load_year(year);
+}
+
 function load_year(year)
 {
-    ajax_request('loadyear', {year: year},
-                function(data){
-                    var div = $('div#list_'+data.year);
-                    if (div.length)
-                        div.html(data.list);
-                    else
-                        window.location.reload();
-                });
+    $('div#list_'+year).show();
+    $.invoke('SpritLog/List', {year: year});
 }
 </script></protect>