Files
Metadata_PHP/metadata/dbms/editrecord.js

1566 lines
55 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//Copyright (C) 2008 Ivanov I.M. irigm@mail.ru +77051809750
//For find non english chars: [^\x00-\x7F]+
//Заглушки
function setPropVal(uid,id,c,p){
ERec_mas[uid].setPropVal(id,c,p);
}
var ERec_mas = new Array(); //List of all ERec objects (TODO then you better come up with something).
class EdtRec
{
constructor(caption)
{
this.uid=getUID();
this.win=new TWin();
this.win.BuildGUI(pageX-10,pageY-10);
this.win.setSize("500px","150px");
this.win.setContent('<div id="eDiv'+this.uid+'" style="width: 100%; /*height: 100%;*/ position: relative;"></div>');
let eDiv=document.getElementById('eDiv'+this.uid);
eDiv.innerHTML = '<table width="100%" height="100%"><tr><td style="vertical-align:middle;" bgcolor="#F1F1F1"><center><IMG src="../resources/metadata/dbms/images/loading.gif"></center></td></tr></table>'
if(caption!='')
this.win.setCaption(document.createTextNode(caption));
this.win.obj=this;
this.win.hide(false);
this.name="name"+this.uid;
this.opener=null; //Link to ShowRecord if it is opened from it.
this.nodeMetadata=null;
this.pBarCnt=0; //Progress Bar
this.pBarDiv=null; //Progress Bar
this.request = new TRequest(this);
//this.fields = new Array();
ERec_mas[this.uid]=this;
this.f_TypeName=""; //Имя редактируемого объекта (type->n attribute)
}
//Show progress bar
showProgressBar()
{
this.pBarCnt++;
if(this.pBarDiv==null)
{
this.pBarDiv=document.createElement('div');
this.pBarDiv.style.cssText='position: absolute; left: 0px; top: 0px; z-index: 1; background-color: rgba(0,0,0,0.5); width:100%; height: 100%;';
this.pBarDiv.innerHTML='<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" style="vertical-align: middle;"><img src="../resources/metadata/dbms/images/loading.gif" alt=""></td></tr></table>';
let eDiv=document.getElementById('eDiv'+this.uid);
eDiv.appendChild(this.pBarDiv);
}
};
//Hide progress bar
hideProgressBar()
{
this.pBarCnt--;
if(this.pBarCnt<=0)
{
if(this.pBarDiv!==null) deleteHTML(this.pBarDiv);
this.pBarCnt=0;
this.pBarDiv=null;
}
};
//Функция для создания или редактирования новой записи (аналог callData)
//Если id = -1 то это создание новой записи
eRecNa(typeName,id,settings)
{
this.f_TypeName=typeName;
this.f_Settings=settings;
this.record_id=id;
if(this.request.callServer(ScriptName,'<?xml version="1.0" encoding="utf-8"?><metadata fn="0"><type n="'+typeName+'"></type></metadata>'))
{
this.showProgressBar();
}
};
//Задать CDATA значение для узла "type->properties->prop" по "n"
setPropCdata(name,value)
{
let nodeProperties=findNodeOnPath(this.nodeMetadata, 'type/properties');
let nodeProp=nodeProperties.firstChild;
while(nodeProp!=null)
{
if(nodeProp.nodeName=="prop")
{
if(nodeProp.getAttribute("n")==name)
{
getCdata(nodeProp).nodeValue=value;
}
}
nodeProp=nodeProp.nextSibling;
}
}
//Apply the settings to the current node "type-> n" must match.
setXMLSettings(xml)
{
//Apply the parameters to the current XML filter if there are filter settings in the parent window!
if(xml===null || typeof(xml) == "undefined") return;
if(typeof(xml) == "string"){
if(xml!="")
{
applyNodeToNode(findFirstNodeOnAttribute(CreateXMLDOC(xml), "type", "n", this.f_TypeName), findFirstNodeOnAttribute(this.nodeMetadata, "type", "n", this.f_TypeName), "n");
}
}else
if(typeof(xml) == "object"){
if(xml.getAttribute("n")==this.f_TypeName)
{
applyNodeToNode(xml, findFirstNodeOnAttribute(this.nodeMetadata, "type", "n", this.f_TypeName), "n");
}
}
};
// Create a user GUI from XML ()
// Node - Node "type"
eRecNo(Node,record_id)
{
this.record_id=record_id;
this.nodeMetadata=Node.cloneNode(true); //Для чего клонирую?
var nodeType=findFirstNode(this.nodeMetadata, 'type');
//Appending settings to nodeMetadata
this.setXMLSettings(this.f_Settings);
//Записываю record_id в соответствующее XML поле
this.setPropCdata(nodeType.getAttribute("ObjectID"),record_id);
let str='';
str+=' <table class="SEdit" id="eTable'+this.uid+'" border="0px" cellspacing="1" cellpadding="1" style="width: 100%; height: 100%;">';
str+=' <caption><b id="caption'+this.uid+'"></b></caption>';
str+=' <thead>';
str+=' <tr bgcolor="#dadada">';
str+=' <th width="20%">'+trt('Name')+'</th>';
str+=' <th width="80%">'+trt('Value')+'</th>';
str+=' </tr>';
str+=' </thead>';
str+=' <tbody></tbody>';
str+=' </table>';
document.getElementById('eDiv'+this.uid).innerHTML=str;
//this.win.setContent(str);
//document.getElementById('menu').parentNode.appendChild( this.win.div )
var eTable=document.getElementById('eTable'+this.uid);
var type_name=nodeType.getAttribute("n");
//document.getElementById('caption'+this.uid).appendChild(document.createTextNode(nodeType.getAttribute("d")));
this.win.setCaption(document.createTextNode(nodeType.getAttribute("d")));
var nodeProperties=findNodeOnPath(this.nodeMetadata, 'type/properties');
this.win.setWidth(nodeProperties.getAttribute("width"));
var nodeFilters=findNodeOnPath(Node,'type/objects-list/filter');
var nodeProp=null;
//For convenience, when adding a new record, we rewrite the values from the parent filter in the edit field.
if(nodeFilters!=null)
{
var nodeFilter=nodeFilters.firstChild;
while (nodeFilter!=null)
{
if(nodeFilter.nodeName=="column")
{
nodeProp=nodeProperties.firstChild;
while(nodeProp!=null)
{
if(nodeProp.nodeName=="prop")
{
if (nodeFilter.getAttribute("n")==nodeProp.getAttribute("n"))
{
var cdata1=findFirstNode(nodeFilter,'#cdata-section');
if((cdata1!=null)&&(cdata1.nodeValue!=""))
{
var cdata2=findFirstNode(nodeProp,'#cdata-section');
if (cdata2==null)
{
cdata2 = nodeProp.ownerDocument.createCDATASection("");
nodeProp.appendChild(cdata2);
}
cdata2.nodeValue=cdata1.nodeValue;
}
}
}
nodeProp=nodeProp.nextSibling;
}
}
nodeFilter=nodeFilter.nextSibling;
}
}
nodeProp=nodeProperties.firstChild;
var newRowM=null;
var rpos=0;
while (nodeProp!=null)
{
if (nodeProp.nodeName=="type") //Grouping fields.
{
var tr = document.createElement('tr');
tr.setAttribute("bgColor",'#E0E0E0');
var td = document.createElement('td');
td.style.cssText="font-weight: bold;";
td.colSpan = "2";
var div=document.createElement('div');
div.style.cssText='border: solid 1px black; background-color: rgba(0,0,0,0.5); width:100%; height: 300px;';
div.innerHTML='';
td.appendChild(div);
tr.appendChild(td);
eTable.tBodies[0].appendChild(tr);
var subSRec=new SRec();
subSRec.create(div);
//Перебираю данные из текущего запроса и пытаюсь подменить строку (до получения анных (при создании новой записи))
var nPs=findFirstNode(this.nodeMetadata, 'properties')
var nP=nPs.firstChild
while (nP!=null)
{
if (nP.nodeName=="prop")
{
replaseTextInCDATA(nodeProp,"${"+nP.getAttribute("n")+"}",getCdataValue(nP));
}
nP=nP.nextSibling;
}
subSRec.f_Settings=nodeProp;
subSRec.f_State='0';
if(subSRec.request.callServer(ScriptName,'<?xml version="1.0" encoding="utf-8"?><metadata fn="0"><type n="'+nodeProp.getAttribute("n")+'"></type></metadata>'))
{
//obj.showProgressBar();
}
}else
if (nodeProp.nodeName=="divide") //Grouping fields.
{
var tr = document.createElement('tr');
tr.setAttribute("bgColor",'#E0E0E0');
var td = document.createElement('td');
td.style.cssText="font-weight: bold;";
td.colSpan = "2";
td.appendChild(document.createTextNode(nodeProp.getAttribute("d")));
tr.appendChild(td);
eTable.tBodies[0].appendChild(tr);
}else
if (nodeProp.nodeName=="prop")
{
var bgColor='';
var tr = null;
var td1 = null;
var td2 = null;
var row=nodeProp.getAttribute("row"); //Several fields in the 1st row.
if(row==null)
{
rpos++;
tr = document.createElement('tr');
if (rpos%2==0) bgColor=g_rowColor1; else bgColor=g_rowColor2;
tr.setAttribute("bgColor",bgColor);
if(nodeProp.getAttribute("visible")=='0') tr.style.display='none';
var td1 = document.createElement('td');
var td2 = document.createElement('td');
tr.appendChild(td1);
tr.appendChild(td2);
var table=document.createElement('table');
table.border=0;
table.setAttribute("width","100%");
table.cellspacing=0;
table.cellpadding=0;
td2.appendChild(table);
newRowM=table.insertRow(0);
td2 = newRowM.insertCell(-1);
td2.setAttribute("width","40%");
eTable.tBodies[0].appendChild(tr);
}else
{
td1 = newRowM.insertCell(-1);
td1.style.cssText="width: 10%;white-space:nowrap;";
td2 = newRowM.insertCell(-1);
td2.setAttribute("width","50%");
//td2.style.width=row+"px";
}
td1.appendChild(document.createTextNode(nodeProp.getAttribute("d")));
if(nodeProp.getAttribute("t")!=null) td1.title=nodeProp.getAttribute("t");
if (nodeProp.getAttribute("maybenull")=='0') td1.style.cssText="font-weight: bold;";
var value=getCdata(nodeProp).nodeValue;
var vt=nodeProp.getAttribute("vt");
if(vt=="string" || vt=="str")
{
var table=document.createElement('table');
table.style.cssText="width:100%;border-spacing:0;border-collapse:collapse;";
table.border=0;
let newRow=table.insertRow(0); //add a row to the created table
var newCell1 = newRow.insertCell(0); //in the created line we add a column
newCell1.style.cssText="padding:0px; padding-right:1px; width: 100%;";
var newCell2 = newRow.insertCell(1); //in the created line we add a column
newCell2.style.cssText="padding:0px;";
//If there is a list node with CheckBox elements, then we create them
var nList=findNode(nodeProp, "options");
if(nList!=null)
{
nodeProp.field = new TCheckboxListField(nodeProp.getAttribute("n"));
let nCheckbox = nList.firstChild;
while (nCheckbox!=null) {
if(nCheckbox.nodeName=="option") {
nodeProp.field.addCheckbox(nCheckbox.getAttribute("n"), nCheckbox.getAttribute("d"));
}
nCheckbox = nCheckbox.nextSibling;
}
newCell1.appendChild(nodeProp.field.getDiv());
}else
{
input = document.createElement('input');
input.setAttribute("type","text");
input.style.cssText="width: 100%;overflow:hidden;";
input.setAttribute("name",nodeProp.getAttribute("n"));
if(nodeProp.getAttribute("size")!=null)
input.setAttribute("maxlength",nodeProp.getAttribute("size"),0);
input.setAttribute("value",value);
input.setAttribute("id","prop_"+this.uid+"_"+nodeProp.getAttribute("n"));
newCell1.appendChild( input );
//td2.appendChild( input );
//Button for translation
var tObj=findNode(nodeProp, "type");
if(tObj!=null)
{
let button = document.createElement('input');
button.className='button-secondary';
button.setAttribute("type","button");
button.setAttribute("value","...");
button.style.cssText="width:30px;font-size:9pt;margin:0px;padding:0px;";
button.onclick=function(thiz,nodeProp){ return function(){
thiz.callWindow(nodeProp);
};}(this,nodeProp);
newCell2.appendChild( button );
}
}
td2.appendChild( table );
}else
if(vt=="password")
{
input = document.createElement('input');
input.style.cssText="width: 100%;";
input.setAttribute("type","password");
input.setAttribute("name",nodeProp.getAttribute("n"));
input.setAttribute("value",value);
input.setAttribute("id","prop_"+this.uid+"_"+nodeProp.getAttribute("n"));
td2.appendChild( input );
}else
if(vt=="b")
{
var select = document.createElement('select');
select.style.cssText="width: 100%;";
select.setAttribute("name",nodeProp.getAttribute("n"));
var opt=findFirstNode(nodeProp,"options");
if(opt==null)
{
var option = document.createElement('option');
option.setAttribute("value","");
option.appendChild(document.createTextNode(""));
option.selected = true;
select.appendChild( option );
option = document.createElement("option");
option.setAttribute("value","1");
option.appendChild(document.createTextNode(trt('Yes')));
select.appendChild( option );
option = document.createElement("option");
option.setAttribute("value","0");
option.appendChild(document.createTextNode(trt('Not')));
select.appendChild( option );
}else
{
opt=opt.firstChild
while(opt!=null)
{
if(opt.nodeName=="option")
{
option = document.createElement("option");
option.setAttribute("value",opt.getAttribute("val"));
option.appendChild(document.createTextNode(opt.getAttribute("d")));
select.appendChild( option );
}
opt=opt.nextSibling;
}
}
select.setAttribute("id","prop_"+this.uid+"_"+nodeProp.getAttribute("n"));
td2.appendChild( select );
}else
if(vt=="i4")
{
//If there is a node "list" with the elements "CheckBox" then create them.
let opt=findNode(nodeProp, "options");
if(opt!=null) //If combobox
{
let select = document.createElement('select');
select.style.cssText="width: 100%;";
select.setAttribute("name",nodeProp.getAttribute("n"));
select.setAttribute("id","prop_"+this.uid+"_"+nodeProp.getAttribute("n"));
opt=opt.firstChild
while(opt!=null)
{
if(opt.nodeName=="option")
{
let option = document.createElement("option");
option.setAttribute("value",opt.getAttribute("val"));
option.appendChild(document.createTextNode(opt.getAttribute("d")));
select.appendChild( option );
}
opt=opt.nextSibling;
}
td2.appendChild( select );
}else
{
var table=document.createElement('table');
table.style.cssText="width:100%;border-spacing:0;border-collapse:collapse;";
//table.setAttribute("bgColor","#0000FF");
table.border=0;
let newRow=table.insertRow(0); //add a row to the created table
var newCell1 = newRow.insertCell(0); //in the created line we add a column
newCell1.style.cssText="padding:0px; padding-right:1px; width: 100%;";
var newCell2 = newRow.insertCell(1); //in the created line we add a column
newCell2.style.cssText="padding:0px; padding-right:1px;height:100%;";
var newCell3 = newRow.insertCell(2); //in the created line we add a column
newCell3.style.cssText="padding:0px;height:100%;";
input = document.createElement('input');
input.style.cssText="width: 100%; height:22px;";
input.setAttribute("type","text");
input.setAttribute("name",nodeProp.getAttribute("n"));
input.setAttribute("value",value);
input.setAttribute("id","prop_"+this.uid+"_"+nodeProp.getAttribute("n"));
newCell1.appendChild( input );
button = document.createElement('input');
button.className='button-secondary';
button.setAttribute("type","button");
button.setAttribute("value","+");
button.setAttribute("title",trt("Increase_by_1"));
button.style.cssText="height:100%;width:22px;margin:0px;padding:0px;";
button.onclick=function(inp){return function(){inp.value=getIntVal(inp.value)+1;}}(input);
newCell2.appendChild( button );
button = document.createElement('input');
button.className='button-secondary';
button.setAttribute("type","button");
button.setAttribute("value","-");
button.setAttribute("title",trt("Decrease_by_1"));
button.style.cssText="height:100%;width:22px;margin:0px;padding:0px;";
button.onclick=function(inp){return function(){inp.value=getIntVal(inp.value)-1;}}(input);
newCell3.appendChild( button );
td2.appendChild( table );
}
}else
if(vt=="f4")
{
input = document.createElement('input');
input.style.cssText="width: 100%;";
input.setAttribute("type","text");
input.setAttribute("name",nodeProp.getAttribute("n"));
input.setAttribute("value",value);
input.setAttribute("id","prop_"+this.uid+"_"+nodeProp.getAttribute("n"));
td2.appendChild( input );
}else
if(vt=="object")
{
var input=null;
//objpres = findFirstNode(nodeProp, 'object-presentation')
if(nodeProp.getAttribute("selector")=="combo")
{
var table=document.createElement('table');
table.style.cssText="width:100%;border-spacing:0;border-collapse:collapse;";
//table.setAttribute("bgColor","#0000FF");
table.border=0;
let newRow=table.insertRow(0); //add a row to the created table
var newCell1 = newRow.insertCell(0); //in the created line we add a column
newCell1.style.cssText="padding:0px;padding-right:1px;width:100%;";
var newCell2 = newRow.insertCell(1); //in the created line we add a column
newCell2.style.cssText="padding:0px;height:100%;";
select = document.createElement('select');
select.style.cssText="width: 100%; height:22px; line-height: 22px;";
select.setAttribute("name",nodeProp.getAttribute("n"));
//select.setAttribute("value",value) does not work because when creating no values in the list
select.setAttribute("id","prop_"+this.uid+"_"+nodeProp.getAttribute("n"));
select.onchange = function(thiz,node){ return function()
{
thiz.onComboObjectChangeHandler(node);
};}(this,nodeProp);
//td2.appendChild( select )
newCell1.appendChild(select);
//cmbInp.addEventListener(IndexChangeEvent.CHANGE,onComboObjectChangeHandler);
var button = document.createElement('input');
button.className='button-secondary';
button.setAttribute("type","button");
button.setAttribute("value","...");
button.style.cssText="width:30px;font-size:9pt;margin:0px;padding:0px;height:100%;";
button.onclick=function(thiz,val1,val2){return function(){thiz.SelectObjects(val1,val2);};}(this,nodeProp.getAttribute("ot"),nodeProp.getAttribute("n"));
newCell2.appendChild(button);
td2.appendChild( table );
//send a request for data (Only if creating a new record (if editing then requesting data only needs to come from the data itself because the data in the hung lists will receive data 2 times))
/*var nTypeF = findFirstNode(nodeProp, "type");
if(nTypeF != null) //Запрос с параметрами не можем отправить без подгрузки данных
{
//Add parameters to request
nTypeF.setAttribute("c",nodeProp.getAttribute("FieldCaption"));
nTypeF.setAttribute("pn",nodeProp.getAttribute("n"));
var strXMLF = getXMLNodeSerialisation(nTypeF);
var nColF=nodeProperties.firstChild;
while(nColF != null)
{
if(nColF.nodeName==="prop")
{
var valF=getCdataValue(nColF);
strXMLF=strXMLF.replace('${'+nColF.getAttribute('n')+'}', valF);
}
nColF = nColF.nextSibling;
}
strXMLF='<?xml version="1.0" encoding="utf-8"?><metadata fn="6">'+strXMLF+'</metadata>';
if(this.request.callServer(ScriptName,strXMLF,true))
{
this.showProgressBar();
}
}else
{
var xml='<?xml version="1.0" encoding="utf-8"?><metadata fn="6"><type n="'+nodeProp.getAttribute("ot")+'" c="'+nodeProp.getAttribute("FieldCaption")+'" pn="'+nodeProp.getAttribute("n")+'" fn="'+nodeProp.getAttribute("fn")+'"></type></metadata>';
if(this.request.callServer(ScriptName,xml,true));
{
this.showProgressBar();
}
}*/
}else
{
var table=document.createElement('table');
table.style.cssText="width:100%;border-spacing:0;border-collapse:collapse;";
//table.setAttribute("bgColor","#0000FF");
table.border=0;
let newRow=table.insertRow(0); //add a row to the created table
var newCell1 = newRow.insertCell(0); //in the created line we add a column
newCell1.style.cssText="padding:0px;width: 100%;";
var newCell2 = newRow.insertCell(1); //in the created line we add a column
newCell2.style.cssText="padding:0px;";
//two elements are placed in the table
input = document.createElement('input');
//After pressing "Enter" we pass the entered line to the server.
input.onkeydown=this.onCallFV(nodeProp.getAttribute("ot"),nodeProp.getAttribute("FieldCaption"),input,nodeProp.getAttribute("n"),nodeProp.getAttribute("fn"));
input.style.cssText="width: 100%; height:22px; line-height: 22px;";
input.setAttribute("type","text");
input.setAttribute("id","prop_"+this.uid+"_"+nodeProp.getAttribute("n")+"_visible");
input.setAttribute("value","");
newCell1.appendChild(input);
//The hidden field where the data is saved (you can make it stored in XML)_
let hidden = document.createElement('input');
hidden.setAttribute("type", "hidden");
hidden.setAttribute("id","prop_"+this.uid+"_"+nodeProp.getAttribute("n"));
hidden.value=value;
newCell1.appendChild(hidden);
var button = document.createElement('input');
button.className='button-secondary';
button.setAttribute("type","button");
button.setAttribute("value","...");
button.style.cssText="width:30px;font-size:9pt;margin:0px;padding:0px;";
button.onclick=function(thiz,val1,val2){return function(){thiz.SelectObjects(val1,val2);};}(this,nodeProp.getAttribute("ot"),nodeProp.getAttribute("n"));
newCell2.appendChild(button);
td2.appendChild( table );
//We request the field title by the field id (if it is filled).
/*if ((value!="")&&(value!=-1))
{
var xml='<?xml version="1.0" encoding="utf-8"?><metadata fn="6"><type n="'+nodeProp.getAttribute("ot")+'" c="'+nodeProp.getAttribute("FieldCaption")+'" pn="'+nodeProp.getAttribute("n")+'" fn="'+nodeProp.getAttribute("fn")+'" id="'+value+'">';
xml+='<objects-list><filter><column n="'+findFirstNode(this.nodeMetadata, 'type').getAttribute('ObjectID')+'"><![CDATA['+value+']]></column></filter></objects-list>';
xml+='</type></metadata>';
if(this.request.callServer(ScriptName,xml,true))
{
this.showProgressBar();
}
}*/
}
}else
if(vt=="text") {
let ta = document.createElement('textarea')
ta.setAttribute("id", "prop_" + this.uid + "_" + nodeProp.getAttribute("n"));
ta.style.cssText = "width: 100%;";
ta.setAttribute("rows", 4);
ta.setAttribute("name", nodeProp.getAttribute("n"));
ta.setAttribute("value", value);
td2.appendChild(ta);
}else
if(vt=="html"){
let ta = document.createElement('textarea')
ta.setAttribute("id", "prop_" + this.uid + "_" + nodeProp.getAttribute("n"));
ta.style.cssText = "width: 100%;";
ta.setAttribute("rows", 4);
ta.setAttribute("name", nodeProp.getAttribute("n"));
ta.setAttribute("value", value);
td2.appendChild(ta);
/*var cdv=document.createElement('div');
cdv.innerHTML+='<a href="javascript:;" onclick="return showTinyMCE(\'prop_'+this.uid+'_'+nodeProp.getAttribute("n")+'\');">[Show]</a>';
cdv.innerHTML+=' <a href="javascript:;" onclick="tinyMCE.get(\'prop_'+this.uid+'_'+nodeProp.getAttribute("n")+'\').hide(); return false;">[Hide]</a>';
td2.appendChild( cdv );*/
}else
if(vt=="blob" || vt=="file")
{
let ifr=createIFrame("prop_"+this.uid+"_"+nodeProp.getAttribute("n")+'_frm', ScriptUName+"?fn=9", td2, false); //IFrame to send the file to the server.
document.body.appendChild(ifr);
var tbl_b=document.createElement('table');
tbl_b.style.cssText="width:100%;border-spacing:0;border-collapse:collapse;";
//table.setAttribute("bgColor","#0000FF");
tbl_b.border=0;
let newRow=tbl_b.insertRow(0);
var newCell1 = newRow.insertCell(0);
newCell1.style.cssText="padding:0px;width: 100%;";
var newCell2 = newRow.insertCell(1);
newCell2.style.cssText="padding:0px;";
var newCell3 = newRow.insertCell(2);
newCell3.style.cssText="padding:0px;";
var newCell4 = newRow.insertCell(3);
newCell4.style.cssText="padding:0px;";
//Two elements are placed in the table
input = document.createElement('input');
//After pressing Enter we pass the entered line to the server
//input.onkeydown=this.onCallFV(nodeProp.getAttribute("ot"),nodeProp.getAttribute("FieldCaption"),input,nodeProp.getAttribute("n"),nodeProp.getAttribute("fn"))
input.style.cssText="width: 100%; color: #777777;";
input.setAttribute("type","text");
input.setAttribute('readonly','readonly');
input.setAttribute("id","prop_"+this.uid+"_"+nodeProp.getAttribute("n"));
//input.setAttribute("value","")
newCell1.appendChild(input);
//Button to send the file to the server
let btnSel = document.createElement('input');
btnSel.className='button-secondary';
btnSel.setAttribute("type","button");
btnSel.setAttribute("value","...");
btnSel.setAttribute("title",trt('Upload'));
btnSel.style.cssText="width:30px;font-size:9pt;margin:0px;padding:0px;";
newCell2.appendChild(btnSel);
let button2 = document.createElement('input');
button2.className='button-secondary';
button2.setAttribute("type","button");
button2.setAttribute("value","X");
button2.setAttribute("title",trt('Delete'));
button2.style.cssText="height:22px;width:22px;margin:0px;padding:0px;";
button2.onclick=function(inp,ifr){return function(){ inp.value=''; getIframeDocument(ifr).forms["form"].reset(); }}(input,ifr);
newCell3.appendChild(button2);
//Download button
newCell4.innerHTML='<form action="'+ScriptDName+'" method="get" style="display:inline;" target="_blank"><input type="hidden" name="fn" value="10"/><input type="hidden" name="n" value="'+nodeProp.getAttribute('cd')+'"/><input type="hidden" name="t" value="'+nodeType.getAttribute('n')+'"/><input type="hidden" name="f" value="'+nodeProp.getAttribute('n')+'"/><input type="hidden" name="i" value="'+record_id+'"/><input class="button-secondary" style="height:22px;width:22px;" type="submit" title="'+trt('Download')+'" value="D" /></form>'
td2.appendChild( tbl_b );
//Send file through iframe
ifr.onload=function(btn,inp,obj)
{
return function()
{ let doc=getIframeDocument(this);
btn.onclick=function(doc){return function(){doc.forms["form"].elements["file"].click()}}(doc) //Enable file selection by pressing
doc.forms["form"].elements["file"].onchange = function(inp) {return function(){inp.value=this.files[0].name;/*this.value;*/};}(inp);
if(BeforeFirst(doc.body.innerHTML,'=')=='ok')
{
var fName=BeforeFirst(AfterFirst(doc.body.innerHTML,'='),"\n");
inp.value=fName;//BeforeLast(inp.value,'.')+'_'+fName;
if(inp.value!='')
{ obj.sendData();
}
}
};
}(btnSel,input,this);
}else
if(vt=="date" || vt=="dateTime")
{
var table=document.createElement('table');
table.style.cssText="width:100%;border-spacing:0;border-collapse:collapse;";
//table.setAttribute("bgColor","#0000FF");
table.border=0;
let newRow=table.insertRow(0);
var newCell1 = newRow.insertCell(0);
newCell1.style.cssText="padding:0px;width: 100%;";
var newCell2 = newRow.insertCell(1);
newCell2.style.cssText="padding:0px;";
input = document.createElement('input');
input.style.cssText="width: 100%;";
input.setAttribute("type","text");
input.setAttribute("name",nodeProp.getAttribute("n"));
input.setAttribute("value",value);
input.setAttribute("id","prop_"+this.uid+"_"+nodeProp.getAttribute("n"));
newCell1.appendChild( input );
var img = document.createElement('img');
img.src='../resources/metadata/dbms/images/datepicker.jpg';
img.style.cssText="cursor: pointer;";
newCell2.appendChild(img);
td2.appendChild( table );
if(vt=="date")
new Calendar({
inputField: input,
dateFormat: "%Y-%m-%d",
trigger: img,
align: "Tl",
bottomBar: false,
showTime: false,
onSelect: function() {
this.hide();
}
});
if(vt=="dateTime")
new Calendar({
inputField: input,
dateFormat: "%Y-%m-%d %H:%M:%S",
trigger: img,
align: "Tl",
bottomBar: false,
showTime: true,
onSelect: function() {
this.hide();
}
});
}else
{
input = document.createElement('input');
input.style.cssText="width: 100%;";
input.setAttribute("type","text");
input.setAttribute("name",nodeProp.getAttribute("n"));
input.setAttribute("value",value);
input.setAttribute("id","prop_"+this.uid+"_"+nodeProp.getAttribute("n"));
td2.appendChild( input );
}
}
nodeProp=nodeProp.nextSibling;
}
//Button apply
tr = document.createElement('tr');
var td = document.createElement('td');
td.style.cssText="padding: 5px; vertical-align: bottom;";
td.setAttribute("colspan", "2");
if (this.record_id==-1) td.innerHTML='<label style="float: left; white-space: nowrap;"><input id="readd_'+this.uid+'" type="checkbox"> '+trt('Repeat_the_addition_of_the_entry')+'</label>';
tr.appendChild(td);
//var td = document.createElement('td');
td.setAttribute("align","right");
button = document.createElement('input');
button.className='button-secondary';
button.setAttribute("type","button");
button.style.cssText="margin:0px;margin-right:1px;";
button.setAttribute("value",trt('Apply'));
button.onclick=()=>this.sendData();
td.appendChild( button );
button = document.createElement('input'); //Button cancel
button.setAttribute("type","button");
button.className='button-secondary';
button.style.cssText="margin:0px;";
button.setAttribute("value",trt('Cancel'));
//button.onclick=function f_exit(this) { alert2(trt('Alert'),this.win.div); }
button.onclick=()=>this.win.Close();
td.appendChild( button );
tr.appendChild(td);
eTable.tBodies[0].appendChild(tr);
//Height adjust the height of the page
//this.win.div.style.width="400px"
//this.win.div.style.height="100px"
//alert2(trt('Alert'),document.documentElement.scrollTop)
//alert2(trt('Alert'),document.documentElement.clientHeight)
this.win.setHeight(eTable.offsetHeight+40); //this.win.div.style.height=(eTable.offsetHeight+40)+"px";
//alert2(trt('Alert'),this.win.div.style.width)
//alert2(trt('Alert'),this.win.div.style.height)
this.win.setCenter();
//this.win.div.style.left=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-parseInt(this.win.div.style.width))/2)+"px"
//this.win.div.style.top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-parseInt(this.win.div.style.height))/2)+"px"
//Initialization
if (this.record_id<0)
{
this.callDataSelect();
this.fillGUIFromXML();
}else
{
if(this.request.callServer(ScriptName,'<?xml version="1.0" encoding="utf-8"?><metadata fn="5"><type id="'+this.record_id+'" n="'+type_name+'" ObjectID="'+nodeType.getAttribute("ObjectID")+'"></type></metadata>',true))
{
this.showProgressBar();
}
}
};
//The event occurs when you change the list of the referenced to "vt = Object" and if there is a dependency, then the field is updated.
onComboObjectChangeHandler(node)
{
//I go through the fields and if there is a configurable query, I re-query the data
var nodeType=findFirstNode(this.nodeMetadata, "type");
var nodeProperties=findNodeOnPath(this.nodeMetadata, 'type/properties');
if(nodeProperties!=null) //Creating HTML elements by XML filter
{
let nodeProp=nodeProperties.firstChild;
while (nodeProp != null)
{
if (nodeProp.nodeName==="prop")
{
var nTypeF = findFirstNode(nodeProp, "type");
if(nTypeF != null)
{
//Add parameters to request
nTypeF.setAttribute("c",nodeProp.getAttribute("FieldCaption"));
nTypeF.setAttribute("pn",nodeProp.getAttribute("n"));
var strXMLF = getXMLNodeSerialisation(nTypeF);
if(strXMLF.indexOf('${'+node.getAttribute('n')+'}')!=-1) //If it does not participate then it does not react to the change
{
var nColF=nodeProperties.firstChild;
while(nColF != null)
{
if(nColF.nodeName==="prop")
{
var elm=document.getElementById('prop_'+this.uid+'_'+nColF.getAttribute("n"));
if(elm!=null)
{
var valF=elm.value;
strXMLF=strXMLF.replace('${'+nColF.getAttribute('n')+'}', valF);
}
}
nColF = nColF.nextSibling;
}
//Сохраняю новое значение в XML так как оно не сохранится после пересоздания выпадающего списка
let option=document.getElementById("prop_"+this.uid+"_"+node.getAttribute("n"));
setCdataValue(node,0,option.value);
strXMLF='<?xml version="1.0" encoding="utf-8"?><metadata fn="6">'+strXMLF+'</metadata>';
if(this.request.callServer(ScriptName,strXMLF,true))
{
this.showProgressBar();
}
}
}
}
nodeProp = nodeProp.nextSibling;
}
}
}
//Request data to fill the "Object" field.
//The result can fill the filter field with complete information or display a window with a further selection of the value.
selObj(typeName,propname)
{
let win=new TWin();
win.BuildGUI(pageX-10,pageY-10);
let str=`
<table id="thetable`+win+`" bgcolor="SlateGrey" style="border: 1px solid rgb(99, 99, 99);" width="100%">
<caption></caption>
<thead><tr><th></th></tr></thead>
<tbody><tr><td></td></tr></tbody>
</table>`;
win.setContent(str);
};
//request data to fill the Object Filter
//The result can fill the filter field with complete information or a window with a further choice of the value
SelectObjects(typeName,propname)
{
let rec=new SRec();
rec.opener=this;
rec.create();
rec.f_State=1;
rec.f_PropName=propname;
rec.f_TypeName=typeName;
rec.win.setLeftTop(pageX-250,pageY-10);
rec.win.setParent(this.win);
rec.callData(rec.f_TypeName,"");
/*if(rec.request.callServer(ScriptName,'<?xml version="1.0" encoding="utf-8"?><metadata fn="0"><type n="'+rec.f_TypeName+'"></type></metadata>'))
{
rec.showProgressBar();
}*/
}
//Call the ShowRecord.html window with the parameters for the filter (not just the object name).
callWindow(nodeProp)
{
let xmlString="";
let TypeName="";
let nT=findNode(nodeProp, "type");
if(nT!=null)
{
xmlString=getXMLNodeSerialisation(nT);
TypeName = nT.getAttribute("n");
}else
{
TypeName=nodeProp.getAttribute("ot");
}
//Write to XML string from GUI
while(true)
{
let sub1=BeforeFirst(xmlString,"${");
if(sub1==null) break;
let sub2=AfterFirst(xmlString,"}");
if(sub2==null) break;
let val=BeforeFirst(AfterFirst(xmlString,"${"),"}");
let obj=document.getElementById("prop_"+this.uid+"_"+val);
if(obj!=null){
xmlString=sub1+obj.value+sub2;
}else{
xmlString=sub1+sub2;
}
}
let rec=new SRec();
rec.create();
rec.f_Settings=xmlString;
rec.f_TypeName=TypeName;
rec.win.setLeftTop(pageX-250,pageY-10);
rec.win.setParent(this.win);
if(rec.request.callServer(ScriptName,'<?xml version="1.0" encoding="utf-8"?><metadata fn="0"><type n="'+TypeName+'"></type></metadata>'))
{
rec.showProgressBar();
}
};
//Запросить данные для выпадающих списков и других объектов (только после загрузки данных полей)
callDataSelect()
{
let nodeProperties=findNodeOnPath(this.nodeMetadata, 'type/properties');
let nodeProp=nodeProperties.firstChild;
while(nodeProp!=null)
{
if(nodeProp.nodeName=="prop")
{
if(nodeProp.getAttribute("vt")=="object")
{
if(nodeProp.getAttribute("selector")=="combo")
{
var nTypeF = findFirstNode(nodeProp, "type");
if(nTypeF != null) //Запрос с параметрами не можем отправить без подгрузки данных
{
//Add parameters to request
nTypeF.setAttribute("c",nodeProp.getAttribute("FieldCaption"));
nTypeF.setAttribute("pn",nodeProp.getAttribute("n"));
var strXMLF = getXMLNodeSerialisation(nTypeF);
var nColF=nodeProperties.firstChild;
while(nColF != null)
{
if(nColF.nodeName==="prop")
{
var valF=getCdataValue(nColF);
strXMLF=strXMLF.replace('${'+nColF.getAttribute('n')+'}', valF);
}
nColF = nColF.nextSibling;
}
strXMLF='<?xml version="1.0" encoding="utf-8"?><metadata fn="6">'+strXMLF+'</metadata>';
if(this.request.callServer(ScriptName,strXMLF,true))
{
this.showProgressBar();
}
}else
{
var xml='<?xml version="1.0" encoding="utf-8"?><metadata fn="6"><type n="'+nodeProp.getAttribute("ot")+'" c="'+nodeProp.getAttribute("FieldCaption")+'" pn="'+nodeProp.getAttribute("n")+'" fn="'+nodeProp.getAttribute("fn")+'"></type></metadata>';
if(this.request.callServer(ScriptName,xml,true));
{
this.showProgressBar();
}
}
}else
{
//We request the field title by the field id (if it is filled).
/*if ((value!="")&&(value!=-1))
{
var xml='<?xml version="1.0" encoding="utf-8"?><metadata fn="6"><type n="'+nodeProp.getAttribute("ot")+'" c="'+nodeProp.getAttribute("FieldCaption")+'" pn="'+nodeProp.getAttribute("n")+'" fn="'+nodeProp.getAttribute("fn")+'" id="'+value+'">';
xml+='<objects-list><filter><column n="'+findFirstNode(this.nodeMetadata, 'type').getAttribute('ObjectID')+'"><![CDATA['+value+']]></column></filter></objects-list>';
xml+='</type></metadata>';
if(this.request.callServer(ScriptName,xml,true))
{
this.showProgressBar();
}
}*/
}
}
}
nodeProp=nodeProp.nextSibling;
}
}
//Function to populate the drop-down lists
setDataSelect(node)
{
let prop_name,prop,option,nodeProp,id,value,cdataNode;
let nodeType=findFirstNode(node, 'type');
prop_name=nodeType.getAttribute("pn"); //field name
prop=document.getElementById("prop_"+this.uid+"_"+prop_name);
let selector=null; //find what kind of object object
let nodeFilter=findFirstNode(this.nodeMetadata, 'properties');
let nodeCur=nodeFilter.firstChild;
while(nodeCur!=null)
{
if((nodeCur.nodeName=="prop")&&(nodeCur.getAttribute("n")==prop_name))
{
selector=nodeCur.getAttribute("selector");
}
nodeCur=nodeCur.nextSibling;
}
if(selector=="combo") //if the drop-down list
{
prop.innerHTML = ""; //Закоментил потому что нужно именно обновлять а то выборка слетит при выборе....
//in the full can be that the list has arrived after the arrival of all data and therefore the drop-down list must be set to the desired value here
//select the value for this list
let val=null;
let nodeProperties=findFirstNode(this.nodeMetadata, 'properties');
nodeProp=nodeProperties.firstChild;
while(nodeProp!=null)
{
if((nodeProp.nodeName=="prop")&&(nodeProp.getAttribute("n")==prop_name))
{
val=getCdataValue(nodeProp);
break;
}
nodeProp=nodeProp.nextSibling;
}
//console.log('Значение в XML '+prop_name+'='+val);
//The first line in the select as NULL value = 1
option = document.createElement('option');
option.setAttribute("value","");
option.appendChild( document.createTextNode(""));
option.selected = true;
if(prop!=null)
{
prop.appendChild( option );
nodeProp=nodeType.firstChild;
while (nodeProp!=null)
{
if (nodeProp.nodeName=="record")
{
id=nodeProp.getAttribute("id");
let caption="";
cdataNode = nodeProp.firstChild;
while (cdataNode!=null)
{
if (cdataNode.nodeName=="#cdata-section")
{
caption+=cdataNode.nodeValue+" ";
//break;
}
cdataNode = cdataNode.nextSibling
}
option = document.createElement('option');
//option.style.color="graytext"
option.setAttribute("value",id);
option.appendChild(document.createTextNode(caption));
//console.log('id='+id+' val='+val);
if (id==val) option.selected=true;
prop.appendChild( option );
}
nodeProp=nodeProp.nextSibling;
}
prop.style.cssText="width: 100%;" //Fuck IE
}
}else //if the field with the button
{
//count the number of values
var count=0;
nodeProp=nodeType.firstChild;
while (nodeProp!=null)
{
if (nodeProp.nodeName=="record") count++;
nodeProp=nodeProp.nextSibling;
}
if(count==0) alert2(trt('Alert'),trt("No_results_were_found_for_your_search"));
else
if(count==1) //1 item has been selected, fill in the field.
{
nodeProp=findFirstNode(nodeType, 'record');
id=nodeProp.getAttribute("id");
value=findNode(nodeProp, '#cdata-section').nodeValue;
prop.value=id;
var propvis=document.getElementById("prop_"+this.uid+"_"+prop_name+"_visible");
propvis.value=value;
propvis.select();
}else
if(count>1) //Display the item selection window.
{
var htmlString='<table width="100%" bgcolor="whitesmoke">';
nodeProp=nodeType.firstChild;
var i=0;
while (nodeProp!=null)
{
if (nodeProp.nodeName=="record")
{
var bgColor='whitesmoke';
if (i%2==0) bgColor='white';
id=nodeProp.getAttribute("id");
value=findNode(nodeProp, '#cdata-section').nodeValue;
value=value.replace(/"/g, "&quot;");
value=value.replace(/'/g, "\\'");
value=value.replace(/\n/g, " ");
htmlString+='<tr><td bgColor="'+bgColor+'" onClick="setPropVal('+this.uid+',\''+id+'\',\''+value+'\',\''+prop_name+'\');" style="cursor: pointer;">'+findFirstNode(nodeProp, '#cdata-section').nodeValue+'</td></tr>'+"\n";
i++;
}
nodeProp=nodeProp.nextSibling;
}
htmlString+='</table>';
var win=new TWin();
win.BuildGUI(pageX-280,pageY-7);
win.setContent(htmlString);
win.setCaption(document.createTextNode(trt("Selection")));
win.setParent(this.win);
//win.obj=this
}
}
};
applyReq(req,fn,node,xmldoc,win)
{ //alert2(trt('Alert'),"erec XML=\n"+getXMLNodeSerialisation(node));
if (fn==-1)
{
alert2(trt('Alert'),findFirstNode(node,'#cdata-section').nodeValue);
//this.pBarCnt=0;
this.hideProgressBar();
}else
if (fn==0)
{
this.hideProgressBar();
this.eRecNo(node,this.record_id);
}else
if (fn==1) //returned id
{
this.hideProgressBar();
this.insertRows(node);
}else
if (fn==2) //Returned id and type of updated record
{
this.hideProgressBar();
this.updateRows(node);
}else
if (fn==3) //Returned id of deleted record
{
this.hideProgressBar();
this.deleteRows(node);
}else
if (fn==5)
{
this.hideProgressBar();
this.setData(node);
}else
if (fn==6) //Fill in the drop-down lists.
{
this.hideProgressBar();
this.setDataSelect(node);
}else
if (fn==7) //
{
this.hideProgressBar();
this.setData(node);
}else
{
alert2(trt('Alert'),"Unknown function! fn=\""+fn+"\"" );
this.hideProgressBar();
}
};
//Request data to fill in the field with the button
setFilterObject(TypeName,prop_id,id)
{
var node=findFirstNodeOnAttribute(this.nodeMetadata,'prop','n',prop_id);
if(node!==null)
{
var name=node.getAttribute("FieldCaption");
findNode(node,'#cdata-section').nodeValue=id;
//We request data from the server to fill in the comments on the id of the record.
var prop=document.getElementById("filter_"+prop_id);
if(prop!==null) prop.value=id;
//Request a comment on the record id from the server
var xml='<?xml version="1.0" encoding="utf-8"?><metadata fn="6"><type n="'+TypeName+'" c="'+name+'" pn="'+prop_id+'" fn="'+name+'">';
xml+='<objects-list><filter><column n="id"><![CDATA['+id+']]></column></filter></objects-list>';
xml+='</type></metadata>';
if(this.request.callServer(ScriptName,xml,true))
{
this.showProgressBar();
}
}else
{
alert2(trt('Alert'),'Field "'+prop_id+'" not find!');
}
};
//We request from the server a list of values almost as for a drop-down list
//typeName - Object name
//name - The name of the column for selecting values (must match the name of any filter in typeName)
//value - Filter value text box
//htmlid - The name of the field in the filter n
//filterName - filter name
callFilterVal(typeName,name,value,htmlid,filterName)
{
//alert2(trt('Alert')," typeName="+typeName+" name="+name+" value="+value+" htmlid="+htmlid);
if(value!="")
{
var xml='<?xml version="1.0" encoding="utf-8"?><metadata fn="6"><type n="'+typeName+'" c="'+name+'" pn="'+htmlid+'"><objects-list><filter>';
xml+='<column n="'+filterName+'"><![CDATA['+value+']]></column>';
xml+='</filter></objects-list></type></metadata>';
if(this.request.callServer(ScriptName,xml,true))
{
this.showProgressBar();
}
}
};
onCallFV(typeName,name,value,htmlid,filterName)
{
var win=this
return function(e){
if(e==null) e=window.event;
if(e.keyCode==13){
win.callFilterVal(typeName,name,value.value,htmlid,filterName);
return false;
}
}
};
//Fill the Metadata XML node with the XML values from the received XML node
setData(node)
{
if(typeof(node) != "undefined" && node!=null)
{
var nProps1=findFirstNode(node, 'properties')
var nProps2=findFirstNode(this.nodeMetadata, 'properties') //Since the values came in abbreviated XML
if(nProps1==null){ alert2(trt('Alert'),'Error, node='+getXMLNodeSerialisation(node)); return; }
if(nProps2==null){ alert2(trt('Alert'),'Error, nodeMetadata='+getXMLNodeSerialisation(this.nodeMetadata)); return; }
var nProp1=nProps1.firstChild
while(nProp1!=null)
{
if (nProp1.nodeName=="prop")
{
var nProp2=findNodeOnAttribute(nProps2,"prop","n",nProp1.getAttribute("n"))
if(nProp2!=null) getCdata(nProp2).nodeValue=getCdata(nProp1).nodeValue
}
nProp1=nProp1.nextSibling;
}//nodeMetadata filled with data
}
this.callDataSelect(); //Запрашиваем выпадающие списки (после загрузки полей)
this.fillGUIFromXML(); //Заполняю GUI элементы из XML
};
//I rewrite values from XML to GIU fields
fillGUIFromXML()
{
var nodeProperties=findFirstNode(this.nodeMetadata, 'properties');
var nodeProp=nodeProperties.firstChild;
while (nodeProp!=null)
{
if (nodeProp.nodeName=="prop")
{
var value=getCdata(nodeProp).nodeValue;
//console.log("name = "+nodeProp.getAttribute("n")+" value= "+value);
if ((value=="true")||(value=="t")) value=1;
if ((value=="false")||(value=="f")) value=0;
if(typeof nodeProp.field == "undefined") //Если не специализированное поле а обычные HTML поля
{
var field=document.getElementById("prop_"+this.uid+"_"+nodeProp.getAttribute("n"));
if(field!=null)
{
field.value=value;
//For entries of the type of a whip, we request a comment on the id field, for the list, add the desired value.
if(nodeProp.getAttribute("vt")=="object")
{
if(nodeProp.getAttribute("selector")=="combo")
{
//console.log("++++++++++field.options.length = "+field.options.length);
//We sort out the elements of the list (options) and set it to the desired value (the snake is not automatically exposed by the automaton).
for(var i=0;i<field.options.length;i++)
{
if(field.options[i].value==value)
{
field.options[i].setAttribute("selected",true);
}
}
}else//Field with a button, request a comment to the field by the record id.
{
if ((value!="")&&(value!=-1))
{
var xml='<?xml version="1.0" encoding="utf-8"?><metadata fn="6"><type n="'+nodeProp.getAttribute("ot")+'" c="'+nodeProp.getAttribute("FieldCaption")+'" pn="'+nodeProp.getAttribute("n")+'" fn="'+nodeProp.getAttribute("fn")+'" id="'+value+'">';
xml+='<objects-list><filter><column n="'+findFirstNode(this.nodeMetadata, 'type').getAttribute('ObjectID')+'"><![CDATA['+value+']]></column></filter></objects-list>';
xml+='</type></metadata>';
if(this.request.callServer(ScriptName,xml,true))
{
this.showProgressBar();
}
}
}
}
}
}else{
//For special fields
nodeProp.field.setValue(value);
}
}
nodeProp=nodeProp.nextSibling;
}
};
//Move data from html fields to an XML string and send to edit or update
sendData()
{
//Send binary data sequentially for each field
var nodeProperties=findFirstNode(this.nodeMetadata, 'properties');
var nodeProp=nodeProperties.firstChild;
var sending=false;
while (nodeProp!=null)
{
if (nodeProp.nodeName=="prop" && (nodeProp.getAttribute("vt")=="blob" || nodeProp.getAttribute("vt")=="file"))
{
var frm=document.getElementById('prop_'+this.uid+'_'+nodeProp.getAttribute("n")+'_frm');
var doc=getIframeDocument(frm);
if(doc.forms["form"].elements["file"].value!='')
{ doc.forms["form"].submit();
sending=true;
}
}
nodeProp=nodeProp.nextSibling;
}
if(sending) return;
//Sending text data
var nodeType=findFirstNode(this.nodeMetadata, 'type')
var nodename=nodeType.getAttribute("n")
var s="";
s+='<?xml version="1.0" encoding="utf-8"?>\n';
if (this.record_id!=-1) s+='<metadata fn="2">\n'; else s+='<metadata fn="1">\n';
s+='<type n="'+nodename+'" id="'+this.record_id+'">\n';
s+=' <properties>\n';
var nodeProperties=findFirstNode(this.nodeMetadata, 'properties')
var nodeProp=nodeProperties.firstChild
while (nodeProp!=null)
{
if (nodeProp.nodeName=="prop")
{
var value="";
if(typeof nodeProp.field == "undefined")
{
value=document.getElementById("prop_"+this.uid+"_"+nodeProp.getAttribute("n")).value;
if((nodeProp.getAttribute("vt")=="object")&&(nodeProp.getAttribute("selector")!="combo"))
{
if(document.getElementById("prop_"+this.uid+"_"+nodeProp.getAttribute("n")+"_visible").value=="")
value="";
}
//console.log("name = "+nodeProp.getAttribute("n")+" value= "+value+" object = "+document.getElementById("prop_"+this.uid+"_"+nodeProp.getAttribute("n")));
}else{
//For special fields (look "TCheckboxListField" class)
value=nodeProp.field.getValue();
}
//Проверяю тип дпнных и заполненость полей
if (!this.checkData(value,nodeProp.getAttribute("vt"),nodeProp.getAttribute("maybenull")))
{
alert2(trt('Alert'),trt("The_field_data_is_incorrect")+" \""+nodeProp.getAttribute("d")+"\"=\""+value+"\"!");
return;
}
s+=' <prop n="'+nodeProp.getAttribute("n")+'"><![CDATA['+value+']]></prop>\n';
}
nodeProp=nodeProp.nextSibling;
}
s+=' </properties>\n';
s+='</type>\n';
s+='</metadata>';
//alert2(trt('Alert'),s);
if(this.request.callServer(ScriptName,s,true))
{
this.showProgressBar();
}
};
//Check the field according to its type
checkData(value,type,maybenull)
{
//console.log("checkData value = "+value+" type= "+type+" maybenull = "+maybenull);
if(value==undefined) return false;
if(type=="i4")
{
if((value=="")&&(maybenull==0)) return false;
return isInt(value)
}else
if(type=="f8")
{
if((value=="")&&(maybenull==0)) return false;
return isFloat(value);
}else
if(type=="object")
{
if(((value=="-1")||(value==""))&&(maybenull==0)) return false;
}else
if((type=="string")||(type=="b")||(type=="dateTime"))
{
if((value=="")&&(maybenull==0)) return false;
}
return true;
};
//inserting the selected record
setPropVal(id,caption,prop_id)
{
//alert2(trt('Alert'),"id="+id+" caption="+caption+" prop_id="+prop_id)
var prop=document.getElementById("prop_"+this.uid+"_"+prop_id);
var propvis=document.getElementById("prop_"+this.uid+"_"+prop_id+"_visible");
if ((prop!=null)&&(propvis!=null))
{
prop.value=id;
propvis.value=caption;
propvis.select();
}
};
//The data was successfully added to the parent now so that he added 1 entry to the end of his list.
insertRows(node)
{ //Update the parent
let typeNode=findFirstNode(node,"type");
let typeName=typeNode.getAttribute("n");
let id=typeNode.getAttribute("id");
if (this.opener!=null)
{
if(this.opener.f_TypeName==typeName) //It would be better to make an array of open windows then check for all and not just for the parent.
{
this.opener.sendFilter(id,-1); //Update data by filter with id records.
}
}
let readd=document.getElementById("readd_"+this.uid);
if(readd!==null && readd.checked){
confirm2(trt('Warning'),trt("Successfully_added_data")+"<br>"+trt("Add_more")+"?",null,()=>this.win.Close());
}else
{
this.win.Close();
}
};
//The data has been updated successfully now telling the parent to update the record.
updateRows(node)
{
let typeNode=findFirstNode(node,"type");
let typeName=typeNode.getAttribute("n");
let id=typeNode.getAttribute("id");
if (this.opener!=null)
{
if(this.opener.f_TypeName==typeName) //It would be better to make an array of open windows then check for everyone.
{
this.opener.sendFilter(id,-1); //Update data by filter with id records.
}
}
this.win.Close();
};
}
//Поле с галочкой (или галочками)
class TCheckboxListField
{
constructor(name)
{
this.name=name;
this.div = document.createElement('div');
this.array = new Array();
}
addCheckbox(value, name) {
var input = document.createElement('input');
this.array.push(input);
input.setAttribute("type", "checkbox");
input.setAttribute("value", value);
var label = document.createElement("Label");
// label.setAttribute("for",id_from_input);
label.appendChild(input);
label.appendChild(document.createTextNode(" " + name + " "));
this.div.appendChild(label);
};
// Return checked values divide ";"
getValue() {
var result = "";
for(var i=0;i<this.array.length;i++)
{
if(this.array[i].checked)
{
result+=this.array[i].value;//+';';
}
}
return result;
};
// Set checked values divide ";"
setValue(val) {
let splits;
if(val.indexOf(';')==-1)
splits = val.split('');
else
splits = val.split(';');
for(let j=0;j<splits.length;j++)
{
for(let i=0;i<this.array.length;i++)
{
if(this.array[i].value==splits[j])
{
this.array[i].checked=true;
}
}
}
};
getDiv() {
return this.div;
};
}