highlight current line
[infodrom/phone] / phone.js
index ad7f6ae..fb1b829 100644 (file)
--- a/phone.js
+++ b/phone.js
@@ -3,6 +3,7 @@ function page_init()
     var frame = document.getElementById('phonecall');
     frame.src = '';
     fetch_incoming();
+    fetch_archive();
 }
 
 function fetch_incoming_callback(data)
@@ -29,6 +30,8 @@ function fetch_incoming_callback(data)
            elem.payload = new Array();
            elem.payload['dir'] = 'incoming';
            elem.payload['fname'] = data.incoming[i].fname;
+           if (data.incoming[i].read == undefined)
+               elem.className = 'new';
            elem.onclick = play_message;
            calls.appendChild(elem);
        }
@@ -42,14 +45,49 @@ function fetch_incoming()
     ajax_request('incoming', '', fetch_incoming_callback);
 }
 
+function fetch_archive_callback(data)
+{
+    var calls = document.getElementById('archive_calls');
+    var div = document.getElementById('archive');
+
+    while (calls.childNodes.length > 0)
+       calls.removeChild(calls.childNodes[0]);
+
+    if (data.archive.length > 0) {
+       div.style.display = '';
+
+       for (var i=0; i < data.archive.length; i++) {
+           var elem = document.createElement('li');
+           var text = data.archive[i].date + ', ';
+           if (data.archive[i].name == '*** Unknown ***' && data.archive[i].number != '0')
+               text += data.archive[i].number;
+           else
+               text += data.archive[i].name;
+           text += ', ' + data.archive[i].length;
+
+           elem.innerHTML = text;
+           elem.payload = new Array();
+           elem.payload['dir'] = 'archive';
+           elem.payload['fname'] = data.archive[i].fname;
+           elem.onclick = play_message;
+           calls.appendChild(elem);
+       }
+    } else {
+       div.style.display = 'none';
+    }
+}
+
+function fetch_archive()
+{
+    ajax_request('archive', '', fetch_archive_callback);
+}
+
 function play_message_callback(data)
 {
     var speaker = document.getElementById('callspeaker');
     var date = document.getElementById('calldate');
     var note = document.getElementById('callnote');
 
-    Debug.ObjDump(data);
-
     var text = data.name;
     if (data.number != '0') text += ' (' + data.number + ')';
     speaker.innerHTML = text;
@@ -59,10 +97,9 @@ function play_message_callback(data)
 
 function play_message(event)
 {
-    Debug.write('Request ' + event.originalTarget.payload['fname'] + ' in ' + event.originalTarget.payload['dir']);
-
     var frame = document.getElementById('phonecall');
     var parms = 'dir='+event.originalTarget.payload['dir']+'&call='+event.originalTarget.payload['fname'];
     ajax_request('callinfo', parms, play_message_callback);
-    // frame.src = 'index.php?'+parms;
+    frame.src = 'index.php?'+parms;
+    event.originalTarget.className = '';
 }