Add call edit functionality
authorJoey Schulze <joey@infodrom.org>
Sat, 12 Dec 2009 14:50:35 +0000 (15:50 +0100)
committerJoey Schulze <joey@infodrom.org>
Fri, 25 Feb 2011 17:40:22 +0000 (18:40 +0100)
index.php
phone.css
phone.js
phone.php

index 1e4362b..d37f4e6 100644 (file)
--- a/index.php
+++ b/index.php
@@ -13,6 +13,10 @@ if (!empty($_POST['func'])) {
     delete_call($_POST['dir'],$_POST['call']);
   } elseif ($_POST['func'] == 'callinfo') {
     $data = callinfo($_POST['dir'],$_POST['call']);
     delete_call($_POST['dir'],$_POST['call']);
   } elseif ($_POST['func'] == 'callinfo') {
     $data = callinfo($_POST['dir'],$_POST['call']);
+    $data['dir'] = $_POST['dir'];
+    $data['call'] = $_POST['call'];
+  } elseif ($_POST['func'] == 'save') {
+    save_call();
   }
   header('Content-type: application/json; charset=UTF-8');
   echo json_encode($data);
   }
   header('Content-type: application/json; charset=UTF-8');
   echo json_encode($data);
@@ -63,5 +67,20 @@ if (!empty($_POST['func'])) {
 <p id="callnote"></p>
 </div>
 
 <p id="callnote"></p>
 </div>
 
+<div class="editcall">
+<p class="title">Edit message</p>
+<div style="padding-left: 5px;">
+<form id="edit_form">
+<span id="edit_date">&nbsp;</span><br>
+<input id="edit_dir" type="hidden">
+<input id="edit_call" type="hidden">
+Name<br><input id="edit_name" type="text" size="31"><br>
+Note<br><input id="edit_note" type="text" size="31"><br>
+<input type="button" class="button" value="Save" onclick="save()" style="margin-top: 5px;">
+<span id="edit_status"></span>
+</form>
+</div>
+</div>
+
 </body>
 </html>
 </body>
 </html>
index abbe1bd..4add06b 100644 (file)
--- a/phone.css
+++ b/phone.css
@@ -36,6 +36,15 @@ div.phonelist {
     margin-bottom: 3px;
 }
 
     margin-bottom: 3px;
 }
 
+input {
+    border: 1px solid #aaaaaa;
+    background-color: #f6f6f6;
+    font-size: 10px;
+}
+input.button:hover {
+    background-color: #e0e0e0;
+}
+
 p.title {
     margin-top: 0px;
     border-bottom: 1px solid #bfbfbf;
 p.title {
     margin-top: 0px;
     border-bottom: 1px solid #bfbfbf;
@@ -68,7 +77,7 @@ div.phonecall {
     border: 1px solid #bfbfbf;
     width: 200px;
     position: absolute;
     border: 1px solid #bfbfbf;
     width: 200px;
     position: absolute;
-    left: 500px;
+    left: 600px;
     top: 5px;
 }
 div.phonecall p {
     top: 5px;
 }
 div.phonecall p {
@@ -81,3 +90,19 @@ iframe.phonecall {
     margin-left: 10px;
     border: 0;
 }
     margin-left: 10px;
     border: 0;
 }
+
+div.editcall {
+    border: 1px solid #bfbfbf;
+    width: 210px;
+    position: absolute;
+    left: 350px;
+    top: 5px;
+}
+div.editcall p {
+    margin: 0;
+    padding-left: 3px;
+}
+
+span#edit_status {
+    padding-left: 5px;
+}
index 9b5d51d..58e5371 100644 (file)
--- a/phone.js
+++ b/phone.js
@@ -1,6 +1,7 @@
 var menu_list = {
     'title': 'Calls',
     'items': [{'name': 'Archive', 'callback': menu_list_archive},
 var menu_list = {
     'title': 'Calls',
     'items': [{'name': 'Archive', 'callback': menu_list_archive},
+              {'name': 'Edit', 'callback': menu_list_edit},
               {'name': 'Delete', 'callback': menu_list_delete},
               {'name': 'Cancel', 'type': 'hide'}]
 };
               {'name': 'Delete', 'callback': menu_list_delete},
               {'name': 'Cancel', 'type': 'hide'}]
 };
@@ -113,6 +114,24 @@ function play_message(event)
     event.originalTarget.className = '';
 }
 
     event.originalTarget.className = '';
 }
 
