mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-17 07:51:12 +08:00
Refactored PR, updated CHANGELOG
This commit is contained in:
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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);");
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user