Shout: Continue working on dialplan editor UI
authorBen Klang <ben@alkaloid.net>
Sun, 28 Feb 2010 22:22:23 +0000 (17:22 -0500)
committerBen Klang <ben@alkaloid.net>
Sun, 28 Feb 2010 22:22:23 +0000 (17:22 -0500)
shout/config/conf.xml
shout/dialplan.php
shout/lib/Ajax/Application.php
shout/lib/Application.php
shout/lib/Driver/Sql.php
shout/lib/Shout.php
shout/templates/dialplan/show.inc [deleted file]
shout/templates/menu.inc
shout/themes/screen.css

index cb5ba5b..ab0cf07 100644 (file)
@@ -19,7 +19,6 @@
     <case name="Sql" desc="SQL">
      <configsection name="params">
       <configsql switchname="driverconfig" />
-      <configstring name="table" desc="Table to hold the list of contexts/customers" required="true">shout_contexts</configstring>
      </configsection>
     </case>
    </configswitch>
    </configswitch>
   </configsection>
  </configtab>
+ <configtab name="dialplan" desc="Dialplan">
+  <configsection name="dialplan">
+   <configheader>Dialplan Storage</configheader>
+   <configswitch name="driver" desc="What backend should we use for storing Asterisk dialplan information?">Sql
+    <case name="Ldap" desc="LDAP">
+     <configsection name="params">
+      <configldap switchname="driverconfig" />
+     </configsection>
+    </case>
+    <case name="Sql" desc="SQL">
+     <configsection name="params">
+      <configsql switchname="driverconfig" />
+      <configstring name="table" desc="Table to hold the dialplan" required="true">extensions_table</configstring>
+     </configsection>
+    </case>
+   </configswitch>
+  </configsection>
+ </configtab>
 </configuration>
 
index a801ed2..a08413d 100644 (file)
@@ -14,10 +14,28 @@ $shout = Horde_Registry::appInit('shout');
 
 require_once SHOUT_BASE . '/lib/Forms/ExtensionForm.php';
 
-//$action = Horde_Util::getFormData('action');
-$action = 'show';
+$action = Horde_Util::getFormData('action');
+$menu = Horde_Util::getFormData('menu');
 $context = $_SESSION['shout']['context'];
 
+$menus = $shout->storage->getMenus($context);
+
+switch($action) {
+case 'edit':
+    if (!isset($menus[$menu])) {
+        $notification->push(_("That menu does not exist."), 'horde.error');
+        $action = 'list';
+        break;
+    }
+    $menu = $menus[$menu];
+    break;
+case 'list':
+default:
+    $action = 'list';
+    break;
+}
+
+Horde::addScriptFile('stripe.js', 'horde');
 Horde::addScriptFile('prototype.js', 'horde');
 
 require SHOUT_TEMPLATES . '/common-header.inc';
index 054bd42..55075ff 100644 (file)
@@ -84,5 +84,31 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base
         }
     }
 
+    /**
+     * TODO
+     */
+    public function getMenuInfo()
+    {
+        $vars = $this->_vars;
+        $shout = Horde_Registry::appInit('shout');
+        $context = $_SESSION['shout']['context'];
+        $menus = $shout->storage->getMenus($context);
+        $menu = $vars->menu;
+        if (!isset($menus[$menu])) {
+            Horde::logMessage("User requested a menu that does not exist.", __FILE__, __LINE__, PEAR_LOG_ERR);
+            $notification->push(_("That menu does not exist."), 'horde.error');
+            $action = 'list';
+            // FIXME notifications
+            return false;
+        }
+        try {
+            $data['meta'] = $menus[$menu];
+            $data['actions'] = $shout->dialplan->getMenuActions($context, $menu);
+            return $data;
+        } 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;
+        }
+    }
 }
-
index 81dabd6..4110a39 100644 (file)
@@ -45,7 +45,7 @@ class Shout_Application extends Horde_Registry_Application
     /**
      * TODO
      */
-    public $contexts = null;
+    public $storage = null;
 
     /**
      * TODO
@@ -60,6 +60,11 @@ class Shout_Application extends Horde_Registry_Application
     /**
      * TODO
      */
