Author: david
Date: 2008-11-10 14:21:31 -0800 (Mon, 10 Nov 2008)
New Revision: 1545

Modified:
   
trunk/qubit/apps/qubit/modules/informationobject/actions/updateAction.class.php
   
trunk/qubit/apps/qubit/modules/informationobject/templates/_newActorEventDialog.php
   
trunk/qubit/apps/qubit/modules/informationobject/templates/editIsadSuccess.php
   trunk/qubit/web/js/newActorEventDialog.js
Log:
Add event type, place, and description to newActorEvent dialog and 
informationobject/update.

Modified: 
trunk/qubit/apps/qubit/modules/informationobject/actions/updateAction.class.php
===================================================================
--- 
trunk/qubit/apps/qubit/modules/informationobject/actions/updateAction.class.php 
    2008-11-10 20:27:18 UTC (rev 1544)
+++ 
trunk/qubit/apps/qubit/modules/informationobject/actions/updateAction.class.php 
    2008-11-10 22:21:31 UTC (rev 1545)
@@ -60,7 +60,7 @@
     $this->updateNotes($this->informationObject);
     $this->updateProperties($this->informationObject);
     $this->updateObjectTermRelations($this->informationObject);
-    $this->updateActorEvents($this->informationObject);
+    $this->addActorEvents($this->informationObject);
     $this->updateDigitalObjects($request,$this->informationObject);
     $this->updatePhysicalObjects($this->informationObject);
     //$this->updateRecursiveRelations($informationObject);
@@ -81,8 +81,8 @@
         SearchIndex::updateTranslatedLanguages($this->informationObject);
       }
 
-     // return to edit template
-     return $this->redirect(array('module' => 'informationobject', 'action' => 
'edit', 'id' => $this->informationObject->getId()));
+      // return to edit template
+      return $this->redirect(array('module' => 'informationobject', 'action' 
=> 'edit', 'id' => $this->informationObject->getId()));
     }
 
   }
@@ -342,12 +342,30 @@
   }
 
   /**
-   * Update ObjectTermRelations (Subject and place access points)
+   * Update ObjectTermRelations - Subject, name and place access points and
+   * Material types.
    *
-   * @param QubitInformationObject $informationObject current information 
objects
+   * @param QubitInformationObject $informationObject current information 
object
    */
   public function updateObjectTermRelations($informationObject)
   {
+    // Add name access points
+    if ($name_ids = $this->getRequestParameter('name_id'))
+    {
+      // Make sure that $name_ids is an array, even if it's only got one value
+      $name_ids = (is_array($name_ids)) ? $name_ids : array($name_ids);
+
+      foreach ($name_ids as $name_id)
+      {
+        if (intval($name_id))
+        {
+          $informationObject->addNameAccessPoint($name_id, 
QubitTerm::SUBJECT_ID);
+          $this->foreignKeyUpdate = true;
+        }
+      }
+    }
+
+    // Add subject access points
     if ($subject_ids = $this->getRequestParameter('subject_id'))
     {
       // Make sure that $subject_id is an array, even if it's only got one 
value
@@ -359,11 +377,11 @@
         {
           $informationObject->addTermRelation($subject_id, 
QubitTaxonomy::SUBJECT_ID);
           $this->foreignKeyUpdate = true;
-
         }
       }
     }
 
+    // Add place access points
     if ($place_ids = $this->getRequestParameter('place_id'))
     {
       // Make sure that $place_id is an array, even if it's only got one value
@@ -379,6 +397,7 @@
       }
     }
 
+    // Add material types
     if ($material_type_ids = $this->getRequestParameter('material_type_id'))
     {
       // Make sure that $material_type_id is an array, even if it's only got 
one value
@@ -390,53 +409,54 @@
         {
           $informationObject->addTermRelation($material_type_id, 
QubitTaxonomy::MATERIAL_TYPE_ID);
           $this->foreignKeyUpdate = true;
-
         }
       }
     }
 
   }
 
