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 52 52 return $this->forward('<?php echo $this->getModuleName() ?>', 'edit'); 53 53 } 54 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 65 if ($actionName[0] == '_') 66 { 67 $actionName = substr($actionName, 1); 68 $name = $actionName; 69 $action = $actionName; 70 } 71 else 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 55 104 public function executeEdit() 56 105 { 57 106 $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; ?> 1 4 <table cellspacing="0" class="sf_admin_list"> 2 5 <thead> 3 6 <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; ?> 4 10 [?php include_partial('list_th_<?php echo $this->getParameterValue('list.layout', 'tabular') ?>') ?] 5 11 <?php if ($this->getParameterValue('list.object_actions')): ?> 6 12 <th id="sf_admin_list_th_sf_actions">[?php echo __('Actions') ?]</th> … … 10 16 <tbody> 11 17 [?php $i = 1; foreach ($pager->getResults() as $<?php echo $this->getSingularName() ?>): $odd = fmod(++$i, 2) ?] 12 18 <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() ?>)) ?] 13 20 [?php include_partial('list_td_<?php echo $this->getParameterValue('list.layout', 'tabular') ?>', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?] 14 21 [?php include_partial('list_td_actions', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?] 15 22 </tr> 16 23 [?php endforeach; ?] 17 24 </tbody> 18 25 <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) ?>"> 20 27 <div class="float-right"> 21 28 [?php if ($pager->haveToPaginate()): ?] 22 29 [?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 23 23 [?php else: ?] 24 24 [?php include_partial('<?php echo $this->getModuleName() ?>/list', array('pager' => $pager)) ?] 25 25 [?php endif; ?] 26 [?php include_partial('list_batch_actions') ?] 26 27 [?php include_partial('list_actions') ?] 27 28 </div> 28 29 -
lib/generator/sfAdminGenerator.class.php
old new 225 225 } 226 226 227 227 /** 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 /** 228 258 * Returns HTML code for a column in edit mode. 229 259 * 230 260 * @param string The column name -
test/functional/backend/customizationTest.php
old new 65 65 checkResponseElement('body input[class="sf_admin_action_create"][onclick*="/article/create"]', false)-> 66 66 checkResponseElement('body input[class="myButtonClass"][onclick*="/article/myAction"][value="my button"]', true)-> 67 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)-> 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 68 81 // edit 69 82 checkEditCustomization('edit title customization', array('title' => 'edit test title'))-> 70 83 checkResponseElement('body h1', 'edit test title')->