v0.0.6
+ Запросы объеденины в соответствующие модули + Оптимизация кода
This commit is contained in:
		
							parent
							
								
									ab4b8c6bad
								
							
						
					
					
						commit
						2ba510adac
					
				
					 23 changed files with 462 additions and 530 deletions
				
			
		
							
								
								
									
										545
									
								
								js/script.js
									
										
									
									
									
								
							
							
						
						
									
										545
									
								
								js/script.js
									
										
									
									
									
								
							|  | @ -4,58 +4,50 @@ var sms = []; | |||
| $(document).ready(function () { | ||||
|     noticer = new Noticer; | ||||
| 
 | ||||
|     let tabs = { | ||||
|         0: () => { showListNumbers($("#accordion-numbers .ui-accordion-content-active")) }, | ||||
|         1: () => { showListSMS($("#accordion-sms .ui-accordion-content-active")) }, | ||||
|         2: () => {}, | ||||
|         3: () => {} | ||||
|     }; | ||||
| 
 | ||||
|     let groups = { | ||||
|         0: () => { generateListGroupNumbers($("#accordion-numbers .ui-accordion-content-active")) }, | ||||
|         1: () => { generateListGroupSMS($("#accordion-sms .ui-accordion-content-active")) }, | ||||
|         2: () => { noticer.success('Вкладка "USSD"') }, | ||||
|         3: () => { noticer.success('Вкладка "Сервер"') } | ||||
|     }; | ||||
| 
 | ||||
|     $("button").button(); | ||||
|     $("#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"); | ||||
| 
 | ||||
|     $("#tabs").tabs({ | ||||
|         activate: function( event, ui ) { | ||||
|             tabs[$(this).tabs( "option", "active" )](); | ||||
|             $("#add-number").button( "option", "disabled", $(this).tabs( "option", "active" ) > 0 ); | ||||
|         } | ||||
|     }); | ||||
| 
 | ||||
|     $("#update").click(() => { | ||||
|         ({ | ||||
|             0: () => { generateGroupNumbers($("#accordion-numbers .ui-accordion-content-active")) }, | ||||
|             1: () => { generateListSMS($("#accordion-sms .ui-accordion-content-active")) }, | ||||
|             2: () => { noticer.success('Вкладка "USSD"') }, | ||||
|             3: () => { noticer.success('Вкладка "Сервер"') } | ||||
|         })[$("#tabs").tabs( "option", "active" )]() | ||||
|         groups[$("#tabs").tabs( "option", "active" )]() | ||||
|     }); | ||||
| 
 | ||||
|     $("#add-number").click(() => { | ||||
|         addNumber($("#accordion-numbers .ui-accordion-content-active")) | ||||
|     }); | ||||
| 
 | ||||
|     $("body").fadeTo(500, 1); | ||||
| 
 | ||||
|     $("#search").on("input", function () { | ||||
|         ({ | ||||
|             0: () => { showNumbers($("#accordion-numbers .ui-accordion-content-active")) }, | ||||
|             1: () => { showSMS($("#accordion-sms .ui-accordion-content-active")) }, | ||||
|             2: () => {}, | ||||
|             3: () => {} | ||||
|         })[$("#tabs").tabs( "option", "active" )]() | ||||
|         tabs[$("#tabs").tabs( "option", "active" )]() | ||||
|     }).keydown(function (e) { | ||||
|         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" )]() | ||||
|         ) | ||||
|         e.key == "Escape" && ($(this).val(""), tabs[$("#tabs").tabs( "option", "active" )]()) | ||||
|     }); | ||||
| 
 | ||||
|     loadNumbers(); | ||||
|     loadSMS(); | ||||
| 
 | ||||
|     $("body").fadeTo(500, 1); | ||||
| }) | ||||
| 
 | ||||