-  public function updateActorEvents($informationObject)
+  /**
+   * Add new actor events for this info object.
+   *
+   * @param QubitInformationObject $informationObject
+   */
+  protected function addActorEvents($informationObject)
   {
-    // Get an array of Actor Events (even if there's only one)
+    // Get an array of new actor events (even if there's only one)
     if (!is_array($newActorEvents = 
$this->getRequestParameter('newActorEvents')))
     {
       $newActorEvents = array($this->getRequestParameter('newActorEvent'));
     }
 
-    // Loop thru new Actor Events
+    // Loop through new actor events
     foreach ($newActorEvents as $thisEvent)
     {
       $newActorEvent = new QubitEvent;
+      $saveEvent = false; // Only save if we have an actor or a date
 
-      // add actor
+      // Use existing actor if one is selected (overrides new actor creation)
       if ($thisEvent['actorId'])
       {
         $newActorEvent->setActorId($thisEvent['actorId']);
-        $newActorEvent->setInformationObjectId($informationObject->getId());
-        $newActorEvent->setTypeId($thisEvent['eventTypeId']);
-        $newActorEvent->save();
-        $this->foreignKeyUpdate = true;
+        $saveEvent = true;
       }
+
+      // or, create a new actor and associate with Actor Event
       else if ($thisEvent['newActorAuthorizedName'])
       {
+        // Create actor
         $actor = new QubitActor;
         $actor->setAuthorizedFormOfName($thisEvent['newActorAuthorizedName']);
         $actor->save();
+
+        // Assign actor to event
         $newActorEvent->setActorId($actor->getId());
-        $newActorEvent->setInformationObjectId($informationObject->getId());
-        $newActorEvent->setTypeId($thisEvent['eventTypeId']);
-        $newActorEvent->setDescription($thisEvent['description']);
-        $newActorEvent->save();
-        $this->foreignKeyUpdate = true;
+        $saveEvent = true;
       }
 
       // add actor event date/date range
       if (($thisEvent['year']) || ($thisEvent['endYear']))
       {
-        $newActorEvent->setTypeId($thisEvent['eventTypeId']);
-        $newActorEvent->setInformationObjectId($informationObject->getId());
         $newActorEvent->setStartDate($thisEvent['year'].'-01-01');
         $newActorEvent->setEndDate($thisEvent['endYear'].'-01-01');
 
@@ -454,13 +474,22 @@
           $newActorEvent->setDateDisplay($dateString);
         }
 
+        $saveEvent = true;
+      }
+
+      // Save the actor event if it's valid (has actor OR date)
+      if ($saveEvent)
+      {
+        $newActorEvent->setTypeId($thisEvent['eventTypeId']);
         $newActorEvent->setDescription($thisEvent['description']);
+        $newActorEvent->setInformationObjectId($informationObject->getId());
+
         $newActorEvent->save();
         $this->foreignKeyUpdate = true;
       }
 
       // add place
-      if ($newActorEvent->getId() & ($thisEvent['placeId']))
+      if ($saveEvent && strlen($thisEvent['placeId']))
       {
         $place = new QubitObjectTermRelation;
         $place->setObjectId($newActorEvent->getId());
@@ -468,21 +497,6 @@
         $place->save();
       }
     }
-
-    if ($name_ids = $this->getRequestParameter('name_id'))
-    {
-      // Make sure that $name_ids is an array, even if it's only got one value
-      $name_ids = (is_array($name_ids)) ? $name_ids : array($name_ids);
-
-      foreach ($name_ids as $name_id)
-      {
-        if (intval($name_id))
-        {
-          $informationObject->addNameAccessPoint($name_id, 
QubitTerm::SUBJECT_ID);
-          $this->foreignKeyUpdate = true;
-        }
-      }
-    }
   }
 
   /**
@@ -527,7 +541,7 @@
         // Set parent
         if ($usageId == QubitTerm::MASTER_ID)
         {
-           // If this is a master digital object upload, info object is parent
+          // If this is a master digital object upload, info object is parent
           
$newDigitalObject->setInformationObjectId($informationObject->getId());
         }
         else
@@ -608,7 +622,7 @@
   public function updatePhysicalObjects($informationObject)
   {
     $oldPhysicalObjects = 
QubitRelation::getRelatedSubjectsByObjectId($informationObject->getId(),
-      array('typeId'=>QubitTerm::HAS_PHYSICAL_OBJECT_ID));
+    array('typeId'=>QubitTerm::HAS_PHYSICAL_OBJECT_ID));
 
     // Preferentially use "new container" input data over the selector so that
     // new object data is not lost (but only if an object name is entered)

Modified: 
trunk/qubit/apps/qubit/modules/informationobject/templates/_newActorEventDialog.php
===================================================================
--- 
trunk/qubit/apps/qubit/modules/informationobject/templates/_newActorEventDialog.php
 2008-11-10 20:27:18 UTC (rev 1544)
+++ 
trunk/qubit/apps/qubit/modules/informationobject/templates/_newActorEventDialog.php
 2008-11-10 22:21:31 UTC (rev 1545)
@@ -18,7 +18,10 @@
    * Dialog object, so we don't see them when Javascript is turned off. Include
    * them here (instead of in .js file) to allow PHP to parse i18n tags. 
    */
-  
+
+  // Get i18n labels
+  Qubit.labels = ({"unknown": "<?php echo __('unknown') ?>"});
+
   // Do this after newActorEventDialog.js actions
   Drupal.behaviors.writeNewActorEventHTML = function(context) 
   {
@@ -34,10 +37,10 @@
         '</div>' +
       '</div>'
     );
