+ Обновлен скрипт SQL - добавлена таблица с описанием типов USSD
+ Реализовано: просмотр и удаление USSD
+ Кнопка перезагрузки вкладки; кнопка обновления обновляет данные группы во вкладке
This commit is contained in:
Alexander Zhirov 2023-06-04 02:00:19 +03:00
parent 2ba510adac
commit 69ab43a4ec
11 changed files with 403 additions and 29 deletions

View file

@ -1,36 +1,50 @@
var numbers = [];
var sms = [];
var ussd = [];
$(document).ready(function () {
noticer = new Noticer;
let tabs = {
0: () => { loadNumbers() },
1: () => { loadSMS() },
2: () => { loadUSSD() },
3: () => {}
};
let lists = {
0: () => { showListNumbers($("#accordion-numbers .ui-accordion-content-active")) },
1: () => { showListSMS($("#accordion-sms .ui-accordion-content-active")) },
2: () => {},
2: () => { showListUSSD($("#accordion-ussd .ui-accordion-content-active")) },
3: () => {}
};
let groups = {
0: () => { generateListGroupNumbers($("#accordion-numbers .ui-accordion-content-active")) },
1: () => { generateListGroupSMS($("#accordion-sms .ui-accordion-content-active")) },
2: () => { noticer.success('Вкладка "USSD"') },
2: () => { generateListGroupUSSD($("#accordion-ussd .ui-accordion-content-active")) },
3: () => { noticer.success('Вкладка "Сервер"') }
};
$("button").button();
$("#update").button("option", "icon", "ui-icon-refresh");
$("#update-tab").button("option", "icon", "ui-icon-refresh");
$("#update-group").button("option", "icon", "ui-icon-arrowrefresh-1-s");
$("#add-number").button("option", "icon", "ui-icon-plusthick");
$("#logout").button("option", "icon", "ui-icon-power");
$("#tabs").tabs({
activate: function( event, ui ) {
tabs[$(this).tabs( "option", "active" )]();
lists[$(this).tabs( "option", "active" )]();
$("#add-number").button( "option", "disabled", $(this).tabs( "option", "active" ) > 0 );
// $("#search").attr( "disabled", $("#search").val("") && $(this).tabs( "option", "active" ) > 1 );
}
});
$("#update").click(() => {
$("#update-tab").click(() => {
tabs[$("#tabs").tabs( "option", "active" )]()
});
$("#update-group").click(() => {
groups[$("#tabs").tabs( "option", "active" )]()
});
@ -39,13 +53,14 @@ $(document).ready(function () {
});
$("#search").on("input", function () {
tabs[$("#tabs").tabs( "option", "active" )]()
lists[$("#tabs").tabs( "option", "active" )]()
}).keydown(function (e) {
e.key == "Escape" && ($(this).val(""), tabs[$("#tabs").tabs( "option", "active" )]())
e.key == "Escape" && ($(this).val(""), lists[$("#tabs").tabs( "option", "active" )]())
});
loadNumbers();
loadSMS();
loadUSSD();
$("body").fadeTo(500, 1);
})
@ -81,10 +96,10 @@ function isNumeric(value) {
return /^-?\d+$/.test(value);
}
function divNotFoundNumbers() {
function divNotFoundNumbers(text = '') {
let notFound = $('.notFoundNumbers');
let divTable = $('.body-rows');
let divNotFound = $('<div class="notFoundNumbers"></div>');
let divNotFound = $(`<div class="notFoundNumbers">${text}</div>`);
divNotFound.css({
"color": "#333",
@ -92,8 +107,8 @@ function divNotFoundNumbers() {
"padding": "20px 0 20px 0"
});
this.push = function(text = 'Нет номеров') {
divTable.append(divNotFound.html(text));
this.push = function() {
divTable.append(divNotFound);
}
this.remove = function() {
@ -101,6 +116,10 @@ function divNotFoundNumbers() {
}
}
function pEmpty(text) {
return $(`<p>${text}</p>`).css('text-align', 'center');
}
/************************************************************************************
Обработка таблицы с номерами телефонов
@ -117,7 +136,7 @@ function loadNumbers() {
function generateListNumberGroups(data) {
if (!$(data).children().length) {
$("#tabs-numbers").html('<p>Номера телефонов отсутствуют</p>');
$("#tabs-numbers").html(pEmpty('Номера телефонов отсутствуют'));
return;
}
@ -136,7 +155,7 @@ function generateListNumberGroups(data) {
function generateListGroupNumbers(panel) {
if (!$("#accordion-numbers").children().length) {
noticer.warning("Номера телефонов отсутствуют");
$("#tabs-numbers").html('<p>Номера телефонов отсутствуют</p>');
$("#tabs-numbers").html(pEmpty('Номера телефонов отсутствуют'));
return;
}
@ -171,7 +190,7 @@ function showListNumbers(panel, data = numbers.filter(e => e.number.includes($("
});
if (!body.children().length)
(new divNotFoundNumbers).push();
(new divNotFoundNumbers('Нет номеров')).push();
}
function viewNumber(panel, number) {
@ -321,7 +340,7 @@ function delNumber(panel, currentWindow) {
/************************************************************************************
Обработка таблицы с SMS
Обработка таблицы с SMS
************************************************************************************/
@ -335,7 +354,7 @@ function loadSMS() {
function generateListSMSGroups(data) {
if (!$(data).children().length) {
$("#tabs-sms").html('<p>SMS отсутствуют</p>');
$("#tabs-sms").html(pEmpty('SMS отсутствуют'));
return;
}
@ -354,7 +373,7 @@ function generateListSMSGroups(data) {
function generateListGroupSMS(panel) {
if (!$("#accordion-sms").children().length) {
noticer.warning("SMS отсутствуют");
$("#tabs-sms").html('<p>SMS отсутствуют</p>');
$("#tabs-sms").html(pEmpty('SMS отсутствуют'));
return;
}
@ -386,7 +405,7 @@ function showListSMS(panel, data = sms.filter(e => e.from.includes($("#search").
});
if (!body.children().length)
(new divNotFoundNumbers).push();
(new divNotFoundNumbers('Нет SMS')).push();
}
function viewSMS(panel, id, number) {
@ -454,3 +473,138 @@ function delSMS(panel, currentWindow) {
noticer.error(error.message);
});
}
/************************************************************************************
Обработка таблицы с USSD
************************************************************************************/
function loadUSSD() {
request('listussdgroups', 'text').then(data => {
data.error ? noticer.error(data.message) : generateListUSSDGroups(data);
}).catch(error => {
noticer.error(error.message);
});
}
function generateListUSSDGroups(data) {
if (!$(data).children().length) {
$("#tabs-ussd").html(pEmpty('USSD отсутствуют'));
return;
}
$("#tabs-ussd").html(data);
$("#accordion-ussd").accordion({
heightStyle: "content",
create: function( event, ui ) {
generateListGroupUSSD(ui.panel);
},
beforeActivate: function( event, ui ) {
generateListGroupUSSD(ui.newPanel);
}
})
}
function generateListGroupUSSD(panel) {
if (!$("#accordion-ussd").children().length) {
noticer.warning("USSD отсутствуют");
$("#tabs-ussd").html(pEmpty('USSD отсутствуют'));
return;
}
request('listgroupussd', 'json', { to: panel.data("to") }).then(data => {
if (isJSON(data) && JSON.parse(data).error)
noticer.error(JSON.parse(data).message);
else {
ussd = data;
showListUSSD(panel);
}
}).catch(error => {
noticer.error(error.message);
});
}
function showListUSSD(panel, data = ussd) {
(new divNotFoundNumbers).remove();
let body = panel.find('.body').html('');
$(data).each((i, j) => {
let row = $(`<tr class="row" data-ussd-id="${j.id}"></tr>`);
row.append(`<td class="ussd-content-width">${j.date}</td>`);
row.append(`<td class="ussd-content-width-type">${j.type_comment}</td>`);
row.append(`<td>${j.text}</td>`);
body.append(row);
row.click(function() {
viewUSSD(panel, $(this).data('ussd-id'), j.type_comment);
});
});
if (!body.children().length)
(new divNotFoundNumbers('Нет USSD')).push();
}
function viewUSSD(panel, id, type) {
request('viewussd', 'text', {id: id}).then(data => {
if (isJSON(data) && JSON.parse(data).error)
noticer.error(JSON.parse(data).message);
else {
showViewUSSD(data, [
{
id: "btn-delete",
text: "Удалить",
icon: "ui-icon-trash",
click: function() {
delUSSD(panel, $(this));
}
}
], `USSD: ${type}`);
}
}).catch(error => {
noticer.error(error.message);
});
}
function showViewUSSD(data, actionButton, title) {
let form = $(data);
form.appendTo('body').dialog({
title: title,
height: 'auto',
width: 'auto',
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");
}
}
]
});
}
function delUSSD(panel, currentWindow) {
let id = $('#ussd-content').data('id');
request('delussd', 'json', {
id: id
}).then(data => {
if (data.error)
noticer.error(data.message);
else {
noticer.success(`USSD было удалено`);
generateListGroupUSSD(panel);
currentWindow.dialog("close");
}
}).catch(error => {
noticer.error(error.message);
});
}