Skip to content

Commit

Permalink
Added position for batch actions (top, bottom, both)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasen Yanev committed Aug 6, 2013
1 parent b6aeede commit 96bbf91
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions classes/Kohana/Tart/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
*/
abstract class Kohana_Tart_Index extends Tart_Interface {

const BATCH_POSITION_TOP = 'top';
const BATCH_POSITION_BOTTOM = 'bottom';
const BATCH_POSITION_BOTH = 'both';

protected $_pagination;
protected $_offset;
protected $_batch_actions = array();
protected $_content;
protected $_collection;

protected $_batch_position = Kohana_Tart_Index::BATCH_POSITION_TOP;

public function collection(Jam_Query_Builder_Collection $collection = NULL)
{
if ($collection !== NULL)
Expand All @@ -33,6 +38,17 @@ function __construct(Jam_Query_Builder_Collection $collection, $offset, array $c

$this->_offset = $offset;
}

public function batch_position($batch_position = NULL)
{
if ($batch_position !== NULL)
{
$this->_batch_position = $batch_position;
return $this;
}

return $this->_batch_position;
}

public function content(Tart_Interface_Collection $content = NULL)
{
Expand Down Expand Up @@ -136,8 +152,17 @@ public function render()

$html = Tart::html($this, function($h, $self) use ($content) {
$h->form(Tart::uri($self->controller(), 'batch'), array('method' => 'get'), function($h, $self) use ($content) {
if ($self->batch_position() == Kohana_Tart_Index::BATCH_POSITION_BOTH OR $self->batch_position() == Kohana_Tart_Index::BATCH_POSITION_TOP)
{
$h->add($self->render_batch_actions());
}

$h->add($content);
$h->add($self->render_batch_actions());

if ($self->batch_position() == Kohana_Tart_Index::BATCH_POSITION_BOTH OR $self->batch_position() == Kohana_Tart_Index::BATCH_POSITION_BOTTOM)
{
$h->add($self->render_batch_actions());
}

This comment has been minimized.

Copy link
@hkdobrev

hkdobrev Aug 7, 2013

Contributor

@yanev Why not using an in_array check? It will somewhat reduce the length of such ifs.

});

$h->add($self->pagination()->render());
Expand Down

0 comments on commit 96bbf91

Please sign in to comment.