Author: jablko
Date: Mon Oct 25 17:56:23 2010
New Revision: 8497

Log:
Extend default edit action

Modified:
   trunk/apps/qubit/modules/staticpage/actions/editAction.class.php
   trunk/apps/qubit/modules/staticpage/templates/editSuccess.php

Modified: trunk/apps/qubit/modules/staticpage/actions/editAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/staticpage/actions/editAction.class.php    Mon Oct 
25 17:44:41 2010        (r8496)
+++ trunk/apps/qubit/modules/staticpage/actions/editAction.class.php    Mon Oct 
25 17:56:23 2010        (r8497)
@@ -17,14 +17,23 @@
  * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-class StaticPageEditAction extends sfAction
+class StaticPageEditAction extends DefaultEditAction
 {
   public static
     $NAMES = array(
       'title',
-      'permalink',
+      'slug',
       'content');
 
+  protected function earlyExecute()
+  {
+    $this->resource = new QubitStaticPage;
+    if (isset($this->getRoute()->resource))
+    {
+      $this->resource = $this->getRoute()->resource;
+    }
+  }
+
   protected function addField($name)
   {
     switch ($name)
@@ -36,70 +45,44 @@
 
         break;
 
-      default:
+      case 'slug':
+      case 'title':
         $this->form->setDefault($name, $this->resource[$name]);
         $this->form->setValidator($name, new sfValidatorString);
         $this->form->setWidget($name, new sfWidgetFormInput);
+
+      default:
+
+        return parent::addField($name);
     }
   }
 
   protected function processField($field)
   {
-    switch ($name = $field->getName())
+    switch ($field->getName())
     {
-      case 'permalink':
+      case 'slug':
 
         if (!$this->resource->isProtected())
         {
-          $this->resource[$name] = $this->form->getValue($name);
+          $this->resource->slug = $this->form->getValue('slug');
         }
 
         break;
 
       default:
-        $this->resource[$name] = $this->form->getValue($name);
-    }
-  }
 
-  protected function processForm()
-  {
-    foreach ($this->form as $field)
-    {
-      $this->processField($field);
+        return parent::processField($field)
     }
-
-    $this->resource->save();
   }
 
   public function execute($request)
   {
-    $this->form = new sfForm;
-
-    $this->resource = new QubitStaticPage;
+    parent::execute($request);
 
-    if (isset($request->id))
-    {
-      $this->resource = QubitStaticPage::getById($request->id);
-
-      if (!isset($this->resource))
-      {
-        $this->forward404();
-      }
-    }
-
-    // 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);
-    }
-
-    // Post form
     if ($request->isMethod('post'))
     {
       $this->form->bind($request->getPostParameters());
-
       if ($this->form->isValid())
       {
         $this->processForm();

Modified: trunk/apps/qubit/modules/staticpage/templates/editSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/staticpage/templates/editSuccess.php       Mon Oct 
25 17:44:41 2010        (r8496)
+++ trunk/apps/qubit/modules/staticpage/templates/editSuccess.php       Mon Oct 
25 17:56:23 2010        (r8497)
@@ -1,8 +1,10 @@
-<h1><?php echo __('Add/edit page') ?></h1>
+<h1><?php echo __('Edit page') ?></h1>
 
 <h1 class="label"><?php echo render_title($resource) ?></h1>
 
-<?php if (isset($sf_request->id)): ?>
+<?php echo $form->renderGlobalErrors() ?>
+
+<?php if (isset($sf_request->getAttribute('sf_route')->resource)): ?>
   <?php echo $form->renderFormTag(url_for(array($resource, 'module' => 
'staticpage', 'action' => 'edit'))) ?>
 <?php else: ?>
   <?php echo $form->renderFormTag(url_for(array('module' => 'staticpage', 
'action' => 'create'))) ?>
@@ -12,19 +14,13 @@
 
   <?php echo render_field($form->title, $resource) ?>
 
-  <div class="form-item">
-
-    <?php echo $form->permalink->renderLabel() ?><?php if 
($resource->isProtected()): ?><?php echo image_tag('lock_mini') ?><?php endif; 
?>
-
-    <?php if ($resource->isProtected()): ?>
-      <?php echo $form->permalink->render(array('class' => 'disabled', 
'disabled' => 'disabled')) ?>
-    <?php else: ?>
-      <?php echo $form->permalink ?>
-    <?php endif; ?>
-
-  </div>
+  <?php if ($resource->isProtected()): ?>
+    <?php echo $form->slug->renderRow(array('class' => 'readOnly', 'disabled' 
=> 'disabled')) ?>
+  <?php else: ?>
+    <?php echo $form->slug->renderRow() ?>
+  <?php endif; ?>
 
-  <?php echo render_field($form->content, $resource, array('class' => 
'resizable', 'id' => 'staticpage-content')) ?>
+  <?php echo render_field($form->content, $resource, array('class' => 
'resizable')) ?>
 
   <div class="actions section">
 
@@ -32,11 +28,11 @@
 
     <div class="content">
       <ul class="clearfix links">
-        <?php if (isset($sf_request->id)): ?>
-          <li><?php echo link_to(__('Cancel'), array($resource, 'module' => 
'staticpage', 'action' => 'index')) // Force to use index action ?></li>
+        <?php if (isset($sf_request->getAttribute('sf_route')->resource)): ?>
+          <li><?php echo link_to(__('Cancel'), array($resource, 'module' => 
'staticpage')) ?></li>
           <li><input class="form-submit" type="submit" value="<?php echo 
__('Save') ?>"/></li>
         <?php else: ?>
-          <li><?php echo link_to(__('Cancel'), array($resource, 'module' => 
'staticpage', 'action' => 'list')) ?></li>
+          <li><?php echo link_to(__('Cancel'), array('module' => 'staticpage', 
'action' => 'list')) ?></li>
           <li><input class="form-submit" type="submit" value="<?php echo 
__('Create') ?>"/></li>
         <?php endif; ?>
       </ul>

-- 
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