| async function request(query, type, queryData = {}) { | ||||
|  | @ -89,23 +81,259 @@ function isNumeric(value) { | |||
|     return /^-?\d+$/.test(value); | ||||
| } | ||||
| 
 | ||||
| function divNotFoundNumbers() { | ||||
|     let notFound = $('.notFoundNumbers'); | ||||
|     let divTable = $('.body-rows'); | ||||
|     let divNotFound = $('<div class="notFoundNumbers"></div>'); | ||||
| 
 | ||||
|     divNotFound.css({ | ||||
|         "color": "#333", | ||||
|         "text-align": "center", | ||||
|         "padding": "20px 0 20px 0" | ||||
|     }); | ||||
| 
 | ||||
|     this.push = function(text = 'Нет номеров') { | ||||
|         divTable.append(divNotFound.html(text)); | ||||
|     } | ||||
| 
 | ||||
|     this.remove = function() { | ||||
|         notFound.remove(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /************************************************************************************ | ||||
| 
 | ||||
|                     Обработка таблицы с номерами телефонов | ||||
| 
 | ||||
| ************************************************************************************/ | ||||
| 
 | ||||
| function loadNumbers() { | ||||
|     request('listsgroups', 'text').then(data => { | ||||
|         data.error ? noticer.error(data.message) : generateListsGroups(data); | ||||
|     request('listnumbergroups', 'text').then(data => { | ||||
|         data.error ? noticer.error(data.message) : generateListNumberGroups(data); | ||||
|     }).catch(error => { | ||||
|         noticer.error(error.message); | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function generateListNumberGroups(data) { | ||||
|     if (!$(data).children().length) { | ||||
|         $("#tabs-numbers").html('<p>Номера телефонов отсутствуют</p>'); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     $("#tabs-numbers").html(data); | ||||
|     $("#accordion-numbers").accordion({ | ||||
|         heightStyle: "content", | ||||
|         create: function( event, ui ) { | ||||
|             generateListGroupNumbers(ui.panel); | ||||
|         }, | ||||
|         beforeActivate: function( event, ui ) { | ||||
|             generateListGroupNumbers(ui.newPanel); | ||||
|         } | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function generateListGroupNumbers(panel) { | ||||
|     if (!$("#accordion-numbers").children().length) { | ||||
|         noticer.warning("Номера телефонов отсутствуют"); | ||||
|         $("#tabs-numbers").html('<p>Номера телефонов отсутствуют</p>'); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     request('listgroupnumbers', 'json', { group: panel.data("group-name") }).then(data => { | ||||
|         if (isJSON(data) && JSON.parse(data).error) | ||||
|             noticer.error(JSON.parse(data).message); | ||||
|         else { | ||||
|             numbers = data; | ||||
|             showListNumbers(panel); | ||||
|         } | ||||
|     }).catch(error => { | ||||
|         noticer.error(error.message); | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function showListNumbers(panel, data = numbers.filter(e => e.number.includes($("#search").val()))) { | ||||
|     (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() { | ||||
|             viewNumber(panel, $(this).data('number')); | ||||
|         });         | ||||
|     }); | ||||
| 
 | ||||
|     if (!body.children().length) | ||||
|         (new divNotFoundNumbers).push(); | ||||
| } | ||||
| 
 | ||||
| function viewNumber(panel, number) { | ||||
|     request('viewnumber', 'text', {number: number}).then(data => { | ||||
|         if (isJSON(data) && JSON.parse(data).error) | ||||
|             noticer.error(JSON.parse(data).message); | ||||
|         else { | ||||
|             showViewNumber(data, [ | ||||
|                 { | ||||
|                     id: "btn-save", | ||||
|                     text: "Сохранить", | ||||
|                     icon: "ui-icon-check", | ||||
|                     click: function() { | ||||
|                         actionNumber(panel, $(this), 'updatenumber'); | ||||
|                     } | ||||
|                 }, | ||||
|                 { | ||||
|                     id: "btn-delete", | ||||
|                     text: "Удалить", | ||||
|                     icon: "ui-icon-trash", | ||||
|                     click: function() { | ||||
|                         delNumber(panel, $(this)); | ||||
|                     } | ||||
|                 } | ||||
|             ], `Редактирование номера ${number}`); | ||||
|         } | ||||
|     }).catch(error => { | ||||
|         noticer.error(error.message); | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function showViewNumber(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"); | ||||
|                 } | ||||
|             } | ||||
|         ] | ||||
|     }); | ||||
| 
 | ||||
|     $('#number-group, #number-list').selectmenu({ | ||||
|         width: 200 | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function actionNumber(panel, currentWindow, query) { | ||||
|     let pattern_number = /^\+7\d{10}$/g; | ||||
| 
 | ||||
|     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(); | ||||
| 
 | ||||
|     let error = false; | ||||
| 
 | ||||
|     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; | ||||
| 
 | ||||
|     request(query, 'json', { | ||||
|         number: number, | ||||
|         group: group, | ||||
|         list: list, | ||||
|         all_cc: parseInt(all_cc), | ||||
|         white_cc: parseInt(white_cc), | ||||
|         black_cc: parseInt(black_cc), | ||||
|         comment: comment | ||||
|     }).then(data => { | ||||
|         if (data.error) | ||||
|             noticer.error(data.message); | ||||
|         else | ||||
|         { | ||||
|             query == 'write' ? noticer.success(`Номер ${number} был добавлен`) : noticer.success(`Номер ${number} был обновлен`); | ||||
|             generateListGroupNumbers(panel); | ||||
|             currentWindow.dialog("close"); | ||||
|         } | ||||
|     }).catch(error => { | ||||
|         noticer.error(error.message); | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function addNumber(panel) { | ||||
|     request('addnumber', 'text', { group: panel.data("group-name") }).then(data => { | ||||
|         if (isJSON(data) && JSON.parse(data).error) | ||||
|             noticer.error(JSON.parse(data).message); | ||||
|         else { | ||||
|             showViewNumber(data, [{ | ||||
|                 id: "btnSave", | ||||
|                 text: "Добавить", | ||||
|                 icon: "ui-icon-check", | ||||
|                 click: function() { | ||||
|                     actionNumber(panel, $(this), 'writenumber'); | ||||
|                 } | ||||
|             }], "Добавление нового номера"); | ||||
|         } | ||||
|     }).catch(error => { | ||||
|         noticer.error(error.message); | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function delNumber(panel, currentWindow) { | ||||
|     let number = $('#number-number').val(); | ||||
| 
 | ||||
|     let error = false; | ||||
|     if (!number.length) { noticer.warning('Номер не может быть пуст'); error = true; } | ||||
|     if (error) return; | ||||
| 
 | ||||
|     request('delnumber', 'json', { | ||||
|         number: number | ||||
|     }).then(data => { | ||||
|         if (data.error) | ||||
|             noticer.error(data.message); | ||||
|         else { | ||||
|             noticer.success(`Номер ${number} был удален`); | ||||
|             generateListGroupNumbers(panel); | ||||
|             currentWindow.dialog("close"); | ||||
|         } | ||||
|     }).catch(error => { | ||||
|         noticer.error(error.message); | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| /************************************************************************************ | ||||
| 
 | ||||
|                     Обработка таблицы с SMS | ||||
| 
 | ||||
| ************************************************************************************/ | ||||
| 
 | ||||
| function loadSMS() { | ||||
|     request('smsnumbers', 'text').then(data => { | ||||
|         data.error ? noticer.error(data.message) : generateListsSMSNumber(data); | ||||
|     request('listsmsgroups', 'text').then(data => { | ||||
|         data.error ? noticer.error(data.message) : generateListSMSGroups(data); | ||||
|     }).catch(error => { | ||||
|         noticer.error(error.message); | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function generateListsSMSNumber(data) { | ||||
| function generateListSMSGroups(data) { | ||||
|     if (!$(data).children().length) { | ||||
|         $("#tabs-sms").html('<p>SMS отсутствуют</p>'); | ||||
|         return; | ||||
|  | @ -115,34 +343,34 @@ function generateListsSMSNumber(data) { | |||
|     $("#accordion-sms").accordion({ | ||||
|         heightStyle: "content", | ||||
|         create: function( event, ui ) { | ||||
|             generateListSMS(ui.panel); | ||||
|             generateListGroupSMS(ui.panel); | ||||
|         }, | ||||
|         beforeActivate: function( event, ui ) { | ||||
|             generateListSMS(ui.newPanel); | ||||
|             generateListGroupSMS(ui.newPanel); | ||||
|         } | ||||
|     }) | ||||
| } | ||||
| 
 | ||||
| function generateListSMS(panel) { | ||||
| function generateListGroupSMS(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 => { | ||||
|     request('listgroupsms', '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); | ||||
|             showListSMS(panel); | ||||
|         } | ||||
|     }).catch(error => { | ||||
|         noticer.error(error.message); | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function showSMS(panel, data = sms.filter(e => e.from.includes($("#search").val()))) { | ||||
| function showListSMS(panel, data = sms.filter(e => e.from.includes($("#search").val()))) { | ||||
|     (new divNotFoundNumbers).remove(); | ||||
|     let body = panel.find('.body').html(''); | ||||
|     $(data).each((i, j) => { | ||||
|  | @ -219,232 +447,7 @@ function delSMS(panel, currentWindow) { | |||
|             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", | ||||
|         create: function( event, ui ) { | ||||
|             generateGroupNumbers(ui.panel); | ||||
|         }, | ||||
|         beforeActivate: function( event, ui ) { | ||||
|             generateGroupNumbers(ui.newPanel); | ||||
|         } | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| 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); | ||||
|         else { | ||||
|             numbers = data; | ||||
|             showNumbers(panel); | ||||
|         } | ||||
|     }).catch(error => { | ||||
|         noticer.error(error.message); | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function showNumbers(panel, data = numbers.filter(e => e.number.includes($("#search").val()))) { | ||||
|     (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() { | ||||
|             editNumber(panel, $(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 editNumber(panel, 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(panel, $(this), 'updatenumber'); | ||||
|                     } | ||||
|                 }, | ||||
|                 { | ||||
|                     id: "btn-delete", | ||||
|                     text: "Удалить", | ||||
|                     icon: "ui-icon-trash", | ||||
|                     click: function() { | ||||
|                         delNumber(panel, $(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', | ||||
|         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(panel, currentWindow, query) { | ||||
|     let pattern_number = /^\+7\d{10}$/g; | ||||
| 
 | ||||
|     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(); | ||||
| 
 | ||||
|     let error = false; | ||||
| 
 | ||||
|     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; | ||||
| 
 | ||||
|     request(query, 'json', { | ||||
|         number: number, | ||||
|         group: group, | ||||
|         list: list, | ||||
|         all_cc: parseInt(all_cc), | ||||
|         white_cc: parseInt(white_cc), | ||||
|         black_cc: parseInt(black_cc), | ||||
|         comment: comment | ||||
|     }).then(data => { | ||||
|         if (data.error) | ||||
|             noticer.error(data.message); | ||||
|         else | ||||
|         { | ||||
|             query == 'write' ? noticer.success(`Номер ${number} был добавлен`) : noticer.success(`Номер ${number} был обновлен`); | ||||
|             generateGroupNumbers(panel); | ||||
|             currentWindow.dialog("close"); | ||||
|         } | ||||
|     }).catch(error => { | ||||
|         noticer.error(error.message); | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function addNumber(panel) { | ||||
|     request('addnumber', 'text', { group: panel.data("group-name") }).then(data => { | ||||
|         if (isJSON(data) && JSON.parse(data).error) | ||||
|             noticer.error(JSON.parse(data).message); | ||||
|         else { | ||||
|             showEditNumber(data, [{ | ||||
|                 id: "btnSave", | ||||
|                 text: "Добавить", | ||||
|                 icon: "ui-icon-check", | ||||
|                 click: function() { | ||||
|                     actionNumber(panel, $(this), 'writenumber'); | ||||
|                 } | ||||
|             }], "Добавление нового номера"); | ||||
|         } | ||||
|     }).catch(error => { | ||||
|         noticer.error(error.message); | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function delNumber(panel, currentWindow) { | ||||
|     let number = $('#number-number').val(); | ||||
| 
 | ||||
|     let error = false; | ||||
|     if (!number.length) { noticer.warning('Номер не может быть пуст'); error = true; } | ||||
|     if (error) return; | ||||
| 
 | ||||
|     request('delnumber', 'json', { | ||||
|         number: number | ||||
|     }).then(data => { | ||||
|         if (data.error) | ||||
|             noticer.error(data.message); | ||||
|         else { | ||||
|             noticer.success(`Номер ${number} был удален`); | ||||
|             generateGroupNumbers(panel); | ||||
|             generateListGroupSMS(panel); | ||||
|             currentWindow.dialog("close"); | ||||
|         } | ||||
|     }).catch(error => { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alexander Zhirov
						Alexander Zhirov