Fix action handling.
authorGunnar Wrobel <p@rdus.de>
Mon, 4 May 2009 08:24:33 +0000 (10:24 +0200)
committerGunnar Wrobel <p@rdus.de>
Mon, 4 May 2009 08:24:33 +0000 (10:24 +0200)
koward/lib/Koward/Controller/ObjectController.php
koward/lib/Koward/Form/Actions.php

index ef3b585..6fe0752 100644 (file)
@@ -151,21 +151,10 @@ class ObjectController extends Koward_Controller_Application
                 $this->allowEdit = $this->koward->hasAccess('object/edit/' . $this->object_type,
                                                             Koward::PERM_EDIT);
 
-                $actions = $this->object->getActions();
-                if (!empty($actions)) {
-                    $buttons = array();
-                    foreach ($actions as $action) {
-                        if (isset($this->koward->objects[$this->object_type]['actions'][$action])
-                            && $this->koward->hasAccess('object/action/' . $this->object_type . '/' . $action,
-                                                        Koward::PERM_EDIT)) {
-                            $buttons[] = $this->koward->objects[$this->object_type]['actions'][$action];
-                        }
-                    }
-                }
-                    
+                $buttons = $this->_getButtons($this->object, $this->object_type);
                 if (!empty($buttons)) {
                     try {
-                        $this->actions = new Koward_Form_Actions($buttons);
+                        $this->actions = new Koward_Form_Actions($this->object, $buttons);
 
                         $this->post = $this->urlFor(array('controller' => 'object', 
                                                       'action' => 'view',
@@ -176,8 +165,8 @@ class ObjectController extends Koward_Controller_Application
 
                             /** Reload the object */
                             $this->object = $this->koward->getObject($this->params->id);
-                            $actions = $this->object->getActions();
-                            $this->actions = new Koward_Form_Actions($this->object);
+                            $buttons = $this->_getButtons($this->object, $this->object_type);
+                            $this->actions = new Koward_Form_Actions($this->object, $buttons);
                         }
                     } catch (Exception $e) {
                         $this->koward->notification->push($e->getMessage(), 'horde.error');
@@ -204,6 +193,22 @@ class ObjectController extends Koward_Controller_Application
         $this->render();
     }
 
+    private function _getButtons(&$object, $type)
+    {
+        $actions = $object->getActions();
+        if (!empty($actions)) {
+            $buttons = array();
+            foreach ($actions as $action) {
+                if (isset($this->koward->objects[$type]['actions'][$action])
+                    && $this->koward->hasAccess('object/action/' . $type . '/' . $action,
+                                                Koward::PERM_EDIT)) {
+                    $buttons[] = $this->koward->objects[$type]['actions'][$action];
+                }
+            }
+        }
+        return $buttons;
+    }
+
     public function add()
     {
         $this->object = null;
index 69db861..eb081ed 100644 (file)
@@ -15,7 +15,7 @@ class Koward_Form_Actions extends Horde_Form {
      */
     protected $koward;
 
-    public function __construct($buttons)
+    public function __construct(&$object, $buttons)
     {
         $this->koward = &Koward::singleton();
 
@@ -23,6 +23,8 @@ class Koward_Form_Actions extends Horde_Form {
 
         $this->setTitle(_("Object actions"));
 
+        $this->object  = $object;
+
         if (!empty($buttons)) {
             $this->setButtons($buttons);
         }
@@ -34,7 +36,8 @@ class Koward_Form_Actions extends Horde_Form {
 
         $submit = Util::getFormData('submitbutton');
         if (!empty($submit)) {
-            foreach ($this->koward->objects[$this->type]['actions'] as $action => $label) {
+            $type = $this->koward->getType($this->object);
+            foreach ($this->koward->objects[$type]['actions'] as $action => $label) {
                 if ($submit == $label) {
                     $this->object->$action();
                 }