Shout: Enable removing actions from digits
authorBen Klang <ben@alkaloid.net>
Sun, 28 Mar 2010 02:33:14 +0000 (22:33 -0400)
committerBen Klang <ben@alkaloid.net>
Sun, 28 Mar 2010 02:33:14 +0000 (22:33 -0400)
shout/lib/Ajax/Application.php
shout/lib/Driver/Sql.php
shout/lib/Shout.php
shout/templates/dialplan/edit.inc

index 449dfaf..3d42a16 100644 (file)
@@ -139,6 +139,13 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base
             $digit = $vars->get('digit');
             $menu = $vars->get('menu');
             $action = $vars->get('action');
+
+            if ($action == 'none') {
+                // Remove the menu action and return
+                $shout->dialplan->deleteMenuAction($account, $menu, $digit);
+                return true;
+            }
+
             $actions = Shout::getMenuActions();
             if (!isset($actions[$action])) {
                 throw new Shout_Exception('Invalid action requested.');
@@ -148,6 +155,7 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base
                 $args[$name] = $vars->get($name);
             }
             $shout->dialplan->saveMenuAction($account, $menu, $digit, $action, $args);
+            return true;
         } catch (Exception $e) {
             //FIXME: Create a way to notify the user of the failure.
             Horde::logMessage($e, 'ERR');
index 93e55ae..47c5680 100644 (file)
@@ -208,7 +208,7 @@ class Shout_Driver_Sql extends Shout_Driver
         return $menuActions[$menu];
     }
 
-    public function saveMenuAction($account, $menu, $digit, $action, $args)
+    public function deleteMenuAction($account, $menu, $digit)
     {
         // Remove any existing action
         $sql = 'DELETE FROM menu_entries WHERE menu_id = ' .
@@ -222,6 +222,11 @@ class Shout_Driver_Sql extends Shout_Driver
         if ($result instanceof PEAR_Error) {
             throw new Shout_Exception($result);
         }
+    }
+
+    public function saveMenuAction($account, $menu, $digit, $action, $args)
+    {
+        $this->deleteMenuAction($account, $menu, $digit);
 
         $sql = 'INSERT INTO menu_entries (menu_id, digit, action_id, args) ' .
                'VALUES((SELECT id FROM menus WHERE account_id = ' .
index d88a9c5..6291daa 100644 (file)
@@ -205,7 +205,12 @@ class Shout
                 'description' => _("Restart menu"),
                 'args' => array()
             ),
-            // TODO: Actions to implement: Queue
+            'none' => array(
+                'description' => _("No action"),
+                'args' => array()
+            )
+
+            // TODO: Actions to implement: Queue, VoicemailLogin
         );
     }
 
index 5e25c9e..6ca77ee 100644 (file)
@@ -132,11 +132,6 @@ function editAction(digit)
         if (menuInfo.get(curmenu).actions[digit] != null) {
             select.value = menuInfo.get(curmenu).actions[digit].action
         }
-        var option = document.createElement('option');
-        option.value = 'none';
-        var text = document.createTextNode('<?php echo _("No action"); ?>');
-        option.appendChild(text);
-        select.appendChild(option);
         $('selectAction').appendChild(select);
 
         // Cancel button
@@ -234,6 +229,7 @@ function editAction(digit)
             div.appendChild(img);
             break;
 
+        case 'directory':
         case 'rewind':
         case 'none':
             break;