<?php
$this->title="Тэги";
$parent_id = $model->id;

$newsDataProvider = new \yii\data\ActiveDataProvider(
    [
        "query"=>\app\models\base\Tags::find()->orderBy(["order"=>SORT_ASC]),
            "pagination" => false
    ]
);
	$key = 'tags_list2';
	$cache = Yii::$app->cache;
	$s = $cache->get($key);
	if ($s === false) {
	$s = '';
		foreach( $newsDataProvider->getModels() as $item ){
			$s .= '
		<tr>
			<td>'.$item->id.'</td>
			<td>'.$item->title.'</td>
			<td><span class="btn btn-primary" onclick="mergeto('.$parent_id.','.$item->id.', \''.$item->title.'\',mtitle);">Выбрать</span></td>
		</tr>
';
		}
		$cache->set($key, $s, 60*60);
	}
?>

<div class="callout callout-info">
<h5>Тэг: <?=$model->title?></h5>
<p><img class="align-self-start m-3 p-1 img-thumbnail" src="https://www.amic.ru/tags-images/<?=$model->id?>_size4.jpg" alt="<?=$model->title?>">Обьединение тэгов в один, выбирите тэг который необходимо слить с тэгом  <?=$model->title?> и удалить.</p>
</div>


<link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.css" />
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.js"></script>

<table id="tags" class="table table-bordered table-striped">
	<thead>
		<tr>
			<th style="width: 10px;">ID#</th>
			<th>Заголовок</th>
			<th>Выбор</th>
		</tr>
	</thead>
	<tbody>
	<?=$s?>
	</tbody>
	<tfoot>
		<tr>
			<th>номер</th>
			<th>title</th>
			<th>Action</th>
		</tr>
	</tfoot>
</table>

<div class="modal fade" id="modal-default" style="display: none;" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4 class="modal-title">Проверьте правильность обьединения</h4>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">×</span>
				</button>
			</div>
			<div class="modal-body">
				<p id="text" class="h5"></p>
			</div>
			<div class="modal-footer justify-content-between">
				<button type="button" class="btn btn-default" data-dismiss="modal">Отменить</button>
				<button type="button" class="btn btn-primary" onClick="window.location.href='/manager/tags/mergeto?id='+window.tagsid+'&idto=<?=$model->id?>'">Обьединить</button>
			</div>
		</div>
	</div>
</div>

<script>
  var mtitle='<?=$model->title?>';
  $(function () {
    $("#tags").DataTable({
	  "paging": true,
      "lengthChange": false,
      "searching": true,
      "ordering": false,
      "info": true,
      "autoWidth": true,
      "responsive": true,
	  "pageLength": 40
    });
  });
  function mergeto( pid, id, title, mtitle ){
	    $('#text').html('Слить тэг <b>"'+title+'"</b> в <b>"'+mtitle+'"</b>');
		window.tagsid = id;
		$('#modal-default').modal('show');
  }
</script>
