-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRGridViewWidget.php
More file actions
142 lines (127 loc) · 3.97 KB
/
RGridViewWidget.php
File metadata and controls
142 lines (127 loc) · 3.97 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* RGridViewWidget class file.
*
* @author Slava Rudnev <slava.rudnev@gmail.com>
* @link https://github.com/RSol/RGridView
*/
Yii::import('zii.widgets.grid.CGridView');
/**
* RGridViewWidget displays a list of ordered data items in terms of a table. This widget based on CGridView widget.
* You can order your model drageble.
*
* Using:
*
* <pre>
* $this->widget('ext.RGridViewWidget.RGridViewWidget', array(
* 'dataProvider'=>$dataProvider,
* 'rowCssId'=>'$data->id',
* 'orderUrl'=>array('order'),
* 'successOrderMessage'=>'Success',
* 'buttonLabel'=>'Order',
* 'template' => '{summary} {items} {order}',
* 'options'=>array(
* 'cursor' => 'crosshair',
* ),
* 'columns'=>array(
* ...
* ),
* ));
* </pre>
*
* Additional
*
* @author Slava Rudnev <slava.rudnev@gmail.com>
* @version 0.2
*/
class RGridViewWidget extends CGridView
{
/**
* @var string a PHP expression that will be evaluated for every data row and whose result will be rendered as the css id of the data row. In this expression, the variable $row the row number (zero-based); $data the data model for the row; and $this the column object
*/
public $rowCssId = '$data->id';
/**
* @var mixed a URL or an action route that can be used to create a URL.
* See {@see normalizeUrl} for more details about how to specify this parameter.
*/
public $orderUrl = array('order');
/**
* @var string After successfully order message
*/
public $successOrderMessage = 'Models succesfuly ordered';
/**
* @var string Label for ajax button
*/
public $buttonLabel = 'Order';
/**
* @var string the template to be used to control the layout of various sections in the view.
* These tokens are recognized: {summary}, {items} and {order}.
* They will be replaced with the summary text, the items, and the order ajax button (pager not used).
*/
public $template = '{summary} {items} {order}';
/**
* @var array the initial JavaScript options that should be passed to the JUI plugin.
*/
public $options = array();
/**
* Renders a table body row.
* @param integer $row the row number (zero-based).
*/
public function renderTableRow($row)
{
$id = '';
if($this->rowCssId !== null)
{
$data = $this->dataProvider->data[$row];
$id = ' id="' . $this->evaluateExpression($this->rowCssId, array('row' => $row, 'data' => $data)) . '" ';
}
if($this->rowCssClassExpression !== null)
{
$data = $this->dataProvider->data[$row];
echo '<tr '.$id.'class="rgridviewwidget ' . $this->evaluateExpression($this->rowCssClassExpression, array('row' => $row, 'data' => $data)) . '">';
}
else if(is_array($this->rowCssClass) && ($n = count($this->rowCssClass)) > 0)
echo '<tr '.$id.'class="rgridviewwidget ' . $this->rowCssClass[$row % $n] . '">';
else
echo '<tr'.$id.' class="rgridviewwidget">';
foreach($this->columns as $column)
$column->renderDataCell($row);
echo "</tr>\n";
}
/**
* Initializes the grid view.
* This method will initialize required property values and instantiate {@link columns} objects.
*/
public function init()
{
$options = array('items'=>'tr.rgridviewwidget');
if(is_array($this->options))
{
$options = array_merge($this->options, $options);
}
Yii::app()->clientScript->registerCoreScript('jquery.ui');
Yii::app()->clientScript->registerScript(__CLASS__, '$( "#'.$this->getId().'" ).sortable('.CJavaScript::encode($options).');');
parent::init();
$this->pager = null;
}
/**
* Renders a order ajax buttons.
* @param integer $row the row number (zero-based).
*/
public function renderOrder()
{
echo CHtml::ajaxButton($this->buttonLabel, $this->orderUrl, array(
'type' => 'POST',
'data' => array(
'Order' => 'js:$("#'.$this->getId().'").sortable("toArray").toString()',
),
'dataType' => 'json',
'success' => 'js:function(ansver){
if(ansver.msg=="Ok")
alert("'.$this->successOrderMessage.'");
else
alert(ansver.msg);
}',
));
}
}