Simple sprit accounting module
[infodrom.org/service.infodrom.org] / src / InfoCon / sprit / list.wml
1 #include <infocon.style>
2
3 <future>
4 <page func=InfoCon title="Tankbuch">
5 <calendar_init -5>
6 <popups>
7 <style type="text/css">
8 div#details {
9     width: 270px;
10 }
11 </style>
12
13 <div id="details" class="popup" style="margin-top: 5px;display:none;">
14 <div class="popup_title">Bearbeiten</div>
15 <div class="popup_body">
16 <input type="hidden" id="id" name="id" value="">
17 <input type="hidden" id="machine" name="machine">
18 <label for="date">Datum</label>
19 <input type="text" id="date" name="date" size="8">
20 <img class="calendar" src="<root_prefix>pix/calendar.gif" onclick="event.cancelBubble=true;popcalendar('date');">
21
22 <label for="city">Ort</label>
23 <input type="text" id="city" name="city" size="30">
24 <label for="tankstelle">Tankstelle</label>
25 <input type="text" id="tankstelle" name="tankstelle" size="30">
26
27 <label for="price_liter">Preis pro Liter</label>
28 <input type="text" id="price_liter" name="price_liter" size="30">
29
30 <label for="liter">Liter / Preis</label>
31 <input type="text" id="liter" name="liter" size="13">
32 <input type="text" id="price" name="price" size="13">
33
34 <label for="km">Tageskilometer / Gesamt</label>
35 <input type="text" id="km" name="km" size="13">
36 <input type="text" id="km_total" name="km_total" size="13">
37
38 <div style="margin-top: 8px; text-align: center;">
39 <input type="submit" onclick="return log_save()" value="Speichern">
40 &nbsp;&nbsp;&nbsp;
41 <input type="submit" onclick="$('#details').hide();return false" value="Abbrechen">
42 </div>
43 </div>
44 </div>
45
46 <?php
47   $log = new SpritLog();
48   $list = $log->distinctYears();
49   foreach ($list as $row) {
50     printf('<h3 year="%d" class="bar year">%d</h3>', $row->year, $row->year);
51     printf('<div id="list_%d"></div>', $row->year);
52   }
53   if (count($list)) {
54     $out = <<<EOT
55 <script type="text/javascript">
56 $(function(){
57     load_year({$list[0]->year});
58     $('h3.year').click(function(e){
59         var year = \$(this).attr('year');
60         load_year(year);
61     });
62 });
63 </script>
64 EOT;
65 echo $out;
66   }
67 ?>
68
69 </page>
70 <protect><script text="text/javascript">
71 var sprit_machine = <?=intval($_POST['machine'])?>;
72 function log_new()
73 {
74     $('#details input').not('input[type="submit"]').val('');
75     $('input#machine').val(sprit_machine);
76     if ($('#details').css('left') == '0px')
77       $('#details').css('left', ($(window).width()-280)+'px').css('top', '30px');
78     $('#details').show();
79     return false;
80 }
81
82 function log_save()
83 {
84     ajax_request('savelog', $('#details input').serialize(),
85            function(data){
86                load_year(data.year);
87                $('#details').hide();
88            });
89     return false;
90 }
91
92 function load_year(year)
93 {
94     ajax_request('loadyear', {year: year},
95                  function(data){
96                      var div = $('div#list_'+data.year);
97                      if (div.length)
98                          div.html(data.list);
99                      else
100                          window.location.reload();
101                  });
102 }
103 </script></protect>