-    
+
     // build the dialog
     renderEventDialog();
-  
+
     // Write a link to show the dialog
     $("table#actorEvents").append('<tr id="addActorEventLink"><td colspan="4" 
style="text-align: right"><a 
href="javascript:Qubit.newActorEventDialog.show()"><?php echo __('add new') 
?></a></td></tr>');
   }

Modified: 
trunk/qubit/apps/qubit/modules/informationobject/templates/editIsadSuccess.php
===================================================================
--- 
trunk/qubit/apps/qubit/modules/informationobject/templates/editIsadSuccess.php  
    2008-11-10 20:27:18 UTC (rev 1544)
+++ 
trunk/qubit/apps/qubit/modules/informationobject/templates/editIsadSuccess.php  
    2008-11-10 22:21:31 UTC (rev 1545)
@@ -85,10 +85,10 @@
 
       <table id="actorEvents" class="inline" style="margin-top: 25px;">
         <tr style="border-top: 1px solid #999999;">
-          <td style="width: 35%; color: #999999; font-weight: bold"><?php echo 
__('Name') ?></td>
+          <td style="width: 40%; color: #999999; font-weight: bold"><?php echo 
__('Name') ?></td>
           <td style="width: 25%; color: #999999; font-weight: bold"><?php echo 
__('Role') ?></td>
           <td style= "width: 30%; color: #999999; font-weight: bold"><?php 
echo __('Date(s)') ?></td>
-          <td style="width:10%"></td>
+          <td style="width:5%"></td>
         </tr>
         <?php if(count($actorEvents)): ?>
         <?php foreach ($actorEvents as $actorEvent): ?>
@@ -118,8 +118,8 @@
 
 
     <div class="form-item">
-      <div style="border: 1px solid #cccccc; padding: 1px;">
-      <label for="event"><?php echo __('new event'); ?></label>
+      <fieldset id="newActorEventFields" style="border: 1px solid #cccccc; 
padding: 1px; background: #fff">
+      <label for="newActorEvent"><?php echo __('new event'); ?></label>
 
       <!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  -->
       <!-- NOTE: The newActorEventDialog script cuts this *entire*          -->
@@ -136,7 +136,7 @@
               'name' => 'newActorEvent[actorId]',
               'include_blank' => true,
               'peer_method' => 'getAllExceptUsers')) ?></td>
-          <td><?php echo input_tag('newCreationEvent[newActorAuthorizedName]') 
?></td>
+          <td><?php echo input_tag('newActorEvent[newActorAuthorizedName]') 
?></td>
         </tr>
         <tr>
           <td colspan="2" class="headerCell" style="width: 55%;"><?php echo 
__('event type') ?></td><td class="headerCell" style="width: 40%;"><?php echo 
__('place') ?></td>
@@ -149,7 +149,7 @@
           <td class="headerCell"><?php echo __('year'); ?></td><td 
class="headerCell"><?php echo __('end year'); ?></td>
           <td class="headerCell"><?php echo __('date display (defaults to date 
range)'); ?></td></tr>
         <tr>
