-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTextInputColumn.php
More file actions
104 lines (83 loc) · 3.35 KB
/
Copy pathTextInputColumn.php
File metadata and controls
104 lines (83 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace dacduong\inlinegrid;
use kartik\grid\GridView;
use yii\helpers\Html;
class TextInputColumn extends DataColumn
{
const CONTROL_DEFAULT_VALUE = 'defaultValue';
const HELP_BLOCK = '<div class="help-block error-%s"></div>';
protected $help_block_str;
public $name = 'ddtextinput';
public $defaultValue = '';
public $cssClass = 'dd-row-textinput';
public $rowHighlight = true;
public $rowSelectedClass = GridView::TYPE_WARNING;
protected $_clientVars = '';
public $controlOptions = [];
public $refreshGrid = false;
/**
* @inheritdoc
*/
public function init()
{
parent::init();
InputColumnAsset::register($this->_view);
$this->help_block_str = sprintf(self::HELP_BLOCK, $this->attribute);
//mark model field as: value-$attribute
if (!array_key_exists('class', $this->controlOptions)) {
$this->controlOptions['class'] = 'value-'.$this->attribute;
} else {
$this->controlOptions['class'] .= ' value-'.$this->attribute;
}
//mark table footer pageSummaryFunc
if ($this->pageSummary) {
$this->pageSummaryOptions['data-func'] = $this->pageSummaryFunc;
$this->pageSummaryOptions['data-field'] = 'summary-'.$this->attribute;
$this->pageSummaryOptions['data-format'] = $this->format;
}
}
/**
* @inheritdoc
*/
public function renderDataCell($model, $key, $index)
{
$options = $this->fetchContentOptions($model, $key, $index);
$this->parseGrouping($options, $model, $key, $index);
$this->parseExcelFormats($options, $model, $key, $index);
//hightlight + name
if ($this->rowHighlight) {
Html::addCssClass($options, $this->cssClass);
}
if ($this->attribute !== null) {
$this->name = Html::getInputName($model, "[{$index}]{$this->attribute}");
}
//highlight row changed
$css = $this->rowHighlight ? $this->rowSelectedClass : '';
$grid = $this->grid->options['id'];
$this->_clientVars = "'{$grid}', '{$this->name}', '{$this->cssClass}', '{$css}'";
$this->_clientScript = "itSelectInput({$this->_clientVars});";
$this->_view->registerJs($this->_clientScript);
$this->initPjax($this->_clientScript);
return Html::tag('td', $this->renderDataCellContent($model, $key, $index), $options);
}
/**
* @inheritdoc
*/
protected function renderDataCellContent($model, $key, $index)
{
if ($this->content === null) {
$value = $this->getDataCellValue($model, $key, $index);
$formatedValue = '';
if ($value) {
$formatedValue = $this->grid->formatter->format($this->getDataCellValue($model, $key, $index), $this->format);
} else {
if (in_array(self::CONTROL_DEFAULT_VALUE, $this->controlOptions)) {
$formatedValue = $this->controlOptions[self::CONTROL_DEFAULT_VALUE];
}
}
return Html::textInput($this->name, $formatedValue, $this->controlOptions).$this->help_block_str;
} else {
return parent::renderDataCellContent($model, $key, $index);
}
}
}