207 lines
5.6 KiB
JavaScript
207 lines
5.6 KiB
JavaScript
var numbers = [];
|
|
|
|
$(document).ready(function () {
|
|
noticer = new Noticer;
|
|
|
|
$("button").button();
|
|
$("#tabs").tabs();
|
|
|
|
// $(".addNumber").click(() => {
|
|
// numberAdd()
|
|
// });
|
|
|
|
$("body").fadeTo(500, 1);
|
|
|
|
$(".search").on("input", function () {
|
|
showNumbers(
|
|
$("#accordion-numbers .ui-accordion-content-active"),
|
|
numbers.filter(e => e.number.includes($(this).val()))
|
|
)
|
|
}).on("focus", function () {
|
|
if ($(this).val())
|
|
showNumbers(
|
|
$("#accordion-numbers .ui-accordion-content-active"),
|
|
numbers.filter(e => e.number.includes($(this).val()))
|
|
);
|
|
}).keydown(function (e) {
|
|
e.key == "Escape" && ($(this).val(""), showNumbers($("#accordion-numbers .ui-accordion-content-active")))
|
|
});
|
|
|
|
loadData();
|
|
})
|
|
|
|
async function request(query, type, queryData = {}) {
|
|
let response = await fetch('.', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json;charset=utf-8'
|
|
},
|
|
body: JSON.stringify({
|
|
...queryData,
|
|
query: query
|
|
})
|
|
});
|
|
|
|
if (!response.ok)
|
|
throw new Error(`Произошла неизвестаня ошибка: ${response.status}`);
|
|
|
|
const data = await response[type]();
|
|
return data;
|
|
}
|
|
|
|
function isJSON(str) {
|
|
try {
|
|
return (JSON.parse(str) && !!str);
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function loadData() {
|
|
request('listsgroups', 'text').then(data => {
|
|
data.error ? noticer.error(data.message) : generateListsGroups(data);
|
|
}).catch(error => {
|
|
noticer.error(error.message);
|
|
});
|
|
}
|
|
|
|
function generateListsGroups(data) {
|
|
$("#tabs-numbers").html(data);
|
|
$("#accordion-numbers").accordion({
|
|
heightStyle: "content",
|
|
create: function( event, ui ) {
|
|
generateGroupNumbers(ui.panel);
|
|
},
|
|
beforeActivate: function( event, ui ) {
|
|
generateGroupNumbers(ui.newPanel);
|
|
}
|
|
});
|
|
}
|
|
|
|
function generateGroupNumbers(panel) {
|
|
request('groupnumbers', 'json', { group: panel.data("group-name") }).then(data => {
|
|
if (isJSON(data) && JSON.parse(data).error)
|
|
noticer.error(JSON.parse(data).message);
|
|
else {
|
|
numbers = data;
|
|
showNumbers(panel);
|
|
}
|
|
}).catch(error => {
|
|
noticer.error(error.message);
|
|
});
|
|
}
|
|
|
|
function showNumbers(panel, data = numbers) {
|
|
(new divNotFoundNumbers).remove();
|
|
let body = panel.find('.body').html('');
|
|
$(data).each((i, j) => {
|
|
let row = $(`<tr class="row" data-number="${j.number}"></tr>`);
|
|
row.append(`<td>${j.number}</td>`);
|
|
row.append(`<td>${j.list}</td>`);
|
|
row.append(`<td>${j.all_cc}</td>`);
|
|
row.append(`<td>${j.white_cc}</td>`);
|
|
row.append(`<td>${j.black_cc}</td>`);
|
|
row.append(`<td>${j.comment}</td>`);
|
|
body.append(row);
|
|
|
|
row.click(function() {
|
|
numberEdit($(this).data('number'));
|
|
});
|
|
});
|
|
|
|
if (!body.children().length)
|
|
(new divNotFoundNumbers).push();
|
|
}
|
|
|
|
|
|
function divNotFoundNumbers() {
|
|
let notFound = $('.failNumbers');
|
|
let divTable = $('.body-rows');
|
|
let divFound = $('<div class="failNumbers"></div>');
|
|
|
|
divFound.css({
|
|
"color": "#333",
|
|
"text-align": "center",
|
|
"padding": "20px 0 20px 0"
|
|
});
|
|
|
|
this.push = function(text = 'Нет номеров') {
|
|
divTable.append(divFound.html(text));
|
|
}
|
|
|
|
this.remove = function() {
|
|
notFound.remove();
|
|
}
|
|
}
|
|
|
|
function numberEdit(number) {
|
|
request('editnumber', 'text', {number: number}).then(data => {
|
|
if (isJSON(data) && JSON.parse(data).error)
|
|
noticer.error(JSON.parse(data).message);
|
|
else {
|
|
showEditNumber(data, [
|
|
{
|
|
id: "btn-save",
|
|
text: "Сохранить",
|
|
icon: "ui-icon-check",
|
|
click: function() {
|
|
actionNumber($(this), 'update');
|
|
}
|
|
},
|
|
{
|
|
id: "btn-delete",
|
|
text: "Удалить",
|
|
icon: "ui-icon-trash",
|
|
click: function() {
|
|
// removeNumber($(this));
|
|
}
|
|
}
|
|
], `Редактирование номера ${number}`);
|
|
}
|
|
}).catch(error => {
|
|
noticer.error(error.message);
|
|
});
|
|
}
|
|
|
|
function showEditNumber(data, actionButton, title) {
|
|
let form = $(data);
|
|
|
|
form.appendTo('body').dialog({
|
|
title: title,
|
|
height: 'auto',
|
|
width: 'auto',
|
|
maxHeight: 500,
|
|
minHeight: 50,
|
|
resizable: false,
|
|
modal: true,
|
|
show: { effect: "fade", duration: 500 },
|
|
close: function(event, ui) {
|
|
$(this).dialog('destroy').remove()
|
|
},
|
|
buttons: [
|
|
...actionButton,
|
|
{
|
|
text: "Отмена",
|
|
icon: "ui-icon-cancel",
|
|
click: function() {
|
|
$(this).dialog("close");
|
|
}
|
|
}
|
|
]
|
|
});
|
|
|
|
$('#number-group, #number-list').selectmenu({
|
|
width: 200
|
|
});
|
|
}
|
|
|
|
function actionNumber(currentWindow, query) {
|
|
let number = $('#number-number').val();
|
|
let group = $('#number-group').val();
|
|
let list = $('#number-list').val();
|
|
let all_cc = $('#number-all-cc').val();
|
|
let white_cc = $('#number-white-cc').val();
|
|
let black_cc = $('#number-black-cc').val();
|
|
let comment = $('#number-comment').val();
|
|
}
|
|
|