Author: sevein
Date: Mon Jul 11 18:58:38 2011
New Revision: 9276

Log:
Add donor basic edit and index actions

Added:
   trunk/apps/qubit/modules/donor/actions/editAction.class.php
   trunk/apps/qubit/modules/donor/actions/indexAction.class.php
   trunk/apps/qubit/modules/donor/config/
   trunk/apps/qubit/modules/donor/config/view.yml
   trunk/apps/qubit/modules/donor/templates/editSuccess.php
   trunk/apps/qubit/modules/donor/templates/indexSuccess.php

Added: trunk/apps/qubit/modules/donor/actions/editAction.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/donor/actions/editAction.class.php Mon Jul 11 
18:58:38 2011        (r9276)
@@ -0,0 +1,114 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+class DonorEditAction extends DefaultEditAction
+{
+  // Arrays not allowed in class constants
+  public static
+    $NAMES = array(
+      'authorizedFormOfName');
+
+  protected function addField($name)
+  {
+    switch ($name)
+    {
+      case 'authorizedFormOfName':
+        $this->form->setDefault('authorizedFormOfName', 
$this->resource->authorizedFormOfName);
+        $this->form->setValidator('authorizedFormOfName', new 
sfValidatorString);
+        $this->form->setWidget('authorizedFormOfName', new sfWidgetFormInput);
+
+        break;
+
+      default:
+
+        return parent::addField($name);
+    }
+  }
+
+  protected function earlyExecute()
+  {
+    $this->form->getValidatorSchema()->setOption('allow_extra_fields', true);
+
+    $this->resource = new QubitDonor;
+
+    if (isset($this->getRoute()->resource))
+    {
+      $this->resource = $this->getRoute()->resource;
+
+      // Check that this isn't the root
+      if (!isset($this->resource->parent))
+      {
+        $this->forward404();
+      }
+
+      // Check user authorization
+      if (!QubitAcl::check($this->resource, 'update'))
+      {
+        QubitAcl::forwardUnauthorized();
+      }
+
+      // Add optimistic lock
+      $this->form->setDefault('serialNumber', $this->resource->serialNumber);
+      $this->form->setValidator('serialNumber', new sfValidatorInteger);
+      $this->form->setWidget('serialNumber', new sfWidgetFormInputHidden);
+    }
+    else
+    {
+      // Check user authorization
+      if (!QubitAcl::check($this->resource, 'create'))
+      {
+        QubitAcl::forwardUnauthorized();
+      }
+    }
+
+    $title = $this->context->i18n->__('Add new donor');
+    if (isset($this->getRoute()->resource))
+    {
+      if (1 > strlen($title = $this->resource->__toString()))
+      {
+        $title = $this->context->i18n->__('Untitled');
+      }
+
+      $title = $this->context->i18n->__('Edit %1%', array('%1%' => $title));
+    }
+
+    $this->response->setTitle("$title - {$this->response->getTitle()}");
+  }
+
+  public function execute($request)
+  {
+    parent::execute($request);
+
+    if ($request->isMethod('post'))
+    {
+      $this->form->bind($request->getPostParameters());
+
+      if ($this->form->isValid())
+      {
+        $this->processForm();
+
+        $this->resource->save();
+
+        // $this->updateContactInformation();
+
+        $this->redirect(array($this->resource, 'module' => 'donor'));
+      }
+    }
+  }
+}