+    public $dialplan = null;
+
+    /**
+     * TODO
+     */
     static protected $_perms = array();
 
     /**
@@ -69,12 +74,13 @@ class Shout_Application extends Horde_Registry_Application
      */
     protected function _init()
     {
-        $this->contexts = Shout_Driver::factory('storage');
+        $this->storage = Shout_Driver::factory('storage');
         $this->extensions = Shout_Driver::factory('extensions');
         $this->devices = Shout_Driver::factory('devices');
+        $this->dialplan = Shout_Driver::factory('dialplan');
 
         try {
-            $contexts = $this->contexts->getContexts();
+            $contexts = $this->storage->getContexts();
         } catch (Shout_Exception $e) {
             $GLOBALS['notification']->push($e);
             $contexts = false;
index 2f5f829..7573d89 100644 (file)
@@ -48,8 +48,7 @@ class Shout_Driver_Sql extends Shout_Driver
     {
         $this->_connect();
 
-        $sql = 'SELECT context_name FROM %s';
-        $sql = sprintf($sql, $this->_params['table']);
+        $sql = 'SELECT context_name FROM shout_contexts';
         $vars = array();
 
         $msg = 'SQL query in Shout_Driver_Sql#getContexts(): ' . $sql;
@@ -66,10 +65,7 @@ class Shout_Driver_Sql extends Shout_Driver
 
         $contexts = array();
         while ($row && !($row instanceof PEAR_Error)) {
-            /* Add this new foo to the $_foo list. */
             $contexts[] = $row['context_name'];
-
-            /* Advance to the new row in the result set. */
             $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
         }
 
@@ -77,6 +73,50 @@ class Shout_Driver_Sql extends Shout_Driver
          return $contexts;
     }
 
+    public function getMenus($context)
+    {
+        static $menus;
+        if (isset($menus[$context])) {
+            return $menus[$context];
+        }
+
+        $this->_connect();
+
+        $sql = 'SELECT menu_name, menu_description, menu_soundfile ' .
+               'FROM shout_menus WHERE context_name = ?';
+        $vars = array($context);
+
+        $msg = 'SQL query in Shout_Driver_Sql#getContexts(): ' . $sql;
+        Horde::logMessage($msg, __FILE__, __LINE__, PEAR_LOG_DEBUG);
+        $result = $this->_db->query($sql, $vars);
+        if ($result instanceof PEAR_Error) {
+            throw new Shout_Exception($result);
+        }
+
+        $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
+        if ($row instanceof PEAR_Error) {
+            throw new Shout_Exception($row);
+        }
+
+        $menus[$context] = array();
+        while ($row && !($row instanceof PEAR_Error)) {
+            $menu = $row['menu_name'];
+            $menus[$context][$menu] = array(
+                'name' => $menu,
+                'description' => $row['menu_description'],
+                'soundfile' => $row['menu_soundfile']
+            );
+            $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
+        }
+        $result->free();
+        return $menus[$context];
+    }
+
+    function getMenuActions($context, $menu)
+    {
+        return array();
+    }
+
     /**
      * Get a list of devices for a given context
      *
index ebbf777..65e7b33 100644 (file)
@@ -30,10 +30,10 @@ class Shout
 
         $menu = new Horde_Menu(Horde_Menu::MASK_ALL);
 
+        $menu->add(Horde::applicationUrl('dialplan.php'), _("Incoming Calls"), "dialplan.png");
         $menu->add(Horde::applicationUrl('extensions.php'), _("Extensions"), "user.png");
         $menu->add(Horde::applicationUrl('devices.php'), _("Devices"), "shout.png");
-        $menu->add(Horde::applicationUrl('routes.php'), _("Call Paths"));
-
+        $menu->add(Horde::applicationUrl('recordings.php'), _("Recordings"), "recordings.png");
 
         if ($returnType == 'object') {
             return $menu;
diff --git a/shout/templates/dialplan/show.inc b/shout/templates/dialplan/show.inc
deleted file mode 100644 (file)
index 9123402..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<script type="text/javascript">
-<!--
-function editAction(digit)
-{
-    $('digitAction').show();
-}
-
-function saveAction(digit)
-{
-    $('digitAction').hide();
-}
-// -->
-</script>
-
-<div id="digitpad">
-  <div id="digitAction">
-      <div onClick="saveAction('x');">SAVE</div>
-  </div>
-  <div class="digit" onClick="editAction('1');"><span class="digitLabel">1</span></div>
-  <div class="digit" onClick="editAction('2');"><span class="digitLabel">2</span></div>
-  <div class="digit" onClick="editAction('3');"><span class="digitLabel">3</span></div>
-  <br style="clear:both;">
-  <div class="digit" onClick="editAction('4');"><span class="digitLabel">4</span></div>
-  <div class="digit" onClick="editAction('5');"><span class="digitLabel">5</span></div>
-  <div class="digit" onClick="editAction('6');"><span class="digitLabel">6</span></div>
-  <br style="clear:both;">
-  <div class="digit" onClick="editAction('7');"><span class="digitLabel">7</span></div>
-  <div class="digit" onClick="editAction('8');"><span class="digitLabel">8</span></div>
-  <div class="digit" onClick="editAction('9');"><span class="digitLabel">9</span></div>
-  <br style="clear:both;">
-  <div class="digit" onClick="editAction('*');"><span class="digitLabel">*</span></div>
-  <div class="digit" onClick="editAction('0');"><span class="digitLabel">0</span></div>
-  <div class="digit" onClick="editAction('#');"><span class="digitLabel">#</span></div>
-</div>
-
-<script type="text/javascript">
-<!--
-$('digitAction').hide();
-// -->
-</script>
\ No newline at end of file
index 7c08e9e..0139928 100644 (file)
@@ -10,7 +10,7 @@ $menu_view = $prefs->getValue('menu_view');
 <?php
 // Only show the context selector if there is more than one available context
 try {
-    $contexts = $shout->contexts->getContexts();
+    $contexts = $shout->storage->getContexts();
 } catch (Exception $e) {
     $contexts = array();
 }
index ed9f31a..f555193 100644 (file)
@@ -68,6 +68,19 @@ ul {
     font-style: italic;
 }
 
+#menuInfo {
+    float: left;
+    width: 300px;
+}
+
+#menuInfo img:hover {
+    cursor: pointer;
+}
+
+.menuStatName {
+    font-weight: bold;
+}
+
 #digitpad {
     width: 300px;
     height: 400px;
@@ -87,6 +100,8 @@ ul {
     padding: 3px;
     margin: 1px;
     background-image: url('graphics/digit-bg.png');
+    -moz-border-radius: 10px;
+    -webkit-border-radius: 10px;
 }
 
 .digitLabel {