Add task edit feature via AJAX
authorJoey Schulze <joey@infodrom.org>
Sun, 7 Apr 2013 15:34:34 +0000 (15:34 +0000)
committerJoey Schulze <joey@infodrom.org>
Sun, 7 Apr 2013 15:34:34 +0000 (15:34 +0000)
src/InfoCon/stempel/status.wml

index 8367499..56d6c68 100644 (file)
@@ -47,7 +47,7 @@
     $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=0>
     $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=0>
-  <tr class="head">
+  <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=15%%>Datum</th>
     <th width=5%%>Dauer</th>
     <th width=5%%>St.</th>
@@ -65,7 +65,7 @@
                  '<input type="hidden" name="fields" value="%d">'.
                  '</form>';
 
                  '<input type="hidden" name="fields" value="%d">'.
                  '</form>';
 
-    $table_row = '<tr class=t%d><td>%s</td><td align="center">%s</td><td align="center">%s</td><td>%s</td></tr>';
+    $table_row = '<tr class="t%d"><td>%s</td><td align="center">%s</td><td align="center">%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>';
 
     $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 ";
     $table_sum = '<tr class="t%d"><td>&nbsp;</td><td align="center">%s</td><td>&nbsp;</td><td>Summe</td></tr>';
 
     $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 ";
   }
 ?>
 
   }
 ?>
 
+<script src="$(prefix)basics.js"></script>
 <script type="text/javascript">
 var color_checked = '#c4ffc3';
 function format_int(value, width)
 <script type="text/javascript">
 var color_checked = '#c4ffc3';
 function format_int(value, width)
@@ -242,6 +243,53 @@ function add_sum(form, checkbox)
     }
     sum.innerHTML = timestr(newval);
 }
     }
     sum.innerHTML = timestr(newval);
 }
+
+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 = document.createElement('input');
+       input.value = obj.innerHTML
+       input.style.fontSize = '90%';
+       input.style.width = '100%';
+       input.style.background = 'yellow';
+
+       obj.innerHTML = '';
+       obj.appendChild(input);
+       input.focus();
+    }
+}
+
+function edit_task_save()
+{
+    if (!task_parent) return;
+
+    if (task_parent.children[0].value != task_title)
+       ajax_request('save','oid='+task_oid+'&task='+encodeURIComponent(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();
+}
+
 </script>
 
 <style type="text/css">
 </script>
 
 <style type="text/css">
@@ -312,6 +360,5 @@ span.sum {
 </page>
 
 # Local variables:
 </page>
 
 # Local variables:
-# mode: text
-# mode: auto-fill
+# mode: php
 # end:
 # end: