Author: sevein
Date: Thu Jul 21 15:25:21 2011
New Revision: 9344

Log:
Rights module and component, used in accession

Added:
   trunk/apps/qubit/modules/right/
   trunk/apps/qubit/modules/right/actions/
   trunk/apps/qubit/modules/right/actions/editComponent.class.php
   trunk/apps/qubit/modules/right/actions/indexAction.class.php
   
trunk/plugins/qtAccessionPlugin/modules/accession/actions/rightComponent.class.php
   (contents, props changed)
   trunk/plugins/qtAccessionPlugin/modules/accession/templates/_right.php
Modified:
   
trunk/plugins/qtAccessionPlugin/modules/accession/actions/editAction.class.php
   trunk/plugins/qtAccessionPlugin/modules/accession/templates/editSuccess.php

Added: trunk/apps/qubit/modules/right/actions/editComponent.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/right/actions/editComponent.class.php      Thu Jul 
21 15:25:21 2011        (r9344)
@@ -0,0 +1,168 @@
+<?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 RightEditComponent extends sfComponent
+{
+  protected function addField($name)
+  {
+    switch ($name)
+    {
+      case 'endDate':
+        $this->form->setValidator('endDate', new sfValidatorString);
+        $this->form->setWidget('endDate', new sfWidgetFormInput);
+
+        
$this->form->getWidgetSchema()->endDate->setLabel($this->context->i18n->__('End'));
+
+        break;
+
+      case 'startDate':
+        $this->form->setValidator('startDate', new sfValidatorString);
+        $this->form->setWidget('startDate', new sfWidgetFormInput);
+
+        
$this->form->getWidgetSchema()->startDate->setLabel($this->context->i18n->__('Start'));
+
+        break;
+
+      case 'act':
+
+        foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::RIGHT_ACT_ID) as 
$item)
+        {
+          $choices[$this->context->routing->generate(null, array($item, 
'module' => 'term'))] = $item->__toString();
+        }
+
+        $this->form->setValidator('act', new sfValidatorString);
+        $this->form->setWidget('act', new sfWidgetFormSelect(array('choices' 
=> $choices)));
+
+        break;
+
+      case 'basis':
+
+        foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::RIGHT_BASIS_ID) as 
$item)
+        {
+          $choices[$this->context->routing->generate(null, array($item, 
'module' => 'term'))] = $item->__toString();
+        }
+
+        $this->form->setValidator('basis', new sfValidatorString);
+        $this->form->setWidget('basis', new sfWidgetFormSelect(array('choices' 
=> $choices)));
+
+        break;
+    }
+  }
+
+  protected function processField($field)
+  {
+    switch ($field->getName())
+    {
+      case 'act':
+      case 'basis':
+        unset($this->right[$field->getName()]);
+
+        $value = $this->form->getValue($field->getName());
+        if (isset($value))
+        {
+          $params = $this->context->routing->parse(Qubit::pathInfo($value));
+          $this->right[$field->getName()] = $params['_sf_route']->resource;
+        }
+
+        break;
+
+      default:
+        $this->right[$field->getName()] = 
$this->form->getValue($field->getName());
+    }
+  }
+
+  public function processForm()
+  {
+    // Ignore this method if duplicating
+    if (isset($this->request->sourceId))
+    {
+      return;
+    }
+
+    $params = array($this->request->editRight);
+    if (isset($this->request->editRights))
+    {
+      // If dialog JavaScript did it's work, then use array of parameters
+      $params = $this->request->editRights;
+    }
+
+    foreach ($params as $item)
+    {
+      // Continue only if user typed something
+      foreach ($item as $value)
+      {
+        if (0 < strlen($value))
+        {
+          break;
+        }
+      }
+
+      if (1 > strlen($value))
+      {
+        continue;
+      }
+
+      $this->form->bind($item);
+      if ($this->form->isValid())
+      {
+        if (isset($item['id']))
+        {
+          $params = 
$this->context->routing->parse(Qubit::pathInfo($item['id']));
+          $this->right = $params['_sf_route']->resource;
+        }
+        else
+        {
+          $this->resource->rights[] = $this->right = new QubitRight;
+        }
+
+        foreach ($this->form as $field)
+        {
+          if (isset($item[$field->getName()]))
+          {
+            $this->processField($field);
+          }
+        }
+      }
+    }
+
+    if (isset($this->request->deleteRights))
+    {
+      foreach ($this->request->deleteRights as $item)
+      {
+        $params = $this->context->routing->parse(Qubit::pathInfo($item));
+        $params['_sf_route']->resource->delete();
+      }
+    }
+  }
+
+  public function execute($request)
+  {
+    $this->form = new sfForm;
+    $this->form->getValidatorSchema()->setOption('allow_extra_fields', true);
+    $this->form->getWidgetSchema()->setNameFormat('editRight[%s]');
+
+    // 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);
+    }
+  }
+}

Added: trunk/apps/qubit/modules/right/actions/indexAction.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/right/actions/indexAction.class.php        Thu Jul 
21 15:25:21 2011        (r9344)
@@ -0,0 +1,64 @@
+<?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 EventIndexAction extends sfAction
+{
+  public function execute($request)
+  {
+    $this->resource = $this->getRoute()->resource;
+
+    $value = array();
+
+    if (isset($this->resource->actor))
+    {
+      $value['actor'] = $this->context->routing->generate(null, 
array($this->resource->actor, 'module' => 'actor'));
+    }
+
+    if (isset($this->resource->date))
+    {
+      $value['date'] = $this->resource->date;
+    }
+
+    $value['endDate'] = Qubit::renderDate($this->resource->endDate);
+    $value['startDate'] = Qubit::renderDate($this->resource->startDate);
+
+    if (isset($this->resource->description))
+    {
+      $value['description'] = $this->resource->description;
+    }
+
+    if (isset($this->resource->informationObject))
+    {
+      $value['informationObject'] = $this->context->routing->generate(null, 
array($this->resource->informationObject, 'module' => 'informationobject'));
+    }
+
+    $place = $this->resource->getPlace();
+    if (isset($place))
+    {
+      $value['place'] = $this->context->routing->generate(null, array($place, 
'module' => 'term'));
+    }
+
+    if (isset($this->resource->type))
+    {
+      $value['type'] = $this->context->routing->generate(null, 
array($this->resource->type, 'module' => 'term'));
+    }
+
+    return $this->renderText(json_encode($value));
+  }
+}

