Stop editing when clicking on sum row
[infodrom.org/service.infodrom.org] / src / InfoCon / stempel / status.wml
index 0da5bd8..7212551 100644 (file)
@@ -3,6 +3,7 @@
 
 <future>
 <page func=InfoCon title="Stempeluhr">
+<script type="text/javascript" src="<root_prefix>jquery.editable.js"></script>
 
 <?
   session_name('STEMPEL');
@@ -39,7 +40,7 @@
   <form action="status.php" method="POST">
   <table class="smallfont border" id="table_%d" width="100%%" cellpadding=0 cellspacing=0>
   <thead>
-  <tr class="head" onclick="edit_task_finish(this)">
+  <tr class="head">
     <th width=15%%>Datum</th>
     <th width=5%%>Dauer</th>
     <th width=5%%>St.</th>
 
     foreach ($stati as $k=>$v)
       $table_foot .= sprintf('<input type="radio" name="status" value="%s"%s>%s&nbsp;', $k, 0==$k?' checked':'', $v);
-      $table_foot .= '<input type="submit" class="button" value="Aktualisieren"></p></div>'.
+    $table_foot .= '<input type="submit" class="button" value="Aktualisieren" onclick="return status_change(event)"></p></div>'.
                  '<input type="hidden" name="fields" value="%d">'.
                  '</form>';
 
-    $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 = '</tbody><tfoot><tr class="t%d"><td>&nbsp;</td><td align="center">%s</td><td>&nbsp;</td><td>Summe</td></tr></tfoot>';
+    $table_row = '<tr class="t%d" status="%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><span route="Stempel/EditTask" item_id="%d">%s</span></td></tr>';
+    $table_sum = '</tbody><tfoot><tr class="t%d" onclick="edit_task_finish(this)">' .
+       '<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 ";
+    $query = "SELECT stempel.oid,stempel.id,stempel.status,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 .= "AND cast(start AS TEXT) LIKE '".$month."-%' ";
     if (isset($cust) && strlen($cust))
                       $row['oid'],
                       $form);
       $date = sprintf('<span onclick="toggle_checkbox(%d,this)">%s</span>', $form, $d[0]);
-      printf($table_row, $color, $check.$date, $form, min2hour($row['time']), $form, $row['kurz'], htmlspecialchars($row['task'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'));
+      printf($table_row, $color, $row['status'], $check.$date, $form, min2hour($row['time']), $form, $row['kurz'],
+            $row['id'],
+            htmlspecialchars($row['task'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'));
       $color = !$color;
     }
     if (pg_num_rows($sth) > 0) {
@@ -210,18 +214,20 @@ function check(id, value)
            add_sum(id, checkbox);
        }
     });
+
+    return false;
 }
 
 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('<input class="filter" id="filter_'+form+'" size="10" value="">');
   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">');
+                '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('<a href="#" onclick="return check('+form+',true)">Check all</a>');
   document.write("&nbsp;/&nbsp;");
-  document.write('<a href="javascript:check('+form+',false)">Uncheck all</a>');
+  document.write('<a href="#" onclick="return check('+form+',false)">Uncheck all</a>');
   document.write("&nbsp;");
   document.write('<span id="time_'+form+'" class="sum">0:00</span>' );
   document.write('<span id="sum_'+form+'" class="sum">&euro;0.00</span>');
@@ -248,53 +254,8 @@ function add_sum(form, checkbox)
     sum.html('&euro;' + ((newval/60)*rate.val()).toFixed(2));
 }
 
-var task_parent = null;
-var task_title = '';
-var task_oid = 0;
-function edit_task(obj)
-{
-    if (task_oid) {
-       if (task_oid != obj.parentNode.children[0].children[0].value)
-           edit_task_save();
-    }
-
-    if (!task_oid) {
-       task_parent = obj;
-       task_title = obj.innerHTML;
-       task_oid = obj.parentNode.children[0].children[0].value;
-
-       var input = $('<input>');
-       input.val(obj.innerHTML.replace('&gt;', '>').replace('&lt;', '<').replace('&amp;', '&'));
-       input.css('fontSize', '100%').css('width', '100%').css('background', 'yellow');
-       obj.innerHTML = '';
-       $(obj).append(input);
-       input.focus();
-    }
-}
-
-function edit_task_save()
-{
-    if (!task_parent) return;
-
-    if (task_parent.children[0].value != task_title)
-       $.invoke('Sales/Text', {id: task_oid, text: task_parent.children[0].value});
-
-    task_parent.innerHTML = task_parent.children[0].value;
-    task_parent = null;
-    task_title = '';
-    task_oid = 0;
-}
-
-function edit_task_finish(obj)
-{
-    if (task_oid)
-       edit_task_save();
-}
-
 function toggle_checkbox(form, obj)
 {
-    edit_task_finish(obj);
-
     var row = $(obj).parents('tr:first');
     var checkbox = row.find('input[type="checkbox"]')
     checkbox.prop('checked', !checkbox.prop('checked'));
@@ -308,19 +269,22 @@ 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){
+    var cnum = 0;
+    $('table#table_'+form+' tbody tr').not('.deleted').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 (td.text().toLowerCase().indexOf(filter) > -1) {
+               $(this).removeClass('t0').removeClass('t1').addClass('t'+cnum).show();
+               cnum = cnum ? 0 : 1;
+           } else {
                if ($(this).find('input[type="checkbox"]').prop('checked')) {
                    toggle_checkbox(form, td);
                }
                $(this).hide();
            }
        } else {
-           $(this).show();
+           $(this).removeClass('t0').removeClass('t1').addClass('t'+cnum).show();
+           cnum = cnum ? 0 : 1;
        }
     });
 }
@@ -328,12 +292,46 @@ function filter_change(e)
 function filter_clear(e)
 {
     var form = $(this).attr('id').split('_')[1];
-    $('div.jscode input.filter#filter_'+form).val('').change();
+    $('div.jscode input.filter#filter_'+form).val('').keyup();
+}
+
+function status_change(e)
+{
+    var ids = [];
+    var form = $(e.target).parents('form:first');
+    var p = $(e.target).parents('p:first');
+    form.find('tr').not('.deleted').find('input.checkbox').each(function(i,e){
+       if ($(this).prop('checked') == true)
+           ids.push($(this).val());
+    });
+
+    var new_status = 0;
+    p.find('input[name="status"]').each(function(i,e){
+       if ($(this).prop('checked') == true)
+           new_status = $(this).val();
+    });
+
+    $.invoke('Sales/SetStatus', {status: new_status, ids: ids}, function(data){
+       for (var i=0; i < ids.length; i++) {
+           show_message('Positionen aktualisiert');
+           var checkbox = form.find('input.checkbox[value="'+ids[i]+'"]');
+           var row = checkbox.parents('tr:first');
+
+           checkbox.prop('checked',false);
+           add_sum(form.find('table:first').attr('id').split('_')[1], checkbox);
+
+           if (row.attr('status') != new_status)
+               row.addClass('deleted').hide();
+       }
+    });
+
+    return false;
 }
 
 $(function(){
-    $('div.jscode input.filter').change(filter_change);
+    $('div.jscode input.filter').keyup(filter_change);
     $('div.jscode img.filter').click(filter_clear);
+    make_editable('table.smallfont tr span');
 });
 </protect>
 </script>
@@ -344,6 +342,17 @@ div.jscode {
   margin-top: -13px;
   font-size: 12px;
 }
+div.jscode input.filter {
+  font-size: 90%;
+  position: relative;
+  bottom: 2px;
+}
+div.jscode img.filter {
+  position: relative;
+  bottom: -3px;
+  margin-left: 1px;
+  margin-right: 10px;
+}
 span.sum {
   display: inline;
   border: 1px solid #9b9b9b;