Applying patch from 'kuja' to give default class names to links generated by Paginator::sort().

Fixes #6239
This commit is contained in:
mark_story 2009-08-26 23:33:13 -04:00
parent 38a4b619e6
commit 4f2d415663
2 changed files with 16 additions and 9 deletions

View file

@ -237,10 +237,17 @@ class PaginatorHelper extends AppHelper {
$sortKey = $this->sortKey($options['model']);
$isSorted = ($sortKey === $key || $sortKey === $this->defaultModel() . '.' . $key);
if ($isSorted && $this->sortDir($options['model']) === 'asc') {
$dir = 'desc';
if ($isSorted) {
if ($this->sortDir($options['model']) === 'asc') {
$dir = 'desc';
}
$class = $dir === 'asc' ? 'desc' : 'asc';
if (!empty($options['class'])) {
$options['class'] .= $class;
} else {
$options['class'] = $class;
}
}
if (is_array($title) && array_key_exists($dir, $title)) {
$title = $title[$dir];
}

View file

@ -152,7 +152,7 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->sort('date');
$expected = array(
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:date/direction:desc'),
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:date/direction:desc', 'class' => 'asc'),
'Date',
'/a'
);
@ -181,7 +181,7 @@ class PaginatorHelperTest extends CakeTestCase {
$this->Paginator->params['paging']['Article']['options']['sort'] = 'title';
$result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title');
$expected = array(
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:desc'),
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:desc', 'class' => 'asc'),
'descending',
'/a'
);
@ -190,13 +190,13 @@ class PaginatorHelperTest extends CakeTestCase {
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
$this->Paginator->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title');
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">Title<\/a>$/', $result);
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$this->Paginator->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title');
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc">Title<\/a>$/', $result);
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
}
/**
@ -216,7 +216,7 @@ class PaginatorHelperTest extends CakeTestCase {
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
$result = $this->Paginator->sort('Title','Article.title');
$expected = array(
'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:asc'),
'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:asc', 'class' => 'desc'),
'Title',
'/a'
);
@ -225,7 +225,7 @@ class PaginatorHelperTest extends CakeTestCase {
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$result = $this->Paginator->sort('Title','Article.title');
$expected = array(
'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:desc'),
'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:desc', 'class' => 'asc'),
'Title',
'/a'
);