Старт

This commit is contained in:
2023-11-07 19:51:49 +06:00
commit 86542a157f
5002 changed files with 199551 additions and 0 deletions

View File

@ -0,0 +1,332 @@
//Класс для отображения и обработки сообщения пользователя
class TUserMessage
{
constructor(parent){
this.id=null;
this.parent = parent;
this.win = null;
}
//Отметить сообщение как обработанное
MarkAsProcessed(id)
{
var description=document.getElementById("msg_desc").value;
var data = {
id: id,
description: description
};
$.ajax({
url: '/monitoring/pscripts/messages.php?fn=5',
data: JSON.stringify(data),
contentType: 'application/json; charset=utf-8',
type: "POST",
dataType: "json",
success: function(thiz){return function(data,status){
if(status=='success')
{
if(data.errorCode=='0')
{
//alert(trt('Saved')+'!');
thiz.win.Close();
//Обновляю список
thiz.parent.Filtering();
}else
{
alert(trt('Error')+': "'+data.errorMessage);
thiz.win.hideProgressBar();
}
}else
{
alert(status);
thiz.win.hideProgressBar();
}
}}(this)
});
this.win.showProgressBar();
}
//Загрузить сообщение в окно
ShowMessage(id)
{
if(this.win!=null) this.win.Close();
this.win = new TWin();
this.win.setParent(this.parent.win);
this.win.BuildGUI(10,10);
this.win.setCaption(trt('Message'));
this.win.setSize("600px","400px");
this.win.setCenter();
this.win.hide(false);
this.win.showProgressBar();
//Запрашиваю данные для отображения в окне
var data = {
id: id
};
var req=createRequestObject();
req.onreadystatechange = function(thiz)
{
return function(){
if(req.readyState === 4){
thiz.win.hideProgressBar(); //Всё "OK" скрываю "Progress bar"
var data=null;
try {
data = JSON.parse(req.responseText);
} catch (e) {
alert(e.message);
}
if(data!=null)
{
//Отображаю окошко с необработанными сообщениями
var html='<table class="SShow" style="width:100%;height:100%; background-color: #3a3a3a;">';
html+='<thead><tr><th style="width:30%;">'+trt('Name')+'</th><th style="width:70%;">'+trt('Value')+'</th></tr></thead>';
html+='<tr><td style="padding:2px;font-weight:bold;vertical-align:top;">'+trt('Theme')+'</td><td style="padding: 2px;vertical-align:top;">'+trt(data.subject)+'</td>';
html+='<tr style="height:100%;"><td style="font-weight:bold;padding:2px;vertical-align:top;">'+trt('Content')+'</td><td style="padding: 2px;vertical-align:top;">'+data.text+'</td></tr>';
if(data.action_name!='' && data.action_name!=null)
{
html+='<tr"><td style="padding:2px;vertical-align:top;">'+trt('Action')+'</td><td style="padding: 2px;vertical-align:top;"><button type="button" class="button-secondary" id="create_msg_a" style="width:100%;">'+trt(data.action_name)+'</button></td></tr>';
}
html+='<tr style="height:100%;"><td style="padding:2px;vertical-align:top;">'+trt('Additional_Information')+' ('+trt('Action_taken')+')'+'</td><td style="padding: 2px;vertical-align:top;"><textarea id="msg_desc" style="width:100%;height:100px;"></textarea></td></tr>';
html+='<tr><td style="padding: 2px;text-align:right;" colspan="2"><button class="button-secondary" onclick="g_UserMessage.MarkAsProcessed('+data.id+');">'+trt('Mark_as_processed')+'</button></td></tr>';
html+='</table>';
thiz.win.setContent(html);
//Обработчик события нажатия на кнопку действия
var btn = document.getElementById('create_msg_a');
if(btn!=null)
{
btn.onclick=function(name,settings){ return function(){
if(name=='Create_trip')
g_trips.createTrip(settings);
else if(name=='Edit_trip')
g_trips.editTrip(settings);
else
alert('Unknown action "'+name+'"!');
}; }(data.action_name,data.action_settings);
}
}
}
};
}(this);
req.open("POST", '/monitoring/pscripts/messages.php?fn=4', true);
req.setRequestHeader("Content-type", "text/plain");
req.send(JSON.stringify(data));
}
}
class TUserMessages
{
consctuctor(){
this.win = null;
}
//this.win.addResizeListener(function(obj){return function(){obj.updateSize();}}(this));
//Update dimensions of the elements (the main table in absolute coordinates).
updateSize()
{
var dv1=document.getElementById("tblMsgContainer");
var dv2=document.getElementById("tblMsgSContainer");
if(dv1!=null && dv2!=null)
{
dv1.style.width = dv2.offsetWidth+"px";
dv1.style.height = dv2.offsetHeight+"px";
}
}
//Отобразить окно с сообщениями пользователя
ShowMessages()
{
if(this.win!=null) this.win.Close();
this.win=new TWin();
this.win.BuildGUI(10,10);
this.win.setCaption(trt('User_messages'));
this.win.setSize("1000px","500px");
this.win.hide(false);
var content = '';
content+='<table style="width:100%; height:100%;"><tr><td>';
content+='<table style="width:100%; border: 1px solid rgb(99, 99, 99); table-layout: auto; margin-bottom: 10px;">';
content+='<caption></caption>';
content+='<thead></thead>';
content+='<tbody>';
content+=' <tr><td style="padding: 1px; white-space: nowrap;">'+trt('Company')+'</td><td style="padding: 1px; width: 100%;"><select id="sCompany_3" style="width: 100%;"></select></td></tr>';
content+=' <tr><td style="padding: 1px; white-space: nowrap;">'+trt('Status')+'</td><td style="padding: 1px; width: 100%;"><select id="sEvents_3" style="width: 100%;"><option value="1">'+trt('Processed')+'</option><option selected="selected" value="0">'+trt('Unprocessed')+'</option></select></td></tr>';
content+=' <tr><td style="padding: 1px;"></td><td style="padding: 1px; text-align:right;"><input class="button-secondary" type="button" value="Фильтровать" id="btnfilter_3"></td></tr>';
content+='</tbody>';
content+='</table>';
//Контент
content+='</td></tr><tr><td style="width:100%; height:100%;">';
content+='<div id="tblMsgSContainer" style="width:100%; height:100%;" bgcolor="green">';
content+='<div id="tblMsgContainer" style="position: absolute; overflow: scroll; width: 400px; height: 300px;">';
content+='</div>';
content+='</div>';
content+='</td></tr></table>';
this.win.setContent(content);
this.win.setCenter();
this.win.addResizeListener(function(thiz){return function(){thiz.updateSize();}}(this));
//Кнопочка фильтровать
var obj = document.getElementById("btnfilter_3");
obj.onclick = function(thiz){ return function(){ thiz.Filtering(); };}(this);
//Запрашиваю данные для заполнения выпадающего списка компаний
this.Filtering();
//Запрашиваю данные для заполнения компании
$.ajax({
url: "/monitoring/pscripts/user.php?fn=10",
type: "POST",
success: function(response) {
let b = document.getElementById("sCompany_3");
b.innerHTML += response;
}
});
}
//Запросить данные для отображения в фильтре
Filtering()
{
var data = {
state: ''
};
var req=createRequestObject();
req.onreadystatechange = function(thiz)
{
return function(){
if(req.readyState === 4){
var data=null;
try {
data = JSON.parse(req.responseText);
} catch (e) {
alert(e.message);
}
if(data!=null)
{
if(data.errorMessage !== undefined && data.errorMessage!='')
{
alert(data.errorMessage);
thiz.win.hideProgressBar();
return;
}
//Отображаю окошко с необработанными сообщениями
var html='<table class="SShow">';
html+='<thead><tr style="background-color: rgb(218, 218, 218);"><th>Тема</th><th>Содержание</th></tr></thead>';
for(i=0;i<data.length;i++)
{
let bgColor='';
if (i%2==0) bgColor='var(--row-color-1)'; else bgColor='var(--row-color-2)';
html+='<tr onclick="g_UserMessage.ShowMessage('+data[i].id+');" onmouseover="this.style.backgroundColor=\'var(--btn-color2)\';" onmouseout="this.style.backgroundColor=\''+bgColor+'\';" style="cursor: pointer; background-color:'+bgColor+';">';
//html+='<td>'+data[i].id+'</td>';
html+='<td>'+data[i].subject+'</td>';
html+='<td>'+data[i].text+'</td>';
html+='</tr>';
/*var userMessage = new TUserMessage();
userMessage.id=data[i].id;
thiz.messages.push(userMessage);*/
}
html+='</table>';
var cont=document.getElementById("tblMsgContainer");
cont.innerHTML = html;
}
thiz.win.hideProgressBar();
}
};
}(this);
req.open( "GET", '/monitoring/pscripts/messages.php?fn=3&status='+document.getElementById("sEvents_3").value, true );
req.send( null );
this.win.showProgressBar();
}
}
var g_UserMessages = new TUserMessages();
var g_UserMessage = new TUserMessage(g_UserMessages);
//Функция для переодическогой проверки количество сообщений требующих обработки а также кол-во сообщений для текущего пользователя
function getAllMessagesCount()
{
var data = {
test: ''
};
$.ajax({
url: '/monitoring/pscripts/messages.php?fn=1',
data: JSON.stringify(data),
contentType: 'application/json; charset=utf-8',
type: "POST",
dataType: "json",
success: function(thiz){return function(data,status){
if(status=='success')
{
//Отображаю окошко с количеством необработанных сообщений
if(g_winCntMsg==null || g_winCntMsg.closed==true)
{
g_winCntMsg=new TWin();
g_winCntMsg.BuildGUI(20,60);
g_winCntMsg.setCaption(trt('Messages'));
//this.win.setContent(str);
g_winCntMsg.setSize("130px","120px");
//g_winCntMsg.setCenter();
//g_winCntMsg.shadow=true;
g_winCntMsg.hide(false);
}
//g_winCntMsg.setLeftTop(20,60);
g_winCntMsg.hide(false);
if(g_count!=parseInt(data.count))
{
beep();
g_count = parseInt(data.count);
}
var mCNTUser = parseInt(data.user);
var content = '';
content+=trt("Unassigned")+":<br>";
if(g_count>0){
content+="<button class=\"button-secondary\" id=\"takeMessage\" style=\"width:100%;height:50px;font-size:24pt;font-weight:bold;color:red;\" onclick=\"takeMessage();\"><blink class=\"blink\">"+g_count+"</blink></button>";
}else{
content+="<button class=\"button-secondary\" id=\"takeMessage\" style=\"width:100%;height:50px;font-size:24pt;font-weight:bold;\" onclick=\"takeMessage();\">"+g_count+"</button>";
}
content+=trt("Designated")+":<br>";
if(mCNTUser>0){
content+="<button class=\"button-secondary\" style=\"width:100%;height:50px;font-size:24pt;font-weight:bold;color:red;\" onclick=\"g_UserMessages.ShowMessages();\"><blink class=\"blink\">"+mCNTUser+"</blink></button>";
}else{
content+="<button class=\"button-secondary\" style=\"width:100%;height:50px;font-size:24pt;font-weight:bold;\" onclick=\"g_UserMessages.ShowMessages();\">0</button>";
}
g_winCntMsg.setContent(content);
}else
{
alert(status);
}
}}(this)
});
}
//Запрашиваем каждые 5 секунд
var timerId = setInterval(function() {
getAllMessagesCount();
}, 5000);