Shout: improve menu selection UI
authorBen Klang <ben@alkaloid.net>
Thu, 25 Mar 2010 23:26:23 +0000 (19:26 -0400)
committerBen Klang <ben@alkaloid.net>
Thu, 25 Mar 2010 23:27:29 +0000 (19:27 -0400)
shout/dialplan.php
shout/lib/Ajax/Application.php
shout/templates/dialplan/edit.inc
shout/templates/dialplan/list.inc [deleted file]

index de4134d..f4b8c06 100644 (file)
@@ -49,21 +49,14 @@ case 'add':
 
     break;
 case 'edit':
-    if (!isset($menus[$menu])) {
-        $notification->push(_("That menu does not exist."), 'horde.error');
-        $action = 'list';
-        break;
-    }
-    $menu = $menus[$menu];
+default:
+    $action = 'edit';
     try {
         $destinations = $shout->extensions->getExtensions($curaccount);
     } catch (Exception $e) {
         $notification->push(_("Problem getting destination information."));
     }
-    break;
-case 'list':
-default:
-    $action = 'list';
+
     break;
 }
 
index df8eba9..3416163 100644 (file)
@@ -102,24 +102,17 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base
     /**
      * TODO
      */
-    public function getMenuInfo()
+    public function getMenus()
     {
         try {
-            $vars = $this->_vars;
             $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
             $account = $_SESSION['shout']['curaccount'];
             $menus = $shout->storage->getMenus($account);
-            $menu = $vars->menu;
-            if (!isset($menus[$menu])) {
-                Horde::logMessage("User requested a menu that does not exist.", 'ERR');
-                //$GLOBALS['notification']->push(_("That menu does not exist."), 'horde.error');
-                // FIXME notifications
-                return false;
+            foreach ($menus as $menu => $info) {
+                // Fill in the actions for each menu
+                $menus[$menu]['actions'] = $shout->dialplan->getMenuActions($account, $menu);
             }
-
-            $data['meta'] = $menus[$menu];
-            $data['actions'] = $shout->dialplan->getMenuActions($account, $menu);
-            return $data;
+            return $menus;
         } catch (Exception $e) {
             //FIXME: Create a way to notify the user of the failure.
             die(var_dump($e));
@@ -142,7 +135,7 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base
             $vars = $this->_vars;
             $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
             $account = $_SESSION['shout']['curaccount'];
-            $actions = Shout::getMenuActions($contex, $menu);
+            $actions = Shout::getMenuActions();
             return $actions;
         } catch (Exception $e) {
             //FIXME: Create a way to notify the user of the failure.
index fb491fd..1296c74 100644 (file)
@@ -1,6 +1,32 @@
 <div id="dialplan">
-    <table id="menuInfo" class="striped">
-    </table>
+    <div id="menuInfo">
+        <table class="striped">
+            <tr>
+                <td class="metaStatName">Menu</td>
+                <td class="metaStatInfo"><select id="menu.select" onchange="refreshMenu()"></select></td>
+            </tr>
+            <tr>
+                <td class="metaStatName">Description</td>
+                <td class="metaStatInfo" id="menu.description"></td>
+            </tr>
+            <tr>
+                <td class="metaStatName">Sound File</td>
+                <td class="metaStatInfo"><span id="menu.soundfile"></span></td>
+            </tr>
+        </table>
+        <br style="clear:both;">
+        <ul id="controls">
+        <?php
+        $addurl = Horde::applicationUrl('dialplan.php');
+        $addurl = Horde_Util::addParameter($addurl, 'action', 'add');
+
+        ?>
+        <li class="button"><a href="<?php echo $addurl; ?>">
+            <?php echo Horde::img('add-menu.png'); ?>&nbsp;New Menu
+            </a>
+        </li>
+        </ul>
+    </div>
 
     <div id="digitpad">
       <div id="editActionOverlay">
@@ -31,7 +57,7 @@
 <script type="text/javascript">
 <!--
 var ajax_url = '<?php echo Horde::getServiceLink('ajax', 'shout') ?>';
-var menu = '<?php echo $menu['name']; ?>';
+var curmenu = null;
 var menuInfo = $H();
 var menuActions = $H(<?php echo Horde_Serialize::serialize(Shout::getMenuActions(), Horde_Serialize::JSON, Horde_Nls::getCharset()); ?>);
 var destinations = $H(<?php echo Horde_Serialize::serialize($destinations, Horde_Serialize::JSON, Horde_Nls::getCharset()); ?>);
@@ -124,7 +150,7 @@ function saveAction(digit)
             {
                 method: 'post',
                 parameters: $H({
-                    'menu': menu
+                    'menu': curmenu
                 }),
                 onSuccess: function(r) {
                     menuInfo = $H(r.responseJSON.response);
@@ -205,45 +231,19 @@ function playSoundFile()
 
 function refreshMenu()
 {
-    var row;
-    var col;
-    var img;
-    var text;
-    empty('menuInfo');
-
-    var meta = menuInfo.get('meta');
+    curmenu = $('menu.select').value;
+    if (!curmenu || !menuInfo.get(curmenu)) {
+        // TODO Show an error of some kind
+        return false;
+    }
 
-    // Draw the menu metainfo box
-    row = getMetaRow('<?php echo _("Menu Name"); ?>', meta.name);
-    $('menuInfo').appendChild(row);
-    row = getMetaRow('<?php echo _("Description"); ?>', meta.description);
-    $('menuInfo').appendChild(row);
+    var text = document.createTextNode(menuInfo.get(curmenu).description);
+    empty('menu.description');
+    $('menu.description').appendChild(text);
 
-    // Handle the soundfile row specially
-    row = document.createElement('tr');
-    col = document.createElement('td');
-    col.className = 'menuStatName';
-    text = document.createTextNode('<?php echo _("Sound file"); ?>');
-    col.appendChild(text);
-    row.appendChild(col);
-    col = document.createElement('td');
-    col.id = 'editSound';
-    col.className='menuStatValue';
-    text = document.createTextNode(meta.soundfile);
-    col.appendChild(text);
-    img = document.createElement('img');
-    img.src = '<?php echo Horde_Themes::img('edit.png') ?>';
-    img.alt = '<?php echo _("Change Sound File"); ?>';
-    img.setAttribute('onclick', 'changeSoundFile()');
-    col.appendChild(img);
-    img = document.createElement('img');
-    img.src = '<?php echo Horde_Themes::img('recordings.png') ?>';
-    img.alt = '<?php echo _("Play Sound File"); ?>';
-    img.setAttribute('onclick', 'playSoundFile()');
-    img.setAttribute("style", img.getAttribute("style") + "; float:right; ");
-    col.appendChild(img);
-    row.appendChild(col);
-    $('menuInfo').appendChild(row);
+    var text = document.createTextNode(menuInfo.get(curmenu).soundfile);
+    empty('menu.soundfile');
+    $('menu.soundfile').appendChild(text);
 
     // Fill in the actions
     $H(menuInfo.get('actions')).each(function (pair) {
@@ -336,14 +336,18 @@ function empty(p)
 }
 
 $('editActionOverlay').hide();
-new Ajax.Request(ajax_url + 'getMenuInfo',
+new Ajax.Request(ajax_url + 'getMenus',
 {
-    method: 'post',
-    parameters: $H({
-        'menu': menu
-    }),
+    method: 'get',
     onSuccess: function(r) {
         menuInfo = $H(r.responseJSON.response);
+        menuInfo.each(function (item) {
+            var option = document.createElement('option');
+            option.value = item.key;
+            var text = document.createTextNode(item.value.name);
+            option.appendChild(text);
+            $('menu.select').appendChild(option);
+        })
         refreshMenu();
     }
 });
diff --git a/shout/templates/dialplan/list.inc b/shout/templates/dialplan/list.inc
deleted file mode 100644 (file)
index 9ebb3c7..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<div class="header">
-    Account: <?php echo $_SESSION['shout']['accounts'][$curaccount]; ?>
-</div>
-<?php
-$editurl = Horde::applicationUrl('dialplan.php');
-$editurl = Horde_Util::addParameter($editlink, 'action', 'edit');
-?>
-<div id="extensionList">
-    <table width="100%" cellspacing="0" class="striped">
-        <tr>
-            <th width="15%" class="uheader">Menu Name</th>
-            <th width="85%" class="uheader">Description</th>
-        </tr>
-        <?php foreach ($menus as $menu) {
-            $url = Horde_Util::addParameter($editurl, 'menu', $menu['name']);
-            ?>
-        <tr>
-            <td><?php echo Horde::link($url) . $menu['name'] . '</a>'; ?></td>
-            <td><?php echo $menu['description']; ?></td>
-        </tr>
-        <?php } ?>
-    </table>
-</div>
-<ul id="controls">
-    <?php
-    $addurl = Horde::applicationUrl('dialplan.php');
-    $addurl = Horde_Util::addParameter($addurl, 'action', 'add');
-
-    ?>
-    <li class="button"><a href="<?php echo $addurl; ?>">
-        <?php echo Horde::img('add-menu.png'); ?>&nbsp;New Menu
-        </a>
-    </li>
-</ul>
\ No newline at end of file