Development

#2100: batch_actions.patch

You must first sign up to be able to contribute.

Ticket #2100: batch_actions.patch

File batch_actions.patch, 10.1 kB (added by francois, 1 year ago)
  • data/generator/sfPropelAdmin/default/template/actions/actions.class.php

    old new  
    5252    return $this->forward('<?php echo $this->getModuleName() ?>', 'edit'); 
    5353  } 
    5454 
     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'); 
     102  } 
     103   
    55104  public function executeEdit() 
    56105  { 
    57106    $this-><?php echo $this->getSingularName() ?> = $this->get<?php echo $this->getClassName() ?>OrCreate(); 
  • data/generator/sfPropelAdmin/default/template/templates/_list.php

    old new  
     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')): ?> 
    612  <th id="sf_admin_list_th_sf_actions">[?php echo __('Actions') ?]</th> 
     
    1016<tbody> 
    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() ?>)) ?] 
    1522</tr> 
    1623[?php endforeach; ?] 
    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()): ?] 
    2229  [?php echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/first.png', array('align' => 'absmiddle', 'alt' => __('First'), 'title' => __('First'))), '<?php echo $this->getModuleName() ?>/list?page=1') ?] 
  • data/generator/sfPropelAdmin/default/template/templates/_list_batch_actions.php

    old new  
     1<?php $listActions = $this->getParameterValue('list.batch_actions') ?> 
     2<?php if (null !== $listActions): ?>   
     3<div id="sf_admin_batch_action_choice"> 
     4  <select name="sf_admin_batch_action"> 
     5    <option value="">[?php echo __('Choose an action') ?]</option> 
     6    <?php foreach ((array) $listActions as $actionName => $params): ?> 
     7    <?php echo $this->addCredentialCondition($this->getOptionToAction($actionName, $params), $params) ?> 
     8    <?php endforeach; ?> 
     9  </select> 
     10  [?php echo submit_tag(__('Ok')) ?] 
     11  </form> 
     12</div> 
     13<?php endif; ?> 
  • data/generator/sfPropelAdmin/default/template/templates/_list_td_batch_actions.php

    old new  
     1<?php if ($this->getParameterValue('list.batch_actions')): ?> 
     2<td> 
     3[?php echo checkbox_tag('sf_admin_batch_selection[]', $<?php echo $this->getSingularName() ?>->getPrimaryKey(), 0, array('class' => 'sf_admin_batch_checkbox')) ?] 
     4</td> 
     5<?php endif; ?> 
  • data/generator/sfPropelAdmin/default/template/templates/listSuccess.php

    old new  
    2323[?php else: ?] 
    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> 
    2829 
  • lib/generator/sfAdminGenerator.class.php

    old new  
    225225  } 
    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   * 
    230260   * @param string  The column name 
  • test/functional/backend/customizationTest.php

    old new  
    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)-> 
    6767 
     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)-> 
     74   
     75  checkListCustomization('add batch action', array('batch_actions' => array('_deleteSelected' => null, 'custom' => array('name' => 'my button', 'action' => 'myAction'))))-> 
     76  checkResponseElement('table.sf_admin_list tr.sf_admin_row_0 td input[class="sf_admin_batch_checkbox"][type="checkbox"]', true)-> 
     77  checkResponseElement('body div[id="sf_admin_batch_action_choice"] select[name="sf_admin_batch_action"]', true)-> 
     78  checkResponseElement('body div[id="sf_admin_batch_action_choice"] select[name="sf_admin_batch_action"] option[value="deleteSelected"]', "Delete Selected")-> 
     79  checkResponseElement('body div[id="sf_admin_batch_action_choice"] select[name="sf_admin_batch_action"] option[value="custom"]', "my button")-> 
     80     
    6881  // edit 
    6982  checkEditCustomization('edit title customization', array('title' => 'edit test title'))-> 
    7083  checkResponseElement('body h1', 'edit test title')->