This commit is contained in:
2023-10-25 11:20:07 +06:00
15 changed files with 11778 additions and 529 deletions

View File

@ -9,14 +9,14 @@ function trt(key)
if(val==null || val===undefined)
{
for(let item in g_translations) {
if(item.toLowerCase()==key.toLowerCase())
if(item.toLowerCase()==(''+key).toLowerCase())
{
val=g_translations[item];
break;
}
}
}
if(val==null || val===undefined) return key.replace(/_/g, ' ');
if(val==null || val===undefined) return (''+key).replace(/_/g, ' ');
else return val;
}
@ -28,7 +28,7 @@ function resizeDivTile(parent,minWidth)
if(parent==null) return;
let dx=Math.floor(parent.offsetWidth/(minWidth));
//console.log("parent.offsetWidth="+parent.offsetWidth+" minWidth="+minWidth+" margin="+margin+" dx="+dx);
//log.info("parent.offsetWidth="+parent.offsetWidth+" minWidth="+minWidth+" margin="+margin+" dx="+dx);
let addW=0;
for(let i=0;i<minWidth+2;i++)
@ -36,24 +36,24 @@ function resizeDivTile(parent,minWidth)
if(dx>=parent.offsetWidth/(minWidth+i))
{
addW=i-1;
//console.log("addW="+addW+" parent.offsetWidth/(minWidth+margin+i)="+(parent.offsetWidth/(minWidth+margin+i)));
//log.info("addW="+addW+" parent.offsetWidth/(minWidth+margin+i)="+(parent.offsetWidth/(minWidth+margin+i)));
break;
}
}
for(let i = 0; i < parent.children.length; i++) {
//console.log(parent.children[i].tagName);
//log.info(parent.children[i].tagName);
if(parent.children[i].tagName.toUpperCase()=='DIV')
{
parent.children[i].style.width = (minWidth+addW)+"px";
}
}
//console.log("minWidth+addW="+(minWidth+addW));
//log.info("minWidth+addW="+(minWidth+addW));
//Центрирую, путем добавления пространства с лева
parent.style.paddingLeft = Math.floor((parent.offsetWidth-(dx*(minWidth+addW)))/2) + "px";
//console.log("parent.style.paddingLeft="+parent.style.paddingLeft+" calc="+(Math.floor((parent.offsetWidth-(dx*(minWidth+addW)))/2)));
//log.info("parent.style.paddingLeft="+parent.style.paddingLeft+" calc="+(Math.floor((parent.offsetWidth-(dx*(minWidth+addW)))/2)));
}
//Получить уникальный идентификатор в рамках текущего NAMESPACE из глобальной переменной
@ -306,6 +306,59 @@ function confirm2(title,smallText,fullText,okFunc,cancelFunc)
return win;
}
//С поле ввода
function prompt2(title,smallText,fieldText,defaultText,okFunc,cancelFunc){
let win=new TWin();
win.BuildGUI(10,10);
win.setCaption(document.createTextNode(title));
let html='\n\
<table cellpadding="0" cellspacing="0" style="width: 100%; height: 100%;">\n\
<tr style="width: 100%;">\n\
<td colspan="3" style="text-align: center; vertical-align: middle; width: 100%;">'+smallText+'</td>\n\
</tr>\n\
<tr style="width: 100%;">\n\
<td colspan="3" style="width: 100%;">'+fieldText+'</td>\n\
</tr>\n\
<tr style="width: 100%;">\n\
<td colspan="3" style="width: 100%;"><textarea rows="5" style="width: 100%;" id="text_'+win.uid+'">'+defaultText+'</textarea></td>\n\
</tr>\n\
<tr style="height: 10px;">\n\
<td style="width: 100%;">&nbsp;</td>\n\
<td><button class="button-secondary" id="'+win.uid+'_ok" style="width: 80px;margin:1px;">'+trt('Ok')+'</button></td>\n\
<td><button class="button-secondary" id="'+win.uid+'_cancel" style="width: 80px;margin:1px;">'+trt('Cancel')+'</button></td>\n\
</tr>\n\
</table>';
win.setContent(html);
let btnO=document.getElementById(win.uid+'_ok');
btnO.focus();
if(btnO!=null){
btnO.onclick=function(win){
return function(){
let text=document.getElementById('text_'+win.uid).value;
win.Close();
if(okFunc!=null) okFunc(text);
};
}(win,okFunc);
}
let btnC=document.getElementById(win.uid+'_cancel');
if(btnC!=null) {
btnC.onclick = function (win) {
return function () {
win.Close();
if(cancelFunc!=null) cancelFunc();
};
}(win,cancelFunc);
}
win.setSize("350px","200px");
win.setCenter();
win.shadow=true;
win.hide(false);
return win;
}
/**
* Добавить событие к объекту
* @param {object} obj Объект
@ -971,7 +1024,7 @@ function delChild(obj)
function applyNodeToNode(first, second, name)
{
if(first===null || second===null || name ===null){
console.error("first="+first+" second="+second+" name="+name);
log.error("first="+first+" second="+second+" name="+name);
return;
}
//Если есть совпадающие узлы то передаём в рекурсию если нет то просто копируем
@ -1006,6 +1059,13 @@ function applyNodeToNode(first, second, name)
}
}
/*function applyObjectToObject(first, second, name){
if(first===null || second===null || name ===null){
log.error("first="+first+" second="+second+" name="+name);
return;
}
}*/
function escapeRegExp(str) {
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
@ -1057,39 +1117,97 @@ class TRequest
}
processReqChange(xmlHttpRequest,url,xmlString)
{
if(typeof(xmlHttpRequest.status)=='undefined' || xmlHttpRequest.status == 200)
{
if(xmlHttpRequest.responseXML!=null) {
//if(typeof(xmlHttpRequest.responseXML)=='undefined' && xmlHttpRequest.contentType.match(/\/xml/)) //For IE XDomainRequest
// xmlHttpRequest.responseXML=CreateXMLDOC(xmlHttpRequest.responseText);
let xmldoc = xmlHttpRequest.responseXML;
if (xmldoc == null) {
alert2(trt('Alert'), trt('Wrong_XML_document') + "!\nXML=(" + xmlHttpRequest.responseText + ')\nURL=(' + url + ')\nxmlString=(' + xmlString + ')');
return;
}
let node = xmldoc.documentElement;
if ((node == null) || (node.getAttribute("fn") == null)){
alert2(trt('Error'), trt('No_data')+"! \n" + xmlHttpRequest.responseText);
}else {
let fn = node.getAttribute("fn");
if (this.winObj != null) {
this.winObj.applyReq(this, fn, node, xmldoc, this.winObj);
return null;
}
}
}else{
let obj = JSON.parse(xmlHttpRequest.responseText);
if(obj==null) {
alert2(trt('Alert'), trt('Wrong_JSON_document') + "!\nJSON=(" + xmlHttpRequest.responseText + ')');
return;
}
if(this.winObj!=null)
{
this.winObj.applyReq(this,obj.fn,obj,null,this.winObj);
return null;
}
}
}else
{
if(confirm(trt('Failed_to_get_data')+"\n URL: "+url+"\n"+xmlHttpRequest.statusText+trt('Repeat_request')+'?'))
{
this.callServer(url,xmlString);
};
}
return null;
}
/*processReqChange(xmlHttpRequest,url,xmlString)
{
//if (typeof(xmlHttpRequest.readyState)=='undefined' || xmlHttpRequest.readyState == 4)
//{
if(typeof(xmlHttpRequest.status)=='undefined' || xmlHttpRequest.status == 200)
{
if(typeof(xmlHttpRequest.responseXML)=='undefined' && xmlHttpRequest.contentType.match(/\/xml/)) //For IE XDomainRequest
xmlHttpRequest.responseXML=CreateXMLDOC(xmlHttpRequest.responseText);
//загрузился xml документ начинаем его разбирать (по id функции в документе)
let xmldoc = xmlHttpRequest.responseXML;
if(xmldoc==null){
alert2(trt('Alert'),trt('Wrong_XML_document')+"!\nXML=("+xmlHttpRequest.responseText+')\nURL=('+url+')\nxmlString=('+xmlString+')');
return;
}
let node = xmldoc.documentElement;
if((node==null)||(node.getAttribute("fn")==null)) alert(trt('Error')+"\n"+trt('No_data')+"!\n"+xmlHttpRequest.responseText);
else
{
//alert("XML=\n"+getXMLNodeSerialisation(node));
let fn = node.getAttribute("fn");
if(this.winObj!=null)
{
//this.winObj.alert("Принятый браузером XML=\n"+getXMLNodeSerialisation(node));
/* каждый слушатель должен сам реализовать
* if (fn==-1)
alert(JSON.stringify(xmlHttpRequest));
if(typeof(xmlHttpRequest.responseXML)=='undefined') {
if(xmlHttpRequest.contentType.match(/\/xml/)) {
xmlHttpRequest.responseXML = CreateXMLDOC(xmlHttpRequest.responseText);
if(xmlHttpRequest.responseXML==null) {
alert2(trt('Alert'), trt('Wrong_XML_document') + "!\nXML=(" + xmlHttpRequest.responseText + ')\nURL=(' + url + ')\nxmlString=(' + xmlString + ')');
return;
}
//загрузился xml документ начинаем его разбирать (по id функции в документе)
let node = xmlHttpRequest.responseXML.documentElement;
if((node==null)||(node.getAttribute("fn")==null)) alert(trt('Error')+"\n"+trt('No_data')+"!\n"+xmlHttpRequest.responseText);
else
{
alert(findFirstNode(node,'#cdata-section').nodeValue);
}else*/
this.winObj.applyReq(this,fn,node,xmldoc,this.winObj);
return null;
}else if(fn==0) alert(findFirstNode(node,'#cdata-section').nodeValue);
let fn = node.getAttribute("fn");
if(this.winObj!=null)
{
this.winObj.applyReq(this,fn,node,xmldoc,this.winObj);
return null;
}else if(fn==0) alert(findFirstNode(node,'#cdata-section').nodeValue);
}
}else if(xmlHttpRequest.contentType.match(/\/json/)){
xmlHttpRequest.responseXML = JSON.parse(xmlHttpRequest.responseText);
if(xmlHttpRequest.responseXML==null) {
alert2(trt('Alert'), trt('Wrong_JSON_document') + "!\nJSON=(" + xmlHttpRequest.responseText + ')\nURL=(' + url + ')\njsonString=(' + xmlString + ')');
return;
}
//загрузился xml документ начинаем его разбирать (по id функции в документе)
let node=xmlHttpRequest.responseXML;
if((node==null)||(node.fn==null)) alert(trt('Error')+"\n"+trt('No_data')+"!\n"+xmlHttpRequest.responseText);
else
{
if(this.winObj!=null)
{
this.winObj.applyReq(this,node.fn,node,null,this.winObj);
return null;
}else if(fn==0) alert(findFirstNode(node,'#cdata-section').nodeValue);
}
}
}
}else
{
if(confirm(trt('Failed_to_get_data')+"\n URL: "+url+"\n"+xmlHttpRequest.statusText+"\nПовторить запрос?"))
@ -1099,7 +1217,7 @@ class TRequest
}
//}
return null;
}
}*/
};
/** Класс асинхронных запросов к серверу