Author: jablko
Date: Mon Oct 25 09:13:35 2010
New Revision: 8462

Log:
Extend default edit action

Modified:
   trunk/apps/qubit/modules/term/actions/editAction.class.php

Modified: trunk/apps/qubit/modules/term/actions/editAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/term/actions/editAction.class.php  Mon Oct 25 
08:37:14 2010        (r8461)
+++ trunk/apps/qubit/modules/term/actions/editAction.class.php  Mon Oct 25 
09:13:35 2010        (r8462)
@@ -17,7 +17,7 @@
  * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-class TermEditAction extends sfAction
+class TermEditAction extends DefaultEditAction
 {
   // Arrays not allowed in class constants
   public static
@@ -40,6 +40,58 @@
   protected 
     $updatedLabel = false;
 
+  protected function earlyExecute()
+  {
+    $this->form->getValidatorSchema()->setOption('allow_extra_fields', true);
+
+    $this->resource = new QubitTerm;
+    if (isset($request->id))
+    {
+      $this->resource = QubitTerm::getById($request->id);
+
+      if (!$this->resource instanceof QubitTerm)
+      {
+        $this->forward404();
+      }
+
+      // Check authorization
+      if (!(QubitAcl::check($this->resource, 'update') || 
QubitAcl::check($this->resource, 'translate')))
+      {
+        QubitAcl::forwardUnauthorized();
+      }
+
+      // Add optimistic lock
+      $this->form->setDefault('serialNumber', $this->resource->serialNumber);
+      $this->form->setValidator('serialNumber', new sfValidatorInteger);
+      $this->form->setWidget('serialNumber', new sfWidgetFormInputHidden);
+
+      QubitTreeView::addAssets($this->response);
+    }
+    else
+    {
+      if (isset($request->parent) && 0 < strlen($request->parent))
+      {
+        $params = 
$this->context->routing->parse(Qubit::pathInfo($request->parent));
+        $this->resource->parentId = $params['id'];
+      }
+      else
+      {
+        $this->resource->parentId = QubitTerm::ROOT_ID;
+      }
+
+      if (isset($request->taxonomyId))
+      {
+        $this->resource->taxonomyId = $request->taxonomyId;
+      }
+
+      // Check authorization to create term
+      if (!QubitAcl::check($this->resource, 'create', array('taxonomyId' => 
$request->taxonomyId)))
+      {
+        QubitAcl::forwardUnauthorized();
+      }
+    }
+  }
+
   protected function addField($name)
   {
     switch ($name)
@@ -159,6 +211,10 @@
         $this->form->setWidget($name, new 
QubitWidgetFormInputMany(array('defaults' => $defaults, 'fieldname' => 
'content')));
 
         break;
+
+      default:
+
+        return parent::addField($name);
     }
   }
 
@@ -360,7 +416,8 @@
         break;
 
       default:
-        $this->resource[$field->getName()] = 
$this->form->getValue($field->getName());
+
+        return parent::processField($field);
     }
   }
 
@@ -371,10 +428,7 @@
    */
   protected function processForm()
   {
-    foreach ($this->form as $field)
-    {
-      $this->processField($field);
-    }
+    parent::processForm();
 
     // Assign root node as parent, if another parent (broad-term) is not
     // selected
@@ -394,65 +448,8 @@
 
   public function execute($request)
   {
-    $this->form = new sfForm;
-    $this->form->getValidatorSchema()->setOption('allow_extra_fields', true);
-
-    $this->resource = new QubitTerm;
-    if (isset($request->id))
-    {
-      $this->resource = QubitTerm::getById($request->id);
-
-      if (!$this->resource instanceof QubitTerm)
-      {
-        $this->forward404();
-      }
-
-      // Check authorization
-      if (!(QubitAcl::check($this->resource, 'update') || 
QubitAcl::check($this->resource, 'translate')))
-      {
-        QubitAcl::forwardUnauthorized();
-      }
-
-      // Add optimistic lock
-      $this->form->setDefault('serialNumber', $this->resource->serialNumber);
-      $this->form->setValidator('serialNumber', new sfValidatorInteger);
-      $this->form->setWidget('serialNumber', new sfWidgetFormInputHidden);
-
-      QubitTreeView::addAssets($this->response);
-    }
-    else
-    {
-      if (isset($request->parent) && 0 < strlen($request->parent))
-      {
-        $params = 
$this->context->routing->parse(Qubit::pathInfo($request->parent));
-        $this->resource->parentId = $params['id'];
-      }
-      else
-      {
-        $this->resource->parentId = QubitTerm::ROOT_ID;
-      }
-
-      if (isset($request->taxonomyId))
-      {
-        $this->resource->taxonomyId = $request->taxonomyId;
-      }
-
-      // Check authorization to create term
-      if (!QubitAcl::check($this->resource, 'create', array('taxonomyId' => 
$request->taxonomyId)))
-      {
-        QubitAcl::forwardUnauthorized();
-      }
-    }
-
-    // HACK Use static::$NAMES in PHP 5.3,
-    // http://php.net/oop5.late-static-bindings
-    $class = new ReflectionClass($this);
-    foreach ($class->getStaticPropertyValue('NAMES') as $name)
-    {
-      $this->addField($name);
-    }
+    parent::execute($request);
 
-    // Post form
     if ($request->isMethod('post'))
     {
       $this->form->bind($request->getPostParameters());

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to