Skip to content

Commit

Permalink
Rename placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Tupikov committed May 30, 2015
1 parent dfd203f commit 0ab288e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions src/MultipleInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private function getRowTemplate()
$hiddenInputs = [];
foreach ($this->columns as $columnIndex => $column) {
/* @var $column MultipleInputColumn */
$value = $column->name . '_value';
$value = 'multiple-' . $column->name . '-value';
$this->replacementKeys[$value] = $column->defaultValue;
$value = '{' . $value . '}';

Expand Down Expand Up @@ -238,7 +238,7 @@ private function collectJsTemplates()
{
$this->jsTemplates = [];
foreach ($this->getView()->js[View::POS_READY] as $key => $js) {
if (preg_match('/\(.#[^)]+{index}[^)]+\)/', $js) === 1) {
if (preg_match('/\(.#[^)]+{multiple-index}[^)]+\)/', $js) === 1) {
$this->jsTemplates[] = $js;
unset($this->getView()->js[View::POS_READY][$key]);
}
Expand All @@ -257,10 +257,10 @@ private function renderActionColumn()
[
'tagName' => 'div',
'encodeLabel' => false,
'label' => Html::tag('i', null, ['class' => 'glyphicon glyphicon-{btn_action}']),
'label' => Html::tag('i', null, ['class' => 'glyphicon glyphicon-{multiple-btn-action}']),
'options' => [
'id' => $this->getElementId('button'),
'class' => "{btn_type} multiple-input-list__btn btn js-input-{btn_action}",
'class' => "{multiple-btn-type} multiple-input-list__btn btn js-input-{multiple-btn-action}",
]
]
);
Expand All @@ -281,19 +281,19 @@ private function renderRow($index, $data = null)
{
$btnAction = $index == 0 ? self::ACTION_ADD : self::ACTION_REMOVE;
$btnType = $index == 0 ? 'btn-default' : 'btn-danger';
$search = ['{index}', '{btn_action}', '{btn_type}'];
$search = ['{multiple-index}', '{multiple-btn-action}', '{multiple-btn-type}'];
$replace = [$index, $btnAction, $btnType];

foreach ($this->columns as $column) {
/* @var $column MultipleInputColumn */
$search[] = '{' . $column->name . '_value}';
$search[] = '{multiple-' . $column->name . '-value}';
$replace[] = $column->prepareValue($data);
}

$row = str_replace($search, $replace, $this->getRowTemplate());

foreach ($this->jsTemplates as $js) {
$this->getView()->registerJs(strtr($js, ['{index}' => $index]), View::POS_READY);
$this->getView()->registerJs(strtr($js, ['{multiple-index}' => $index]), View::POS_READY);
}
return $row;
}
Expand All @@ -308,7 +308,7 @@ private function renderRow($index, $data = null)
public function getElementName($name, $index = null)
{
if ($index === null) {
$index = '{index}';
$index = '{multiple-index}';
}
return $this->getInputNamePrefix($name) . (
count($this->columns) > 1
Expand Down Expand Up @@ -367,8 +367,8 @@ public function registerClientScript()
'id' => $this->getId(),
'template' => $this->getRowTemplate(),
'jsTemplates' => $this->jsTemplates,
'btn_action' => self::ACTION_REMOVE,
'btn_type' => 'btn-danger',
'btnAction' => self::ACTION_REMOVE,
'btnType' => 'btn-danger',
'limit' => $this->limit,
'replacement' => $this->replacementKeys,
]
Expand Down
10 changes: 5 additions & 5 deletions src/assets/src/js/jquery.multipleInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
id: null,
template: null,
jsTemplates: [],
btn_action: null,
btn_type: null,
btnAction: null,
btnType: null,
limit: 1,
replacement: []
};
Expand Down Expand Up @@ -78,8 +78,8 @@
if (settings.limit != null && count >= settings.limit) {
return;
}
var search = ['{index}', '{btn_action}', '{btn_type}', '{value}'],
replace = [data.currentIndex, settings.btn_action, settings.btn_type, ''];
var search = ['{multiple-index}', '{multiple-btn-action}', '{multiple-btn-type}', '{multiple-value}'],
replace = [data.currentIndex, settings.btnAction, settings.btnType, ''];

for (var i in search) {
template = template.replaceAll(search[i], replace[i]);
Expand All @@ -96,7 +96,7 @@

var jsTemplate;
for (i in settings.jsTemplates) {
jsTemplate = settings.jsTemplates[i].replaceAll('{index}', data.currentIndex);
jsTemplate = settings.jsTemplates[i].replaceAll('{multiple-index}', data.currentIndex);
window.eval(jsTemplate);
}
wrapper.data('multipleInput').currentIndex++;
Expand Down

0 comments on commit 0ab288e

Please sign in to comment.