Shout: Continue creating the recordings UI
authorBen Klang <ben@alkaloid.net>
Wed, 17 Mar 2010 16:25:03 +0000 (12:25 -0400)
committerBen Klang <ben@alkaloid.net>
Wed, 17 Mar 2010 16:25:31 +0000 (12:25 -0400)
shout/config/conf.xml
shout/lib/Ajax/Application.php
shout/lib/Application.php
shout/lib/Shout.php
shout/recordings.php [new file with mode: 0644]
shout/templates/dialplan/edit.inc
shout/templates/recordings/list.inc [new file with mode: 0644]
shout/themes/graphics/recording-add.png [new file with mode: 0755]

index 9138f8d..e07bad1 100644 (file)
    </configswitch>
   </configsection>
  </configtab>
- <configtab name="vfs" desc="IVR Prompt Storage">
-  <configsection name="vfs">
+ <configtab name="ivr" desc="IVR Prompt Storage">
+  <configsection name="ivr">
    <configheader>IVR Prompt Storage Settings</configheader>
-   <configvfs switchname="type"/>
+   <configvfs switchname="driver"/>
   </configsection>
  </configtab>
 </configuration>
index 8a05290..83f20d5 100644 (file)
@@ -201,6 +201,17 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base
         }
     }
 
+    public function getRecordings()
+    {
+        try {
+            return Shout::getRecordings($_SESSION['shout']['curaccount']);
+        } catch (Exception $e) {
+            //FIXME: Create a way to notify the user of the failure.
+            Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
+            return false;
+        }
+    }
+
     public function responseType()
     {
         return $this->_responseType;
index 9b230d6..1fbef59 100644 (file)
@@ -85,7 +85,7 @@ class Shout_Application extends Horde_Registry_Application
             $this->devices = Shout_Driver::factory('devices');
             $this->dialplan = Shout_Driver::factory('dialplan');
             $conf = $GLOBALS['conf'];
-            $this->vfs = VFS::singleton($conf['vfs']['driver'], $conf['vfs']['params']);
+            $this->vfs = VFS::singleton($conf['ivr']['driver'], $conf['ivr']['params']);
 
             $accounts = $this->storage->getAccounts();
         } catch (Shout_Exception $e) {
index 9ed2fff..b59251e 100644 (file)
@@ -217,4 +217,22 @@ class Shout
         return $res;
     }
 
+    static public function getRecordings($account)
+    {
+        $rlist = $shout->vfs->listFolder($account);
+
+        // In Asterisk, filenames the same basename and different extension are
+        // functionally equivalent.  Asterisk chooses the file based on the least cost
+        // to transcode.  For that reason, we will drop the filename extension when
+        // handling files.
+        $recordings = array();
+        foreach ($rlist as $name => $info) {
+            $name = substr($name, 0, strrpos($name, '.'));
+            $info['name'] = $name;
+            $recordings[$name] = $info;
+        }
+
+        return $recordings;
+    }
+
 }
