Summarise time
authorJoey Schulze <joey@infodrom.org>
Sat, 15 Aug 2009 21:52:16 +0000 (21:52 +0000)
committerJoey Schulze <joey@infodrom.org>
Sat, 15 Aug 2009 21:52:16 +0000 (21:52 +0000)
src/InfoCon/stempel/status.wml

index 4a9a145..57e5ff9 100644 (file)
@@ -2,14 +2,19 @@
 #include "common.inc"
 
 <script type="text/javascript">
-function check(form, value)
+function check(id, value)
 {
-  var form = document.forms[form];
+  var form = document.forms[id];
 
   for (i=0; i< form.elements.length; i++) {
     if (form.elements[i].name.substr(0,4) == 'oid_')
       form.elements[i].checked = value;
   }
+
+  if (value == false) {
+      var sum = document.getElementById('sum_'+id.toString()); 
+      sum.innerHTML = '0';
+  }
 }
 
 function plant(form)
@@ -19,8 +24,26 @@ function plant(form)
   document.write("&nbsp;/&nbsp;");
   document.write('<a href="javascript:check('+form+',false)">Uncheck all</a>');
   document.write("&nbsp;");
+  document.write('<span id="sum_'+form+'" class="sum">0</span>');
+  document.write("&nbsp;");
   document.write('</div>');
 }
+
+var sum = array();
+function add_sum(form, checkbox)
+{
+    var sum = document.getElementById('sum_'+form.toString()); 
+    var newval;
+
+    var ta = checkbox.parentNode.nextSibling.innerHTML.split(':');
+    var time = parseInt(ta[0]) * 60 + parseInt(ta[1]);
+
+    if (checkbox.checked)
+       newval = parseInt(sum.innerHTML) + time;
+    else
+       newval = parseInt(sum.innerHTML) - time;
+    sum.innerHTML = newval.toString();
+}
 </script>
 
 <style type="text/css">
@@ -29,6 +52,12 @@ div.jscode {
   margin-top: -13px;
   font-size: 12px;
 }
+span.sum {
+  display: inline;
+  border: 1px solid #9b9b9b;
+  background: #d9e2ea;
+  width: 20px;
+}
 </style>
 
 <?
@@ -59,7 +88,7 @@ div.jscode {
 
     $table_head = '<h3 class="bar">Kunde: %s</h3><script type="text/javascript">plant(%d);</script>
   <form action="status.php" method="POST">
-  <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=1>
+  <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=0>
   <tr class="head">
     <th width=15%%>Datum</th>
     <th width=5%%>Dauer</th>
@@ -104,8 +133,9 @@ div.jscode {
        if (strlen($customer)) {
          printf($table_sum, $color, min2hour($sum));
          printf($table_foot, $fieldnr);
+         $form++;
        }
-       printf($table_head, ucfirst($row['customer']), $form++);
+       printf($table_head, ucfirst($row['customer']), $form);
        $customer = $row['customer'];
        $fieldnr = 0;
        $sum = 0;
@@ -115,7 +145,7 @@ div.jscode {
       $sum += $row['time'];
       $d = explode(' ', $row['start']);
 
-      $check = '<input type="checkbox" name="oid_'.$fieldnr++.'" value="'.$row['oid'].'">';
+      $check = sprintf('<input type="checkbox" class="checkbox" name="oid_'.$fieldnr++.'" value="'.$row['oid'].'" onclick="add_sum(%d,this)">',$form);
       printf($table_row, $color, $check.$d[0], min2hour($row['time']), $row['kurz'], $row['task']);
       $color = !$color;
     }