Browse Source

Refactored PR, updated CHANGELOG

tags/2.0.8
SilverFire - Dmitry Naumenko 9 years ago
parent
commit
d3beca32b4
  1. 1
      framework/CHANGELOG.md
  2. 10
      framework/assets/yii.gridView.js
  3. 62
      framework/grid/CheckboxColumn.php
  4. 9
      framework/grid/GridView.php

1
framework/CHANGELOG.md

@ -243,6 +243,7 @@ Yii Framework 2 Change Log
- Bug #9046: Fixed problem with endless error loop when an error occurred after sending a stream or file download response to the user (cebe)
- Bug #9059: Fixed PHP Notice in error handler view (dynasource, andrewnester, samdark)
- Bug #9063: Workaround for MySQL losing table case when adding index (sebathi)
- Bug #9074: Fixed JS call `$('#grid').yiiGridView('getSelectedRows')` when `GridView::$showHeader` is set to false (NekitoSP, silverfire)
- Bug #9076: Fixed `yii\filters\PageCache` not using the configured duration and dependency when caching the response data (kidol)
- Bug #9091: `UrlManager::createUrl()` did not create correct url when defaults were used, internal cache is now skipped in certain situations (cebe)
- Bug #9127, #9128: Fixed MSSQL `QueryBuilder::renameColumn()` and `QueryBuilder::renameTable()` escaping (sitawit)

10
framework/assets/yii.gridView.js

@ -55,7 +55,12 @@
return this.each(function () {
var $e = $(this);
var settings = $.extend({}, defaults, options || {});
gridData[$e.attr('id')] = {settings: settings};
var id = $e.attr('id');
if (gridData[id] === undefined) {
gridData[id] = {};
}
gridData[id] = $.extend(gridData[id], {settings: settings});
var enterPressed = false;
$(document).off('change.yiiGridView keydown.yiiGridView', settings.filterSelector)
@ -142,6 +147,9 @@
setSelectionColumn: function (options) {
var $grid = $(this);
var id = $(this).attr('id');
if (gridData.id === undefined) {
gridData[id] = {};
}
gridData[id].selectionColumn = options.name;
if (!options.multiple || !options.checkAll) {
return;

62
framework/grid/CheckboxColumn.php

@ -10,6 +10,7 @@ namespace yii\grid;
use Closure;
use yii\base\InvalidConfigException;
use yii\helpers\Html;
use yii\helpers\Json;
/**
* CheckboxColumn displays a column of checkboxes in a grid view.
@ -82,14 +83,7 @@ class CheckboxColumn extends Column
$this->name .= '[]';
}
$name = $this->grid->showHeader ? $this->getHeaderCheckBoxName() : NULL;
$id = $this->grid->options['id'];
$options = json_encode([
'name' => $this->name,
'multiple' => $this->multiple,
'checkAll' => $name,
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$this->grid->getView()->registerJs("jQuery('#$id').yiiGridView('setSelectionColumn', $options);");
$this->registerClientScript();
}
/**
@ -100,28 +94,10 @@ class CheckboxColumn extends Column
*/
protected function renderHeaderCellContent()
{
$name = $this->name;
if (substr_compare($name, '[]', -2, 2) === 0) {
$name = substr($name, 0, -2);
}
if (substr_compare($name, ']', -1, 1) === 0) {
$name = substr($name, 0, -1) . '_all]';
} else {
$name .= '_all';
}
$id = $this->grid->options['id'];
$options = json_encode([
'name' => $this->name,
'multiple' => $this->multiple,
'checkAll' => $name,
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$this->grid->getView()->registerJs("jQuery('#$id').yiiGridView('setSelectionColumn', $options);");
if ($this->header !== null || !$this->multiple) {
return parent::renderHeaderCellContent();
} else {
return Html::checkbox($name, false, ['class' => 'select-on-check-all']);
return Html::checkbox($this->getHeaderCheckBoxName(), false, ['class' => 'select-on-check-all']);
}
}
@ -137,7 +113,7 @@ class CheckboxColumn extends Column
}
if (!isset($options['value'])) {
$options['value'] = is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : $key;
$options['value'] = is_array($key) ? Json::encode($key) : $key;
}
return Html::checkbox($this->name, !empty($options['checked']), $options);
@ -146,9 +122,35 @@ class CheckboxColumn extends Column
/**
* Returns header checkbox name
* @return string header checkbox name
* @since 2.0.8
*/
private function getHeaderCheckBoxName()
protected function getHeaderCheckBoxName()
{
return rtrim($this->name, '[]') . '_all';
$name = $this->name;
if (substr_compare($name, '[]', -2, 2) === 0) {
$name = substr($name, 0, -2);
}
if (substr_compare($name, ']', -1, 1) === 0) {
$name = substr($name, 0, -1) . '_all]';
} else {
$name .= '_all';
}
return $name;
}
/**
* Registers the needed JavaScript
* @since 2.0.8
*/
public function registerClientScript()
{
$id = $this->grid->options['id'];
$options = Json::encode([
'name' => $this->name,
'multiple' => $this->multiple,
'checkAll' => $this->grid->showHeader ? $this->getHeaderCheckBoxName() : null,
]);
$this->grid->getView()->registerJs("jQuery('#$id').yiiGridView('setSelectionColumn', $options);");
}
}

9
framework/grid/GridView.php

@ -272,11 +272,6 @@ class GridView extends BaseListView
$this->filterRowOptions['id'] = $this->options['id'] . '-filters';
}
$id = $this->options['id'];
$options = Json::htmlEncode($this->getClientOptions());
$view = $this->getView();
$view->registerJs("jQuery('#$id').yiiGridView($options);");
$this->initColumns();
}
@ -285,9 +280,11 @@ class GridView extends BaseListView
*/
public function run()
{
$id = $this->options['id'];
$options = Json::htmlEncode($this->getClientOptions());
$view = $this->getView();
GridViewAsset::register($view);
$view->registerJs("jQuery('#$id').yiiGridView($options);");
parent::run();
}

Loading…
Cancel
Save