Convert in-place edit of task to jquery.editable
authorJoey Schulze <joey@infodrom.org>
Mon, 17 Jul 2017 22:03:46 +0000 (00:03 +0200)
committerJoey Schulze <joey@infodrom.org>
Mon, 17 Jul 2017 22:03:46 +0000 (00:03 +0200)
class/stempel.class.php [new file with mode: 0644]
src/InfoCon/stempel/index.wml
src/InfoCon/stempel/status.wml

diff --git a/class/stempel.class.php b/class/stempel.class.php
new file mode 100644 (file)
index 0000000..23a8cff
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+
+class Stempel extends DatabaseTable {
+
+  public function __construct($id=false)
+  {
+    parent::__construct('stempel', $id);
+  }
+
+  public function ajaxEditTask(Array $data)
+  {
+    if (!strlen($data['content'])) return false;
+    return $this->modify('task', $data['content']);
+  }
+
+}
index cda1025..5087641 100644 (file)
@@ -24,7 +24,9 @@
     $month = date('Y-m');
 ?>
 
     $month = date('Y-m');
 ?>
 
+<future>
 <page func=InfoCon title="Stempeluhr">
 <page func=InfoCon title="Stempeluhr">
+<script type="text/javascript" src="<root_prefix>jquery.editable.js"></script>
 
 <?
   $name = load_customers();
 
 <?
   $name = load_customers();
   <th width=80%%>Arbeitsbeschreibung</th>
 </tr>';
   $table_foot = '</table>';
   <th width=80%%>Arbeitsbeschreibung</th>
 </tr>';
   $table_foot = '</table>';
-  $table_row = '<tr class="t%d"><td>%s</td><td align="center">%s</td><td align="center">%s</td><td><a href="edit.php?id=%d">%s</a></td></tr>';
+  if (strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/') === false)
+    $table_row = '<tr class="t%d"><td>%s</td><td align="center">%s</td><td align="center">%s</td><td><a href="edit.php?id=%d">%s</a></td></tr>';
+  else
+    $table_row = '<tr class="t%d"><td>%s</td><td align="center">%s</td><td align="center">%s</td><td><span route="Stempel/EditTask" item_id="%d">%s</span></td></tr>';
   $table_sum = '<tr class="t%d"><td>&nbsp;</td><td align="center"><strong>%s</strong></td><td>&nbsp;</td><td><strong>Summe</strong></td></tr>';
 
   $query = <<<EOS
   $table_sum = '<tr class="t%d"><td>&nbsp;</td><td align="center"><strong>%s</strong></td><td>&nbsp;</td><td><strong>Summe</strong></td></tr>';
 
   $query = <<<EOS
-SELECT stempel.oid,start,stempel_customer.name AS customer,time,task,kurz
+SELECT stempel.oid,stempel.id,start,stempel_customer.name AS customer,time,task,kurz
 FROM stempel
 JOIN stempel_customer ON (stempel.customer = stempel_customer.short)
 JOIN stempel_status ON (stempel.status = stempel_status.id)
 FROM stempel
 JOIN stempel_customer ON (stempel.customer = stempel_customer.short)
 JOIN stempel_status ON (stempel.status = stempel_status.id)
@@ -73,7 +78,9 @@ EOS;
     $sum += $row['time'];
     $d = explode(' ', $row['start']);
  
     $sum += $row['time'];
     $d = explode(' ', $row['start']);
  
-    printf($table_row, $color, $d[0], min2hour($row['time']), $row['kurz'], $row['oid'], htmlspecialchars($row['task'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'));
+    printf($table_row, $color, $d[0], min2hour($row['time']), $row['kurz'],
+          strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/') === false ? $row['oid'] : $row['id'],
+          htmlspecialchars($row['task'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'));
     $color = !$color;
   }
   printf($table_sum, $color, min2hour($sum));
     $color = !$color;
   }
   printf($table_sum, $color, min2hour($sum));
@@ -101,6 +108,11 @@ EOS;
 </form>
 <div style="padding-top: 0.5em"></div>
 
 </form>
 <div style="padding-top: 0.5em"></div>
 
+<protect><script type="text/javascript">
+$(function(){
+    make_editable('table.smallfont tr span');
+});
+</script></protect>
 </page>
 
 # Local variables:
 </page>
 
 # Local variables:
index 822d46e..5ee8b4d 100644 (file)
@@ -3,6 +3,7 @@
 
 <future>
 <page func=InfoCon title="Stempeluhr">
 
 <future>
 <page func=InfoCon title="Stempeluhr">
+<script type="text/javascript" src="<root_prefix>jquery.editable.js"></script>
 
 <?
   session_name('STEMPEL');
 
 <?
   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>
   <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>
     <th width=15%%>Datum</th>
     <th width=5%%>Dauer</th>
     <th width=5%%>St.</th>
                  '</form>';
 
     $table_row = '<tr class="t%d" status="%d"><td>%s</td><td align="center" onclick="toggle_checkbox(%d,this)">%s</td>' .
                  '</form>';
 
     $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 onclick="edit_task(this)">%s</td></tr>';
+      '<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"><td>&nbsp;</td><td align="center">%s</td><td>&nbsp;</td><td>Summe</td></tr></tfoot>';
 
     $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,stempel.status,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))
     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]);
                       $row['oid'],
                       $form);
       $date = sprintf('<span onclick="toggle_checkbox(%d,this)">%s</span>', $form, $d[0]);
-      printf($table_row, $color, $row['status'], $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) {
       $color = !$color;
     }
     if (pg_num_rows($sth) > 0) {
@@ -250,53 +253,8 @@ function add_sum(form, checkbox)
     sum.html('&euro;' + ((newval/60)*rate.val()).toFixed(2));
 }
 
     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)
 {
 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'));
     var row = $(obj).parents('tr:first');
     var checkbox = row.find('input[type="checkbox"]')
     checkbox.prop('checked', !checkbox.prop('checked'));
@@ -372,6 +330,7 @@ function status_change(e)
 $(function(){
     $('div.jscode input.filter').keyup(filter_change);
     $('div.jscode img.filter').click(filter_clear);
 $(function(){
     $('div.jscode input.filter').keyup(filter_change);
     $('div.jscode img.filter').click(filter_clear);
+    make_editable('table.smallfont tr span');
 });
 </protect>
 </script>
 });
 </protect>
 </script>