v0.0.7
+ Обновлен скрипт SQL - добавлена таблица с описанием типов USSD + Реализовано: просмотр и удаление USSD + Кнопка перезагрузки вкладки; кнопка обновления обновляет данные группы во вкладке
This commit is contained in:
		
							parent
							
								
									2ba510adac
								
							
						
					
					
						commit
						69ab43a4ec
					
				
					 11 changed files with 403 additions and 29 deletions
				
			
		| 
						 | 
					@ -44,6 +44,21 @@ create table if not exists da_sms (
 | 
				
			||||||
    constraint da_sms_pk primary key (da_id)
 | 
					    constraint da_sms_pk primary key (da_id)
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					create table if not exists da_ussd_type (
 | 
				
			||||||
 | 
					    da_id bigserial not null,
 | 
				
			||||||
 | 
					    da_comment varchar(100) not null,
 | 
				
			||||||
 | 
					    constraint da_ussd_type_pk primary key (da_id)
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					insert into da_ussd_type (da_id, da_comment)
 | 
				
			||||||
 | 
						values
 | 
				
			||||||
 | 
							('0', 'Уведомление'),
 | 
				
			||||||
 | 
							('1', 'Запрос'),
 | 
				
			||||||
 | 
							('2', 'Прервано сетью'),
 | 
				
			||||||
 | 
							('3', 'Ответ другого локального клиента'),
 | 
				
			||||||
 | 
							('4', 'Операция не поддерживается'),
 | 
				
			||||||
 | 
							('5', 'Тайм-аут сети');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
create table if not exists da_ussd (
 | 
					create table if not exists da_ussd (
 | 
				
			||||||
    da_id bigserial not null,
 | 
					    da_id bigserial not null,
 | 
				
			||||||
    da_date timestamp not null default NOW(),
 | 
					    da_date timestamp not null default NOW(),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 24 KiB  | 
							
								
								
									
										190
									
								
								js/script.js
									
										
									
									
									
								
							
							
						
						
									
										190
									
								
								js/script.js
									
										
									
									
									
								
							| 
						 | 
					@ -1,36 +1,50 @@
 | 
				
			||||||
var numbers = [];
 | 
					var numbers = [];
 | 
				
			||||||
var sms = [];
 | 
					var sms = [];
 | 
				
			||||||
 | 
					var ussd = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(document).ready(function () {
 | 
					$(document).ready(function () {
 | 
				
			||||||
    noticer = new Noticer;
 | 
					    noticer = new Noticer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let tabs = {
 | 
					    let tabs = {
 | 
				
			||||||
 | 
					        0: () => { loadNumbers() },
 | 
				
			||||||
 | 
					        1: () => { loadSMS() },
 | 
				
			||||||
 | 
					        2: () => { loadUSSD() },
 | 
				
			||||||
 | 
					        3: () => {}
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let lists = {
 | 
				
			||||||
        0: () => { showListNumbers($("#accordion-numbers .ui-accordion-content-active")) },
 | 
					        0: () => { showListNumbers($("#accordion-numbers .ui-accordion-content-active")) },
 | 
				
			||||||
        1: () => { showListSMS($("#accordion-sms .ui-accordion-content-active")) },
 | 
					        1: () => { showListSMS($("#accordion-sms .ui-accordion-content-active")) },
 | 
				
			||||||
        2: () => {},
 | 
					        2: () => { showListUSSD($("#accordion-ussd .ui-accordion-content-active")) },
 | 
				
			||||||
        3: () => {}
 | 
					        3: () => {}
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let groups = {
 | 
					    let groups = {
 | 
				
			||||||
        0: () => { generateListGroupNumbers($("#accordion-numbers .ui-accordion-content-active")) },
 | 
					        0: () => { generateListGroupNumbers($("#accordion-numbers .ui-accordion-content-active")) },
 | 
				
			||||||
        1: () => { generateListGroupSMS($("#accordion-sms .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('Вкладка "Сервер"') }
 | 
					        3: () => { noticer.success('Вкладка "Сервер"') }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $("button").button();
 | 
					    $("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");
 | 
					    $("#add-number").button("option", "icon", "ui-icon-plusthick");
 | 
				
			||||||
    $("#logout").button("option", "icon", "ui-icon-power");
 | 
					    $("#logout").button("option", "icon", "ui-icon-power");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $("#tabs").tabs({
 | 
					    $("#tabs").tabs({
 | 
				
			||||||
        activate: function( event, ui ) {
 | 
					        activate: function( event, ui ) {
 | 
				
			||||||
            tabs[$(this).tabs( "option", "active" )]();
 | 
					            lists[$(this).tabs( "option", "active" )]();
 | 
				
			||||||
            $("#add-number").button( "option", "disabled", $(this).tabs( "option", "active" ) > 0 );
 | 
					            $("#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" )]()
 | 
					        groups[$("#tabs").tabs( "option", "active" )]()
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,13 +53,14 @@ $(document).ready(function () {
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $("#search").on("input", function () {
 | 
					    $("#search").on("input", function () {
 | 
				
			||||||
        tabs[$("#tabs").tabs( "option", "active" )]()
 | 
					        lists[$("#tabs").tabs( "option", "active" )]()
 | 
				
			||||||
    }).keydown(function (e) {
 | 
					    }).keydown(function (e) {
 | 
				
			||||||
        e.key == "Escape" && ($(this).val(""), tabs[$("#tabs").tabs( "option", "active" )]())
 | 
					        e.key == "Escape" && ($(this).val(""), lists[$("#tabs").tabs( "option", "active" )]())
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    loadNumbers();
 | 
					    loadNumbers();
 | 
				
			||||||
    loadSMS();
 | 
					    loadSMS();
 | 
				
			||||||
 | 
					    loadUSSD();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $("body").fadeTo(500, 1);
 | 
					    $("body").fadeTo(500, 1);
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
| 
						 | 
					@ -81,10 +96,10 @@ function isNumeric(value) {
 | 
				
			||||||
    return /^-?\d+$/.test(value);
 | 
					    return /^-?\d+$/.test(value);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function divNotFoundNumbers() {
 | 
					function divNotFoundNumbers(text = '') {
 | 
				
			||||||
    let notFound = $('.notFoundNumbers');
 | 
					    let notFound = $('.notFoundNumbers');
 | 
				
			||||||
    let divTable = $('.body-rows');
 | 
					    let divTable = $('.body-rows');
 | 
				
			||||||
    let divNotFound = $('<div class="notFoundNumbers"></div>');
 | 
					    let divNotFound = $(`<div class="notFoundNumbers">${text}</div>`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    divNotFound.css({
 | 
					    divNotFound.css({
 | 
				
			||||||
        "color": "#333",
 | 
					        "color": "#333",
 | 
				
			||||||
| 
						 | 
					@ -92,8 +107,8 @@ function divNotFoundNumbers() {
 | 
				
			||||||
        "padding": "20px 0 20px 0"
 | 
					        "padding": "20px 0 20px 0"
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.push = function(text = 'Нет номеров') {
 | 
					    this.push = function() {
 | 
				
			||||||
        divTable.append(divNotFound.html(text));
 | 
					        divTable.append(divNotFound);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.remove = function() {
 | 
					    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) {
 | 
					function generateListNumberGroups(data) {
 | 
				
			||||||
    if (!$(data).children().length) {
 | 
					    if (!$(data).children().length) {
 | 
				
			||||||
        $("#tabs-numbers").html('<p>Номера телефонов отсутствуют</p>');
 | 
					        $("#tabs-numbers").html(pEmpty('Номера телефонов отсутствуют'));
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -136,7 +155,7 @@ function generateListNumberGroups(data) {
 | 
				
			||||||
function generateListGroupNumbers(panel) {
 | 
					function generateListGroupNumbers(panel) {
 | 
				
			||||||
    if (!$("#accordion-numbers").children().length) {
 | 
					    if (!$("#accordion-numbers").children().length) {
 | 
				
			||||||
        noticer.warning("Номера телефонов отсутствуют");
 | 
					        noticer.warning("Номера телефонов отсутствуют");
 | 
				
			||||||
        $("#tabs-numbers").html('<p>Номера телефонов отсутствуют</p>');
 | 
					        $("#tabs-numbers").html(pEmpty('Номера телефонов отсутствуют'));
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -171,7 +190,7 @@ function showListNumbers(panel, data = numbers.filter(e => e.number.includes($("
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!body.children().length)
 | 
					    if (!body.children().length)
 | 
				
			||||||
        (new divNotFoundNumbers).push();
 | 
					        (new divNotFoundNumbers('Нет номеров')).push();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function viewNumber(panel, number) {
 | 
					function viewNumber(panel, number) {
 | 
				
			||||||
| 
						 | 
					@ -321,7 +340,7 @@ function delNumber(panel, currentWindow) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/************************************************************************************
 | 
					/************************************************************************************
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    Обработка таблицы с SMS
 | 
					                                Обработка таблицы с SMS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
************************************************************************************/
 | 
					************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -335,7 +354,7 @@ function loadSMS() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function generateListSMSGroups(data) {
 | 
					function generateListSMSGroups(data) {
 | 
				
			||||||
    if (!$(data).children().length) {
 | 
					    if (!$(data).children().length) {
 | 
				
			||||||
        $("#tabs-sms").html('<p>SMS отсутствуют</p>');
 | 
					        $("#tabs-sms").html(pEmpty('SMS отсутствуют'));
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -354,7 +373,7 @@ function generateListSMSGroups(data) {
 | 
				
			||||||
function generateListGroupSMS(panel) {
 | 
					function generateListGroupSMS(panel) {
 | 
				
			||||||
    if (!$("#accordion-sms").children().length) {
 | 
					    if (!$("#accordion-sms").children().length) {
 | 
				
			||||||
        noticer.warning("SMS отсутствуют");
 | 
					        noticer.warning("SMS отсутствуют");
 | 
				
			||||||
        $("#tabs-sms").html('<p>SMS отсутствуют</p>');
 | 
					        $("#tabs-sms").html(pEmpty('SMS отсутствуют'));
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -386,7 +405,7 @@ function showListSMS(panel, data = sms.filter(e => e.from.includes($("#search").
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!body.children().length)
 | 
					    if (!body.children().length)
 | 
				
			||||||
        (new divNotFoundNumbers).push();
 | 
					        (new divNotFoundNumbers('Нет SMS')).push();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function viewSMS(panel, id, number) {
 | 
					function viewSMS(panel, id, number) {
 | 
				
			||||||
| 
						 | 
					@ -454,3 +473,138 @@ function delSMS(panel, currentWindow) {
 | 
				
			||||||
        noticer.error(error.message);
 | 
					        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);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -125,7 +125,7 @@ tr.row:hover, tr.row:nth-child(even):hover {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* EDIT NUMBER */
 | 
					/* EDIT NUMBER */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.number-label, .sms-label {
 | 
					.number-label, .sms-label, .ussd-label {
 | 
				
			||||||
    color: #333;
 | 
					    color: #333;
 | 
				
			||||||
    text-align: right;
 | 
					    text-align: right;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -134,11 +134,11 @@ tr.row:hover, tr.row:nth-child(even):hover {
 | 
				
			||||||
    height: 30px;
 | 
					    height: 30px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.sms-label-text {
 | 
					.sms-label-text, .ussd-label-text {
 | 
				
			||||||
    vertical-align:top
 | 
					    vertical-align:top
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.sms-value {
 | 
					.sms-value, .ussd-value {
 | 
				
			||||||
    width: 300px;
 | 
					    width: 300px;
 | 
				
			||||||
    text-align: left;
 | 
					    text-align: left;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -171,17 +171,17 @@ tr.row:hover, tr.row:nth-child(even):hover {
 | 
				
			||||||
    padding: 15px 0 5px 0;
 | 
					    padding: 15px 0 5px 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.comment-content, .sms-content {
 | 
					.comment-content, .sms-content, .ussd-content {
 | 
				
			||||||
    width: 100%;
 | 
					    width: 100%;
 | 
				
			||||||
    height: 100%;
 | 
					    height: 100%;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#number-comment, #sms-content {
 | 
					#number-comment, #sms-content, #ussd-content {
 | 
				
			||||||
    width: calc(100% - 6px);
 | 
					    width: calc(100% - 6px);
 | 
				
			||||||
    resize: none;
 | 
					    resize: none;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#sms-content {
 | 
					#sms-content, #ussd-content {
 | 
				
			||||||
    height: 150px;
 | 
					    height: 150px;
 | 
				
			||||||
    outline: none;
 | 
					    outline: none;
 | 
				
			||||||
    border: 1px solid#c5c5c5;
 | 
					    border: 1px solid#c5c5c5;
 | 
				
			||||||
| 
						 | 
					@ -190,6 +190,10 @@ tr.row:hover, tr.row:nth-child(even):hover {
 | 
				
			||||||
    padding: 5px 10px 5px 10px;
 | 
					    padding: 5px 10px 5px 10px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
th.sms-content-width, td.sms-content-width {
 | 
					th.sms-content-width, td.sms-content-width, th.ussd-content-width, td.ussd-content-width {
 | 
				
			||||||
    width: 155px;
 | 
					    width: 155px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					th.ussd-content-width-type, td.ussd-content-width-type {
 | 
				
			||||||
 | 
					    width: 240px;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,6 +18,7 @@ import structures;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import requests.numbers;
 | 
					import requests.numbers;
 | 
				
			||||||
import requests.sms;
 | 
					import requests.sms;
 | 
				
			||||||
 | 
					import requests.ussd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static ServerInfo serverInfo;
 | 
					static ServerInfo serverInfo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -210,6 +211,18 @@ void postReq(HTTPServerRequest req, HTTPServerResponse res) {
 | 
				
			||||||
        case "delsms":
 | 
					        case "delsms":
 | 
				
			||||||
            sendDelSMS(req, res);
 | 
					            sendDelSMS(req, res);
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
 | 
					        case "listussdgroups":
 | 
				
			||||||
 | 
					            getListUSSDGroups(req, res);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        case "listgroupussd":
 | 
				
			||||||
 | 
					            getListGroupUSSD(req, res);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        case "viewussd":
 | 
				
			||||||
 | 
					            getViewUSSD(req, res);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        case "delussd":
 | 
				
			||||||
 | 
					            sendDelUSSD(req, res);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
            res.redirect("/");
 | 
					            res.redirect("/");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										39
									
								
								source/requests/ussd.d
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								source/requests/ussd.d
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,39 @@
 | 
				
			||||||
 | 
					module requests.ussd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import vibe.vibe;
 | 
				
			||||||
 | 
					import response;
 | 
				
			||||||
 | 
					import structures;
 | 
				
			||||||
 | 
					import sql;
 | 
				
			||||||
 | 
					import singlog;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Получить список всех групп USSD
 | 
				
			||||||
 | 
					void getListUSSDGroups(HTTPServerRequest req, HTTPServerResponse res) {
 | 
				
			||||||
 | 
					    auto numbers = sqlGetUSSDNumbers();
 | 
				
			||||||
 | 
					    render!("list_ussd_groups.dt", numbers)(res);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Получить список USSD конкретной группы
 | 
				
			||||||
 | 
					void getListGroupUSSD(HTTPServerRequest req, HTTPServerResponse res) {
 | 
				
			||||||
 | 
					    auto jsr = req.json;
 | 
				
			||||||
 | 
					    res.writeJsonBody(sqlGetListUSSD(jsr["to"].get!string).serializeToJson());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Просмотр USSD
 | 
				
			||||||
 | 
					void getViewUSSD(HTTPServerRequest req, HTTPServerResponse res) {
 | 
				
			||||||
 | 
					    auto jsr = req.json;
 | 
				
			||||||
 | 
					    auto dataUSSD = sqlGetUSSD(jsr["id"].to!int);
 | 
				
			||||||
 | 
					    render!("ussd.dt", dataUSSD)(res);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Удалить USSD
 | 
				
			||||||
 | 
					void sendDelUSSD(HTTPServerRequest req, HTTPServerResponse res) {
 | 
				
			||||||
 | 
					    auto jsr = req.json;
 | 
				
			||||||
 | 
					    int idussd = jsr["id"].get!int;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if (!sqlDeleteUSSD(idussd)) {
 | 
				
			||||||
 | 
					        res.send(true, "Не удалось удалить USSD");
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    res.send();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										115
									
								
								source/sql.d
									
										
									
									
									
								
							
							
						
						
									
										115
									
								
								source/sql.d
									
										
									
									
									
								
							| 
						 | 
					@ -6,6 +6,12 @@ import structures;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import std.conv;
 | 
					import std.conv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Запросы для таблицы номеров телефонов
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GroupDB[] sqlGetListGroups() {
 | 
					GroupDB[] sqlGetListGroups() {
 | 
				
			||||||
    GroupDB[] groups;
 | 
					    GroupDB[] groups;
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
| 
						 | 
					@ -201,6 +207,12 @@ bool sqlInsertNumber(NumberDB number) {
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Запросы для таблицы SMS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SMSDB[] sqlGetSMSNumbers() {
 | 
					SMSDB[] sqlGetSMSNumbers() {
 | 
				
			||||||
    SMSDB[] numbers;
 | 
					    SMSDB[] numbers;
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
| 
						 | 
					@ -293,3 +305,106 @@ bool sqlDeleteSMS(int idsms) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Запросы для таблицы USSD
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					USSDDB[] sqlGetUSSDNumbers() {
 | 
				
			||||||
 | 
					    USSDDB[] numbers;
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					        auto queryResult = pgsql.sql(
 | 
				
			||||||
 | 
					            "select distinct da_to from da_ussd"
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        foreach (row; queryResult) {
 | 
				
			||||||
 | 
					            USSDDB data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            data.to = row["da_to"];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            numbers ~= data;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    } catch (Exception e) {
 | 
				
			||||||
 | 
					        log.e("Не удалось выполнить запрос к БД. " ~ e.msg);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return numbers;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					USSDDB[] sqlGetListUSSD(string to) {
 | 
				
			||||||
 | 
					    USSDDB[] ussd;
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					        auto queryResult = pgsql.sql(
 | 
				
			||||||
 | 
					            "select
 | 
				
			||||||
 | 
					                dau.da_id,
 | 
				
			||||||
 | 
					                to_char(dau.da_date, 'YYYY.MM.DD HH24:MI:SS') da_date,
 | 
				
			||||||
 | 
					                dau.da_to,
 | 
				
			||||||
 | 
					                dau.da_type,
 | 
				
			||||||
 | 
					                daut.da_comment da_type_comment,
 | 
				
			||||||
 | 
					                dau.da_text
 | 
				
			||||||
 | 
					            from da_ussd dau
 | 
				
			||||||
 | 
					            inner join da_ussd_type daut
 | 
				
			||||||
 | 
					            on dau.da_type = daut.da_id
 | 
				
			||||||
 | 
					            where dau.da_to = ?
 | 
				
			||||||
 | 
					            order by dau.da_date desc",
 | 
				
			||||||
 | 
					            to
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        foreach (row; queryResult) {
 | 
				
			||||||
 | 
					            USSDDB data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            data.id = row["da_id"].to!int;
 | 
				
			||||||
 | 
					            data.date = row["da_date"];
 | 
				
			||||||
 | 
					            data.to = row["da_to"];
 | 
				
			||||||
 | 
					            data.type = row["da_type"].to!int;
 | 
				
			||||||
 | 
					            data.type_comment = row["da_type_comment"];
 | 
				
			||||||
 | 
					            data.text = row["da_text"];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            ussd ~= data;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    } catch (Exception e) {
 | 
				
			||||||
 | 
					        log.e("Не удалось выполнить запрос к БД. " ~ e.msg);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ussd;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					USSDDB sqlGetUSSD(int idussd) {
 | 
				
			||||||
 | 
					    USSDDB data;
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					        auto queryResult = pgsql.sql(
 | 
				
			||||||
 | 
					            "select
 | 
				
			||||||
 | 
					                da_id,
 | 
				
			||||||
 | 
					                to_char(da_date, 'YYYY.MM.DD HH24:MI:SS') da_date,
 | 
				
			||||||
 | 
					                da_to,
 | 
				
			||||||
 | 
					                da_type,
 | 
				
			||||||
 | 
					                da_text
 | 
				
			||||||
 | 
					            from da_ussd
 | 
				
			||||||
 | 
					            where da_id = ?",
 | 
				
			||||||
 | 
					            idussd
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        foreach (row; queryResult) {
 | 
				
			||||||
 | 
					            data.id = row["da_id"].to!int;
 | 
				
			||||||
 | 
					            data.date = row["da_date"];
 | 
				
			||||||
 | 
					            data.to = row["da_to"];
 | 
				
			||||||
 | 
					            data.type = row["da_type"].to!int;
 | 
				
			||||||
 | 
					            data.text = row["da_text"];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    } catch (Exception e) {
 | 
				
			||||||
 | 
					        log.e("Не удалось выполнить запрос к БД. " ~ e.msg);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return data;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool sqlDeleteUSSD(int idussd) {
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					        pgsql.sql(
 | 
				
			||||||
 | 
					            "delete from da_ussd where da_id = ?", idussd
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    } catch (Exception e) {
 | 
				
			||||||
 | 
					        log.e("Ошибка удаления USSD в БД. " ~ e.msg);
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,3 +44,12 @@ struct SMSDB {
 | 
				
			||||||
    string from;
 | 
					    string from;
 | 
				
			||||||
    string text;
 | 
					    string text;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct USSDDB {
 | 
				
			||||||
 | 
					    int id;
 | 
				
			||||||
 | 
					    string date;
 | 
				
			||||||
 | 
					    string to;
 | 
				
			||||||
 | 
					    int type;
 | 
				
			||||||
 | 
					    string type_comment;
 | 
				
			||||||
 | 
					    string text;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,13 +10,14 @@ head
 | 
				
			||||||
    script(src='script.js')
 | 
					    script(src='script.js')
 | 
				
			||||||
body
 | 
					body
 | 
				
			||||||
    div.div-header
 | 
					    div.div-header
 | 
				
			||||||
        div.div-update.main-button
 | 
					 | 
				
			||||||
            button#update
 | 
					 | 
				
			||||||
        div.div-add.main-button
 | 
					        div.div-add.main-button
 | 
				
			||||||
            button#add-number Добавить номер
 | 
					            button#add-number Добавить номер
 | 
				
			||||||
        div.div-search
 | 
					        div.div-search.main-button
 | 
				
			||||||
            input.input-focus#search(name='search', type='text', value='', placeholder='Найти номер')
 | 
					            input.input-focus#search(name='search', type='text', value='', placeholder='Найти номер')
 | 
				
			||||||
        // div.div-user Вы вошли как #{user.name}
 | 
					        div.div-update-tab.main-button
 | 
				
			||||||
 | 
					            button#update-tab Перезагрузить
 | 
				
			||||||
 | 
					        div.div-update-tab.main-button
 | 
				
			||||||
 | 
					            button#update-group Обновить
 | 
				
			||||||
        div.div-user
 | 
					        div.div-user
 | 
				
			||||||
        div.div-logout
 | 
					        div.div-logout
 | 
				
			||||||
            button#logout Выход
 | 
					            button#logout Выход
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										13
									
								
								views/list_ussd_groups.dt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								views/list_ussd_groups.dt
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,13 @@
 | 
				
			||||||
 | 
					div#accordion-ussd
 | 
				
			||||||
 | 
					    - foreach (number; numbers)
 | 
				
			||||||
 | 
					        h3 На номер #{number.to}
 | 
				
			||||||
 | 
					        div.group-content(data-to='#{number.to}')
 | 
				
			||||||
 | 
					            table
 | 
				
			||||||
 | 
					                thead.head
 | 
				
			||||||
 | 
					                    tr
 | 
				
			||||||
 | 
					                        th.ussd-content-width Дата
 | 
				
			||||||
 | 
					                        th.ussd-content-width-type Тип
 | 
				
			||||||
 | 
					                        th Текст сообщения
 | 
				
			||||||
 | 
					            div.body-rows
 | 
				
			||||||
 | 
					                table
 | 
				
			||||||
 | 
					                    tbody.body
 | 
				
			||||||
							
								
								
									
										11
									
								
								views/ussd.dt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								views/ussd.dt
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,11 @@
 | 
				
			||||||
 | 
					div#ussd-data
 | 
				
			||||||
 | 
					    table
 | 
				
			||||||
 | 
					        tbody
 | 
				
			||||||
 | 
					            tr
 | 
				
			||||||
 | 
					                td.ussd-label Дата:
 | 
				
			||||||
 | 
					                td.ussd-value #{dataUSSD.date}
 | 
				
			||||||
 | 
					            tr
 | 
				
			||||||
 | 
					                td.ussd-label.ussd-label-text Текст:
 | 
				
			||||||
 | 
					                td.ussd-value
 | 
				
			||||||
 | 
					                    div.ussd-content
 | 
				
			||||||
 | 
					                        textarea#ussd-content(readonly, data-id="#{dataUSSD.id}") #{dataUSSD.text}
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue