1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* HiPanel core package |
5
|
|
|
* |
6
|
|
|
* @link https://hipanel.com/ |
7
|
|
|
* @package hipanel-core |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hipanel\grid; |
13
|
|
|
|
14
|
|
|
use hipanel\helpers\ArrayHelper; |
15
|
|
|
use hipanel\widgets\XEditable; |
16
|
|
|
use Yii; |
17
|
|
|
use yii\helpers\Html; |
18
|
|
|
use yii\helpers\Url; |
19
|
|
|
|
20
|
|
|
class MainColumn extends DataColumn |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var true|string |
24
|
|
|
* true - note editing is enabled in this column, target attribute name is `note` |
25
|
|
|
* string - target atttribute name |
26
|
|
|
*/ |
27
|
|
|
public $note; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array will be passed to the ```pluginOptions``` of [[XEditable]] plugin |
31
|
|
|
*/ |
32
|
|
|
public $noteOptions = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Builds url. |
36
|
|
|
* @param string $url |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
|
public function buildUrl($url) |
40
|
|
|
{ |
41
|
|
|
if (strncmp($url, '/', 0) === 0) { |
42
|
|
|
return $url; |
43
|
|
|
} |
44
|
|
|
$baseUrl = isset($this->grid->controllerUrl) ? $this->grid->controllerUrl : ''; |
45
|
|
|
return $baseUrl ? Url::to($baseUrl . '/' . $url) : Url::to($url); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function init() |
49
|
|
|
{ |
50
|
|
|
parent::init(); |
51
|
|
|
$this->noteOptions = ArrayHelper::merge([ |
52
|
|
|
'url' => $this->buildUrl('set-note'), |
53
|
|
|
], $this->noteOptions); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** {@inheritdoc} */ |
57
|
|
|
protected function renderDataCellContent($model, $key, $index) |
58
|
|
|
{ |
59
|
|
|
$value = parent::renderDataCellContent($model, $key, $index); |
60
|
|
|
$html = Html::a($value, [$this->buildUrl('view'), 'id' => $model->id], ['class' => 'bold']); |
61
|
|
|
if ($this->note) { |
62
|
|
|
$html .= $this->renderEditableNote($model, $key, $index); |
63
|
|
|
} |
64
|
|
|
return $html; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Renders link to edit note. |
69
|
|
|
* @param $model |
70
|
|
|
* @param $key |
71
|
|
|
* @param $index |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
public function renderEditableNote($model, $key, $index) |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
return '<br>' . Html::tag('span', Yii::t('app', 'Note') . ': ', ['class' => 'bold']) . XEditable::widget([ |
77
|
|
|
'model' => $model, |
78
|
|
|
'attribute' => $this->note === true ? 'note' : $this->note, |
79
|
|
|
'pluginOptions' => $this->noteOptions, |
80
|
|
|
]); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.