-          <td><?php echo input_tag('newActorEvent[creationYear]', '', 
'maxlength=4 style="width:35px;"') ?></td>
+          <td><?php echo input_tag('newActorEvent[year]', '', 'maxlength=4 
style="width:35px;"') ?></td>
           <td><?php echo input_tag('newActorEvent[endYear]', '', 'maxlength=4 
style="width:35px;"') ?></td>
           <td><?php echo input_tag('newActorEvent[dateDisplay]') ?></td>
         </tr>
@@ -160,7 +160,7 @@
           <td colspan="3"><?php echo input_tag('newActorEvent[description]') 
?></td>
         </tr>
       </table>
-      </div>
+      </fieldset>
     </div>
 
     <?php if ($creators): ?>

Modified: trunk/qubit/web/js/newActorEventDialog.js
===================================================================
--- trunk/qubit/web/js/newActorEventDialog.js   2008-11-10 20:27:18 UTC (rev 
1544)
+++ trunk/qubit/web/js/newActorEventDialog.js   2008-11-10 22:21:31 UTC (rev 
1545)
@@ -14,6 +14,8 @@
   var handleSubmit = function() {
     var thisData = this.getData();
     var actorSelector = $('table#newActorEvent 
select[name="newActorEvent[actorId]"]');
+    var eventTypeSelector = $('table#newActorEvent 
select[name="newActorEvent[eventTypeId]"]');
+    var placeSelector = $('table#newActorEvent 
select[name="newActorEvent[placeId]"]');
 
     // Hide dialog
     this.hide();
@@ -22,22 +24,26 @@
     var newHiddens = '';
     newHiddens += '<input class="addedHidden'+i+'" type="hidden" 
name="newActorEvents['+i+'][actorId]" 
value="'+thisData['newActorEvent[actorId]']+'" />\n';
     newHiddens += '<input class="addedHidden'+i+'" type="hidden" 
name="newActorEvents['+i+'][newActorAuthorizedName]" 
value="'+thisData['newActorEvent[newActorAuthorizedName]']+'" />\n';
-    newHiddens += '<input class="addedHidden'+i+'" type="hidden" 
name="newActorEvents['+i+'][creationYear]" 
value="'+thisData['newActorEvent[creationYear]']+'" />\n';
+    newHiddens += '<input class="addedHidden'+i+'" type="hidden" 
name="newActorEvents['+i+'][eventTypeId]" 
value="'+thisData['newActorEvent[eventTypeId]']+'" />\n';
+    newHiddens += '<input class="addedHidden'+i+'" type="hidden" 
name="newActorEvents['+i+'][placeId]" 
value="'+thisData['newActorEvent[placeId]']+'" />\n';
+    newHiddens += '<input class="addedHidden'+i+'" type="hidden" 
name="newActorEvents['+i+'][year]" value="'+thisData['newActorEvent[year]']+'" 
/>\n';
     newHiddens += '<input class="addedHidden'+i+'" type="hidden" 
name="newActorEvents['+i+'][endYear]" 
value="'+thisData['newActorEvent[endYear]']+'" />\n';
-    newHiddens += '<input class="addedHidden'+i+'" type="hidden" 
name="newActorEvents['+i+'][creationDateNote]" 
value="'+thisData['newActorEvent[creationDateNote]']+'" />\n';
+    newHiddens += '<input class="addedHidden'+i+'" type="hidden" 
name="newActorEvents['+i+'][dateDisplay]" 
value="'+thisData['newActorEvent[dateDisplay]']+'" />\n';
+    newHiddens += '<input class="addedHidden'+i+'" type="hidden" 
name="newActorEvents['+i+'][description]" 
value="'+thisData['newActorEvent[description]']+'" />\n';
 
     // Append hidden input fields
     $('table#actorEvents').append(newHiddens);
 
     // Determine the actor name to show in the creation events table
     var actorId = thisData['newActorEvent[actorId]'];
+    var nameDisplay = Qubit.labels.unknown;
     if (actorId > 0)
     {
-      var nameDisplay = actorSelector.find('option:selected').text();
+      nameDisplay = actorSelector.find('option:selected').text();
     }
     else if (thisData['newActorEvent[newActorAuthorizedName]'].length > 0)
     {
-      var nameDisplay = thisData['newActorEvent[newActorAuthorizedName]'];
+      nameDisplay = thisData['newActorEvent[newActorAuthorizedName]'];
     }
 
     // Determine the date(s) to show in the creation events table
@@ -51,10 +57,18 @@
       }
     }
 
+    // Get event type text
+    var eventTypeId = thisData['newActorEvent[eventTypeId]'];
+    var eventTypeDisplay = '';
+    if (eventTypeId.length > 0)
+    {
+      eventTypeDisplay = eventTypeSelector.find('option:selected').text()
+    }
+
     // Build visible row to append to the creationEvents Table
     var newRow = $('<tr id="newRow'+i+'">'+
      '<td><div>'+nameDisplay+'</div></td>'+
-     '<td><div>TODO: Get Role<div></td>'+
+     '<td><div>'+eventTypeDisplay+'<div></td>'+
      '<td><div>'+dateDisplay+'<div></td>'+
      '<td><div><a href="javascript:removeRow('+i+')"><img 
src="'+$('img#imagesDeletePng').attr('src')+'" /></a></div></td>'+
      '</tr>'
@@ -70,7 +84,10 @@
     $('table#newActorEvent input[name="newActorEvent[year]"]').val('');
     $('table#newActorEvent input[name="newActorEvent[endYear]"]').val('');
     $('table#newActorEvent input[name="newActorEvent[dateDisplay]"]').val('');
+    $('table#newActorEvent input[name="newActorEvent[description]"]').val('');
     actorSelector.get(0).options[0].selected = true;
+    eventTypeSelector.get(0).options[0].selected = true;
+    placeSelector.get(0).options[0].selected = true;
 
     i++; // increment counter
   };
@@ -84,6 +101,8 @@
   var newActorEventTable = $('table#newActorEvent');
   newActorEventTable.clone().appendTo('div#newActorEventDialog div.bd form');
   newActorEventTable.remove();
+  $('label[for=newActorEvent]').remove();
+  $('fieldset#newActorEventFields').remove();
 
   // Instantiate the Dialog
   Qubit.newActorEventDialog = new YAHOO.widget.Dialog("newActorEventDialog",


--~--~---------~--~----~------------~-------~--~----~
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.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to