v0.0.5
+ Добавлены проверки на обновление/добавление/удаление номера + Реализовано: просмотр и удаление SMS - Необходим рефакторинг (убрать повторяющийся код в JS), оптимизировать - Объединить запросы в D в модули (подпапки)
This commit is contained in:
		
							parent
							
								
									de17e88d37
								
							
						
					
					
						commit
						ab4b8c6bad
					
				
					 20 changed files with 467 additions and 33 deletions
				
			
		
							
								
								
									
										4
									
								
								js/noticer.min.js
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								js/noticer.min.js
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
/*! noticer - v0.1.0 - 2023-05-31
 | 
			
		||||
/*! noticer - v0.1.1 - 2023-06-02
 | 
			
		||||
* https://git.zhirov.kz/alexander/noticer
 | 
			
		||||
* Copyright Alexander Zhirov; Licensed GPL-2.0 */
 | 
			
		||||
class Noticer{timer;constructor(){this.div=$('<div id="noticer"></div>'),this.div.css({position:"absolute",top:"10px",right:"20px","z-index":"1000"}),$("body").append(this.div)}success(e,t=6e3){this.print(e,t,"#52b818","#bffdc0")}warning(e,t=6e3){this.print(e,t,"#b8ae18","#f8fdbf")}error(e,t=6e3){this.print(e,t,"#b96161","#fddede")}print=function(e,t,n,s){t<6e3&&(t=6e3);let i=function(e,t){let n,s,o=t;this.pause=function(){clearTimeout(n),o-=new Date-s},this.resume=function(){s=new Date,clearTimeout(n),n=setTimeout(e,o)},this.dead=function(){clearTimeout(n)},this.resume()},o=$(`<div class="notice">${e}</div>`);o.css({border:`1px solid ${n}`,"background-color":`${s}`,color:"#333",padding:"10px 30px","text-align":"center",display:"none",margin:"10px 0 0 0",width:"350px",opacity:"1",cursor:"pointer"}),o.hover(function(){$(this).css({opacity:"1"})},function(){$(this).css({opacity:"0.3"})}),this.div.append(o);let a=setTimeout(function(){o.fadeTo(1e3,.3)},2500);o.fadeIn(500).mouseenter(()=>{clearTimeout(a),this.timer.pause()}).mouseleave(()=>{this.timer.resume()}).click(()=>{this.timer.dead(),o.fadeOut(0,function(){this.remove()})}),this.timer=new i(()=>{o.fadeOut(500,function(){this.remove()})},t)}}
 | 
			
		||||
class Noticer{constructor(){this.div=$('<div id="noticer"></div>'),this.div.css({position:"absolute",top:"10px",right:"20px","z-index":"1000"}),$("body").append(this.div)}success(e,t=6e3){this.print(e,t,"#52b818","#bffdc0")}warning(e,t=6e3){this.print(e,t,"#b8ae18","#f8fdbf")}error(e,t=6e3){this.print(e,t,"#b96161","#fddede")}print=function(e,t,n,s){t<6e3&&(t=6e3);let a=function(e,t){let n,s,o=t;this.pause=function(){clearTimeout(n),o-=new Date-s},this.resume=function(){s=new Date,clearTimeout(n),n=setTimeout(e,o)},this.dead=function(){clearTimeout(n)},this.resume()},o=$(`<div class="notice">${e}</div>`);o.css({border:`1px solid ${n}`,"background-color":`${s}`,color:"#333",padding:"10px 30px","text-align":"center",display:"none",margin:"10px 0 0 0",width:"350px",opacity:"1",cursor:"pointer"}),o.hover(function(){$(this).css({opacity:"1"})},function(){$(this).css({opacity:"0.3"})}),this.div.append(o);let r=setTimeout(function(){o.fadeTo(1e3,.3)},2500);o.fadeIn(500).mouseenter(()=>{clearTimeout(r),i.pause()}).mouseleave(()=>{i.resume()}).click(()=>{i.dead(),o.fadeOut(0,function(){this.remove()})});let i=new a(()=>{o.fadeOut(500,function(){this.remove()})},t)}}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										200
									
								
								js/script.js
									
										
									
									
									
								
							
							
						
						
									
										200
									
								
								js/script.js
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,21 +1,31 @@
 | 
			
		|||