+function save_callback(data)
+{
+    field = document.getElementById('edit_status');
+    field.innerHTML = 'Call saved';
+}
+
+function save()
+{
+    var dir = document.getElementById('edit_dir');
+    var call = document.getElementById('edit_call');
+    var name = document.getElementById('edit_name');
+    var note = document.getElementById('edit_note');
+    var params = 'dir=' + dir.value + '&call=' + call.value;
+    params += '&name=' + name.value + '&note=' + note.value;
+
+    ajax_request('save', params, save_callback);
+}
+
 function list_context(e)
 {
     var menu = document.getElementById('menu_list');
 function list_context(e)
 {
     var menu = document.getElementById('menu_list');
@@ -135,6 +154,28 @@ function menu_list_archive_callback(data)
     fetch_archive();
 }
 
     fetch_archive();
 }
 
+function menu_list_edit_callback(data)
+{
+    var fields = ['name','note','dir','call'];
+    var field;
+
+    for (var i=0; i < fields.length; i++) {
+       field = document.getElementById('edit_' + fields[i]);
+       field.value = data[fields[i]];
+    }
+
+    fields = ['name','note'];
+    for (var i=0; i < fields.length; i++) {
+       field = document.getElementById('edit_' + fields[i]);
+       field.innerHTML = data[fields[i]];
+    }
+
+    field = document.getElementById('edit_date');
+    field.innerHTML = data.date + ', ' + data.length;
+    field = document.getElementById('edit_status');
+    field.innerHTML = '';
+}
+
 function menu_list_archive(e)
 {
     if (e.target.parentNode.payload['dir'] == 'incoming')
 function menu_list_archive(e)
 {
     if (e.target.parentNode.payload['dir'] == 'incoming')
@@ -143,6 +184,14 @@ function menu_list_archive(e)
     e.target.parentNode.style.display = 'none';
 }
 
     e.target.parentNode.style.display = 'none';
 }
 
+function menu_list_edit(e)
+{
+    var params = 'dir='+e.target.parentNode.payload['dir']+'&call='+e.target.parentNode.payload['call'];
+    ajax_request('callinfo', params, menu_list_edit_callback);
+
+    e.target.parentNode.style.display = 'none';
+}
+
 function menu_list_delete(e)
 {
     var params = 'dir='+e.target.parentNode.payload['dir']+'&call='+e.target.parentNode.payload['call'];
 function menu_list_delete(e)
 {
     var params = 'dir='+e.target.parentNode.payload['dir']+'&call='+e.target.parentNode.payload['call'];
index b2dbd6d..5f77ba9 100644 (file)
--- a/phone.php
+++ b/phone.php
@@ -4,7 +4,9 @@ define('SPOOL_DIR', '/var/spool/vbox/ttyI6');
 function read_info($dir, $call)
 {
   $info = array();
 function read_info($dir, $call)
 {
   $info = array();
-  if (($f = fopen(SPOOL_DIR . '/' . $dir . '/' . $call . '.info', 'r')) !== false) {
+  $fname = SPOOL_DIR . '/' . $dir . '/' . $call . '.info';
+
+  if (is_file($fname) && ($f = fopen($fname, 'r')) !== false) {
     $line = fgets($f, 1024);
     fclose($f);
     $info = unserialize($line);
     $line = fgets($f, 1024);
     fclose($f);
     $info = unserialize($line);
@@ -141,4 +143,13 @@ function delete_call($dir, $call)
   unlink($basename . '.info');
 }
 
   unlink($basename . '.info');
 }
 
+function save_call()
+{
+  $info = read_info($_POST['dir'], $_POST['call']);
+  $info['name'] = $_POST['name'];
+  $info['note'] = $_POST['note'];
+
+  error_log(var_export($info,true));
+}
+
 ?>
 ?>