Development

Changeset 5102

You must first sign up to be able to contribute.

Changeset 5102

Show
Ignore:
Timestamp:
09/15/07 09:47:25 (1 year ago)
Author:
fabien
Message:

added batch action in admin generator list (closes #2100 - patch from francois)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/generator/sfAdminGenerator.class.php

    r5098 r5102  
    226226 
    227227  /** 
     228   * Returns HTML code for an action option in a select tag. 
     229   * 
     230   * @param string  The action name 
     231   * @param array   The parameters 
     232   * 
     233   * @return string HTML code 
     234   */ 
     235  public function getOptionToAction($actionName, $params) 
     236  { 
     237    $options = isset($params['params']) ? sfToolkit::stringToArray($params['params']) : array(); 
     238 
     239    // default values 
     240    if ($actionName[0] == '_') 
     241    { 
     242      $actionName = substr($actionName, 1); 
     243      if ($actionName == 'deleteSelected') 
     244      { 
     245        $params['name'] = 'Delete Selected'; 
     246      } 
     247    } 
     248    $name = isset($params['name']) ? $params['name'] : $actionName; 
     249 
     250    $options['value'] = $actionName; 
     251 
     252    $phpOptions = var_export($options, true); 
     253 
     254    return '[?php echo content_tag(\'option\', __(\''.$name.'\')'.($options ? ', '.$phpOptions : '').') ?]'; 
     255  } 
     256 
     257  /** 
    228258   * Returns HTML code for a column in edit mode. 
    229259   * 
  • trunk/lib/plugins/sfPropelPlugin/data/generator/sfPropelAdmin/default/template/actions/actions.class.php

    r4934 r5102  
    5151  { 
    5252    return $this->forward('<?php echo $this->getModuleName() ?>', 'edit'); 
     53  } 
     54 
     55<?php $listActions = $this->getParameterValue('list.batch_actions') ?> 
     56<?php if (null !== $listActions): ?> 
     57  public function executeBatchAction() 
     58  { 
     59    $action = $this->getRequestParameter('sf_admin_batch_action'); 
     60    switch($action) 
     61    { 
     62<?php foreach ((array) $listActions as $actionName => $params): ?> 
     63<?php 
     64// default values 
     65if ($actionName[0] == '_') 
     66{ 
     67  $actionName = substr($actionName, 1); 
     68  $name       = $actionName; 
     69  $action     = $actionName; 
     70} 
     71else 
     72{ 
     73  $name   = $actionName; 
     74  $action = isset($params['action']) ? $params['action'] : sfInflector::camelize($actionName); 
     75} 
     76?> 
     77      case "<?php echo $name ?>": 
     78        $this->forward('<?php echo $this->getModuleName() ?>', '<?php echo $action ?>'); 
     79        break; 
     80<?php endforeach; ?> 
     81    } 
     82 
     83    return $this->redirect('<?php echo $this->getModuleName() ?>/list'); 
     84  } 
     85<?php endif; ?> 
     86 
     87  public function executeDeleteSelected() 
     88  { 
     89    $this->selectedItems = $this->getRequestParameter('sf_admin_batch_selection', array()); 
     90 
     91    try 
     92    { 
     93      <?php echo $this->getClassName() ?>Peer::doDelete($this->selectedItems); 
     94    } 
     95    catch (PropelException $e) 
     96    { 
     97      $this->getRequest()->setError('delete', 'Could not delete the selected <?php echo sfInflector::humanize($this->getPluralName()) ?>. Make sure they do not have any associated items.'); 
     98      return $this->forward('<?php echo $this->getModuleName() ?>', 'list'); 
     99    } 
     100 
     101    return $this->redirect('<?php echo $this->getModuleName() ?>/list'); 
    53102  } 
    54103 
  • trunk/lib/plugins/sfPropelPlugin/data/generator/sfPropelAdmin/default/template/templates/_list.php

    r2786 r5102  
     1<?php if ($this->getParameterValue('list.batch_actions')): ?> 
     2[?php echo form_tag('<?php echo $this->getModuleNAme() ?>/batchAction') ?] 
     3<?php endif; ?> 
    14<table cellspacing="0" class="sf_admin_list"> 
    25<thead> 
    36<tr> 
     7<?php if ($this->getParameterValue('list.batch_actions')): ?> 
     8  <th id="sf_admin_list_th_sf_batch_actions">[?php echo checkbox_tag('foo', 1, 0, array('onclick' => "boxes = document.getElementsByTagName('input'); for(index in boxes) { box = boxes[index]; if (box.type == 'checkbox' && box.className == 'sf_admin_batch_checkbox') box.checked = this.checked } return true;")) ?]</th> 
     9<?php endif; ?> 
    410[?php include_partial('list_th_<?php echo $this->getParameterValue('list.layout', 'tabular') ?>') ?] 
    511<?php if ($this->getParameterValue('list.object_actions')): ?> 
     
    1117[?php $i = 1; foreach ($pager->getResults() as $<?php echo $this->getSingularName() ?>): $odd = fmod(++$i, 2) ?] 
    1218<tr class="sf_admin_row_[?php echo $odd ?]"> 
     19[?php include_partial('list_td_batch_actions', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?] 
    1320[?php include_partial('list_td_<?php echo $this->getParameterValue('list.layout', 'tabular') ?>', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?] 
    1421[?php include_partial('list_td_actions', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?] 
     
    1724</tbody> 
    1825<tfoot> 
    19 <tr><th colspan="<?php echo $this->getParameterValue('list.object_actions') ? count($this->getColumns('list.display')) + 1 : count($this->getColumns('list.display')) ?>"> 
     26<tr><th colspan="<?php echo count($this->getColumns('list.display')) + ($this->getParameterValue('list.object_actions') ? 1 : 0) + ($this->getParameterValue('list.batch_actions') ? 1 : 0) ?>"> 
    2027<div class="float-right"> 
    2128[?php if ($pager->haveToPaginate()): ?] 
  • trunk/lib/plugins/sfPropelPlugin/data/generator/sfPropelAdmin/default/template/templates/listSuccess.php

    r3310 r5102  
    2424[?php include_partial('<?php echo $this->getModuleName() ?>/list', array('pager' => $pager)) ?] 
    2525[?php endif; ?] 
     26[?php include_partial('list_batch_actions') ?] 
    2627[?php include_partial('list_actions') ?] 
    2728</div> 
  • trunk/test/functional/backend/customizationTest.php

    r4251 r5102  
    6565  checkResponseElement('body input[class="sf_admin_action_create"][onclick*="/article/create"]', false)-> 
    6666  checkResponseElement('body input[class="myButtonClass"][onclick*="/article/myAction"][value="my button"]', true)-> 
     67 
     68  checkListCustomization('add object action button', array('object_actions' => array('_edit' => null, '_delete' => null, 'custom' => array('name' => 'my button', 'action' => 'myAction'))))-> 
     69  checkResponseElement('table.sf_admin_list tr.sf_admin_row_0 td ul[class="sf_admin_td_actions"]', true)-> 
     70  checkResponseElement('table.sf_admin_list tr.sf_admin_row_0 td ul[class="sf_admin_td_actions"] li a', 3)-> 
     71  checkResponseElement('table.sf_admin_list tr.sf_admin_row_0 td ul[class="sf_admin_td_actions"] li a img[title="edit"]', true)-> 
     72  checkResponseElement('table.sf_admin_list tr.sf_admin_row_0 td ul[class="sf_admin_td_actions"] li a img[title="delete"]', true)-> 
     73  checkResponseElement('table.sf_admin_list tr.sf_admin_row_0 td ul[class="sf_admin_td_actions"] li a[href*="/article/myAction"] img[title="my button"]', true)-> 
    6774 
    6875  // edit 
  • trunk/test/functional/fixtures/project/apps/backend/modules/article/actions/actions.class.php

    r2288 r5102  
    1111class articleActions extends autoarticleActions 
    1212{ 
     13  public function executeMyAction() 
     14  { 
     15    return $this->renderText('Selected '.implode(', ', $this->getRequestParameter('sf_admin_batch_selection', array()))); 
     16  } 
    1317}