Modified: 
trunk/plugins/qtAccessionPlugin/modules/accession/actions/editAction.class.php
==============================================================================
--- 
trunk/plugins/qtAccessionPlugin/modules/accession/actions/editAction.class.php  
    Thu Jul 21 12:34:18 2011        (r9343)
+++ 
trunk/plugins/qtAccessionPlugin/modules/accession/actions/editAction.class.php  
    Thu Jul 21 15:25:21 2011        (r9344)
@@ -79,6 +79,10 @@
     $this->relatedDonorComponent = new 
AccessionRelatedDonorComponent($this->context, 'accession', 'relatedDonor');
     $this->relatedDonorComponent->resource = $this->resource;
     $this->relatedDonorComponent->execute($this->request);
+
+    $this->rightComponent = new AccessionRightComponent($this->context, 
'accession', 'right');
+    $this->rightComponent->resource = $this->resource;
+    $this->rightComponent->execute($this->request);
   }
 
   protected function addField($name)
@@ -283,6 +287,8 @@
       {
         $this->relatedDonorComponent->processForm();
 
+        $this->eventComponent->processForm();
+
         if (isset($this->request->deleteRelations))
         {
           foreach ($this->request->deleteRelations as $item)

Added: 
trunk/plugins/qtAccessionPlugin/modules/accession/actions/rightComponent.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ 
trunk/plugins/qtAccessionPlugin/modules/accession/actions/rightComponent.class.php
  Thu Jul 21 15:25:21 2011        (r9344)
@@ -0,0 +1,29 @@
+<?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 AccessionRightComponent extends RightEditComponent
+{
+  // Arrays not allowed in class constants
+  public static
+    $NAMES = array(
+    'act',
+    'basis',
+    'endDate',
+    'startDate');
+}

Added: trunk/plugins/qtAccessionPlugin/modules/accession/templates/_right.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/plugins/qtAccessionPlugin/modules/accession/templates/_right.php      
Thu Jul 21 15:25:21 2011        (r9344)
@@ -0,0 +1,73 @@
+<?php
+
+$sf_response->addStylesheet('/vendor/yui/container/assets/skins/sam/container',
 'first');
+
+$sf_response->addJavaScript('/vendor/yui/datasource/datasource-min');
+$sf_response->addJavaScript('/vendor/yui/container/container-min');
+$sf_response->addJavaScript('dialog');
+
+use_helper('Javascript');
+
+// Template for new display table rows
+$editHtml = image_tag('pencil', array('alt' => 'edit', 'style' => 'align: 
top'));
+
+$rowTemplate = json_encode(<<<value
+<tr id="{{$form->getWidgetSchema()->generateName('id')}}">
+  <td>
+    {{$form->startDate->renderName()}}
+  </td><td>
+    {{$form->endDate->renderName()}}
+  </td><td style="text-align: right">
+    $editHtml <button class="delete-small" name="delete" type="button"/>
+  </td>
+</tr>
+
+value
+);
+
+// Omit edit button if object is being duplicated
+$editButtonJs = null;
+if (!isset($sf_request->source))
+{
+  $editButtonJs = <<<editButtonJs
+// Add edit button to rows
+jQuery('#relatedRights tr[id]', context)
+  .click(function ()
+    {
+      dialog.open(this.id);
+    })
+  .find('td:last')
+  .prepend('$editHtml');
+
+editButtonJs;
+}
+
+echo javascript_tag(<<<content
+Drupal.behaviors.right = {
+  attach: function (context)
+    {
+      // Define dialog
+      var dialog = new QubitDialog('updateRight', {
+        'displayTable': 'relatedRights',
+        'newRowTemplate': $rowTemplate });
+
+      $editButtonJs
+    } }
+
+content
+) ?>
+
+<!-- NOTE dialog.js wraps this *entire* table in a YUI dialog -->
+<div class="section" id="updateRight">
+
+  <h3><?php echo __('Right') ?></h3>
+
+  <?php echo $form->startDate->renderRow() ?>
+
+  <?php echo $form->endDate->renderRow() ?>
+
+  <?php echo $form->act->renderRow() ?>
+
+  <?php echo $form->basis->renderRow() ?>
+
+</div>

Modified: 
trunk/plugins/qtAccessionPlugin/modules/accession/templates/editSuccess.php
==============================================================================
--- trunk/plugins/qtAccessionPlugin/modules/accession/templates/editSuccess.php 
Thu Jul 21 12:34:18 2011        (r9343)
+++ trunk/plugins/qtAccessionPlugin/modules/accession/templates/editSuccess.php 
Thu Jul 21 15:25:21 2011        (r9344)
@@ -76,6 +76,8 @@
 
     <legend><?php echo __('Rights area') ?></legend>
 
+    <?php echo get_partial('accession/right', 
$rightComponent->getVarHolder()->getAll()) ?>
+
   </fieldset>
 
   <div class="actions section">

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