@@ -28,32 +28,26 @@ class MultipleInput extends InputWidget
28
28
{
29
29
const ACTION_ADD = 'plus ' ;
30
30
const ACTION_REMOVE = 'remove ' ;
31
-
32
31
/**
33
32
* @var ActiveRecord[]|array[] input data
34
33
*/
35
34
public $ data = null ;
36
-
37
35
/**
38
36
* @var array columns configuration
39
37
*/
40
38
public $ columns = [];
41
-
42
39
/**
43
40
* @var integer inputs limit
44
41
*/
45
42
public $ limit ;
46
-
47
43
/**
48
44
* @var string generated template, internal variable.
49
45
*/
50
46
protected $ template ;
51
-
52
47
/**
53
48
* @var string
54
49
*/
55
50
protected $ replacementKeys ;
56
-
57
51
public function init ()
58
52
{
59
53
parent ::init ();
@@ -64,14 +58,15 @@ public function init()
64
58
}
65
59
}
66
60
}
67
-
68
-
69
61
/**
70
62
* Run widget.
71
63
*/
72
64
public function run ()
73
65
{
74
- echo Html::beginTag ('div ' , ['id ' => $ this ->getId (), 'class ' => 'list-group ' ]);
66
+ echo Html::beginTag ('div ' , [
67
+ 'id ' => $ this ->getId (),
68
+ 'class ' => 'multiple-input '
69
+ ]);
75
70
echo Html::beginTag ('table ' , [
76
71
'class ' => 'multiple-input-list table table-condensed '
77
72
]);
@@ -89,10 +84,8 @@ public function run()
89
84
echo Html::endTag ('tbody ' );
90
85
echo Html::endTag ('table ' );
91
86
echo Html::endTag ('div ' );
92
-
93
87
$ this ->registerClientScript ();
94
88
}
95
-
96
89
/**
97
90
* Render header.
98
91
*
@@ -124,7 +117,6 @@ private function renderHeader()
124
117
echo Html::endTag ('tr ' );
125
118
echo Html::endTag ('thead ' );
126
119
}
127
-
128
120
/**
129
121
* Check that at least one column has a header.
130
122
*
@@ -139,7 +131,6 @@ private function hasHeader()
139
131
}
140
132
return false ;
141
133
}
142
-
143
134
private function getRowTemplate ()
144
135
{
145
136
if (empty ($ this ->template )) {
@@ -150,16 +141,12 @@ private function getRowTemplate()
150
141
foreach ($ this ->getColumns () as $ columnIndex => $ column ) {
151
142
$ field = $ column ['name ' ];
152
143
$ name = $ this ->getElementName ($ field );
153
-
154
144
$ value = $ field . '_value ' ;
155
145
$ this ->replacementKeys [$ value ] = ArrayHelper::getValue ($ column , 'defaultValue ' , '' );
156
146
$ value = '{ ' . $ value . '} ' ;
157
-
158
147
$ options = ArrayHelper::getValue ($ column , 'options ' , []);
159
148
$ options ['id ' ] = $ this ->getElementId ($ field );
160
-
161
149
$ type = ArrayHelper::getValue ($ column , 'type ' , 'textInput ' );
162
-
163
150
if ($ type == 'hiddenInput ' ) {
164
151
$ hiddenFields .= Html::hiddenInput ($ name , $ value , $ options );
165
152
} else {
@@ -207,9 +194,10 @@ private function getRowTemplate()
207
194
'tagName ' => 'div ' ,
208
195
'encodeLabel ' => false ,
209
196
'label ' => Html::tag ('i ' , null , ['class ' => 'glyphicon glyphicon-{btn_action} ' ]),
197
+ 'type ' => '{btn_type} ' ,
210
198
'options ' => [
211
199
'id ' => $ this ->getElementId ('button ' ),
212
- 'class ' => "{btn_type} multiple-input-list__btn btn js- { $ this -> getId ()} -input-{btn_action} " ,
200
+ 'class ' => "multiple-input-list__btn btn js-input-{btn_action} " ,
213
201
]
214
202
]
215
203
);
@@ -219,7 +207,6 @@ private function getRowTemplate()
219
207
}
220
208
return $ this ->template ;
221
209
}
222
-
223
210
/**
224
211
* Render row.
225
212
*
@@ -230,7 +217,6 @@ private function renderRow($index, $data = null)
230
217
{
231
218
$ btnAction = $ index == 0 ? self ::ACTION_ADD : self ::ACTION_REMOVE ;
232
219
$ btnType = $ index == 0 ? 'btn-default ' : 'btn-danger ' ;
233
-
234
220
$ search = ['{index} ' , '{btn_action} ' , '{btn_type} ' ];
235
221
$ replace = [$ index , $ btnAction , $ btnType ];
236
222
foreach ($ this ->getColumns () as $ column ) {
@@ -239,7 +225,6 @@ private function renderRow($index, $data = null)
239
225
}
240
226
echo str_replace ($ search , $ replace , $ this ->getRowTemplate ());
241
227
}
242
-
243
228
/**
244
229
* @param $column
245
230
* @param $data
@@ -263,7 +248,6 @@ private function prepareColumnValue($column, $data)
263
248
}
264
249
return $ value ;
265
250
}
266
-
267
251
/**
268
252
* @param $name
269
253
* @param string $index
@@ -280,7 +264,6 @@ private function getElementName($name, $index = null)
280
264
: '[ ' . $ name . '][ ' . $ index . '] ' ;
281
265
return $ elementName ;
282
266
}
283
-
284
267
/**
285
268
* @param $name
286
269
* @return mixed
@@ -289,16 +272,14 @@ private function getElementId($name)
289
272
{
290
273
return $ this ->normalize ($ this ->getElementName ($ name ));
291
274
}
292
-
293
275
/**
294
276
* @param $name
295
277
* @return mixed
296
278
*/
297
279
private function normalize ($ name ) {
298
280
return str_replace (['[] ' , '][ ' , '[ ' , '] ' , ' ' , '. ' ], ['' , '- ' , '- ' , '' , '- ' , '- ' ], strtolower ($ name ));
299
281
}
300
-
301
- /**
282
+ /**
302
283
* @return string
303
284
*/
304
285
private function getName ()
@@ -308,7 +289,6 @@ private function getName()
308
289
}
309
290
return $ this ->name ;
310
291
}
311
-
312
292
/**
313
293
* @return array
314
294
*/
@@ -321,7 +301,6 @@ private function getColumns()
321
301
}
322
302
return $ this ->columns ;
323
303
}
324
-
325
304
/**
326
305
* Регистрирует клиентский скрипт и опции.
327
306
*/
@@ -343,4 +322,4 @@ public function registerClientScript()
343
322
$ js = "jQuery('# $ id').multipleInput( $ options); " ;
344
323
$ this ->getView ()->registerJs ($ js );
345
324
}
346
- }
325
+ }
0 commit comments