Commit e250b96a by Nikola Trifunovic

Added summaryOptions and emptyTextOptions to BaseListView

parent 13ab9e2d
...@@ -3,6 +3,7 @@ Yii Framework 2 Change Log ...@@ -3,6 +3,7 @@ Yii Framework 2 Change Log
2.0.0 beta under development 2.0.0 beta under development
---------------------------- ----------------------------
- Enh: Added summaryOptions and emptyTextOptions to BaseListView (johonunu)
- Bug #1265: AssetController does not override 'js' and 'css' for compressed bundles (klimov-paul) - Bug #1265: AssetController does not override 'js' and 'css' for compressed bundles (klimov-paul)
- Bug #1326: The `visible` setting for `DetailView` doesn't work as expected (qiangxue) - Bug #1326: The `visible` setting for `DetailView` doesn't work as expected (qiangxue)
- Bug #1412: `FileValidator` and `ImageValidator` still trigger `uploadRequired` error in some case when `skipOnEmpty` is true and no upload is provided (qiangxue) - Bug #1412: `FileValidator` and `ImageValidator` still trigger `uploadRequired` error in some case when `skipOnEmpty` is true and no upload is provided (qiangxue)
......
...@@ -54,6 +54,12 @@ abstract class BaseListView extends Widget ...@@ -54,6 +54,12 @@ abstract class BaseListView extends Widget
*/ */
public $summary; public $summary;
/** /**
* @var array the HTML attributes for the summary of the list view.
* The "tag" element specifies the tag name of the summary element and defaults to "div".
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $summaryOptions = ['class' => 'summary'];
/**
* @var boolean whether to show the list view if [[dataProvider]] returns no data. * @var boolean whether to show the list view if [[dataProvider]] returns no data.
*/ */
public $showOnEmpty = false; public $showOnEmpty = false;
...@@ -62,6 +68,12 @@ abstract class BaseListView extends Widget ...@@ -62,6 +68,12 @@ abstract class BaseListView extends Widget
*/ */
public $emptyText; public $emptyText;
/** /**
* @var array the HTML attributes for the emptyText of the list view.
* The "tag" element specifies the tag name of the emptyText element and defaults to "div".
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $emptyTextOptions = ['class' => 'empty'];
/**
* @var string the layout that determines how different sections of the list view should be organized. * @var string the layout that determines how different sections of the list view should be organized.
* The following tokens will be replaced with the corresponding section contents: * The following tokens will be replaced with the corresponding section contents:
* *
...@@ -139,7 +151,8 @@ abstract class BaseListView extends Widget ...@@ -139,7 +151,8 @@ abstract class BaseListView extends Widget
*/ */
public function renderEmpty() public function renderEmpty()
{ {
return '<div class="empty">' . ($this->emptyText === null ? Yii::t('yii', 'No results found.') : $this->emptyText) . '</div>'; $tag = ArrayHelper::remove($this->emptyTextOptions, 'tag', 'div');
return Html::tag($tag, ($this->emptyText === null ? Yii::t('yii', 'No results found.') : $this->emptyText), $this->emptyTextOptions);
} }
/** /**
...@@ -151,6 +164,7 @@ abstract class BaseListView extends Widget ...@@ -151,6 +164,7 @@ abstract class BaseListView extends Widget
if ($count <= 0) { if ($count <= 0) {
return ''; return '';
} }
$tag = ArrayHelper::remove($this->summaryOptions, 'tag', 'div');
if (($pagination = $this->dataProvider->getPagination()) !== false) { if (($pagination = $this->dataProvider->getPagination()) !== false) {
$totalCount = $this->dataProvider->getTotalCount(); $totalCount = $this->dataProvider->getTotalCount();
$begin = $pagination->getPage() * $pagination->pageSize + 1; $begin = $pagination->getPage() * $pagination->pageSize + 1;
...@@ -161,29 +175,27 @@ abstract class BaseListView extends Widget ...@@ -161,29 +175,27 @@ abstract class BaseListView extends Widget
$page = $pagination->getPage() + 1; $page = $pagination->getPage() + 1;
$pageCount = $pagination->pageCount; $pageCount = $pagination->pageCount;
if (($summaryContent = $this->summary) === null) { if (($summaryContent = $this->summary) === null) {
return '<div class="summary">' return Html::tag($tag, Yii::t('yii', 'Showing <b>{begin, number}-{end, number}</b> of <b>{totalCount, number}</b> {totalCount, plural, one{item} other{items}}.', [
. Yii::t('yii', 'Showing <b>{begin, number}-{end, number}</b> of <b>{totalCount, number}</b> {totalCount, plural, one{item} other{items}}.', [
'begin' => $begin, 'begin' => $begin,
'end' => $end, 'end' => $end,
'count' => $count, 'count' => $count,
'totalCount' => $totalCount, 'totalCount' => $totalCount,
'page' => $page, 'page' => $page,
'pageCount' => $pageCount, 'pageCount' => $pageCount,
]) ]), $this->summaryOptions);
. '</div>';
} }
} else { } else {
$begin = $page = $pageCount = 1; $begin = $page = $pageCount = 1;
$end = $totalCount = $count; $end = $totalCount = $count;
if (($summaryContent = $this->summary) === null) { if (($summaryContent = $this->summary) === null) {
return '<div class="summary">' . Yii::t('yii', 'Total <b>{count, number}</b> {count, plural, one{item} other{items}}.', [ return Html::tag($tag, Yii::t('yii', 'Total <b>{count, number}</b> {count, plural, one{item} other{items}}.', [
'begin' => $begin, 'begin' => $begin,
'end' => $end, 'end' => $end,
'count' => $count, 'count' => $count,
'totalCount' => $totalCount, 'totalCount' => $totalCount,
'page' => $page, 'page' => $page,
'pageCount' => $pageCount, 'pageCount' => $pageCount,
]) . '</div>'; ]), $this->summaryOptions);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment