Логика работы стр. категорий

parent 58125b54
......@@ -35,6 +35,18 @@
url('../fonts/RalewayRegular.ttf') format('truetype'),
url('../fonts/RalewayRegular.svg#RalewayRegular') format('svg');
}
@font-face {
font-family: 'RobotoCondensed-Regular';
src: url('../fonts/RobotoCondensed-Regular.ttf');
}
@font-face {
font-family: 'RobotoCondensed-Light';
src: url('../fonts/RobotoCondensed-Light.ttf');
}
@font-face {
font-family: 'RobotoCondensed-Bold';
src: url('../fonts/RobotoCondensed-Bold.ttf');
}
html {
font-size: 20px;
......
......@@ -38,3 +38,470 @@
/* .feeds-cats */
.feed-title
{
font-size: 16px;
color: #2E6DA4;
font-size: 14px;
font-style: italic;
font-weight: bold;
}
.table.feeds-cats
{
/*font-family: monospace;*/
font-family: 'RobotoCondensed-Regular', sans-serif;
}
.table.feeds-cats tbody
{
display: none;
}
.table.feeds-cats.open tbody
{
display: table-row-group;
}
.table.feeds-cats thead th.data
{
width: 1px;
min-width: 80px;
text-align: right;
}
.table.feeds-cats .cat-title-main,
.table.feeds-cats .cat-title
{
cursor: pointer;
}
.table.feeds-cats span.group
{
display: inline-block;
min-width: 12px;
color: #697075;
cursor: pointer;
}
.table.feeds-cats tbody tr td.percent
{
text-align: right;
}
.table.feeds-cats tbody tr td.percent .edited
{
cursor: pointer;
border-bottom: 1px dashed #697075;
}
.table.feeds-cats tbody tr td.percent .edited.was-edited,
.table.feeds-cats tbody tr td.percent .edited.was-changed
{
color: #009444;
border-color: #009444;
}
.table.feeds-cats tbody tr td.percent .old-value
{
display: none;
color: #697075;
font-size: 11px;
text-decoration: line-through;
}
.table.feeds-cats tbody tr td.percent .editing-wrap
{
display: none;
}
.table.feeds-cats tbody tr td.percent input.percent-input
{
margin-top: -2px;
width: 45px;
text-align: right;
}
.table.feeds-cats tbody tr td.percent
{
}
.table.feeds-cats tbody tr td.percent.own
{
font-family: 'RobotoCondensed-Bold', sans-serif;
}
.table.feeds-cats tbody tr td.percent.inherited
{
font-family: 'RobotoCondensed-Light', sans-serif;
}
.table.feeds-cats tr.feed-cat
{
display: none;
}
.table.feeds-cats tr.feed-cat[data-parent="0"],
.table.feeds-cats tr.feed-cat.open
{
display: table-row;
}
.table.feeds-cats span.group b.open
{
display: none;
}
.table.feeds-cats span.group.open b.closed
{
display: none;
}
.table.feeds-cats span.group.open b.open
{
display: inline;
}
.table.feeds-cats tr.feed-cat .foreign-id
{
font-family: 'RobotoCondensed-Light', sans-serif;
font-size: 14px;
}
.form-actions
{
display: none;
}
.table.feeds-cats .form-actions .btn
{
height: 24px;
line-height: 12px;
}
#period-stats,
#report-cats,
#viewid-stats
{
display: none;
}
input[type="checkbox"]
{
vertical-align: -2px;
}
.form-group .form-control
{
font-family: monospace;
}
.form-group select.form-control
{
height: 34px;
line-height: 14px;
padding-right: 15px;
border-color: #BDCED4;
background: url(../img/icon-open-accordeon.svg) right 4px center no-repeat;
background-size: 10px;
cursor: pointer;
}
.b-feeds-stat_data-loading
{
display: none;
position: absolute;
width: 100%;
height: 100%;
background: #FFF url(../img/gif-load.gif) center 200px no-repeat;
opacity: 0.5;
z-index: 10;
}
.b-feeds-stat_controls
{
margin-bottom: 25px;
height: 34px;
}
.b-feeds-stat_controls-report
{
float: left;
}
.b-feeds-stat_controls-period
{
float: right;
}
.b-feeds-stat_controls input.date-value
{
width: 100px;
}
.b-feeds-stat_controls select
{
display: inline-block;
margin: 0 15px 0 2px;
width: 120px;
height: 30px;
line-height: 15px;
}
.b-feeds-stat_controls .stat-period
{
width: 135px;
}
.chart-graph-stat-info,
.chart-graph-stat-error,
.chart-graph-stat-loading
{
display: none;
padding-top: 160px;
height: 370px;
text-align: center;
}
.b-table_wrapp.report
{
display: none;
margin-top: 30px;
}
.table.table-striped.admin.common
{
font-family: monospace;
}
.table.table-striped.admin.transaction
{
font-size: 13px;
}
.table.table-striped.admin.transaction thead
{
color: #337ab7;
line-height: 14px;
font-weight: bold;
}
table.table-striped.admin.transaction tbody
{
font-size: 12px;
}
.table.table-striped.admin thead.metric.sortable tr b
{
cursor: pointer;
}
.table.table-striped.admin thead.metric.sortable tr b.not-sorted
{
cursor: default;
}
.table.table-striped.admin.common thead.metric.sortable tr b.selected
{
color: #2CA02C;
}
.table.table-striped.admin.common thead.metric.sortable tr span
{
display: inline-block;
border-bottom: 2px solid red;
}
.table.table-striped.admin.transaction thead tr th.OrderSum
{
text-align: right;
}
.table.table-striped.admin.viewid thead tr th,
.table.table-striped.admin.transaction.viewid thead tr th.OrderSum
{
width: 1px;
}
.table.table-striped.admin.transaction.viewid thead tr th.Basket
{
width: 550px;
}
/* .b-basket-content */
.table.table-striped.admin.transaction thead tr th.period
{
min-width: 100px;
}
.table.table-striped.admin thead tr th.Timestamp
{
width: 100px;
line-height: 14px;
}
.table.table-striped.admin tbody td.Timestamp
{
line-height: 13px;
}
.table.table-striped.admin thead tr th.Basket
{
line-height: 14px;
}
.table.table-striped.admin thead tr th.Basket .basket-link,
.table.table-striped.admin thead tr th.Basket .quantity,
.table.table-striped.admin thead tr th.Basket .price
{
display: inline-block;
}
.table.table-striped.admin thead tr th.Basket .basket-link
{
width: 530px;
}
.table.table-striped.admin.viewid thead tr th.Basket .basket-link
{
width: 450px;
}
.table.table-striped.admin.viewid thead tr th.Basket .quantity,
.table.table-striped.admin.viewid thead tr th.Basket .price
{
text-align: center;
width: 50px;
}
.table.table-striped.admin thead tr th.Basket .quantity
{
text-align: center;
width: 55px;
}
.table.table-striped.admin.transaction thead tr th.OrderSum
{
width: 100px;
}
.table.table-striped.admin td.Basket
{
padding: 2px;
}
.table.table-striped.admin.transaction td.OrderSum
{
font-weight: bold;
text-align: right;
}
.table.table-striped.admin.transaction td.Pages
{
text-align: center;
}
.table.table-striped.admin.transaction tbody tr.total-orders
{
font-weight: bold;
font-size: 13px;
}
.table.table-striped.admin.common tbody tr.total
{
font-weight: bold;
}
.table.table-striped thead tr th.period b:after
{
content: " / ";
}
.table.table-striped thead tr th.period b:last-child:after
{
content: "";
}
.b-basket-content
{
margin: 4px;
padding: 2px;
font-size: 12px;
line-height: 14px;
}
.b-basket-content .basket-link
{
display: inline-block;
width: 540px;
}
table.viewid .b-basket-content .basket-link
{
display: inline-block;
width: 450px;
font-size: 11px;
font-weight: bold;
}
.b-basket-content .view-id-url
{
display: inline-block;
width: 450px;
margin-bottom: 4px;
word-break: break-word;
}
table.viewid .b-basket-content .quantity,
table.viewid .b-basket-content .price
{
width: 50px;
text-align: right;
}
.b-basket-content .quantity
{
display: inline-block;
width: 55px;
text-align: center;
}
.b-basket-content .price
{
display: inline-block;
width: 100px;
text-align: left;
}
table.viewid .b-basket-content .price
{
width: 40px;
}
.table.table-striped.admin thead.metric tr b .arrow
{
display: none;
}
.table.table-striped.admin thead.metric.sortable tr b.selected .arrow.asc,
.table.table-striped.admin thead.metric.sortable tr b.selected.desc .arrow.desc
{
display: inline;
}
.table.table-striped.admin thead.metric.sortable tr b.selected .arrow.desc,
.table.table-striped.admin thead.metric.sortable tr b.selected.desc .arrow.asc
{
display: none;
}
$(document).ready(function () {
"use strict";
/* Стр. категорий магазина */
var
$tableCats = $('.table.feeds-cats'),
isChanged = 0;
// Покидание страницы:
window.onbeforeunload = function(e) {
if (isChanged) {
return "Данные не сохранены. Закрыть страницу без сохранения?";
}
};
// Разворачиваем каждую ветку до того уровня где есть own-проценты:
ShowOwnPercents();
function ShowOwnPercents()
{
var
$groupTable = $('.cat-title-main .group', $tableCats),
$tr = $('tbody tr', $tableCats);
function OpenParentCat(id)
{
var
$parentTr = $('tbody tr[data-id="' + id + '"]', $tableCats),
$parentGroup = $('tbody tr[data-id="' + id + '"] .group', $tableCats),
parentId = $parentTr.attr('data-parent');
if ($parentTr.length) {
$parentTr.addClass('open');
$parentGroup.addClass('open');
OpenParentCat(parentId);
}
}
$.each($tr, function() {
var
$trItem = $(this),
$percent = $('td.percent', $trItem);
if ($percent.hasClass('own')) {
var
parentId = $trItem.attr('data-parent'),
$siblingsTr = $('tbody tr[data-parent="' + parentId + '"]', $tableCats);
// Разворачиваем соседей и предка:
$siblingsTr.addClass('open');
OpenParentCat(parentId);
// Разворачиваем основную таблицу:
$tableCats.addClass('open');
$groupTable.addClass('open');
}
});
}
// Свернуть-развернуть список категорий фида:
$('.cat-title-main', $tableCats).on('click', function(e) {
var
$this = $(this),
$group = $('.group', $this),
//$wrap = $this.parents('.feeds-cats').eq(0),
$wrap = $tableCats,
$allTrs = $('tr.feed-cat', $wrap),
$groupAllTrs = $('.group', $allTrs),
$mainTrs = $('tr.feed-cat[data-parent="0"]', $wrap),
isOpen;
$group.toggleClass('open');
isOpen = $group.hasClass('open');
if (isOpen) {
$groupAllTrs.addClass('open');
$allTrs.addClass('open');
} else {
$groupAllTrs.removeClass('open');
$allTrs.removeClass('open');
$mainTrs.addClass('open');
}
});
// Свернуть-развернуть категории в списке:
$('.cat-title', $tableCats).on('click', function(e) {
var
$this = $(this),
$group = $('.group', $this),
$wrap = $this.parents('.feed-cat').eq(0),
id = $wrap.data('id'),
$subcats,
isOpen;
$group.toggleClass('open');
isOpen = $group.hasClass('open');
$subcats = $('.feed-cat[data-parent="'+ id + '"]','.table.feeds-cats');
if (isOpen) {
$subcats.addClass('open');
} else {
$.each($subcats, function(i, item) {
var $span = $('span.group', $(item));
if ($span.hasClass('open')) {
$span.click();
}
});
$subcats.removeClass('open');
}
});
// Изменение значения процента для категории:
$('tbody tr td.percent .edited', $tableCats).on('click', function(){
var
$field = $(this),
$fieldValue = $('.percent-value', $field),
$td = $field.parents('td.percent').eq(0),
id = $td.parent().attr('data-id'),
$wrap = $field.parent(),
$inputWrap = $('.editing-wrap', $wrap),
$input = $('.editing', $wrap),
$oldValue = $('.old-value', $wrap),
oldVal = $field.attr('data-old-value'),
oldText = $fieldValue.html(),
oldType = $td.attr('data-old-type'),
$formActions = $('.form-actions');
$oldValue.hide();
$field.hide();
$inputWrap.show();
$input.off('blur').off('keyup').focus();
$input.on('keyup', function(e) {
if (e.keyCode == 13) {
$input.blur();
}
if (e.keyCode == 27) {
$input.off('blur');
$input.val(oldVal);
$fieldValue.html(oldText);
$inputWrap.hide();
$field.show();
}
});
$input.on('blur', function() {
var
textInput = $input.val(),
textField = textInput,
typeValue,
match, regex;
// Убираем пробелы, разделитель точкой:
textField = textField.replace(' ', '').replace(',', '.');
if (textField != '') {
// Проверка на число от 0.1 до 99.9 :
regex = /^[0-9]*[.,]?[0-9]+$/g;
match = regex.exec(textField)
if (!match || (textField < 0.1) || textField > 99.9) {
textField = oldVal;
$input.val(oldVal)
}
$fieldValue.removeClass('empty');
$td.removeClass('inherited').addClass('own');
}
$inputWrap.hide();
$fieldValue.html(textField);
// Очистили значение:
if (textField == '') {
$fieldValue.addClass('empty');
$td.removeClass('own').addClass('inherited');
var
parentValue,
parentId = $td.parent().attr('data-parent'),
$parentTr;
if (parentId == 0) {
parentValue = $tableCats.attr('data-feed-percent');
} else {
$parentTr = $('tbody tr[data-id="' + parentId + '"]', $tableCats);
parentValue = $('td .percent-input', $parentTr).val();
}
$fieldValue.html(parentValue);
$input.val(parentValue);
textField = parentValue;
}
// Прописываем значение у потомков c inherited:
SetChildInheritedValue(id, textField);
var valueType = $td.hasClass('own') ? 'own' : 'inherited';
if (textField != oldVal) {
$field.addClass('was-edited');
$oldValue.show();
} else {
//$field.removeClass('was-edited');
if (valueType != oldType) {
$field.addClass('was-edited');
} else {
$field.removeClass('was-edited');
}
$oldValue.hide();
}
CheckDiff();
$field.show();
});
function SetChildInheritedValue(id, val)
{
var
$childTrs = $('tbody tr[data-parent="' + id + '"]', $tableCats);
$childTrs.each(function(){
var
$childTr = $(this),
childId = $childTr.attr('data-id'),
$tdPercent = $('td.percent', $childTr);
if ($tdPercent.hasClass('inherited') ) {
$('.percent-value', $tdPercent).text(val);
$('.percent-input', $tdPercent).val(val);
var $edited = $('.edited', $tdPercent);
if (val != $edited.attr('data-old-value')) {
$edited.addClass('was-changed');
} else {
$edited.removeClass('was-changed');
}
SetChildInheritedValue(childId, val);
}
});
}
function CheckDiff()
{
var isDiff = $('.table.feeds-cats tbody tr td.percent .edited.was-edited').length;
isChanged = isDiff;
if (isDiff) {
$formActions.show();
} else {
$formActions.hide();
}
}
});
// Клик на "Сохранить":
$('.btn.btn-primary.submit-action').on('click', function(){
window.onbeforeunload = function() {};
var
$this = $(this),
action = $this.attr('action'),
method = $this.attr('method'),
formData = new FormData(),
cats = {};
$('tbody tr td.percent .edited', $tableCats).each(function(){
var
$this = $(this),
id, percentValue, feedId, catId, foreignId;
if ($this.hasClass('was-edited')) {
id = parseInt($this.parents('.feed-cat').eq(0).attr('data-id'));
percentValue = ($('.percent-value', $this).hasClass('empty')) ? null : parseFloat($('.percent-value', $this).text().trim())*10;
feedId = parseInt($this.parents('.feeds-cats').eq(0).attr('data-feed-id'));
foreignId = parseInt($('.foreign-id', $this.parents('.feed-cat').eq(0)).attr('data-id'));
cats[id] = {
'id' : id,
'fi' : feedId,
'fc' : foreignId,
'p' : percentValue,
}
}
});
formData.append('cats', JSON.stringify(cats));
console.log('AAA catsData = ', cats);
//return false;
$.ajax(action, {
type: method,
data: formData,
cache:false,
contentType: false,
processData: false,
success: function(data) {
console.log('AAA data = ', data);
if(data) {
if(data.result === true && data.redirect) {
document.location.href = data.redirect;
}
if(data.result === false && data.msg) {
$.showMessage('error', data.msg);
}
}
},
error: function(rew, status, err) {
console.log(status, err);
$.showMessage('error', err);
}
});
return false;
});
});
\ No newline at end of file
......@@ -26,38 +26,22 @@
/** @var $this \Zend\View\Renderer\PhpRenderer */
$this->headScript()
->appendFile('/js/jquery.cookie.js')
->appendFile('/js/bootstrap.min.js')
->appendFile('/js/feed-cats.js')
;
$this->headLink()
->appendStylesheet('/css/styles-feeds-stat.css')
->appendStylesheet('/css/styles-feeds-system.css')
;
/** @var \App\Entity\IdentityInterface $identity */
$identity = $this->identity();
$gravatar = $this->gravatar($identity->getEmail());
$gravatar->setDefaultImg(\Zend\View\Helper\Gravatar::DEFAULT_IDENTICON);
$sxml = new SimpleXMLElement(substr($gravatar, 0, -1) . '/>');
$src = $sxml['src'];
$error = $this->error;
if (!$error) {
/*
$current_report = $this->current_report;
$report_conf = $this->report_conf;
$reports_list = $this->reports_list;
$data_request_link = $this->url('user.cabinet', ['lang' => $this->lang, 'report' => $current_report]);
$system_link = $this->url('adm.system.actions');
*/
}
$lang = $this->lang;
$feeds_cats = $this->feeds_cats;
?>
<?php if($error): ?>
<section class="b-content__work">
......@@ -72,7 +56,6 @@ if (!$error) {
<div class="wrapp" style="position: relative;">
<div class="b-feeds-stat_controls form-group">
<?php /* Переключатель страниц */ ?>
<div class="b-filter__switch display">
<span class="b-filter__switch-item text"><a href="<?= $this->url('user.cabinet', ['lang' => $this->lang, 'report' => 'common']) ?>"><?= _t('Сводный отчет') ?></a></span>
......@@ -81,6 +64,86 @@ if (!$error) {
</div>
</div>
<?php
function render_cat($i, $cat)
{
$i++;
$symb = (count($cat['sub_cats']) > 0) ? '<span class="group"><b class="closed">+</b><b class="open">&ndash;</b></span>' : '<span class="group"></span>';
?>
<tr class="feed-cat" style="font-size: <?= 16-$i+1 ?>px;" data-id="<?= $cat['id'] ?>" data-parent="<?= $cat['parentid'] ?>">
<td>
<span class="cat-title" style="padding-left: <?= ($i-1)*40 ?>px;"><?= $symb ?><?= $cat['title'] ?> <span class="foreign-id" data-id="<?= $cat['foreignid'] ?>">[<?= $cat['foreignid'] ?>]</span></span>
</td>
<td class="percent <?= ($cat['own']) ? 'own': 'inherited' ?>" data-old-type="<?= ($cat['own']) ? 'own': 'inherited' ?>">
<span class="edited" data-old-value="<?= $cat['percent'] ?>"><span class="percent-value"><?= $cat['percent'] ?></span>&nbsp;%</span>
<span class="editing-wrap"><input class="percent-input editing" value="<?= $cat['percent'] ?>">&nbsp;%</span>
<br /><span class="old-value"><?= $cat['percent'] ?>&nbsp;%</span>
</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<?php if (count($cat['sub_cats']) > 0): ?>
<?php foreach ($cat['sub_cats'] as $sub_cat) : ?>
<?= render_cat($i, $sub_cat) ?>
<?php endforeach; ?>
<?php endif; ?>
<?php
}
?>
<?php foreach ($feeds_cats as $feeds_cat) : ?>
<div class="feed-title">категории фида <b><?= $feeds_cat['title'] ?></b>:</div>
<table class="table table-striped feeds-cats" data-content="cats" data-feed-id="<?= $feeds_cat['id'] ?>" data-feed-percent="<?= $feeds_cat['percent'] ?>">
<thead>
<tr>
<th>
<span class="cat-title-main">
<span class="group"><b class="closed">+</b><b class="open">&ndash;</b></span>Название категории</span>
<!-- Сохранить / Отмена -->
<span class="form-actions">
<a class="btn btn-primary submit-action" href="#" action="<?= $form_link ?>" method="post"><?= _t('Сохранить') ?></a>
<a class="btn btn-default cancel-action" href="<?= $link_cancel ?>"><?= _t('Отмена')?></a>
</span>
</th>
<th class="data"><span>Процент</span></th>
<th class="data"><span>Показы</span></th>
<th class="data"><span>Клики</span></th>
<th class="data"><span>Заказы</span></th>
<th class="data"><span>Стоимость</span></th>
<th class="data"><span>Комиссия</span></th>
</tr>
</thead>
<tbody>
<?php foreach ($feeds_cat['cats'] as $cat) : ?>
<?= render_cat(0, $cat) ?>
<?php endforeach; ?>
</tbody>
</table>
<?php endforeach; ?>
<!-- Сохранить / Отмена -->
<div class="form-actions">
<a class="btn btn-primary submit-action" href="#" action="<?= $form_link ?>" method="post"><?= _t('Сохранить') ?></a>
<a class="btn btn-default cancel-action" href="<?= $link_cancel ?>"><?= _t('Отмена')?></a>
</div>
</div>
</section>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment