Author: jablko
Date: Fri Sep  4 10:40:33 2009
New Revision: 3172

Log:
Get choices of creators and repositories with XHR, don't build full lists of 
creators or repositories in actions, fixes issue 346 -- force

Modified:
   trunk/apps/qubit/modules/informationobject/actions/editAction.class.php
   trunk/apps/qubit/modules/informationobject/actions/editIsadAction.class.php
   trunk/apps/qubit/modules/informationobject/templates/editIsadSuccess.php
   trunk/apps/qubit/modules/informationobject/templates/editRadSuccess.php
   trunk/web/js/autocomplete.js

Modified: 
trunk/apps/qubit/modules/informationobject/actions/editAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/actions/editAction.class.php     
Fri Sep  4 10:05:35 2009        (r3171)
+++ trunk/apps/qubit/modules/informationobject/actions/editAction.class.php     
Fri Sep  4 10:40:33 2009        (r3172)
@@ -73,15 +73,7 @@
       case 'repository':
         $this->form->setDefault('repository', 
$this->context->routing->generate(null, array('module' => 'repository', 
'action' => 'show', 'id' => $this->informationObject->repository->id)));
         $this->form->setValidator('repository', new sfValidatorString);
-
-        $choices = array();
-        $choices[null] = null;
-        foreach (QubitRepository::getAll() as $repository)
-        {
-          $choices[$this->context->routing->generate(null, array('module' => 
'repository', 'action' => 'show', 'id' => $repository->id))] = $repository;
-        }
-
-        $this->form->setWidget('repository', new 
sfWidgetFormSelect(array('choices' => $choices)));
+        $this->form->setWidget('repository', new 
sfWidgetFormSelect(array('choices' => 
array($this->context->routing->generate(null, array('module' => 'repository', 
'action' => 'show', 'id' => $this->informationObject->repository->id)) => 
$this->informationObject->repository))));
 
         break;
 

Modified: 
trunk/apps/qubit/modules/informationobject/actions/editIsadAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/actions/editIsadAction.class.php 
Fri Sep  4 10:05:35 2009        (r3171)
+++ trunk/apps/qubit/modules/informationobject/actions/editIsadAction.class.php 
Fri Sep  4 10:40:33 2009        (r3172)
@@ -74,24 +74,15 @@
         $criteria->add(QubitEvent::TYPE_ID, QubitTerm::CREATION_ID);
 
         $values = array();
+        $choices = array();
         foreach ($this->events = QubitEvent::get($criteria) as $event)
         {
           $values[] = $this->context->routing->generate(null, array('module' 
=> 'actor', 'action' => 'show', 'id' => $event->actor->id));
+          $choices[$this->context->routing->generate(null, array('module' => 
'actor', 'action' => 'show', 'id' => $event->actor->id))] = $event->actor;
         }
 
         $this->form->setDefault('creators', $values);
         $this->form->setValidator('creators', new sfValidatorPass);
-
-        $criteria = new Criteria;
-        $criteria->addJoin(QubitActor::ID, QubitUser::ID, 'LEFT JOIN');
-        $criteria->add(QubitUser::ID);
-
-        $choices = array();
-        foreach (QubitActor::get($criteria) as $actor)
-        {
-          $choices[$this->context->routing->generate(null, array('module' => 
'actor', 'action' => 'show', 'id' => $actor->id))] = $actor;
-        }
-
         $this->form->setWidget('creators', new 
sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
 
         break;

Modified: 
trunk/apps/qubit/modules/informationobject/templates/editIsadSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/templates/editIsadSuccess.php    
Fri Sep  4 10:05:35 2009        (r3171)
+++ trunk/apps/qubit/modules/informationobject/templates/editIsadSuccess.php    
Fri Sep  4 10:40:33 2009        (r3172)
@@ -108,9 +108,17 @@
   <fieldset class="collapsible collapsed" id="contextArea">
     <legend><?php echo __('context area') ?></legend>
 
-    <?php echo $form->creators->label(__('Name of 
creator(s)'))->renderRow(array('class' => 'form-autocomplete')) ?>
+    <div class="form-item">
+      <?php echo $form->creators->label(__('Name of 
creator(s)'))->renderLabel() ?>
+      <?php echo $form->creators->render(array('class' => 
'form-autocomplete')) ?>
+      <input class="list" type="hidden" value="<?php echo 
url_for(array('module' => 'actor', 'action' => 'list')) ?>"/>
+    </div>
 
-    <?php echo $form->repository->renderRow(array('class' => 
'form-autocomplete')) ?>
+    <div class="form-item">
+      <?php echo $form->repository->label(__('Repository'))->renderLabel() ?>
+      <?php echo $form->repository->render(array('class' => 
'form-autocomplete')) ?>
+      <input class="list" type="hidden" value="<?php echo 
url_for(array('module' => 'repository', 'action' => 'list')) ?>"/>
+    </div>
 
     <?php echo render_field($form->archivalHistory, $informationObject, 
array('class' => 'resizable')) ?>
 

Modified: 
trunk/apps/qubit/modules/informationobject/templates/editRadSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/templates/editRadSuccess.php     
Fri Sep  4 10:05:35 2009        (r3171)
+++ trunk/apps/qubit/modules/informationobject/templates/editRadSuccess.php     
Fri Sep  4 10:40:33 2009        (r3172)
@@ -76,7 +76,11 @@
       </tr>
     </table>
 
-    <?php echo $form->repository->renderRow(array('class' => 
'form-autocomplete')) ?>
+    <div class="form-item">
+      <?php echo $form->repository->label(__('Repository'))->renderLabel() ?>
+      <?php echo $form->repository->render(array('class' => 
'form-autocomplete')) ?>
+      <input class="list" type="hidden" value="<?php echo 
url_for(array('module' => 'repository', 'action' => 'list')) ?>"/>
+    </div>
 
     <?php echo $form->identifier->renderRow() ?>
 

Modified: trunk/web/js/autocomplete.js
==============================================================================
--- trunk/web/js/autocomplete.js        Fri Sep  4 10:05:35 2009        (r3171)
+++ trunk/web/js/autocomplete.js        Fri Sep  4 10:40:33 2009        (r3172)
@@ -42,18 +42,55 @@
             $(input).val($('option:selected', this).text());
           }
 
-          var dataSource = new YAHOO.util.LocalDataSource();
+          // A following sibling with class .list and a value specifies that
+          // autocomplete items can be requested dynamically from the specified
+          // URI
+          var value = $('~ .list', this).val();
+          if (value)
+          {
+            // Split into URI and selector like jQuery load()
+            var [src, selector] = value.split(' ', 2);
 
-          $('option:enabled', this).each(function ()
-            {
-              if ($(this).val())
+            var dataSource = new YAHOO.util.XHRDataSource(src);
+
+            // Cache at least one query so autocomplete items are only
+            // requested if the value of the autocomplete <input> changes
+            dataSource.maxCacheEntries = 1;
+
+            dataSource.responseType = YAHOO.util.DataSourceBase.TYPE_HTMLTABLE;
+
+            // Overriding doBeforeParseData() and doBeforeCallback() not
+            // powerful enough, override parseHTMLTableData() and skip
+            // isArray(fields) check
+            dataSource.parseHTMLTableData = function (request, response)
               {
-                // For each item, select HTML contents and value of <option>
-                //
-                // Selecting HTML contents is important for <em>Untitled</em>
-                dataSource.liveData.push([$(this).html(), $(this).val()]);
-              }
-            });
+                var results = [];
+                $('tbody tr', response).each(function ()
+                  {
+                    // For each item, select HTML contents and @href of <a> in
+                    // first cell
+                    results.push([$('td a', this).html(), $('td a', 
this).attr('href')]);
+                  });
+
+                return { results: results };
+              };
+          }
+          else
+          {
+            // Otherwise add each enabled <option> to static list of items
+            var dataSource = new YAHOO.util.LocalDataSource();
+
+            $('option:enabled', this).each(function ()
+              {
+                if ($(this).val())
+                {
+                  // For each item, select HTML contents and value of <option>
+                  //
+                  // Selecting HTML contents is important for <em>Untitled</em>
+                  dataSource.liveData.push([$(this).html(), $(this).val()]);
+                }
+              });
+          }
 
           // Can't figure out how to get access to the DOM event which
           // triggered a custom YUI event, so bind a listener to the
@@ -167,14 +204,14 @@
                 // On single <select> item select, simply update the value of
                 // this input
                 $(hidden).val(args[2][1]);
-
-                // Update the value of the autocomplete <input> here with text
-                // of parsed HTML, instead of source
-                //
-                // Use XML() constructor as with multiple <select>, but use
-                // toString() to get text of parsed HTML
-                $(input).val(XML(args[2][0]));
               }
+
+              // Update the value of the autocomplete <input> here with text
+              // of parsed HTML, instead of source
+              //
+              // Use XML() constructor as with multiple <select>, but use
+              // toString() to get text of parsed HTML
+              $(input).val(XML(args[2][0]));
             });
 
           if ($(select).attr('multiple'))
@@ -204,8 +241,8 @@
             }
           }
 
-          // Use custom YUI event to avoid DOM focus events triggered by
-          // YUI widget interaction
+          // Use custom YUI event to avoid DOM focus events triggered by YUI
+          // widget interaction
           autoComplete.textboxFocusEvent.subscribe(sendQuery);
 
           // Listen for click to show autocomplete items after selecting

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