Add per customers filter
authorJoey Schulze <joey@infodrom.org>
Sat, 21 May 2016 08:48:54 +0000 (10:48 +0200)
committerJoey Schulze <joey@infodrom.org>
Sat, 21 May 2016 08:48:54 +0000 (10:48 +0200)
src/InfoCon/stempel/status.wml

index fa3a7ec..9e738b6 100644 (file)
@@ -1,6 +1,7 @@
 #include <infocon.style>
 #include "common.inc"
 
 #include <infocon.style>
 #include "common.inc"
 
+<future>
 <page func=InfoCon title="Stempeluhr">
 
 <?
 <page func=InfoCon title="Stempeluhr">
 
 <?
 
     $table_head = '<h3 class="bar">Kunde: %s</h3><script type="text/javascript">plant(%d,%.2f);</script>
   <form action="status.php" method="POST">
 
     $table_head = '<h3 class="bar">Kunde: %s</h3><script type="text/javascript">plant(%d,%.2f);</script>
   <form action="status.php" method="POST">
-  <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=0>
+  <table class="smallfont border" id="table_%d" width="100%%" cellpadding=0 cellspacing=0>
+  <thead>
   <tr class="head" onclick="edit_task_finish(this)">
     <th width=15%%>Datum</th>
     <th width=5%%>Dauer</th>
     <th width=5%%>St.</th>
     <th width=75%% align=left>Arbeitsbeschreibung</th>
   <tr class="head" onclick="edit_task_finish(this)">
     <th width=15%%>Datum</th>
     <th width=5%%>Dauer</th>
     <th width=5%%>St.</th>
     <th width=75%% align=left>Arbeitsbeschreibung</th>
-  </tr>';
+  </tr>
+  </thead>
+  <tbody>';
 
     if (!is_array($stati))
       $stati = find_status();
 
     if (!is_array($stati))
       $stati = find_status();
@@ -57,7 +61,7 @@
 
     $table_row = '<tr class="t%d"><td>%s</td><td align="center" onclick="toggle_checkbox(%d,this)">%s</td>' .
       '<td align="center" onclick="toggle_checkbox(%d,this)">%s</td><td onclick="edit_task(this)">%s</td></tr>';
 
     $table_row = '<tr class="t%d"><td>%s</td><td align="center" onclick="toggle_checkbox(%d,this)">%s</td>' .
       '<td align="center" onclick="toggle_checkbox(%d,this)">%s</td><td onclick="edit_task(this)">%s</td></tr>';
-    $table_sum = '<tr class="t%d"><td>&nbsp;</td><td align="center">%s</td><td>&nbsp;</td><td>Summe</td></tr>';
+    $table_sum = '</tbody><tfoot><tr class="t%d"><td>&nbsp;</td><td align="center">%s</td><td>&nbsp;</td><td>Summe</td></tr></tfoot>';
 
     $query = "SELECT stempel.oid,start,customer,time,task,kurz FROM stempel JOIN stempel_status ON (stempel.status = stempel_status.id) WHERE time IS NOT NULL ";
     if (isset($month) && strlen($month))
 
     $query = "SELECT stempel.oid,start,customer,time,task,kurz FROM stempel JOIN stempel_status ON (stempel.status = stempel_status.id) WHERE time IS NOT NULL ";
     if (isset($month) && strlen($month))
@@ -86,7 +90,7 @@
        }
        $cname = $name[$row['customer']]['name'];
        if (!strlen($cname)) $cname = ucfirst($row['customer']);
        }
        $cname = $name[$row['customer']]['name'];
        if (!strlen($cname)) $cname = ucfirst($row['customer']);
-       printf($table_head, $cname, $form, $name[$row['customer']]['rate']);
+       printf($table_head, $cname, $form, $name[$row['customer']]['rate'], $form);
        $customer = $row['customer'];
        $fieldnr = 0;
        $sum = 0;
        $customer = $row['customer'];
        $fieldnr = 0;
        $sum = 0;
 
 <script src="<root_prefix>basics.js"></script>
 <script type="text/javascript">
 
 <script src="<root_prefix>basics.js"></script>
 <script type="text/javascript">