var numbers = [];
 | 
			
		||||
var sms = [];
 | 
			
		||||
 | 
			
		||||
$(document).ready(function () {
 | 
			
		||||
    noticer = new Noticer;
 | 
			
		||||
 | 
			
		||||
    $("button").button();
 | 
			
		||||
    $("#tabs").tabs();
 | 
			
		||||
    $("#tabs").tabs({
 | 
			
		||||
        activate: function( event, ui ) {
 | 
			
		||||
            ({
 | 
			
		||||
                0: () => { showNumbers($("#accordion-numbers .ui-accordion-content-active")) },
 | 
			
		||||
                1: () => { showSMS($("#accordion-sms .ui-accordion-content-active")) },
 | 
			
		||||
                2: () => {},
 | 
			
		||||
                3: () => {}
 | 
			
		||||
            })[$(this).tabs( "option", "active" )]();
 | 
			
		||||
 | 
			
		||||
            $("#add-number").button( "option", "disabled", $(this).tabs( "option", "active" ) > 0 );
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    $("#update").button("option", "icon", "ui-icon-refresh");
 | 
			
		||||
    $("#add-number").button("option", "icon", "ui-icon-plusthick");
 | 
			
		||||
    $("#logout").button("option", "icon", "ui-icon-power");
 | 
			
		||||
 | 
			
		||||
    // За каждым индексом закреплена функция для выполнения действия
 | 
			
		||||
    // на активной вкладке при нажатии на кнопку обновления
 | 
			
		||||
    $("#update").click(() => {
 | 
			
		||||
        ({
 | 
			
		||||
            0: () => { generateGroupNumbers($("#accordion-numbers .ui-accordion-content-active")) },
 | 
			
		||||
            1: () => { noticer.success('Вкладка "SMS"') },
 | 
			
		||||
            1: () => { generateListSMS($("#accordion-sms .ui-accordion-content-active")) },
 | 
			
		||||
            2: () => { noticer.success('Вкладка "USSD"') },
 | 
			
		||||
            3: () => { noticer.success('Вкладка "Сервер"') }
 | 
			
		||||
        })[$("#tabs").tabs( "option", "active" )]()
 | 
			
		||||
| 
						 | 
				
			
			@ -28,15 +38,24 @@ $(document).ready(function () {
 | 
			
		|||
    $("body").fadeTo(500, 1);
 | 
			
		||||
 | 
			
		||||
    $("#search").on("input", function () {
 | 
			
		||||
        showNumbers(
 | 
			
		||||
            $("#accordion-numbers .ui-accordion-content-active"),
 | 
			
		||||
            numbers.filter(e => e.number.includes($(this).val()))
 | 
			
		||||
        )
 | 
			
		||||
        ({
 | 
			
		||||
            0: () => { showNumbers($("#accordion-numbers .ui-accordion-content-active")) },
 | 
			
		||||
            1: () => { showSMS($("#accordion-sms .ui-accordion-content-active")) },
 | 
			
		||||
            2: () => {},
 | 
			
		||||
            3: () => {}
 | 
			
		||||
        })[$("#tabs").tabs( "option", "active" )]()
 | 
			
		||||
    }).keydown(function (e) {
 | 
			
		||||
        e.key == "Escape" && ($(this).val(""), showNumbers($("#accordion-numbers .ui-accordion-content-active")))
 | 
			
		||||
        e.key == "Escape" && ($(this).val(""), ({
 | 
			
		||||
                0: () => { showNumbers($("#accordion-numbers .ui-accordion-content-active")) },
 | 
			
		||||
                1: () => { showSMS($("#accordion-sms .ui-accordion-content-active")) },
 | 
			
		||||
                2: () => {},
 | 
			
		||||
                3: () => {}
 | 
			
		||||
            })[$("#tabs").tabs( "option", "active" )]()
 | 
			
		||||
        )
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    loadData();
 | 
			
		||||
    loadNumbers();
 | 
			
		||||
    loadSMS();
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
async function request(query, type, queryData = {}) {
 | 
			
		||||
| 
						 | 
				
			
			@ -66,7 +85,11 @@ function isJSON(str) {
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function loadData() {
 | 
			
		||||
function isNumeric(value) {
 | 
			
		||||
    return /^-?\d+$/.test(value);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function loadNumbers() {
 | 
			
		||||
    request('listsgroups', 'text').then(data => {
 | 
			
		||||
        data.error ? noticer.error(data.message) : generateListsGroups(data);
 | 
			
		||||
    }).catch(error => {
 | 
			
		||||
| 
						 | 
				
			
			@ -74,7 +97,142 @@ function loadData() {
 | 
			
		|||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function loadSMS() {
 | 
			
		||||
    request('smsnumbers', 'text').then(data => {
 | 
			
		||||
        data.error ? noticer.error(data.message) : generateListsSMSNumber(data);
 | 
			
		||||
    }).catch(error => {
 | 
			
		||||
        noticer.error(error.message);
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function generateListsSMSNumber(data) {
 | 
			
		||||
    if (!$(data).children().length) {
 | 
			
		||||
        $("#tabs-sms").html('<p>SMS отсутствуют</p>');
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    $("#tabs-sms").html(data);
 | 
			
		||||
    $("#accordion-sms").accordion({
 | 
			
		||||
        heightStyle: "content",
 | 
			
		||||
        create: function( event, ui ) {
 | 
			
		||||
            generateListSMS(ui.panel);
 | 
			
		||||
        },
 | 
			
		||||
        beforeActivate: function( event, ui ) {
 | 
			
		||||
            generateListSMS(ui.newPanel);
 | 
			
		||||
        }
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function generateListSMS(panel) {
 | 
			
		||||
    if (!$("#accordion-sms").children().length) {
 | 
			
		||||
        noticer.warning("SMS отсутствуют");
 | 
			
		||||
        $("#tabs-sms").html('<p>SMS отсутствуют</p>');
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    request('listsms', 'json', { to: panel.data("to") }).then(data => {
 | 
			
		||||
        if (isJSON(data) && JSON.parse(data).error)
 | 
			
		||||
            noticer.error(JSON.parse(data).message);
 | 
			
		||||
        else {
 | 
			
		||||
            sms = data;
 | 
			
		||||
            showSMS(panel);
 | 
			
		||||
        }
 | 
			
		||||
    }).catch(error => {
 | 
			
		||||
        noticer.error(error.message);
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function showSMS(panel, data = sms.filter(e => e.from.includes($("#search").val()))) {
 | 
			
		||||
    (new divNotFoundNumbers).remove();
 | 
			
		||||
    let body = panel.find('.body').html('');
 | 
			
		||||
    $(data).each((i, j) => {
 | 
			
		||||
        let row = $(`<tr class="row" data-sms-id="${j.id}"></tr>`);
 | 
			
		||||
        row.append(`<td class="sms-content-width">${j.date}</td>`);
 | 
			
		||||
        row.append(`<td class="sms-content-width">${j.from}</td>`);
 | 
			
		||||
        row.append(`<td>${j.text}</td>`);
 | 
			
		||||
        body.append(row);
 | 
			
		||||
 | 
			
		||||
        row.click(function() {
 | 
			
		||||
            viewSMS(panel, $(this).data('sms-id'), j.from);
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (!body.children().length)
 | 
			
		||||
        (new divNotFoundNumbers).push();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function viewSMS(panel, id, number) {
 | 
			
		||||
    request('viewsms', 'text', {id: id}).then(data => {
 | 
			
		||||
        if (isJSON(data) && JSON.parse(data).error)
 | 
			
		||||
            noticer.error(JSON.parse(data).message);
 | 
			
		||||
        else {
 | 
			
		||||
            showViewSMS(data, [
 | 
			
		||||
                {
 | 
			
		||||
                    id: "btn-delete",
 | 
			
		||||
                    text: "Удалить",
 | 
			
		||||
                    icon: "ui-icon-trash",
 | 
			
		||||
                    click: function() {
 | 
			
		||||
                        delSMS(panel, $(this));
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            ], `SMS от ${number}`);
 | 
			
		||||
        }
 | 
			
		||||
    }).catch(error => {
 | 
			
		||||
        noticer.error(error.message);
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function showViewSMS(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 delSMS(panel, currentWindow) {
 | 
			
		||||
    let id = $('#sms-content').data('id');
 | 
			
		||||
    let from = $('#sms-content').data('from');
 | 
			
		||||
 | 
			
		||||
    request('delsms', 'json', {
 | 
			
		||||
        id: id
 | 
			
		||||
    }).then(data => {
 | 
			
		||||
        if (data.error)
 | 
			
		||||
            noticer.error(data.message);
 | 
			
		||||
        else {
 | 
			
		||||
            noticer.success(`SMS от ${from} было удалено`);
 | 
			
		||||
            generateListSMS(panel);
 | 
			
		||||
            currentWindow.dialog("close");
 | 
			
		||||
        }
 | 
			
		||||
    }).catch(error => {
 | 
			
		||||
        noticer.error(error.message);
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function generateListsGroups(data) {
 | 
			
		||||
    if (!$(data).children().length) {
 | 
			
		||||
        $("#tabs-numbers").html('<p>Номера телефонов отсутствуют</p>');
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    $("#tabs-numbers").html(data);
 | 
			
		||||
    $("#accordion-numbers").accordion({
 | 
			
		||||
        heightStyle: "content",
 | 
			
		||||
| 
						 | 
				
			
			@ -88,6 +246,12 @@ function generateListsGroups(data) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
function generateGroupNumbers(panel) {
 | 
			
		||||
    if (!$("#accordion-numbers").children().length) {
 | 
			
		||||
        noticer.warning("Номера телефонов отсутствуют");
 | 
			
		||||
        $("#tabs-numbers").html('<p>Номера телефонов отсутствуют</p>');
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    request('groupnumbers', 'json', { group: panel.data("group-name") }).then(data => {
 | 
			
		||||
        if (isJSON(data) && JSON.parse(data).error)
 | 
			
		||||
            noticer.error(JSON.parse(data).message);
 | 
			
		||||
| 
						 | 
				
			
			@ -203,8 +367,7 @@ function showEditNumber(data, actionButton, title) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
function actionNumber(panel, currentWindow, query) {
 | 
			
		||||
    // Только числа, начинающие с >0 или только 0
 | 
			
		||||
    let regexp = /^(?=\d)(\d|([^0]\d+))$/g;
 | 
			
		||||
    let pattern_number = /^\+7\d{10}$/g;
 | 
			
		||||
 | 
			
		||||
    let number = $('#number-number').val();
 | 
			
		||||
    let group = $('#number-group').val();
 | 
			
		||||
| 
						 | 
				
			
			@ -216,10 +379,13 @@ function actionNumber(panel, currentWindow, query) {
 | 
			
		|||
 | 
			
		||||
    let error = false;
 | 
			
		||||
 | 
			
		||||
    if (!number.length) { noticer.warning('Номер не может быть пуст'); error = true; }
 | 
			
		||||
    if (all_cc.match(regexp) === null) { noticer.warning("Не верно указано общее количество звонков"); error = true; }
 | 
			
		||||
    if (white_cc.match(regexp) === null) { noticer.warning("Не верно указано белое количество звонков"); error = true; }
 | 
			
		||||
    if (black_cc.match(regexp) === null) { noticer.warning("Не верно указано черное количество звонков"); error = true; }
 | 
			
		||||
    if (number.match(pattern_number) === null) { noticer.warning("Номер не соответствует формату +7XXXXXXXXXX"); error = true; }
 | 
			
		||||
    if (!isNumeric(all_cc)) { noticer.warning("Общее количество звонков должно быть числом"); error = true; }
 | 
			
		||||
    if (all_cc < 0) { noticer.warning("Общее количество звонков не может быть отрицательным"); error = true; }
 | 
			
		||||
    if (!isNumeric(white_cc)) { noticer.warning("Белое количество звонков должно быть числом"); error = true; }
 | 
			
		||||
    if (white_cc < 0) { noticer.warning("Белое количество звонков не может быть отрицательным"); error = true; }
 | 
			
		||||
    if (!isNumeric(black_cc)) { noticer.warning("Черное количество звонков должно быть числом"); error = true; }
 | 
			
		||||
    if (black_cc < 0) { noticer.warning("Черное количество звонков не может быть отрицательным"); error = true; }
 | 
			
		||||
 | 
			
		||||
    if (error) return;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue