Initial import
This commit is contained in:
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
|
||||
use app\widgets\services\Includes;
|
||||
use app\widgets\services\UserRight;
|
||||
use app\widgets\services\XLSx;
|
||||
|
||||
/**
|
||||
* @var $this \yii\web\View;
|
||||
* @var $top array
|
||||
* @var $actions array
|
||||
* @var $th array
|
||||
* @var $data array
|
||||
* @var $advanced_filter string
|
||||
* @var $filter array
|
||||
* @var $exportData array
|
||||
* @var $ignoreIds array
|
||||
* @var $listTabs array
|
||||
* @var $model \yii\db\ActiveRecord | null
|
||||
*/
|
||||
?>
|
||||
<?php if ($_SERVER['REQUEST_METHOD'] == 'GET'): ?>
|
||||
<?php if (!UserRight::pub()): ?>
|
||||
<style>
|
||||
label.switch:has([data-key="is_for_publish"]),
|
||||
label.switch:has([data-key="on_partner_page"]),
|
||||
label.switch:has([data-key="partner_page_selected"]) {
|
||||
pointer-events: none;
|
||||
opacity: 0.8
|
||||
}
|
||||
</style>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!UserRight::isAdmin()): ?>
|
||||
<style>
|
||||
label.switch:has([data-key="private"]) {
|
||||
pointer-events: none;
|
||||
opacity: 0.8
|
||||
}
|
||||
</style>
|
||||
<?php endif; ?>
|
||||
<?php if (!UserRight::edit()): ?>
|
||||
<style>
|
||||
label.switch:has([data-key="partner_page_selected"]) {
|
||||
pointer-events: none;
|
||||
opacity: 0.8
|
||||
}
|
||||
</style>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
|
||||
if ($model && isset($_GET['update-indexes']) && $_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['indexes'])) {
|
||||
|
||||
$indexes = [];
|
||||
$ids = [];
|
||||
foreach (json_decode($_POST['indexes']) as $index) {
|
||||
$indexes[$index->id] = $index->order_index;
|
||||
$ids[] = $index->id;
|
||||
}
|
||||
|
||||
$data = $model::find()->where(['IN', 'id', $ids])->all();
|
||||
foreach ($data as $m) {
|
||||
if ($m->hasProperty('order_index')) {
|
||||
$m->{'order_index'} = $indexes[$m->{'id'}];
|
||||
$m->save();
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($_GET['export'])) {
|
||||
$ed = $exportData();
|
||||
//echo json_encode($ed);
|
||||
//exit;
|
||||
$error = 0;
|
||||
foreach (['data', 'file_name', 'header'] as $d) {
|
||||
if (empty($ed[$d]))
|
||||
$error++;
|
||||
}
|
||||
if ($error == 0)
|
||||
XLSx::toXlsWriter($ed['data'], $ed['file_name'], $ed['file_name'], $ed['header']);
|
||||
}
|
||||
|
||||
if (isset($_GET['p']) && sizeof($data['list']) == 0) {
|
||||
header('Location: ' . explode('?', $_SERVER['REQUEST_URI'])[0]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
Includes::top($top['title'] ?? null, $top['data'] ?? null);
|
||||
Includes::setListTabs($listTabs);
|
||||
?>
|
||||
|
||||
<div class="inner-content p10">
|
||||
<?= $this->render('includes/actions', ['actions' => $actions, 'data' => $data, 'exportData' => $exportData]) ?>
|
||||
<?= $this->render('includes/filter', ['filter' => $filter, 'advanced_filter' => $advanced_filter]); ?>
|
||||
<table class="cms-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<?php
|
||||
$j = 0;
|
||||
foreach ($th as $title => $class): ?>
|
||||
<th class="<?= $class ?>">
|
||||
<?php if (sizeof($data['list'])): ?>
|
||||
<?php if (isset($actions['delete']) && UserRight::del()): ?>
|
||||
<?= $j == 0 ? '<input id="checkAll" onclick="checkAll(this)" title="Избери всички" class="delete-checkbox" type="checkbox">' : '' ?>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?= $title ?>
|
||||
</th>
|
||||
<?php
|
||||
$j++;
|
||||
endforeach; ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="<?= sizeof($th) ?>" style="padding: 0"></td>
|
||||
</tr>
|
||||
<?php if (!empty($data['list'])): ?>
|
||||
<?php foreach ($data['list'] as $index => $td): ?>
|
||||
<tr <?= isset($td['order_index']) ? 'data-index="' . $td['order_index'] . '"' : '' ?>>
|
||||
<?php $i = 0;
|
||||
foreach ($th as $title => $class): ?>
|
||||
<td class="<?= $class ?>">
|
||||
<?php if (isset($actions['edit']) || isset($actions['delete'])): ?>
|
||||
<?php if (UserRight::edit() || UserRight::del()): ?>
|
||||
<?php if (!empty($ignoreIds)): ?>
|
||||
<?php if (!in_array($td[$i], $ignoreIds)): ?>
|
||||
<?= $i == 0 ? '<input onclick="checkSingle(this)" data-del="' . $td['id'] . '" class="delete-checkbox" type="checkbox">' : '' ?>
|
||||
<?php else: ?>
|
||||
<?= $i == 0 ? '<input disabled class="delete-checkbox" type="checkbox">' : '' ?>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<?= $i == 0 ? '<input onclick="checkSingle(this)" data-del="' . $td['id'] . '" class="delete-checkbox" type="checkbox">' : '' ?>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?= $td[$i] ?>
|
||||
</td>
|
||||
<?php $i++;endforeach; ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
|
||||
<tr>
|
||||
<td colspan="<?= sizeof($th) ?>" style="background: #fff"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ct" style="font-size: 16px; padding: 20px"
|
||||
colspan="<?= sizeof($th) ?>"><?= isset($_GET['q']) ? Yii::t('cms', 'No data found') : Yii::t('cms', 'No data has been added') ?></td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php if (!empty($data['list'])): ?>
|
||||
<?= $this->render('includes/pagination', ['data' => $data]) ?>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
<script src="/_public/assets/js/order.js"></script>
|
||||
|
||||
<script>
|
||||
let sl = [];
|
||||
|
||||
function checkAll(el) {
|
||||
sl = [];
|
||||
all('td [data-del]').forEach(e => {
|
||||
e.checked = el.checked === true;
|
||||
if (el.checked) {
|
||||
sl.push(e.dataset.del);
|
||||
e.parentNode.parentNode.addClass('checked');
|
||||
} else {
|
||||
e.parentNode.parentNode.removeClass('checked');
|
||||
}
|
||||
|
||||
})
|
||||
updateActionButtons();
|
||||
}
|
||||
|
||||
function checkSingle(e) {
|
||||
if (e) {
|
||||
if (e.checked) {
|
||||
sl.push(e.dataset.del);
|
||||
e.parentNode.parentNode.addClass('checked');
|
||||
} else {
|
||||
let checkedAll = one('#checkAll')
|
||||
if (checkedAll) {
|
||||
checkedAll.checked = false;
|
||||
}
|
||||
e.parentNode.parentNode.removeClass('checked');
|
||||
const f = sl.indexOf(e.dataset.del);
|
||||
sl.splice(f, 1);
|
||||
}
|
||||
updateActionButtons(e.dataset.del);
|
||||
}
|
||||
}
|
||||
|
||||
function updateActionButtons() {
|
||||
const bEdit = one('#bEdit');
|
||||
const bDelete = one('#bDelete');
|
||||
const delCount = one('#delCount');
|
||||
const c = sl.length;
|
||||
if (delCount)
|
||||
delCount.innerText = '(' + c + ')';
|
||||
if (c > 0) {
|
||||
if (bDelete)
|
||||
bDelete.removeClass('disabled');
|
||||
if (bEdit) {
|
||||
if (c < 2) {
|
||||
bEdit.href = window.getUri('o=w&id=' + sl[0])
|
||||
bEdit.removeClass('disabled');
|
||||
} else {
|
||||
bEdit.addClass('disabled');
|
||||
bEdit.href = '';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (bEdit)
|
||||
bEdit.addClass('disabled');
|
||||
if (bDelete)
|
||||
bDelete.addClass('disabled');
|
||||
}
|
||||
}
|
||||
|
||||
function checkDelete(e) {
|
||||
const msg = 'Сигурни ли сте, че искате да изтриете ' + (sl.length > 1 ? 'тези ' + sl.length + ' записа?' : 'този запис?');
|
||||
modal.confirm(msg, () => {
|
||||
request({
|
||||
url: window.getUri('o=d'),
|
||||
post: {
|
||||
ids: JSON.stringify(sl),
|
||||
model: e.dataset.model
|
||||
},
|
||||
done: e => {
|
||||
window.location.reload();
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
window.onscroll = function () {
|
||||
const ab = one('.action-buttons');
|
||||
if (ab) {
|
||||
if (window.pageYOffset > ab.offsetTop) {
|
||||
ab.addClass('buttons-top')
|
||||
} else {
|
||||
ab.removeClass('buttons-top')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('load', function () {
|
||||
all('.delete-checkbox', input => {
|
||||
input.checked = false;
|
||||
})
|
||||
})
|
||||
|
||||
orderItems('[data-index]', '?update-indexes=1', function () {
|
||||
});
|
||||
</script>
|
||||
<?php if (!UserRight::pub()): ?>
|
||||
<script>
|
||||
document.querySelectorAll('[data-key="on_partner_page"], [data-key="is_for_publish"], [data-key="partner_page_selected"]').forEach(e => {
|
||||
e.removeAttribute('onchange')
|
||||
})
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
Reference in New Issue
Block a user