+<protect>
 var color_checked = '#c4ffc3';
 function format_int(value, width)
 {
 var color_checked = '#c4ffc3';
 function format_int(value, width)
 {
@@ -189,31 +194,30 @@ function strtime(time)
 
 function check(id, value)
 {
 
 function check(id, value)
 {
-  var form = document.forms[id];
-  var hours=document.getElementById('time_'+id.toString());
-  var rate= document.getElementById('rate_'+id.toString());
-  var sum = document.getElementById('sum_'+id.toString()); 
-  var newval = 0;
-
-  for (i=0; i< form.elements.length; i++) {
-      if (form.elements[i].name.substr(0,4) == 'oid_') {
-         form.elements[i].checked = value;
-         if (value) {
-             var ta = form.elements[i].parentNode.nextSibling.innerHTML.split(':');
-             newval = newval + parseInt(ta[0],10) * 60 + parseInt(ta[1],10);
-             form.elements[i].parentNode.parentNode.style.backgroundColor = color_checked;
-         } else
-             form.elements[i].parentNode.parentNode.style.backgroundColor = '';
-      }
-  }
-
-  hours.innerHTML = timestr(newval);
-  sum.innerHTML = '&euro;' + ((newval/60)*rate.value).toFixed(2);
+    var hours = $('#time_'+id);
+    var rate = $('#rate_'+id);
+    var sum = $('#sum_'+id);
+    var newval = 0;
+
+    $('table#table_'+id+' tbody tr:visible').each(function(i,e){
+       var checkbox = $(this).find('input[type="checkbox"]');
+       if (checkbox.prop('checked') != value) {
+           checkbox.prop('checked', !checkbox.prop('checked'));
+           if (checkbox.prop('checked'))
+               $(this).css('background-color', color_checked);
+           else
+               $(this).css('background-color', '');
+           add_sum(id, checkbox);
+       }
+    });
 }
 
 function plant(form, rate)
 {
   document.write('<div class="jscode">');
 }
 
 function plant(form, rate)
 {
   document.write('<div class="jscode">');
+  document.write('<input class="filter" id="filter_'+form+'" size="10" value="" style="font-size: 90%; position: relative; bottom: 2px;">');
+  document.write('<img class="filter" id="img_'+form+'" src="/pix/Actions-edit-delete-icon.png" border="0" ' +
+                'style="position: relative; bottom: -3px; margin-left: 1px; margin-right: 10px;" title="Filter löschen">');
   document.write('<input type="hidden" id="rate_'+form+'" value="'+rate+'">');
   document.write('<a href="javascript:check('+form+',true)">Check all</a>');
   document.write("&nbsp;/&nbsp;");
   document.write('<input type="hidden" id="rate_'+form+'" value="'+rate+'">');
   document.write('<a href="javascript:check('+form+',true)">Check all</a>');
   document.write("&nbsp;/&nbsp;");
@@ -227,21 +231,21 @@ function plant(form, rate)
 
 function add_sum(form, checkbox)
 {
 
 function add_sum(form, checkbox)
 {
-    var hours = document.getElementById('time_'+form.toString());
-    var rate= document.getElementById('rate_'+form.toString());
-    var sum = document.getElementById('sum_'+form.toString()); 
-    var time = strtime(checkbox.parentNode.nextSibling.innerHTML);
+    var hours = $('#time_'+form);
+    var rate = $('#rate_'+form);
+    var sum = $('#sum_'+form);
+    var time = strtime($(checkbox).parents('tr:first').find('td:nth-child(2)').text());
     var newval;
 
     var newval;
 
-    if (checkbox.checked) {
-       newval = strtime(hours.innerHTML) + time;
-       checkbox.parentNode.parentNode.style.backgroundColor = color_checked;
+    if ($(checkbox).prop('checked')) {
+       newval = strtime(hours.text()) + time;
+       $(checkbox).parents('tr:first').css('background-color', color_checked);
     } else {
     } else {
-       newval = strtime(hours.innerHTML) - time;
-       checkbox.parentNode.parentNode.style.backgroundColor = '';
+       newval = strtime(hours.text()) - time;
+       $(checkbox).parents('tr:first').css('background-color', '');
     }
     }
-    hours.innerHTML = timestr(newval);
-    sum.innerHTML = '&euro;' + ((newval/60)*rate.value).toFixed(2);
+    hours.text(timestr(newval));
+    sum.html('&euro;' + ((newval/60)*rate.val()).toFixed(2));
 }
 
 var task_parent = null;
 }
 
 var task_parent = null;
@@ -292,17 +296,49 @@ function edit_task_finish(obj)
 
 function toggle_checkbox(form, obj)
 {
 
 function toggle_checkbox(form, obj)
 {
-  edit_task_finish(obj);
+    edit_task_finish(obj);
 
 
-  var row = obj;
-  while (row.tagName.toLowerCase() != 'tr')
-    row = row.parentNode;
+    var row = $(obj).parents('tr:first');
+    var checkbox = row.find('input[type="checkbox"]')
+    checkbox.prop('checked', !checkbox.prop('checked'));
 
 
-  var checkbox = row.children[0].children[0];
+    checkbox.checked = !checkbox.checked;
+    add_sum(form, checkbox);
+}
 
 
-  checkbox.checked = !checkbox.checked;
-  add_sum(form, checkbox);
+function filter_change(e)
+{
+    var form = $(this).attr('id').split('_')[1];
+    var filter = $('input#filter_'+form).val();
+
+    $('table#table_'+form+' tbody tr').each(function(i,e){
+       if (filter.length) {
+           var td = $(this).find('td:nth-child(4)');
+           if (td.text().toLowerCase().indexOf(filter) > -1)
+               $(this).show();
+           else {
+               if ($(this).find('input[type="checkbox"]').prop('checked')) {
+                   toggle_checkbox(form, td);
+               }
+               $(this).hide();
+           }
+       } else {
+           $(this).show();
+       }
+    });
 }
 }
+
+function filter_clear(e)
+{
+    var form = $(this).attr('id').split('_')[1];
+    $('div.jscode input.filter#filter_'+form).val('').change();
+}
+
+$(function(){
+    $('div.jscode input.filter').change(filter_change);
+    $('div.jscode img.filter').click(filter_clear);
+});
+</protect>
 </script>
 
 <style type="text/css">
 </script>
 
 <style type="text/css">