Added: trunk/apps/qubit/modules/donor/actions/indexAction.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/donor/actions/indexAction.class.php        Mon Jul 
11 18:58:38 2011        (r9276)
@@ -0,0 +1,65 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+class DonorIndexAction extends sfAction
+{
+  public function execute($request)
+  {
+    $this->resource = $this->getRoute()->resource;
+
+    // Check that this isn't the root
+    if (!isset($this->resource->parent))
+    {
+      $this->forward404();
+    }
+
+    // Check user authorization
+    if (!QubitAcl::check($this->resource, 'read'))
+    {
+      QubitAcl::forwardUnauthorized();
+    }
+
+    if (1 > strlen($title = $this->resource->__toString()))
+    {
+      $title = $this->context->i18n->__('Untitled');
+    }
+
+    $this->response->setTitle("$title - {$this->response->getTitle()}");
+
+    if (QubitAcl::check($this->resource, 'update'))
+    {
+      $validatorSchema = new sfValidatorSchema;
+      $values = array();
+
+      $validatorSchema->authorizedFormOfName = new sfValidatorString(array(
+        'required' => true), array(
+        'required' => $this->context->i18n->__('Authorized form of name - This 
is a mandatory element.')));
+      $values['authorizedFormOfName'] = 
$this->resource->getAuthorizedFormOfName(array('cultureFallback' => true));
+
+      try
+      {
+        $validatorSchema->clean($values);
+      }
+      catch (sfValidatorErrorSchema $e)
+      {
+        $this->errorSchema = $e;
+      }
+    }
+  }
+}

Added: trunk/apps/qubit/modules/donor/config/view.yml
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/donor/config/view.yml      Mon Jul 11 18:58:38 
2011        (r9276)
@@ -0,0 +1,11 @@
+editSuccess:
+  stylesheets:
+    edit:
+  javascripts:
+    /plugins/sfDrupalPlugin/vendor/drupal/misc/jquery.once.js:
+    /plugins/sfDrupalPlugin/vendor/drupal/misc/collapse:
+    /plugins/sfDrupalPlugin/vendor/drupal/misc/form:
+
+indexSuccess:
+  javascripts:
+    blank:

Added: trunk/apps/qubit/modules/donor/templates/editSuccess.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/donor/templates/editSuccess.php    Mon Jul 11 
18:58:38 2011        (r9276)
@@ -0,0 +1,43 @@
+<h1><?php echo __('Edit donor') ?></h1>
+
+<h1 class="label"><?php echo render_title($resource) ?></h1>
+
+<?php echo $form->renderGlobalErrors() ?>
+
+<?php if (isset($sf_request->getAttribute('sf_route')->resource)): ?>
+  <?php echo $form->renderFormTag(url_for(array($resource, 'module' => 
'donor', 'action' => 'edit')), array('id' => 'editForm')) ?>
+<?php else: ?>
+  <?php echo $form->renderFormTag(url_for(array('module' => 'donor', 'action' 
=> 'add')), array('id' => 'editForm')) ?>
+<?php endif; ?>
+
+  <?php echo $form->renderHiddenFields() ?>
+
+  <fieldset class="collapsible" id="identityArea">
+
+    <legend><?php echo __('Identity area') ?></legend>
+
+    <?php echo render_field($form->authorizedFormOfName, $resource) ?>
+
+  </fieldset>
+
+  <div class="actions section">
+
+    <h2 class="element-invisible"><?php echo __('Actions') ?></h2>
+
+    <div class="content">
+      <ul class="clearfix links">
+
+        <?php if (isset($sf_request->getAttribute('sf_route')->resource)): ?>
+          <li><input class="form-submit" type="submit" value="<?php echo 
__('Save') ?>"/></li>
+          <li><?php echo link_to(__('Cancel'), array($resource, 'module' => 
'donor'), array('title' => __('Cancel'))) ?></li>
+        <?php else: ?>
+          <li><input class="form-submit" type="submit" value="<?php echo 
__('Create') ?>"/></li>
+          <li><?php echo link_to(__('Cancel'), array('module' => 'donor', 
'action' => 'list'), array('title' => __('Cancel'))) ?></li>
+        <?php endif; ?>
+
+      </ul>
+    </div>
+
+  </div>
+
+</form>

Added: trunk/apps/qubit/modules/donor/templates/indexSuccess.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/donor/templates/indexSuccess.php   Mon Jul 11 
18:58:38 2011        (r9276)
@@ -0,0 +1,39 @@
+<h1><?php echo __('View donor') ?></h1>
+
+<?php echo link_to_if(QubitAcl::check($resource, 'update'), '<h1 
class="label">'.render_title($resource).'</h1>', array($resource, 'module' => 
'donor', 'action' => 'edit'), array('title' => __('Edit donor'))) ?>
+
+<?php if (isset($errorSchema)): ?>
+  <div class="messages error">
+    <ul>
+      <?php foreach ($errorSchema as $error): ?>
+        <li><?php echo $error ?></li>
+      <?php endforeach; ?>
+    </ul>
+  </div>
+<?php endif; ?>
+
+<?php echo render_show(__('Authorized form of name'), 
render_value($resource->getAuthorizedFormOfName(array('cultureFallback' => 
true)))) ?>
+
+<div class="actions section">
+
+  <h2 class="element-invisible"><?php echo __('Actions') ?></h2>
+
+  <div class="content">
+    <ul class="clearfix links">
+
+      <?php if (QubitAcl::check($resource, 'update')): ?>
+        <li><?php echo link_to(__('Edit'), array($resource, 'module' => 
'donor', 'action' => 'edit'), array('title' => __('Edit'))) ?></li>
+      <?php endif; ?>
+
+      <?php if (QubitAcl::check($resource, 'delete')): ?>
+        <li><?php echo link_to(__('Delete'), array($resource, 'module' => 
'donor', 'action' => 'delete'), array('title' => __('Delete'))) ?></li>
+      <?php endif; ?>
+
+      <?php if (QubitAcl::check($resource, 'create')): ?>
+        <li><?php echo link_to(__('Add new'), array('module' => 'donor', 
'action' => 'add'), array('title' => __('Add new'))) ?></li>
+      <?php endif; ?>
+
+    </ul>
+  </div>
+
+</div>

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