Shout: Continue implementing action editor for dialplan
authorBen Klang <ben@alkaloid.net>
Thu, 4 Mar 2010 03:01:48 +0000 (22:01 -0500)
committerBen Klang <ben@alkaloid.net>
Thu, 4 Mar 2010 03:01:48 +0000 (22:01 -0500)
shout/lib/Ajax/Application.php
shout/lib/Shout.php
shout/templates/dialplan/edit.inc

index b466f7e..f795743 100644 (file)
@@ -141,7 +141,7 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base
             $context = $_SESSION['shout']['context'];
             $actions = Shout::getMenuActions();
             $action = $actions[$action];
-            $form = new Horde_Form($vars, $action['description']);
+            $form = new Horde_Form($vars, $action['description'], 'editActionForm');
             foreach($action['args'] as $name => $info) {
                 $defaults = array(
                     'required' => true,
@@ -149,13 +149,13 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base
                     'description' => null,
                     'params' => array()
                 );
-                //$info = array_merge($info, $defaults);
+                $info = array_merge($defaults, $info);
                 $form->addVariable($info['name'], $name, $info['type'],
                                    $info['required'], $info['readonly'],
                                    $info['description'], $info['params']);
             }
             $this->_responseType = 'html';
-            $form->renderActive();
+            $form->renderActive(null, null, 'javascript:saveAction()');
             $output = ob_get_clean();
             return $output;
         } catch (Exception $e) {
@@ -165,6 +165,11 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base
         }
     }
 
+    public function saveAction()
+    {
+        return null;
+    }
+
     public function responseType()
     {
         return $this->_responseType;
index 2b0c02f..6b183b3 100644 (file)
@@ -146,7 +146,7 @@ class Shout
             'menu' => array(
                 'description' => _("Jump to menu."),
                 'args' => array (
-                    'menu' => array(
+                    'menuName' => array(
                         'name' => _("Menu"),
                         'type' => 'enum',
                         'required' => true,
index 5686754..58c6d90 100644 (file)
@@ -30,10 +30,12 @@ var ajax_url = '<?php echo Horde::getServiceLink('ajax', 'shout') ?>';
 var menu = '<?php echo $menu['name']; ?>';
 var menuInfo = $H();
 var menuActions = $H();
+var curDigit = null;
 
 function editAction(digit)
 {
     if ($('selectActionForm') == null) {
+        curDigit = digit;
         // Draw the selectActionForm
         $('editAction').show();
         while ((e = $('editAction').childNodes[0]) != null) {
@@ -53,6 +55,9 @@ function editAction(digit)
         });
         form.appendChild(select);
         $('editAction').appendChild(form);
+        var div = document.createElement('div');
+        div.id = 'editActionFormContainer';
+        $('editAction').appendChild(div);
     } else {
         var action = null;
         // Draw the options for this action
@@ -63,10 +68,7 @@ function editAction(digit)
         });
         var params = $H({'action': action});
         var actionForm;
-        var div = document.createElement('div');
-        div.id = 'editActionForm';
-        $('editAction').appendChild(div);
-        new Ajax.Updater('editActionForm', ajax_url + 'getActionForm',
+        new Ajax.Updater('editActionFormContainer', ajax_url + 'getActionForm',
         {
             method: 'post',
             parameters: params
@@ -76,7 +78,21 @@ function editAction(digit)
 
 function saveAction(digit)
 {
-    $('editAction').hide();
+    var params = $('editActionForm').serialize(true);
+    params.menu = menuInfo.get('meta').name;
+    params.digit = curDigit;
+    new Ajax.Request(ajax_url + 'saveAction',
+    {
+        method: 'post',
+        parameters: params,
+        onSuccess: function(r) {
+            alert('FIXME');
+            while ((e = $('editAction').childNodes[0]) != null) {
+                $('editAction').removeChild(e);
+            }
+            $('editAction').hide();
+        }
+    });
 }
 
 function changeSoundfile()