Author: mj
Date: Thu Oct 13 12:50:19 2011
New Revision: 10074

Log:
Refactor global search/replace to use sfForms framework

Modified:
   trunk/apps/qubit/modules/search/actions/globalReplaceAction.class.php
   trunk/apps/qubit/modules/search/templates/advancedSuccess.php
   trunk/apps/qubit/modules/search/templates/globalReplaceSuccess.php

Modified: trunk/apps/qubit/modules/search/actions/globalReplaceAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/search/actions/globalReplaceAction.class.php       
Thu Oct 13 12:07:10 2011        (r10073)
+++ trunk/apps/qubit/modules/search/actions/globalReplaceAction.class.php       
Thu Oct 13 12:50:19 2011        (r10074)
@@ -21,31 +21,34 @@
 {
   public function execute($request)
   {
+    // execute the search request
     parent::execute($request);
 
-    $this->loadColumns();
+    $this->addFields();
 
-    if (isset($request->searchReplace)) {
+    if ($request->isMethod('post')) {
+      // process replacement action
 
       // make sure we have required information for search/replace
       if (empty($request->pattern) || empty($request->replacement)) {
         $this->error = $this->context->i18n->__('Both source and replacement 
fields are required.');
-        return;
       }
     }
+
   }
 
-  public function loadColumns()
+  public function addFields()
   {
     $map = new InformationObjectI18nTableMap;
 
     foreach ($map->getColumns() as $col) {
       if (!$col->isPrimaryKey() && !$col->isForeignKey()) {
         $col_name = $col->getPhpName();
-        $cols[$col_name] = 
sfInflector::humanize(sfInflector::underscore($col_name));
+        $choices[$col_name] = 
sfInflector::humanize(sfInflector::underscore($col_name));
       }
     }
 
-    $this->columns = $cols;
+    $this->form->setValidator('column', new sfValidatorString);
+    $this->form->setWidget('column', new sfWidgetFormSelect(array('choices' => 
$choices)));
    }
 }

Modified: trunk/apps/qubit/modules/search/templates/advancedSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/search/templates/advancedSuccess.php       Thu Oct 
13 12:07:10 2011        (r10073)
+++ trunk/apps/qubit/modules/search/templates/advancedSuccess.php       Thu Oct 
13 12:50:19 2011        (r10074)
@@ -29,9 +29,9 @@
 
 <?php else: ?>
 
-  <?php if(isset($pager)) {
-    echo get_partial('search/searchResults', array('pager' => $pager));
-    echo get_partial('default/pager', array('pager' => $pager));
-  } ?>
+  <?php if(isset($pager)): ?>
+  <?php echo get_partial('search/searchResults', array('pager' => $pager)) ?>
+  <?php echo get_partial('default/pager', array('pager' => $pager)) ?>
+  <?php endif; ?>
 
 <?php endif; ?>

Modified: trunk/apps/qubit/modules/search/templates/globalReplaceSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/search/templates/globalReplaceSuccess.php  Thu Oct 
13 12:07:10 2011        (r10073)
+++ trunk/apps/qubit/modules/search/templates/globalReplaceSuccess.php  Thu Oct 
13 12:50:19 2011        (r10074)
@@ -2,7 +2,7 @@
 
 <h1><?php echo __('Global search/replace') ?></h1>
 
-<form name="globalReplace" action="<?php echo url_for(array('module' => 
'search', 'action' => 'globalReplace')) ?>" method="get">
+<form action="<?php echo url_for(array('module' => 'search', 'action' => 
'globalReplace')) ?>" name="form" method="get">
 
   <?php echo get_partial('search/advancedSearch', array('form' => $form)) ?>
 
@@ -17,11 +17,7 @@
           <td>With:</td>
           <td style="padding: 0px;"><input type="text" 
name="replacement"/></td>
           <td style="white-space:nowrap;">in:
-            <select name="column" id="column" style="width:95%;">
-              <?php foreach($columns as $column => $name): ?>
-                <option value="<?php echo $column ?>"><?php echo __($name) 
?></option>
-              <?php endforeach; ?>
-            </select>
+            <?php echo $form->column->render() ?>
           </td>
         </tr>
       </tbody>
@@ -36,8 +32,7 @@
         <input type="submit" name="Submit" class="form-submit" value="Search" 
/>
 
         <?php if(isset($pager)): ?>
-          <input type="hidden" name="searchReplace" value="true"/>
-          <li><a class="delete" href="#" title="Replace" 
onclick="document.globalReplace.submit();">Replace</a></li>
+          <li><a class="delete" href="#" title="Replace" 
onclick="document.form.submit();">Replace</a></li>
         <?php endif; ?>
 
       </ul>
@@ -56,9 +51,9 @@
 
 <?php else: ?>
 
-  <?php if(isset($pager)):
-    echo get_partial('search/searchResults', array('pager' => $pager));
-    echo get_partial('default/pager', array('pager' => $pager));
-  endif; ?>
+  <?php if(isset($pager)): ?>
+    <?php echo get_partial('search/searchResults', array('pager' => $pager)) ?>
+    <?php echo get_partial('default/pager', array('pager' => $pager)) ?>
+  <?php endif; ?>
 
 <?php endif; ?>

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