Skip to content

Commit

Permalink
Add mass deletion action to grid view (AOEpeople#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
mzeis committed Sep 27, 2015
1 parent bcdf8ad commit f2be115
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Expand Up @@ -20,6 +20,17 @@ public function __construct()
$this->setUseAjax(true);
}

protected function _prepareMassaction() {
$this->setMassactionIdField('stack_id');
$this->getMassactionBlock()->setFormFieldName('stack');

$this->getMassactionBlock()->addItem('delete', array(
'label' => Mage::helper('aoe_profiler')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete'),
'confirm' => Mage::helper('aoe_profiler')->__('Are you sure?')
) );
}

/**
* Prepare grid collection object
*
Expand Down Expand Up @@ -108,4 +119,4 @@ public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=>true));
}
}
}
Expand Up @@ -89,6 +89,32 @@ public function gridAction()
$this->renderLayout();
}

/**
* @return void
*/
public function massDeleteAction()
{
$ids = $this->getRequest()->getParam('stack');
if (!is_array($ids)) {
$this->_getSession()->addError($this->__('Please select stack(s).'));
} else {
if (!empty($ids)) {
try {
foreach ($ids as $id) {
$stack = Mage::getSingleton('aoe_profiler/run')->load($id);
$stack->delete();
}
$this->_getSession()->addSuccess(
$this->__('Total of %d record(s) have been deleted.', count($ids))
);
} catch (Exception $e) {
$this->_getSession()->addError($e->getMessage());
}
}
}
$this->_redirect('*/*/index');
}

/**
* Edit layout instance action
*
Expand Down

0 comments on commit f2be115

Please sign in to comment.