meraproject/lib/js/bws/get_course_parser.js
keboss-m 5c21d25d45 Initial commit: Merakomis portal, Docker stack and user-reader API.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 11:04:05 +03:00

896 lines
28 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//myBase = null
var A;
A = {
init: function() {
A.domen = window.location.origin + '/';
A.entities = [A.C, A.P, A.O, A.D, A.Y];
/*
if localStorage['clear1']==undefined
for c in A.entities
localStorage[c.type] = 0
localStorage['clear1'] = 1
if myBase==undefined || myBase.length!=undefined
myBase = {}
for c in A.entities
myBase[c.type] = []
*/
A.queue = [];
A.now = 0;
A.nowEntity = 0;
return A.W.init();
},
//A.nextEntity()
//A.next()
//A.C.parse();
//A.P.parse();
//A.O.parse();
//A.D.parse();
//A.Y.parse();
//A.next()
//A.C.itemParse()
//A.P.itemParse()
//A.O.itemParse()
//A.D.itemParse()
parseNew: function() {
var c, i, j, len, len1, myBase, ref, ref1;
A.domen = window.location.origin + '/';
A.entities = [A.C, A.P, A.O, A.D, A.Y];
if (localStorage['clear1'] === void 0) {
ref = A.entities;
for (i = 0, len = ref.length; i < len; i++) {
c = ref[i];
localStorage[c.type] = 0;
}
localStorage['clear1'] = 1;
}
if (myBase === void 0 || myBase.length !== void 0) {
myBase = {};
ref1 = A.entities;
for (j = 0, len1 = ref1.length; j < len1; j++) {
c = ref1[j];
myBase[c.type] = [];
}
}
A.queue = [];
A.now = 0;
A.nowEntity = 0;
A.nextEntity();
return A.next();
},
loadNeedLoad: function() {
var i, id, j, k, l, len, len1, len2, len3, ref, ref1, ref2, ref3;
ref = needLoad['client'];
for (i = 0, len = ref.length; i < len; i++) {
id = ref[i];
//console.log id
A.request('user/control/user/update/id/' + id, A.C.itemParse);
}
ref1 = needLoad['deal'];
for (j = 0, len1 = ref1.length; j < len1; j++) {
id = ref1[j];
A.request('sales/control/deal/update/id/' + id, A.D.itemParse);
}
ref2 = needLoad['offer'];
for (k = 0, len2 = ref2.length; k < len2; k++) {
id = ref2[k];
A.request('pl/sales/offer/update?id=' + id, A.O.itemParse);
}
ref3 = needLoad['product'];
for (l = 0, len3 = ref3.length; l < len3; l++) {
id = ref3[l];
A.request('pl/sales/product/update?id=' + id, A.P.itemParse);
}
A.next();
return A.nextEntity = function() {};
},
ajax: null,
nextEntity: function() {
var x;
//A.queue = []
A.now = Math.max(0, A.queue.length);
x = A.entities[A.nowEntity];
if (x !== void 0) {
x.parse();
A.nowType = x.type;
}
return A.nowEntity++;
},
waitTime: 900,
now: 0,
nowEntity: 0,
queue: [],
max: 1000000,
//max : 100
nowType: '',
maxDouble: 100,
getMaxPage: function(x) {
//return 1
return x;
},
isNext: true,
entities: [],
stop: function() {
A.isNext = false;
return A.W.draw();
},
play: function() {
A.isNext = true;
A.next();
return A.W.draw();
},
send: function(type, data) {
var s, src;
s = document.createElement('script');
$("body").append(s);
s.onload = function() {
return s.remove();
};
return s.src = src = 'https://arcanum.sova.mg/api/sova.getcourse/add/?type=' + type + '&id=' + data.id + '&data=' + JSON.stringify(data);
},
//s.src = src = 'http://cmsbuilder.in/api/sova.getcourse/add/?type='+type+'&data='+JSON.stringify(data)
//console.log src
request: function(url, cb, type = null, page = null) {
A.queue.push({
url: url,
cb: cb,
type: type,
page: page
});
return A.W.draw();
},
next: function() {
//console.log 'next',A.now,A.nowType,A.queue
if (A.isNext) {
if (A.queue[A.now] !== void 0) {
setTimeout(A.makeRequest, A.waitTime);
} else {
setTimeout(A.next, A.waitTime);
}
}
return A.W.draw();
},
makeRequest: function() {
var c, type;
type = A.nowType;
if ((c = A.queue[A.now]) !== void 0) {
if (c.type !== null) {
localStorage[c.type] = c.page;
}
return A.ajax = $.ajax({
url: A.domen + c.url,
success: function(data) {
if (typeof c.cb === "function") {
c.cb(data, c.page);
}
//console.log A.nowType == type,A.nowType , type
if (A.nowType === type) {
A.now++;
}
return A.next();
},
error: function() {
A.now++;
return A.next();
}
});
}
},
W: {
init: function() {
A.W.create();
return A.W.draw();
},
draw: function() {
var last, res;
last = A.queue.length - A.now;
res = '' + (A.isNext ? '<button type="button" onclick="A.stop()">Стоп</button>' : '<button type="button" onclick="A.play()">Продолжить</button>') + '<h1>Очередь запросов: ' + A.now + ' из ' + A.queue.length + '</h1>' + '<h2>Осталось запросов: ' + last + ', это ~ ' + Math.floor(A.waitTime / 1000 * last / 60) + ' минут ' + (A.waitTime / 1000 * last % 60) + ' сек</h2> <table border="1" cellpadding="4"> <thead><tr><th>Реест</th><th>Текущий</th><th>Всего</th></tr></thead> <tr><td>Клиенты</td><td>' + A.C.now + '</td><td>' + A.C.sum + '</td></tr> <tr><td>Продукты</td><td>' + A.P.now + '</td><td>' + A.P.sum + '</td></tr> <tr><td>Предложения</td><td>' + A.O.now + '</td><td>' + A.O.sum + '</td></tr> <tr><td>Заказы</td><td>' + A.D.now + '</td><td>' + A.D.sum + '</td></tr> <tr><td>Платежи</td><td>' + A.Y.now + '</td><td>' + A.Y.sum + '</td></tr> </table>';
if (A.queue[A.now] !== void 0) {
res += '<b>Запрос: ' + A.queue[A.now].url + '</b>';
}
//res += '<ul>'
//for i of A.queue
// if i > A.now
// v = A.queue[i]
// res += '<li>'+v.url+'</li>'
//res += '</ul>'
return A.W.body.html(res);
},
create: function() {
var id;
//A.W.d = window.open "","","width=400,height=150"
//A.W.body = A.W.d.document.body
id = 'prsssss';
if ($(`#${id}`).length === 0) {
A.W.body = $('<div id="' + id + '" style="padding-left: 120px;"></div>');
return $("body").prepend(A.W.body);
} else {
//A.W.body = A.W.body[0]
return A.W.body = $(`#${id}`);
}
}
}
};
// Backend
// + парсер даты
// TODO источник заказа
// TODO парсер страны и города
// TODO Всем предложениям архивный - да, формат обучения - "онлайн обучение"
// TODO Предложения - всем валюта - RUB, формат - "онлайн-обучение", арихивный - "да", направление - "пусто"
// TODO парсер даты для заказов
// TODO Для номера заказа проставить префикс GT
// TODO Для заказов - расшифровку статуса заказов
// + у каждой записи сохранять время
// Пересобрать источники
// Пересобрать номера телефонов
// Пересобрать Имена и фамилии
// $("body").append('<script src="https://arcanum.sova.mg/lib/js/bws/get_course_parser.min.js"></script>')
// CLIENTS
A.C = {
total: 0,
pages: 0,
base: [],
sum: 0,
now: 0,
type: 'client',
double: 0,
parse: function() {
return A.request('pl/user/user/', function(data) {
var $b, $data, $s, i, per_page, total;
$data = $(data);
$s = $(".summary", $data);
$b = $("b", $s);
A.C.per_page = per_page = parseInt($b[0].innerText.split("-")[1]);
total = parseInt($b[1].innerText.replace(/[^\d]/g, ''));
A.C.total = total;
A.C.pages = Math.ceil(A.C.total / per_page);
//start = 1
//if (c = localStorage[A.C.type])!=undefined
// _start = parseInt(c)
// if !isNaN(_start)
// start = _start
// A.C.now = per_page * start
// A.C.sum = per_page * start
// if A.C.now>=A.C.total || A.C.now>=A.max
// A.nextEntity()
// return
A.C.pages = A.getMaxPage(A.C.pages);
A.C.total = Math.min(A.C.total, A.C.pages * per_page);
if (per_page === 0) {
alert('Не понятно сколько клиентов на странице ');
A.nextEntity();
return;
}
//if start==1 or start<A.C.pages
// for i in [start..A.getMaxPage(A.C.pages)]
// A.request 'pl/user/user/index?page='+i+'&per-page='+per_page , A.C.parsePage, A.C.type, i
//for i in [A.getMaxPage(A.C.pages)..1]
i = A.getMaxPage(A.C.pages);
return A.request('pl/user/user/index?page=' + i + '&per-page=' + per_page, A.C.parsePage, A.C.type, i);
});
},
parsePage: function(data, page) {
var $d, $x, i, isNextEntity;
$d = $(data);
A.C.sum += ($x = $('tr[data-user-id]', $d)).length;
isNextEntity = parseInt(page) <= 1;
$x.each(function() {
var id;
id = $(this).attr('data-user-id');
//console.log 'id',id,myBase[A.C.type].indexOf(parseInt(id),A.C.now,A.C.double)
if (myBase[A.C.type].indexOf(parseInt(id)) < 0) {
A.request('user/control/user/update/id/' + id, A.C.itemParse);
return A.send('client', {
id: id
});
} else {
A.C.now++;
A.C.double++;
if (A.C.double > A.maxDouble) {
return isNextEntity = true;
}
}
});
//if A.C.now>=A.C.total || A.C.now>=A.max then A.nextEntity()
//console.log('pageParse client',page,'isNextEntity',isNextEntity )
if (isNextEntity) {
return A.nextEntity();
} else {
i = page - 1;
return A.request('pl/user/user/index?page=' + i + '&per-page=' + A.C.per_page, A.C.parsePage, A.C.type, i);
}
},
itemParse: function(data = null) {
var $data, $f, i, j, len, o, ref, x;
if (data === null) {
$data = $("html");
} else {
$data = $(data);
}
$f = $(".page-main-form", $data);
o = {};
ref = $f.attr('action').split('/');
for (j = 0, len = ref.length; j < len; j++) {
i = ref[j];
if (x = parseInt(i)) {
if (!isNaN(x)) {
o.id = x;
break;
}
}
}
$("td", $f).each(function() {
var $t, text, val;
$t = $(this);
text = $.trim($t.text());
switch (text) {
case 'Телефон':
$("script", $t.next()).remove();
val = $.trim($t.next().text());
return o.phone = val === 'изменить' ? '' : val;
case 'Эл. почта':
return o.email = $.trim($t.next().text());
case 'Статус':
val = $.trim($t.next().text());
return o.status = val === 'активен' ? 1 : 2;
//when 'Имя'
// val = $.trim($t.next().text())
// o.name = if val == 'изменить' then '' else val
//when 'Фамилия'
// val = $.trim($t.next().text())
// o.sname = if val == 'изменить' then '' else val
case 'Страна':
val = $.trim($t.next().text());
return o.country = val === 'изменить' ? '' : val;
case 'Предполагаемая страна':
val = $.trim($t.next().text());
return o.country = val === 'изменить' ? '' : val;
case 'День рождения':
val = $.trim($t.next().text());
return o.bdate = val === 'не указано' ? '' : val;
case 'Город':
val = $.trim($t.next().text());
return o.city = val === 'изменить' ? '' : val;
case 'Предполагаемый город':
val = $.trim($t.next().text());
return o.city = val === 'изменить' ? '' : val;
case 'Тип':
val = $("select", $t.next()).val();
return o.type = val === 'user' ? 1 : 0;
case 'Дата регистрации':
return o.date = $.trim($t.next().text());
case 'Тип регистрации':
val = $("select", $t.next()).val();
return o.reg = val === 'Зарегистрировался самостоятельно' ? 1 : 2;
}
});
o.name = $("#User_first_name", $data).val();
o.sname = $("#User_last_name", $data).val();
o.phone = $("#User_phone", $data).val();
o.country = $("#User_country", $data).val();
o.city = $("#User_city", $data).val();
switch ($("#User_subscribe_status", $data).val()) {
case "all":
o.subscribe = 3;
break;
case "no_mailings":
o.subscribe = 2;
break;
case "disabled":
o.subscribe = 1;
}
switch ($("#User_gender", $data).val()) {
case "male":
o.sex = 1;
break;
case "female":
o.sex = 2;
break;
default:
o.sex = 0;
}
o.comment = $("#User_comment", $data).val();
o.sms = $("#smsUnsubscribe", $data).is(":checked") ? 1 : 0;
// TODO Источник
//console.log('парсим клиента ',o)
//A.C.base.push o
o.source = {};
$('.panel-heading').each(function() {
var $t, text;
$t = $(this);
text = $t.text();
if (text.indexOf('Источник') >= 0) {
return $("table tr", $t.parent()).each(function() {
var $tr;
$tr = $(this);
if ($("td:eq(1) a", $tr).length > 0) {
return o.source[$("td:eq(0)", $tr).text()] = $("td:eq(1) a", $tr).attr('href');
} else {
return o.source[$("td:eq(0)", $tr).text()] = $("td:eq(1)", $tr).text();
}
});
}
});
//console.log o
A.send('client', o);
return A.C.now++;
}
};
// if A.C.now>=A.C.sum || A.C.now>=A.max then A.nextEntity()
// DEALS
A.D = {
total: 0,
pages: 0,
base: [],
sum: 0,
now: 0,
type: 'deal',
double: 0,
parse: function() {
return A.request('pl/sales/deal/', function(data) {
var $b, $data, $s, i, per_page, total;
$data = $(data);
$s = $(".summary", $data);
$b = $("b", $s);
A.D.per_page = per_page = parseInt($b[0].innerText.split("-")[1]);
total = parseInt($b[1].innerText.replace(/[^\d]/g, ''));
A.D.total = total;
A.D.pages = Math.ceil(A.D.total / per_page);
if (per_page === 0) {
alert('Не понятно сколько сделок на странице ');
A.nextEntity();
return;
}
A.D.pages = A.getMaxPage(A.D.pages);
A.D.total = Math.min(A.D.total, A.D.pages * per_page);
//start = 1
//if (c = localStorage[A.D.type])!=undefined
// _start = parseInt(c)
// if !isNaN(_start)
// start = _start
// A.D.now = per_page * start
// A.D.sum = per_page * start
// if A.D.now>=A.D.total || A.D.now>=A.max
// A.nextEntity()
// return
//if start==1 or start<A.D.pages
// for i in [start..A.getMaxPage(A.D.pages)]
// A.request 'pl/sales/deal/index?page='+i+'&per-page='+per_page , A.D.parsePage, A.D.type, i
i = A.getMaxPage(A.D.pages);
return A.request('pl/sales/deal/index?page=' + i + '&per-page=' + per_page, A.D.parsePage, A.D.type, i);
});
},
parsePage: function(data, page) {
var $d, $x, i, isNextEntity;
$d = $(data);
A.D.sum += ($x = $('tr[data-deal-id]', $d)).length;
isNextEntity = parseInt(page) <= 1;
$x.each(function() {
var id;
id = $(this).attr('data-deal-id');
//console.log myBase[A.D.type].indexOf(parseInt(id))
if (myBase[A.D.type].indexOf(parseInt(id)) < 0) {
A.request('sales/control/deal/update/id/' + id, A.D.itemParse);
return A.send('deal', {
id: id
});
} else {
A.D.now++;
A.D.double++;
if (A.D.double > A.maxDouble) {
return isNextEntity = true;
}
}
});
if (isNextEntity) {
return A.nextEntity();
} else {
i = page - 1;
return A.request('pl/sales/deal/index?page=' + i + '&per-page=' + A.D.per_page, A.D.parsePage, A.D.type, i);
}
},
itemParse: function(data = null) {
var $data, $f, c, href, i, j, k, len, len1, number, o, ref, ref1, x;
if (data === null) {
$data = $("html");
} else {
$data = $(data);
}
$f = $(".page-main-form", $data);
o = {};
ref = $f.attr('action').split('/');
for (j = 0, len = ref.length; j < len; j++) {
i = ref[j];
if (x = parseInt(i.replace(/[^\d]/g, ''))) {
if (!isNaN(x)) {
o.id = x;
break;
}
}
}
number = $("h1", $data).text();
if (number !== void 0) {
o.number = number.replace(/[^\d]/g, '');
}
$(".deal-info-table td", $data).each(function() {
var $t, text;
$t = $(this);
text = $.trim($t.text());
switch (text) {
case "Создан:":
return o.date = $.trim($t.next().text());
case "Оплачен:":
return o.pdate = $.trim($t.next().text());
}
});
c = $('.panel-body > a[href^="/user/control/user/update/id/"]', $data);
if (c.length > 0) {
href = c.attr('href');
if (href !== void 0) {
ref1 = c.attr('href').split('/');
for (k = 0, len1 = ref1.length; k < len1; k++) {
i = ref1[k];
if (i !== void 0) {
if (x = parseInt(i.replace(/[^\d]/g, ''))) {
if (!isNaN(x)) {
o.client_id = x;
break;
}
}
}
}
}
}
o.status = $("#Deal_change_status", $data).val();
o.offers = [];
$(".deal-position-tr", $data).each(function() {
var $t;
$t = $(this);
return o.offers.push({
//id : if ( c = $(".name b a",$t).attr('href') ) !=undefined then c.replace(/[^\d]/g,'') else ''
//price : if ( c = $(".price",$t).text() ) !=undefined then c.replace(/[^\d]/g,'') else $("[id$=price]",$t).val()
//count : if ( c = $(".quantity",$t).text() ) !=undefined then c.replace(/[^\d]/g,'') else $(".input-position-quantity",$t).val()
id: ((c = $(".name b a", $t)).length > 0) !== void 0 ? c.attr('href').replace(/[^\d]/g, '') : '',
price: ((c = $(".price input", $t)).length > 0) ? c.val() : $(".price", $t).text().replace(/[^\d]/g, ''),
count: ((c = $(".quantity input", $t)).length > 0) ? c.val() : $(".quantity", $t).text().replace(/[^\d]/g, '')
});
});
//console.log('парсим заказ ',o)
o.source = {};
$('.panel-heading').each(function() {
var $t, text;
$t = $(this);
text = $t.text();
if (text.indexOf('Источник') >= 0) {
return $("table tr", $t.parent()).each(function() {
var $tr;
$tr = $(this);
if ($("td:eq(1) a", $tr).length > 0) {
return o.source[$("td:eq(0)", $tr).text()] = $("td:eq(1) a", $tr).attr('href');
} else {
return o.source[$("td:eq(0)", $tr).text()] = $("td:eq(1)", $tr).text();
}
});
}
});
A.D.now++;
return A.send('deal', o);
}
};
//if A.D.now>=A.D.sum || A.D.now>=A.max then A.nextEntity()
//console.log o
// OFFERS
A.O = {
total: 0,
pages: 0,
base: [],
sum: 0,
now: 0,
type: 'offer',
double: 0,
parse: function() {
return A.request('pl/sales/offer/', function(data) {
var $b, $data, $s, i, per_page, total;
$data = $(data);
$s = $(".summary", $data);
$b = $("b", $s);
A.O.per_page = per_page = parseInt($b[0].innerText.split("-")[1]);
total = parseInt($b[1].innerText.replace(/[^\d]/g, ''));
A.O.total = total;
A.O.pages = Math.ceil(A.O.total / per_page);
if (per_page === 0) {
alert('Не понятно сколько предложений на странице ');
A.nextEntity();
return;
}
A.O.pages = A.getMaxPage(A.O.pages);
A.O.total = Math.min(A.O.total, A.O.pages * per_page);
//start = 1
//if (c = localStorage[A.O.type])!=undefined
// _start = parseInt(c)
// if !isNaN(_start)
// start = _start
// A.O.now = per_page * start
// A.O.sum = per_page * start
// if A.O.now>=A.O.total || A.O.now>=A.max
// A.nextEntity()
// return
//if start==1 or start<A.O.pages
// for i in [start..A.getMaxPage(A.O.pages)]
// A.request 'pl/sales/offer/index?page='+i+'&per-page='+per_page , A.O.parsePage, A.O.type, i
i = A.getMaxPage(A.O.pages);
return A.request('pl/sales/offer/index?page=' + i + '&per-page=' + per_page, A.O.parsePage, A.O.type, i);
});
},
parsePage: function(data, page) {
var $d, $x, i, isNextEntity;
//console.log('pageParse offer')
$d = $(data);
A.O.sum += ($x = $('tr[data-key]', $d)).length;
isNextEntity = parseInt(page) <= 1;
$x.each(function() {
var id;
id = $(this).attr('data-key');
if (myBase[A.O.type].indexOf(parseInt(id)) < 0) {
A.request('pl/sales/offer/update?id=' + id, A.O.itemParse);
return A.send('offer', {
id: id
});
} else {
A.O.now++;
A.O.double++;
if (A.O.double > A.maxDouble) {
return isNextEntity = true;
}
}
});
if (isNextEntity) {
return A.nextEntity();
} else {
i = page - 1;
return A.request('pl/sales/offer/index?page=' + i + '&per-page=' + A.O.per_page, A.O.parsePage, A.O.type, i);
}
},
itemParse: function(data = null) {
var $data, $f, i, j, len, o, ref, x;
if (data === null) {
$data = $("html");
} else {
$data = $(data);
}
$f = $("#offerForm", $data);
o = {};
ref = $f.attr('action').split('/');
for (j = 0, len = ref.length; j < len; j++) {
i = ref[j];
if (x = parseInt(i.replace(/[^\d]/g, ''))) {
if (!isNaN(x)) {
o.id = x;
break;
}
}
}
o.name = $("#offer-title", $data).val();
o.price = $("#offer-price", $data).val();
$(".control-label", $data).each(function() {
var $t, text;
$t = $(this);
text = $.trim($t.text());
switch (text) {
case "Дата создания":
return o.date = $t.next().text();
}
});
o.product = [];
$('a[href^="/pl/sales/product/update?id="]', $data).each(function() {
return o.product.push($(this).attr('href').replace(/[^\d]/g, ''));
});
//console.log('парсим предложение ',o)
A.send('offer', o);
return A.O.now++;
}
};
//if A.O.now>=A.O.sum || A.O.now>=A.max then A.nextEntity()
// PAYMENTS
A.Y = {
total: 0,
pages: 0,
base: [],
sum: 0,
now: 0,
type: 'payment',
parse: function() {
return A.request('pl/sales/control/payment/', function(data) {
/*
start = 1
if (c = localStorage[A.Y.type])!=undefined
_start = parseInt(c)
if !isNaN(_start)
start = _start
A.Y.now = per_page * start
A.Y.sum = per_page * start
if A.Y.now>=A.Y.total || A.Y.now>=A.max then alert('Закончили')
*/
var $b, $data, $s, i, j, per_page, ref, ref1, results, start, total;
$data = $(data);
$s = $(".summary", $data);
$b = $("b", $s);
per_page = parseInt($b[0].innerText.split("-")[1]);
total = parseInt($b[1].innerText.replace(/[^\d]/g, ''));
A.Y.total = total;
A.Y.pages = Math.ceil(A.Y.total / per_page);
A.Y.pages = A.getMaxPage(A.Y.pages);
A.Y.total = Math.min(A.Y.total, A.Y.pages * per_page);
if (per_page === 0) {
alert('Не понятно сколько клиентов на странице ');
A.nextEntity();
return;
}
start = 1;
if (start === 1 || start < A.Y.pages) {
results = [];
for (i = j = ref = start, ref1 = A.getMaxPage(A.Y.pages); (ref <= ref1 ? j <= ref1 : j >= ref1); i = ref <= ref1 ? ++j : --j) {
results.push(A.request('pl/sales/control/payment/index?page=' + i + '&per-page=' + per_page, A.Y.parsePage, A.Y.type, i));
}
return results;
}
});
},
parsePage: function(data) {
var $d;
//console.log('pageParse payment')
$d = $(data);
A.Y.sum += $('tr[data-deal-id]', $d).length;
return $('tr[data-deal-id]', $d).each(function() {
var $t, id, o;
A.Y.now++;
$t = $(this);
id = $t.attr('data-deal-id');
o = {
id: id,
client_id: $('a[data-user-id]', $t).attr('data-user-id'),
order_id: $('a[href^="/sales/control/payment/update/id/"]', $t).attr('href').replace(/[^\d]/g, ''),
date: $('td:eq(2)', $t).text(),
status: $('td:eq(3)', $t).text(),
type: $('td:eq(4)', $t).text(),
price: $('td:eq(5)', $t).text().replace(/[^\d]/g, '')
};
return A.send('payment', o);
});
}
};
//if A.Y.now>=A.Y.sum || A.Y.now>=A.max
// A.stop()
// alert('Спрасили')
//A.request 'sales/control/deal/update/id/'+id,A.Y.itemParse
// PRODUCTS
A.P = {
total: 0,
pages: 0,
base: [],
sum: 0,
now: 0,
type: 'product',
double: 0,
parse: function() {
return A.request('pl/sales/product/', function(data) {
var $b, $data, $s, i, per_page, total;
$data = $(data);
$s = $(".summary", $data);
$b = $("b", $s);
A.P.per_page = per_page = parseInt($b[0].innerText.split("-")[1]);
total = parseInt($b[1].innerText.replace(/[^\d]/g, ''));
A.P.total = total;
A.P.pages = Math.ceil(A.P.total / per_page);
if (per_page === 0) {
alert('Не понятно сколько продуктов на странице ');
A.nextEntity();
return;
}
A.P.pages = A.getMaxPage(A.P.pages);
A.P.total = Math.min(A.P.total, A.P.pages * per_page);
//start = 1
//if (c = localStorage[A.P.type])!=undefined
// _start = parseInt(c)
// if !isNaN(_start)
// start = _start
// A.P.now = per_page * start
// A.P.sum = per_page * start
// if A.P.now>=A.P.total || A.P.now>=A.max
// A.nextEntity()
// return
//if start==1 or start<A.P.pages
// for i in [start..A.getMaxPage(A.P.pages)]
// A.request 'pl/sales/product/index?page='+i+'&per-page='+per_page , A.P.parsePage, A.P.type, i
i = A.getMaxPage(A.P.pages);
return A.request('pl/sales/product/index?page=' + i + '&per-page=' + per_page, A.P.parsePage, A.P.type, i);
});
},
parsePage: function(data, page) {
var $d, $x, i, isNextEntity;
//console.log('pageParse product')
$d = $(data);
A.P.sum += ($x = $('tr[data-key]', $d)).length;
isNextEntity = parseInt(page) <= 1;
$x.each(function() {
var id;
id = $(this).attr('data-key');
if (myBase[A.P.type].indexOf(parseInt(id)) < 0) {
A.request('pl/sales/product/update?id=' + id, A.P.itemParse);
return A.send('product', {
id: id
});
} else {
A.P.now++;
A.P.double++;
if (A.P.double > A.maxDouble) {
return isNextEntity = true;
}
}
});
if (isNextEntity) {
return A.nextEntity();
} else {
i = page - 1;
return A.request('pl/sales/product/index?page=' + i + '&per-page=' + A.P.per_page, A.P.parsePage, A.P.type, i);
}
},
itemParse: function(data = null) {
var $data, $f, i, j, len, o, ref, x;
if (data === null) {
$data = $("html");
} else {
$data = $(data);
}
$f = $(".form-vertical", $data);
o = {};
ref = $f.attr('action').split('/');
for (j = 0, len = ref.length; j < len; j++) {
i = ref[j];
if (x = parseInt(i.replace(/[^\d]/g, ''))) {
if (!isNaN(x)) {
o.id = x;
break;
}
}
}
o.name = $("#product-title", $data).val();
o.descr = $("#product-description", $data).val();
$(".control-label", $data).each(function() {
var $t, text;
$t = $(this);
text = $.trim($t.text());
switch (text) {
case "Дата создания":
return o.date = $t.next().text();
}
});
//console.log 'парсим продукт', o
//A.P.base.push o
A.send('product', o);
return A.P.now++;
}
};
//if A.P.now>=A.P.sum || A.P.now>=A.max then A.nextEntity()
A.init();