diff --git a/shout/recordings.php b/shout/recordings.php
new file mode 100644 (file)
index 0000000..74f9454
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+/**
+ * Copyright 2010 Alkaloid Networks LLC (http://projects.alkaloid.net)
+ *
+ * See the enclosed file COPYING for license information (BSD). If you
+ * did not receive this file, see
+ * http://www.opensource.org/licenses/bsd-license.php.
+ *
+ * @author  Ben Klang <ben@alkaloid.net>
+ */
+
+require_once dirname(__FILE__) . '/lib/Application.php';
+$shout = Horde_Registry::appInit('shout');
+
+require_once SHOUT_BASE . '/lib/Forms/MenuForm.php';
+
+$action = Horde_Util::getFormData('action');
+$curaccount = $_SESSION['shout']['curaccount'];
+$recordings = Shout::getRecordings($curaccount);
+
+switch($action) {
+case 'add':
+    $vars = Horde_Variables::getDefaultVariables();
+    $vars->set('account', $curaccount);
+    $Form = new MenuForm($vars);
+
+    if ($Form->isSubmitted() && $Form->validate($vars, true)) {
+        // Form is Valid and Submitted
+        try {
+            $Form->execute();
+            $notification->push(_("Menu added."),
+                                  'horde.success');
+            $menus = $shout->storage->getMenus($curaccount);
+            $action = 'list';
+        } catch (Exception $e) {
+            $notification->push($e);
+        }
+        break;
+    } elseif ($Form->isSubmitted()) {
+        $notification->push(_("Problem processing the form.  Please check below and try again."), 'horde.warning');
+    }
+
+    // Create a new add form
+    $vars = new Horde_Variables();
+    $vars->set('action', $action);
+    //$Form = new MenuForm($vars);
+
+    break;
+case 'edit':
+    if (!isset($menus[$menu])) {
+        $notification->push(_("That menu does not exist."), 'horde.error');
+        $action = 'list';
+        break;
+    }
+    $menu = $menus[$menu];
+    try {
+        $destinations = $shout->extensions->getExtensions($curaccount);
+    } catch (Exception $e) {
+        $notification->push(_("Problem getting destination information."));
+    }
+    break;
+case 'list':
+default:
+    $action = 'list';
+    break;
+}
+
+Horde::addScriptFile('stripe.js', 'horde');
+Horde::addScriptFile('prototype.js', 'horde');
+
+require SHOUT_TEMPLATES . '/common-header.inc';
+require SHOUT_TEMPLATES . '/menu.inc';
+
+$notification->notify();
+
+require SHOUT_TEMPLATES . '/recordings/' . $action . '.inc';
+
+require $registry->get('templates', 'horde') . '/common-footer.inc';
index 446a92c..362c494 100644 (file)
@@ -144,7 +144,21 @@ function cancelEdit()
 
 function changeSoundfile()
 {
-    alert("Changing soundfile");
+    //empty($('editSound'));
+    // FIXME: Add spinner
+    new Ajax.Request(ajax_url + 'getRecordings',
+    {
+        method: 'get',
+        onSuccess: function(r) {
+            //var form = document.createElement('form');
+            //form.name = 'selectSoundFile';
+            //form.id = 'selectSoundFile';
+            //var select = document.createElement('select');
+            //select.name = 'filename';
+            var recordings = r.responseJSON.response;
+            alert('done');
+        }
+    });
 }
 
 function playSoundfile()
@@ -171,6 +185,7 @@ function refreshMenu()
     // Handle the soundfile row specially
     row = document.createElement('tr');
     col = document.createElement('td');
+    col.id = 'editSound';
     col.className = 'menuStatName';
     text = document.createTextNode('<?php echo _("Sound file"); ?>');
     col.appendChild(text);
diff --git a/shout/templates/recordings/list.inc b/shout/templates/recordings/list.inc
new file mode 100644 (file)
index 0000000..dc4f6f4
--- /dev/null
@@ -0,0 +1,45 @@
+<div class="header">
+    <ul id="controls">
+        <?php
+        $addurl = Horde::applicationUrl('recordings.php');
+        $addurl = Horde_Util::addParameter($addurl, 'action', 'add');
+        ?>
+        <li><a href="<?php echo $addurl; ?>">
+            <?php echo Horde::img('recording-add.png'); ?>&nbsp;New Recording
+            </a>
+        </li>
+    </ul>
+    Account: <?php echo $_SESSION['shout']['accounts'][$curaccount]; ?>
+</div>
+
+<div id="extensionList">
+    <table width="100%" cellspacing="0" class="striped">
+        <tr><?php // FIXME: Change Size column to recording length ?>
+            <td class="uheader">Name</td>
+            <td class="uheader">Size</td>
+        </tr>
+        <?php
+            foreach ($recordings as $name => $info) {
+
+                $url = Horde::applicationUrl("recordings.php");
+                $url = Horde_Util::addParameter($url,
+                    array(
+                        'name' => $name,
+                    )
+                );
+                $editurl = Horde_Util::addParameter($url, 'action', 'edit');
+                $deleteurl = Horde_Util::addParameter($url, 'action', 'delete');
+        ?>
+        <tr class="item" style="vertical-align: top">
+            <td>
+                <?php echo Horde::link($editurl); echo $info['name']; ?></a>
+            </td>
+            <td>
+                <?php echo $info['size']; ?>
+            </td>
+        </tr>
+        <?php
+            }
+        ?>
+    </table>
+</div>
diff --git a/shout/themes/graphics/recording-add.png b/shout/themes/graphics/recording-add.png
new file mode 100755 (executable)
index 0000000..965c503
Binary files /dev/null and b/shout/themes/graphics/recording-add.png differ