From 91342a68cc7f18064e91beb7e67bc21ffecfc442 Mon Sep 17 00:00:00 2001 From: Joey Schulze Date: Sat, 12 Dec 2009 13:19:46 +0100 Subject: [PATCH 1/1] Add context menu to list of calls, support archiving and deletion of messages --- index.php | 4 ++++ phone.css | 24 +++++++++++++++++++++++ phone.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++----- phone.php | 21 ++++++++++++++++++-- 4 files changed, 99 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index 7525c2a..1e4362b 100644 --- a/index.php +++ b/index.php @@ -7,6 +7,10 @@ if (!empty($_POST['func'])) { $data['incoming'] = read_directory('incoming'); } elseif ($_POST['func'] == 'archive') { $data['archive'] = read_directory('archive'); + } elseif ($_POST['func'] == 'archive_call') { + archive_call($_POST['call']); + } elseif ($_POST['func'] == 'delete_call') { + delete_call($_POST['dir'],$_POST['call']); } elseif ($_POST['func'] == 'callinfo') { $data = callinfo($_POST['dir'],$_POST['call']); } diff --git a/phone.css b/phone.css index 7ab677c..abbe1bd 100644 --- a/phone.css +++ b/phone.css @@ -5,6 +5,30 @@ body { color: #000000; } +span.popupTitle { + padding-left: 2px; + padding-right: 2px; + background: #e0e0e0; + font-weight: bold; + border-bottom: 1px solid #8f8f8f; + display: block; +} +div.popup { + background: #fffb71; + position: absolute; + border: 1px solid #8f8f8f; + z-index: 10; +} +span.popup { + padding-left: 2px; + padding-right: 2px; + cursor: default; + display: block; +} +span.popup:hover { + background: #96ccff; +} + div.phonelist { border: 1px solid #bfbfbf; width: 300px; diff --git a/phone.js b/phone.js index fb1b829..9b5d51d 100644 --- a/phone.js +++ b/phone.js @@ -1,3 +1,10 @@ +var menu_list = { + 'title': 'Calls', + 'items': [{'name': 'Archive', 'callback': menu_list_archive}, + {'name': 'Delete', 'callback': menu_list_delete}, + {'name': 'Cancel', 'type': 'hide'}] +}; + function page_init() { var frame = document.getElementById('phonecall'); @@ -29,10 +36,11 @@ function fetch_incoming_callback(data) elem.innerHTML = text; elem.payload = new Array(); elem.payload['dir'] = 'incoming'; - elem.payload['fname'] = data.incoming[i].fname; + elem.payload['call'] = data.incoming[i].fname; if (data.incoming[i].read == undefined) elem.className = 'new'; elem.onclick = play_message; + elem.oncontextmenu = list_context; calls.appendChild(elem); } } else { @@ -68,8 +76,9 @@ function fetch_archive_callback(data) elem.innerHTML = text; elem.payload = new Array(); elem.payload['dir'] = 'archive'; - elem.payload['fname'] = data.archive[i].fname; + elem.payload['call'] = data.archive[i].fname; elem.onclick = play_message; + elem.oncontextmenu = list_context; calls.appendChild(elem); } } else { @@ -98,8 +107,46 @@ function play_message_callback(data) function play_message(event) { 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; + var params = 'dir='+event.originalTarget.payload['dir']+'&call='+event.originalTarget.payload['call']; + ajax_request('callinfo', params, play_message_callback); + frame.src = 'index.php?'+params; event.originalTarget.className = ''; } + +function list_context(e) +{ + var menu = document.getElementById('menu_list'); + if (!menu) + menu = menu_create('menu_list', menu_list); + + menu.style.left = e.pageX - 40; + menu.style.top = e.pageY - 15; + menu.style.display = ''; + menu.payload = new Array(); + menu.payload['dir'] = e.target.payload['dir']; + menu.payload['call'] = e.target.payload['call']; + + return false; +} + +function menu_list_archive_callback(data) +{ + fetch_incoming(); + fetch_archive(); +} + +function menu_list_archive(e) +{ + if (e.target.parentNode.payload['dir'] == 'incoming') + ajax_request('archive_call', 'call='+e.target.parentNode.payload['call'], menu_list_archive_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']; + ajax_request('delete_call', params, menu_list_archive_callback); + + e.target.parentNode.style.display = 'none'; +} diff --git a/phone.php b/phone.php index 660e0b6..b2dbd6d 100644 --- a/phone.php +++ b/phone.php @@ -75,7 +75,7 @@ function read_directory($directory) while (($filename = readdir($dir)) !== false) { if (($pos = strpos($filename, '.vmsg')) !== false) { $fname = substr($filename,0,$pos); - $info = message_info('incoming', $fname); + $info = message_info($directory, $fname); $info['fname'] = $fname; $result[] = $info; } @@ -124,4 +124,21 @@ function send_call($dir, $call) pclose($p); } -?> \ No newline at end of file +function archive_call($call) +{ + $basename = SPOOL_DIR . '/' . 'incoming' . '/' . $call; + $basenew = SPOOL_DIR . '/' . 'archive' . '/' . $call; + + rename($basename . '.vmsg', $basenew . '.vmsg'); + rename($basename . '.info', $basenew . '.info'); +} + +function delete_call($dir, $call) +{ + $basename = SPOOL_DIR . '/' . $dir . '/' . $call; + + unlink($basename . '.vmsg'); + unlink($basename . '.info'); +} + +?> -- 2.20.1