//Copyright (C) 2008 Ivanov I.M. ivanov.i@istt.kz //For find non english chars: [^\x00-\x7F]+ function callWindow(uid,id,i) { SRec_mas[uid].callWindow(id,i); } function setFilterVal(uid,id,c,p) { SRec_mas[uid].setFilterVal(id,c,p); } var SRec_mas = new Array(); //List of all objects "EdtRec" (then something better to think of) class SRec { constructor() { this.win=null; this.rwin=null; this.f_State='0'; //"0" - editing, "1" - selecting a single entry, "2" - selecting a multiple record this.f_PropName=""; //If the mode f_State is 1 then f_PropName saves the name of the field for which the data is intended this.f_TypeName=""; //the name of the displayed object (type-> n attribute) //this.record_id=-1; //from here the form of editing takes the values id after its loading this.f_Settings=""; //XML that is superimposed on the current node Metadata this.f_pI=0; this.f_pU=0; this.f_pD=0; this.f_pS=0; //rights this.nodeMetadata=null; //accepted metadata this.nodeMetadataObjList=null; this.f_nodeData=null; //received data, hidden fields this.masCT=new Array();//parameter table for cells this.masCL=new Array();//node table column this.masVis=new Array(); //Whether to display a column this.masChBox=new Array(); //Checkboxes this.xmldoc=null; //accepted XML document (for CDATA creation) this.pagepos=0; //current data page this.pBarCnt=0; //Progress bar this.pBarDiv=null; //Progress bar this.name=""; this.uid=getUID(); this.request = new TRequest(this); SRec_mas[this.uid]=this; this.onUpdate=null; //For call set function this.onInsert=null; //For call set function } applyReq(req,fn,node,xmldoc) { //alert2(trt('Alert'),getXMLNodeSerialisation(node)); this.hideProgressBar(); this.xmldoc=node.ownerDocument; //xmldoc; if (fn==-1) //Information alert { let fullText = findFirstNode(node,'#cdata-section').nodeValue; let smallText = ''; let pos1=fullText.indexOf('[['); let pos2=fullText.indexOf(']]'); if(pos1>=0 && pos2>=0 && pos1=0){ //Если есть идентификатор того что это перезапись let okFunc=()=>{ this.setValue('seq',0); this.sendData(); //Применить ещё раз }; if (smallText != '') confirm2(trt('Warning'),smallText, fullText, okFunc, null); else confirm2(trt('Warning'),smallText, '', okFunc, null); }else { if (smallText != '') alert2(trt('Alert'), smallText, fullText); else alert2(trt('Alert'), fullText); } }else if (fn==0) { //alert2(trt('Alert'),getXMLNodeSerialisation(node)); this.setMetadata(node); this.updateSize(); }else if (fn==11) //Update record after editing, 1 entry has come. { this.updateRows(node); }else if (fn==3) //Information which record or records were deleted. { this.ApplyDelRec(node); }else if (fn==4) //Data after the selection of records, replacement of existing ones. { this.insertRows(node,true); }else if (fn==6) //Fill in the drop-down lists. { this.setDataSelect(node); }else if (fn==8) //There was a link to the report. { if(this.rwin!=null) { this.rwin.hideProgressBar(); this.rwin.setContent('
'+trt('Download_report')+': "'+this.win.getCaption().innerHTML+'".
'); } }else alert2(trt('Alert'),"Unknown function! fn=\""+fn+"\"" ); } //Edit the GUI filter from the xml string. setGUISettings(xmlStr) { if ((xmlStr!=null)&&(xmlStr!="")) { let xmlDOC=CreateXMLDOC(xmlStr); //let nPFilter=findFirstNode(xmlDOC,"filter") let nPFilter=findNodeOnPath(xmlDOC.documentElement,"type/objects-list/filter"); let nPColumn=nPFilter.firstChild; while (nPColumn != null) { if(nPColumn.nodeName=="column") { let prop=document.getElementById('filter_'+this.uid+'_'+nPColumn.getAttribute("n")); if(prop!==null) prop.value=getCdata(nPColumn).nodeValue; /*let np=nPColumn.getAttribute("n") let vp=nPColumn.getAttribute("visible") let cdata=getCdata(nPColumn).nodeValue columnNode=findNodeOnAttribute(nodeFilter, 'column', 'n', np) if(columnNode!=null) { if (vp!=null) columnNode.setAttribute("visible",vp) getCdata(columnNode).nodeValue=cdata }*/ } nPColumn=nPColumn.nextSibling; } let btn=document.getElementById("btnfilter_"+this.uid); if(btn!==null) btn.focus(); } } //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" || xml=="") return; if(typeof(xml) == "string"){ let doc=CreateXMLDOC(xml); if(doc==null) alert2(trt('Alert'),xml); else { let node=findFirstNodeOnAttribute(doc, "type", "n", this.f_TypeName); if(node!=null) applyNodeToNode(node, 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(htmlElement) { let str='\
\
\ \ \
\
\ \ \ \ \ \ \ \
adddelexcel '+trt('Settings')+''+trt('Refresh')+'
\
\
\ \ \ \ \
\
\
\
 
\
\
\ '; if(htmlElement==null || typeof(htmlElement) == "undefined") { this.win=new TWin(); this.win.BuildGUI(pageX-10,pageY-10); this.win.setHeight(400); //this.win.setLeftTop() this.win.setContent(str); this.win.obj=this; this.win.addResizeListener(function(obj){return function(){obj.updateSize();}}(this)); }else{ htmlElement.innerHTML=str; } document.getElementById('SRec_Add_'+this.uid).onclick = ()=>this.insertRecord(); document.getElementById('SRec_Del_'+this.uid).onclick = ()=>this.deleteRecord(); document.getElementById('SRec_Exc_'+this.uid).onclick = ()=>this.showReport('xls'); document.getElementById('SRec_Rfr_'+this.uid).onclick = ()=>{this.appendFilter(); this.sendFilter(-1,0);}; } //Update dimensions of the elements (the main table in absolute coordinates). updateSize() { let dv1=document.getElementById("tblSContainer_"+this.uid); let dv2=document.getElementById("tblContainer_"+this.uid); if(dv1!=null && dv2!=null) { dv1.style.width = dv2.offsetWidth+"px"; dv1.style.height = dv2.offsetHeight+"px"; } } //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='
'; let eDiv=document.getElementById('eDiv'+this.uid); if(eDiv==null) return; 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; } } //Function to fill the drop-down lists (here it is necessary to ensure that everywhere there is a "var" in front of the variables). setDataSelect(node) { //alert2(trt('Alert'),"setDataSelect = " + getXMLNodeSerialisation(node)); let nodeType,prop_id,prop,option,nodeProp,id,value,cdataNode; nodeType=findFirstNode(node, 'type'); prop_id=nodeType.getAttribute("pn");//Field name prop=document.getElementById('filter_'+this.uid+'_'+prop_id); //Determine what type of node was a drop-down list or a field with a button. let selector=null; let nodeFilter=findNodeOnPath(this.nodeMetadata,"type/objects-list/filter"); let nodeCur=findNodeOnAttribute(nodeFilter, 'column', 'n', prop_id); if(nodeCur!=null) selector=nodeCur.getAttribute("selector"); //alert2(trt('Alert'),"nodeCur = " + getXMLNodeSerialisation(nodeCur)); /*nodeCur=nodeFilter.firstChild while(nodeCur!=null) { if((nodeCur.nodeName=="column")&&(nodeCur.getAttribute("n")==prop_id)) { selector=nodeCur.getAttribute("selector"); } nodeCur=nodeCur.nextSibling; }*/ if(selector==="combo") //if the drop-down list { prop.innerHTML = ""; //Select the value for this list let val=null; let nodeFilter=findNodeOnPath(this.nodeMetadata,"type/objects-list/filter"); let nodeCol=nodeFilter.firstChild; while(nodeCol!=null) { if((nodeCol.nodeName==="column")&&(nodeCol.getAttribute("n")==prop_id)) { val=getCdataValue(nodeCol); break; } nodeCol=nodeCol.nextSibling; } //The first line in the selection is NULL value = -1. option = document.createElement('option'); option.setAttribute("value",""); option.appendChild( document.createTextNode("")); option.selected = true; prop.appendChild( option ); if(prop!=null) { nodeProp=nodeType.firstChild; while (nodeProp!=null) { if (nodeProp.nodeName=="record") { id=nodeProp.getAttribute("id"); value=""; cdataNode = nodeProp.firstChild while (cdataNode!=null) { if (cdataNode.nodeName=="#cdata-section") { value+=cdataNode.nodeValue+" "; //break; } cdataNode = cdataNode.nextSibling; } option = document.createElement('option'); option.setAttribute("value",id); if (id==val) option.selected=true; option.appendChild(document.createTextNode(value)); 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 let 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) //fill without window { nodeProp=findFirstNode(nodeType, 'record'); id=nodeProp.getAttribute("id"); value=findFirstNode(nodeProp, '#cdata-section').nodeValue; prop.value=id; let propvis=document.getElementById('filter_'+this.uid+'_'+prop_id+'_visible'); propvis.value=value; propvis.select(); }else if(count>1) //The item selection window is displayed. { let htmlString=''; nodeProp=nodeType.firstChild i=0; while (nodeProp!=null) { if (nodeProp.nodeName=="record") { let bgColor='#e0e0e0'; if (i%2==0) bgColor='white'; id=nodeProp.getAttribute("id"); value=getCdataValue(nodeProp); value=value.replace(/"/g, """); value=value.replace(/'/g, "\\'"); htmlString+=''+"\n"; i++; } nodeProp=nodeProp.nextSibling; } htmlString+='
'+findFirstNode(nodeProp, '#cdata-section').nodeValue+' 
'; let win=new TWin(); win.BuildGUI(pageX-10,pageY-10); win.setHeight(400); win.setContent(htmlString); win.setCaption(document.createTextNode(trt('Selection'))); win.setParent(this.win); //win.obj=this } } }; //Set the value for the object filter with a text field search setFilterVal(id,caption,prop_id) { let prop=document.getElementById('filter_'+this.uid+'_'+prop_id); let propvis=document.getElementById('filter_'+this.uid+'_'+prop_id+'_visible'); if ((prop!=null)&&(propvis!=null)) { prop.value=id; propvis.value=caption; propvis.select(); this.appendFilter(); //We move the values from the HTML fields to XML. this.sendFilter(-1,0); } } //we pass the id to the object filter column_n - the name of the filter setFilterObject(TypeName, column_n, id, filter) { let node=findFirstNodeOnAttribute(this.nodeMetadata,'column','n',column_n); if(node!==null) { let name=node.getAttribute("FieldCaption"); getCdata(node).nodeValue=id; //we request data from the server to fill in the comments on the record id let prop=document.getElementById('filter_'+this.uid+'_'+column_n); if(prop!==null) prop.value = id; //Request a comment on the record id from the server let xml = ''; if(filter!=''){ //Настройка для последующего вызова xml=''+filter+''; applyNodeToNode(CreateXMLDOC(xml).documentElement, node, "n"); //Настройка для фильтрации списка xml = '' + '' + '' + filter + '' + ''; }else{ xml = '' + '' + '' + ''; } if(this.request.callServer(ScriptName,xml,true)) { this.showProgressBar(); } }else { alert2(trt('Alert'),'Filter "'+column_n+'" not find!'); } } //The function to collect data from HTML fields in to XML appendFilter() { let nodeType=findFirstNode(this.nodeMetadata, "type"); let nodeFilter=findNodeOnPath(nodeType,"objects-list/filter"); if (nodeFilter!=null) { let columnNode=nodeFilter.firstChild; while (columnNode != null) { if (columnNode.nodeName=="column") { let value = ''; let input = document.getElementById('filter_'+this.uid+'_'+columnNode.getAttribute("n")); if(input!=null) value=input.value; //'2016-02-27 00:00:00' if(columnNode.getAttribute("vt")=="dateTime" || columnNode.getAttribute("vt")=="date") //If field is "dateTime" then transmit in UnixTime format in second { if(value!=""){ let date = new Date(value.replace(/-/g, "/")); value=date.getTime()/1000;// - date.getTimezoneOffset()*60; if(isNaN(value)) value=''; } } getCdata(columnNode).nodeValue=value; //TODO do check for data type } columnNode = columnNode.nextSibling; } } //alert2(trt('Alert'),getXMLNodeSerialisation(this.nodeMetadata)); } /** Function to send filter data to the server * id - id of record -1 then all * page - result page number */ sendFilter(id,page) { let nodeType=findFirstNode(this.nodeMetadata, "type"); let nodeObjectsList=findFirstNode(nodeType, "objects-list"); let nodeFilter=findNodeOnPath(nodeType,"objects-list/filter"); let typename=nodeType.getAttribute("n"); let xs=''; xs+='\n'; if(id!=-1) xs+='\n'; else xs+='\n'; xs+=' '; //Opera does not serialize CDATA, so we form the filter manually let nextNode=nodeFilter.firstChild; while(nextNode!=null) { if(nextNode.nodeName=="column") { if(nextNode.getAttribute("n")=="id" && id!=-1) { xs+=''; xs+=''; xs+='\n'; }else { xs+=''; xs+=''; xs+='\n'; } } nextNode=nextNode.nextSibling; } xs+='\n'; xs+=''; //alert2(trt('Alert'),xs); if(this.request.callServer(ScriptName,xs)) { this.showProgressBar(); } } //Get metadata records and break them into global variables. setMetadata(node) { this.nodeMetadata=node; this.setXMLSettings(this.f_Settings); //Appending settings to nodeMetadata //Create GUI filter let td,tr,td1,td2; let nodeFilter=null; let tablefilter=document.getElementById('idfilter'+this.uid); if (tablefilter==null || tablefilter.tBodies==null) alert2(trt('Alert'),'tablefilter=null'); let nodeType=findFirstNode(node, "type"); this.f_pI=nodeType.getAttribute("ins");//access rights this.f_pU=nodeType.getAttribute("upd"); this.f_pD=nodeType.getAttribute("del"); this.f_pS=nodeType.getAttribute("sel"); this.f_TypeName = nodeType.getAttribute("n"); this.name=this.f_TypeName; let rep=nodeType.getAttribute("rep"); if(rep!='1') deleteHTML("id_pdf"); //TODO if(this.f_pI!='1') deleteHTML('SRec_Add_'+this.uid); if(this.f_pD!='1') deleteHTML('SRec_Del_'+this.uid); this.nodeMetadataObjList=findNode(nodeType, "objects-list"); if(this.win!=null) { this.win.setWidth(this.nodeMetadataObjList.getAttribute("width")); let height=this.nodeMetadataObjList.getAttribute("height"); if(height!=null){ if(height.indexOf('%')!=-1) height=(window.innerHeight / 100) * parseInt(height.substring(0,height.length-1)); this.win.setHeight(height); } } nodeFilter=findNodeOnPath(nodeType,"objects-list/filter"); //let id=-1; //After loading the metadata, we request the data by sending an XML filter. let count=0; let row=1; let nRow=null; let h=nodeFilter.getAttribute("height"); if((nodeFilter!=null)&&(h!=0)) //Create HTML elements by XML filter. { let columnNode=nodeFilter.firstChild; while (columnNode != null) { if ((columnNode.nodeName==="column")&&(columnNode.getAttribute("visible")!="0")) { count++; let value=getCdataValue(columnNode); if(row>1) row--; if(columnNode.getAttribute("row")!=null) row=parseInt(columnNode.getAttribute("row"))+1; if(columnNode.getAttribute("row")!=null && row>1) { tr = document.createElement('tr'); td1 = document.createElement('td'); tr.appendChild(td1); td1.colSpan='2'; let table=document.createElement('table'); table.style.cssText="border:0px;"; table.setAttribute("width","100%"); table.cellspacing=0; table.cellpadding=0; td1.appendChild(table); nRow=table.insertRow(0); } if(row>1) { td1 = nRow.insertCell(-1); td1.setAttribute("width","1%"); td2 = nRow.insertCell(-1); //td2.setAttribute("width","10%") } if(row==1) { tr = document.createElement('tr'); td1 = document.createElement('td'); tr.appendChild(td1); td2 = document.createElement('td'); td2.style.cssText="width: 100%;"; tr.appendChild(td2); } //td2.style.cssText='white-space:nowrap' td1.appendChild(document.createTextNode(columnNode.getAttribute("d"))); td1.style.cssText='white-space:nowrap;'; if (columnNode.getAttribute("vt")==="dateTime") { let table=document.createElement('table'); table.style.cssText="width:100%;/*table-layout:fixed;*/border-spacing:0;border-collapse:collapse;border:0px;"; let newRow=table.insertRow(0); let newCell1 = newRow.insertCell(0); newCell1.style.cssText="padding:0px;width:100%;"; let newCell2 = newRow.insertCell(1); newCell2.style.cssText="padding:0px;width:25px;"; let input = document.createElement('input'); input.classList.add('DBMS'); input.style.cssText="width: 100%;"; input.setAttribute("type","text"); /*input.onkeydown=function(event){ events = event || window.event; if(events.keyCode==13) events.keyCode=9; };*/ input.setAttribute("name",columnNode.getAttribute("n")); if(columnNode.getAttribute("size")!=null) input.setAttribute("maxlength",columnNode.getAttribute("size"),0); input.setAttribute("value",isNaN(value) || value=='' ? '' : (new Date(value*1000)).toString()); input.setAttribute("id",'filter_'+this.uid+'_'+columnNode.getAttribute("n")); newCell1.appendChild( input ); let img = document.createElement('img'); img.src='../resources/metadata/dbms/images/datepicker.jpg'; img.style.cssText="cursor: pointer;"; newCell2.appendChild(img); td2.appendChild( table ); new Calendar({ inputField: input, dateFormat: "%Y-%m-%d %H:%M:%S", trigger: img, align: "Bl", bottomBar: false, showTime: true, //singleClick: true, onSelect: function(){ this.hide(); } }); }else if (columnNode.getAttribute("vt")==="date") { let table=document.createElement('table'); table.style.cssText="width:100%;/*table-layout:fixed;*/border-spacing:0;border-collapse:collapse;border:0px;"; let newRow=table.insertRow(0); let newCell1 = newRow.insertCell(0); newCell1.style.cssText="padding:0px;width:100%;"; let newCell2 = newRow.insertCell(1); newCell2.style.cssText="padding:0px;width:25px;"; let input = document.createElement('input'); input.classList.add('DBMS'); input.style.cssText="width: 100%;"; input.setAttribute("type","text"); /*input.onkeydown=function(event){ events = event || window.event; if(events.keyCode==13) events.keyCode=9; };*/ input.setAttribute("name",columnNode.getAttribute("n")); if(columnNode.getAttribute("size")!=null) input.setAttribute("maxlength",columnNode.getAttribute("size"),0); input.setAttribute("value",isNaN(value) || value=='' ? '' : (new Date(value*1000)).toString()); input.setAttribute("id",'filter_'+this.uid+'_'+columnNode.getAttribute("n")); newCell1.appendChild( input ); let img = document.createElement('img'); img.src='../resources/metadata/dbms/images/datepicker.jpg'; img.style.cssText="cursor: pointer;"; newCell2.appendChild(img); td2.appendChild( table ); new Calendar.setup({ inputField : input, ifFormat : "%Y-%m-%d", button : img, align : "Tl", singleClick : false, onSelect: function(){ this.hide(); } }); }else if (columnNode.getAttribute("vt")==="b") { let select = document.createElement('select'); select.classList.add('DBMS'); select.onkeydown=function(){ if(event.keyCode==13) event.keyCode=9; }; select.style.cssText="width: 100%;"; let opt=findFirstNode(columnNode,"options"); if(opt==null) { let option=document.createElement("option"); option.setAttribute("value",""); option.appendChild(document.createTextNode("")); if(value=="") option.selected=true; select.appendChild( option ); option=document.createElement("option"); option.setAttribute("value","1"); option.appendChild(document.createTextNode(trt('Yes'))); if(value=="1") option.selected=true; select.appendChild( option ); option=document.createElement("option"); option.setAttribute("value","0"); option.appendChild(document.createTextNode(trt('Not'))); if(value=="0") option.selected=true; select.appendChild( option ); }else { opt=opt.firstChild; while(opt!=null) { if(opt.nodeName=="option") { let option = document.createElement("option"); option.setAttribute("value",opt.getAttribute("val")); if(opt.getAttribute("val")==value) option.selected=true; option.appendChild(document.createTextNode(opt.getAttribute("d"))); select.appendChild( option ); } opt=opt.nextSibling; } } select.setAttribute("id",'filter_'+this.uid+'_'+columnNode.getAttribute("n")); td2.appendChild( select ); }else if (columnNode.getAttribute("vt")==="string") { let input = document.createElement('input'); input.classList.add('DBMS'); input.style.cssText="width: 100%;"; input.setAttribute("type","text"); input.onkeydown=function(event){if(event.which==13) event.which=9;}; input.setAttribute("name",columnNode.getAttribute("n")); if(columnNode.getAttribute("size")!=null) input.setAttribute("maxlength",columnNode.getAttribute("size"),0); input.setAttribute("value",value); input.setAttribute("id",'filter_'+this.uid+'_'+columnNode.getAttribute("n")); td2.appendChild( input ); }else if (columnNode.getAttribute("vt")==="i4") { let opt=findNode(columnNode, "options"); if(opt!=null) //If combobox { let select = document.createElement('select'); select.style.cssText="width: 100%;"; select.setAttribute("name",columnNode.getAttribute("n")); select.setAttribute("id", 'filter_' + this.uid + '_' + columnNode.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 { let table=document.createElement('table'); table.style.cssText="width:100%;/*table-layout:fixed;*/border-spacing:0;border-collapse:collapse;border:0px;"; let newRow=table.insertRow(0); //We add a row in the created table. let newCell1 = newRow.insertCell(0); newCell1.style.cssText="padding:0px;padding-right:1px;width:100%;"; let newCell2 = newRow.insertCell(1); newCell2.style.cssText="padding:0px;padding-right:1px;height:100%;"; let newCell3 = newRow.insertCell(2); newCell3.style.cssText="padding:0px;width:25px;height:100%;"; let input = document.createElement('input'); input.classList.add('DBMS'); input.style.cssText="width: 100%;"; input.setAttribute("type","text"); input.onkeydown=function(){ if(event.keyCode==13) event.keyCode=9; }; input.setAttribute("name",columnNode.getAttribute("n")); if(columnNode.getAttribute("size")!=null) input.setAttribute("maxlength",columnNode.getAttribute("size"),0); input.setAttribute("value",value); input.setAttribute("id",'filter_'+this.uid+'_'+columnNode.getAttribute("n")); newCell1.appendChild( input ); let button = document.createElement('input'); button.classList.add('button-secondary'); button.setAttribute("type","button"); button.setAttribute("value","+"); button.style.cssText="height:100%;width:22px;margin:0px;padding:0px;"; newCell2.appendChild( button ); button.onclick=function(inp){return function(){ inp.value=getIntVal(inp.value)+1; }}(input); button = document.createElement('input'); button.classList.add('button-secondary'); button.setAttribute("type","button"); button.setAttribute("value","-"); 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 (columnNode.getAttribute("vt")==="f8") { let input = document.createElement('input'); input.setAttribute("type","text"); button.classList.add('DBMS'); input.style.cssText="width: 100%;"; input.onkeydown=function(){ if(event.keyCode==13) event.keyCode=9; }; input.setAttribute("name",columnNode.getAttribute("n")); if(columnNode.getAttribute("size")!=null) input.setAttribute("maxlength",columnNode.getAttribute("size"),0); input.setAttribute("value",value); input.setAttribute("id",'filter_'+this.uid+'_'+columnNode.getAttribute("n")); td2.appendChild( input ); }else if (columnNode.getAttribute("vt")==="object") { let selector=columnNode.getAttribute("selector"); let object=columnNode.getAttribute("object"); let fc=columnNode.getAttribute("FieldCaption"); let table=document.createElement('table'); table.style.cssText="width:100%;/*table-layout:fixed;*/border-spacing:0;border-collapse:collapse;border:0px;"; let newRow=table.insertRow(0); //We add a row in the created table. let newCell1 = newRow.insertCell(0); newCell1.style.cssText="padding:0px; border: 0px solid #999999; /*width:100%;*/"; let newCell2 = newRow.insertCell(1); newCell2.style.cssText="padding:0px; padding-left:1px; border: 0px solid #999999; width:30px; height:100%;"; if(selector=="combo") { let select = document.createElement('select'); select.classList.add('DBMS'); select.style.cssText="width: 100%;"; select.onkeydown=function(){ if(event.keyCode==13) event.keyCode=9; }; //select.setAttribute("name",columnNode.getAttribute("n")) select.setAttribute("value",value); select.setAttribute("id",'filter_'+this.uid+'_'+columnNode.getAttribute("n")); select.onchange = function(thiz,node){ return function(){ thiz.onComboObjectChangeHandler(node);}; }(this,columnNode); newCell1.appendChild(select); let button = document.createElement('input'); button.classList.add('button-secondary'); button.setAttribute("type","button"); button.setAttribute("value","..."); button.style.cssText="display:block; box-sizing: border-box; margin: 0px; padding: 0px;width:100%; height:100%; font-size: 9pt;"; button.onclick=function(thiz,val){return function(){thiz.SelectObjects(val);};}(this,columnNode.getAttribute("n")); newCell2.appendChild(button); //I collect values from XML and inserting a request to the server (to fill out the dropdown). let nTypeF = findFirstNode(columnNode, "type"); if(nTypeF != null) { //Add parameters to request nTypeF.setAttribute("c",fc); nTypeF.setAttribute("pn",columnNode.getAttribute("n")); nTypeF.setAttribute("fn",columnNode.getAttribute("n")); let strXMLF = getXMLNodeSerialisation(nTypeF); let nColF=nodeFilter.firstChild; while(nColF != null) { if(nColF.nodeName==="column") { let valF=getCdataValue(nColF); strXMLF=strXMLF.replace('${'+nColF.getAttribute('n')+'}', valF); } nColF = nColF.nextSibling; } strXMLF=''+strXMLF+''; if(this.request.callServer(ScriptName,strXMLF,true)) { this.showProgressBar(); } }else { if(this.request.callServer(ScriptName,'',true)) { this.showProgressBar(); } } }else { //Two elements are placed in the table let input = document.createElement('input'); input.classList.add('DBMS'); //After pressing Enter we pass the entered line to the server input.onkeydown=function(obj,val1,val2,val3,val4){ return function(e){ if(e==null) e=window.event; if(e.keyCode==13){ obj.callFilterVal(val1,val2,-1,val3.value,val4); return false; } }; }(this,object,fc,input,columnNode.getAttribute("n")); input.style.cssText="width: 100%; height:22px; line-height:22px;"; input.setAttribute("type","text"); input.setAttribute("id",'filter_'+this.uid+'_'+columnNode.getAttribute("n")+"_visible"); input.setAttribute("value",""); newCell1.appendChild(input); //A hidden field where data is stored (you can make it stored in XML). let hidden = document.createElement('input'); hidden.setAttribute("type", "hidden"); hidden.setAttribute("id",'filter_'+this.uid+'_'+columnNode.getAttribute("n")); //hidden.setAttribute("value",value) hidden.value=value; newCell1.appendChild(hidden); let button = document.createElement('input'); button.classList.add('button-secondary'); button.setAttribute("type","button"); button.setAttribute("value","..."); button.style.cssText="width:30px; height:100%;margin: 0px; padding: 0px;"; button.onclick=function(thiz,val) { return function(){thiz.SelectObjects(val);}; }(this,columnNode.getAttribute("n")); newCell2.appendChild(button); //If the field is filled then we request the field header by its id if ((value!="")&&(value!=-1)) { let xmlString=''; if(this.request.callServer(ScriptName,xmlString,true)) { this.showProgressBar(); } } } td2.appendChild( table ); }else alert2(trt('Alert'),"Unknown type = "+columnNode.getAttribute("vt")); tablefilter.tBodies[0].appendChild(tr); } columnNode = columnNode.nextSibling; } //button to apply tr = document.createElement('tr'); td = document.createElement('td'); td.appendChild( document.createTextNode(" ")); tr.appendChild(td); td = document.createElement('td'); td.setAttribute("align","right"); let button = document.createElement('input'); button.classList.add('button-secondary'); button.setAttribute("type","button"); button.setAttribute("value",trt("Filtering")); button.setAttribute("id","btnfilter_"+this.uid); button.onclick=function(obj){ return function() { obj.appendFilter(); obj.sendFilter(-1,0); }; }(this); td.appendChild( button ); tr.appendChild(td); tablefilter.tBodies[0].appendChild(tr); } if((count==0)||(h=0)) deleteHTML("idfilter"+this.uid); if(this.f_State>0){ document.getElementById('Selection_'+this.uid).parentNode.style.display = "block"; } //Columns in which there are links to the array let pos=0; let columnNode=this.nodeMetadataObjList.firstChild; while (columnNode != null) { if(columnNode.nodeName=="column") { this.masCL[pos]=columnNode; this.masCT[pos]=findFirstNode(columnNode, "type"); if(columnNode.getAttribute("visible")!="0") this.masVis[pos]=true; else this.masVis[pos]=false; pos++; } columnNode = columnNode.nextSibling; } if (this.win!=null && this.win.getTop()!=40) this.win.setCenter(); //Building the columns of the data table this.buildHead(); //this.sendFilter(id,0); this.sendFilter(-1,0); } /** 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 ask the data again. let nodeType=findFirstNode(this.nodeMetadata, "type"); let nodeFilter=findNodeOnPath(nodeType,"objects-list/filter"); if(nodeFilter!=null) //Create HTML elements by XML filter. { let columnNode=nodeFilter.firstChild; while (columnNode != null) { if (columnNode.nodeName==="column") { let nTypeF = findFirstNode(columnNode, "type"); if(nTypeF != null) { //Add parameters to request nTypeF.setAttribute("c",columnNode.getAttribute("FieldCaption")); nTypeF.setAttribute("pn",columnNode.getAttribute("n")); nTypeF.setAttribute("fn",columnNode.getAttribute("n")); let strXMLF = getXMLNodeSerialisation(nTypeF); if(strXMLF.indexOf('${'+node.getAttribute('n')+'}')!=-1) //If it does not participate then it does not react to the change. { let nColF=nodeFilter.firstChild; while(nColF != null) { if(nColF.nodeName==="column") { let elm=document.getElementById('filter_'+this.uid+'_'+nColF.getAttribute("n")); if(elm!=null) { let valF=elm.value; strXMLF=strXMLF.replace('${'+nColF.getAttribute('n')+'}', valF); } } nColF = nColF.nextSibling; } strXMLF=''+strXMLF+''; if(this.request.callServer(ScriptName,strXMLF,true)) { this.showProgressBar(); } } } } columnNode = columnNode.nextSibling; } } } //We ask the server for a list of values almost like a drop-down list. //typeName - The name of the object (TODO if the current is the variable f TypeName) //name - the name of the column for selecting the values (must match the name of any filter in typeName) //id - id of record if it is necessary to return only the description, if -1 then it is not considered //value - filter value text field //htmlid - field name in filter n callFilterVal(typeName,name,id,value,htmlid) { if(value!="") { if(this.request.callServer(ScriptName,'',true)) { this.showProgressBar(); } }else { document.getElementById("filter_"+htmlid).value=-1; appendFilter(); this.sendFilter(-1,0); } } //Building a table header for the data buildHead() { if(this.win!=null) this.win.setCaption(this.nodeMetadataObjList.getAttribute("d")); let thetable = document.getElementById('thetable'+this.uid); delChild(thetable.tHead); let tr=document.createElement('tr'); tr.style.cssText='background-color: var(--header-color);'; let th=document.createElement('th'); th.appendChild( document.createTextNode('№')); th.style.cssText='width: 1%;'; tr.appendChild(th); th=document.createElement('th'); th.appendChild( document.createTextNode(trt('Del'))); th.title = trt('Invert_selection'); th.style.cssText='width: 1%; cursor: pointer; text-decoration: underline;'; th.onmouseover=function(){ this.style.backgroundColor='var(--row-color-2)'; }; th.onmouseout=function(){ this.style.backgroundColor='var(--header-color)'; }; th.onclick= ()=>{ for(let i=0;i1) { let newRow=tablepages.insertRow(-1); for(let i=0;i=0) //Color from Result { let bgColorT=findNodeOnNum(nodeRecord,"#cdata-section",nColor).nodeValue; if(bgColorT!="") bgColor=bgColorT; } let id=nodeRecord.getAttribute("id"); //add rows to an existing record table let tr = document.createElement('tr'); tr.onmouseover=function(){ this.style.backgroundColor="var(--btn-color2)"; }; tr.onmouseout=function(val1,val2){return function(){val1.style.backgroundColor=val2;}}(tr,bgColor); tr.setAttribute("id",id+'_'+this.uid); tr.style.backgroundColor=bgColor; //sequential record number let td = document.createElement('td'); td.appendChild( document.createTextNode( i+100*this.pagepos ) ); tr.appendChild(td); //CheckBuck to delete records td = document.createElement('td'); td.style.cssText="text-align: center;"; if(!(this.f_pD!="1" || nodeRecord.getAttribute("a").indexOf("d")==-1)) { let checkbox = document.createElement('input'); checkbox.classList.add('DBMS'); this.masChBox.push(checkbox); //checkbox.disabled=true; checkbox.setAttribute("type","checkbox"); checkbox.setAttribute("value",id); checkbox.style.cssText="font: normal normal normal 11px normal Arial;"; td.appendChild( checkbox ); } tr.appendChild(td); //for each column we make a column let colN=0; //column number let cdataNode = nodeRecord.firstChild; while (cdataNode!=null) { if(cdataNode.nodeName=="#cdata-section") { if(this.masVis[colN]) { td = document.createElement('td'); if((this.f_pU=="1")||(this.f_State=="1")){ td.style.cssText="cursor: pointer;"; } let textNode=document.createTextNode(cdataNode.nodeValue); td.setAttribute("id",id+this.masCL[colN].getAttribute("n")); //so that you can identify each record when you update td.appendChild(textNode); //if in the metadata for this column there is a reference object then add a link if (this.masCT[colN]!=null) { //Opening a new window in the filter is passed to the current values of the row td.style.cssText="cursor: pointer; background-color: var(--btn-color); font-weight: bold;"; td.onmouseover=function(){ this.style.backgroundColor="var(--btn-color2)"; }; td.onmouseout=function(){ this.style.backgroundColor="var(--btn-color)"; }; //when you click on a cell, the sent filter is prefilled with variables in accordance with the id of the pressed line //in the function we pass the cell id and the column number td.onclick=function(obj,val1,val2){ return function(){ obj.callWindow(val1,val2); } }(this,id,colN); }else { if((this.f_pU=="1" && nodeRecord.getAttribute("a").indexOf("u")!=-1)||(this.f_State=="1")) { td.onclick=function(thiz,val1,val2){ return function(){thiz.updateRecord(val1);}; }(this,id); }else { td.style.cssText="cursor: default;"; } } tr.appendChild(td); } colN++; } cdataNode = cdataNode.nextSibling; } theTable.tBodies[0].appendChild(tr); } nodeRecord = nodeRecord.nextSibling; } this.updateSize(); } //by the column number, return the reference to the column node (numbering from 0) getColumnOnNum(num) { let i=0; let fNodeProp = findFirstNode(this.nodeMetadata,"objects-list").firstChild; while(fNodeProp != null) { if(fNodeProp.nodeName=="column") { if(num==i) return fNodeProp; i++; } fNodeProp=fNodeProp.nextSibling; } return null; } //Name the column number getColNumOnName(name) { let i=0; let nn = findNode(this.nodeMetadata,"objects-list").firstChild; while (nn != null) { if(nn.nodeName=='column') { if(nextNode.getAttribude('n')==name) return i; i++; } nextNode=nextNode.nextSibling; } } //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(propname) { let nodeColu=findNodeOnPath(this.nodeMetadata, "type/objects-list/filter/column[@n='"+propname+"']"); if(nodeColu!=null) this.callWindowF(nodeColu); } //Call the ShowRecord window with the parameters for the filter (not just the object name). callWindowF(nodeColu) { let settings=""; let TypeName=""; let nT=findNode(nodeColu, "type"); if(nT!=null) { settings=getXMLNodeSerialisation(nT); TypeName = nT.getAttribute("n"); }else { TypeName=nodeColu.getAttribute("object"); } //Write to XML string from GUI while(true) { let sub1=BeforeFirst(settings,"${"); if(sub1==null) break; let sub2=AfterFirst(settings,"}"); if(sub2==null) break; let val=BeforeFirst(AfterFirst(settings,"${"),"}"); let obj=document.getElementById("filter_"+this.uid+"_"+val); if(obj!=null){ settings=sub1+obj.value+sub2; }else{ settings=sub1+sub2; } } let rec=new SRec(); rec.opener=this; rec.create(null); //rec.f_State=1; TODO then finish the job //rec.f_PropName=nodeColu.getAttribute("n"); rec.f_Settings=settings; rec.f_TypeName=TypeName; rec.win.setLeftTop(pageX-250,pageY-10); rec.win.setParent(this.win); if(rec.request.callServer(ScriptName,'')) { rec.showProgressBar(); } }; //Call the ShowRecord window with the parameters for the filter (not just the object name) //id - id records from the database //col - Column Number callWindow(id,col) { //we represent xml as a string and replace values of type $ {id} with values from the current record let typeName=this.masCT[col].getAttribute("n"); let xmlString=getXMLNodeSerialisation(this.masCT[col]); while(true) { let sub1=BeforeFirst(xmlString,"${"); if(sub1==null) break; let sub2=AfterFirst(xmlString,"}"); if(sub2==null) break; let val=BeforeFirst(AfterFirst(xmlString,"${"),"}"); xmlString=sub1+this.getData(id,val)+sub2; } //We assign a string of the global variable so that we can take the infu from the child //Settings.add(0,xmlString) //wishWin = window.open("showrecord.html?name="+typeName,typeName,"width=800,height=600,menubar=no,location=no,resizable=yes,scrollbars=yes"); let rec=new SRec(); rec.create(null); //rec.f_State=1; not used //rec.f_PropName=propname; not used 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,'')) { rec.showProgressBar(); } } //find the node cdata in the data by the record id and column name getDataC(id,col) { let i=0; let b=false; //determine the sequence number of the column let node=findNodeOnPath(this.nodeMetadata,"type/objects-list"); let nodeCol = node.firstChild; while (nodeCol != null) { if(nodeCol.nodeName=="column") { if(nodeCol.getAttribute("n")==col){ b=true; break; } i++; } nodeCol = nodeCol.nextSibling; } if(!b)return null; //we search for value in result set node=findFirstNode(this.f_nodeData, 'type'); let nodeRec=findNodeOnAttribute(node, 'record', 'id', id); return findNodeOnNum(nodeRec,"#cdata-section",i); } //find the value in the result set by the id of the record and the name of the column getData(id,col) { if(findNode(this.nodeMetadata,'type').getAttribute("ObjectID")==col) return id; let cdt=this.getDataC(id,col); if(cdt!=null) return cdt.nodeValue; else return ''; } //look for a string by id and update the values (TODO consecutively without hidden fields) updateRows(node) { //We sort through the received records and update the values let nodeRecord = findNode(node,"type").firstChild while (nodeRecord != null) { if(nodeRecord.nodeName=="record") { let ii=0; let jj=0; let id=nodeRecord.getAttribute("id"); let tr=document.getElementById(id+'_'+this.uid); if (tr==null) { this.insertRows(node,false); //If not then insert }else { tr.style.textDecoration="underline"; let cdataNode = nodeRecord.firstChild; while (cdataNode!=null) { if (cdataNode.nodeName=="#cdata-section") { let cd=this.getDataC(id,this.masCL[ii].getAttribute("n")); if(cd!=null) cd.nodeValue=cdataNode.nodeValue; if(this.masCL[ii].getAttribute("visible")!="0") { while(tr.childNodes[jj+2].childNodes[0]) tr.childNodes[jj+2].removeChild(tr.childNodes[jj+2].childNodes[0]); tr.childNodes[jj+2].appendChild(document.createTextNode(cdataNode.nodeValue)); jj++; } ii++; } cdataNode = cdataNode.nextSibling; } } } nodeRecord = nodeRecord.nextSibling; } } openPage(page) { open(page); } dataalert() { let error_msg=""; if (error_msg!="") alert2(trt('Alert'),"ShowRecords: \n"+error_msg); } showReport(ext) { if(this.rwin!=null) this.rwin.Close(); this.rwin=new TWin(); this.rwin.BuildGUI(pageX-10,pageY-10); this.rwin.setParent(this.win); this.rwin.setSize(280,130); this.rwin.setCaption(trt('Report')); this.rwin.setContent('
'+trt('Preparing_of_report')+'
'); this.appendFilter(); //Call data from server let nodeType=findFirstNode(this.nodeMetadata, "type"); let typename=nodeType.getAttribute("n"); let nodeFilter=findNodeOnPath(nodeType,"objects-list/filter"); let xs=''; xs+='\n'; xs+='\n'; xs+=' \n'; xs+=' '; let nextNode=nodeFilter.firstChild; while(nextNode!=null) { if(nextNode.nodeName=="column") { xs+=''; xs+=''; xs+='\n'; } nextNode=nextNode.nextSibling; } xs+=' \n'; xs+=' \n'; xs+=''; if(this.request.callServer(ScriptName,xs)) { this.rwin.showProgressBar(); } } chp(page) { //The current filter values are sent to the script to form a page change document.forms.filter.xml_page.value=page; document.forms.filter.submit(); } insertRecord() { let erec = new EdtRec(""); erec.opener=this; erec.eRecNo(this.nodeMetadata,-1); erec.win.setParent(this.win); if(this.onInsert!=null) this.onInsert(erec); } updateRecord(id) { if(this.f_State=="0") //editing { let erec = new EdtRec(""); erec.win.setParent(this.win); erec.opener=this; erec.eRecNo(this.nodeMetadata,id); //e.win.setLeftTop(pageX-10,pageY-10); if(this.onInsert!=null) this.onUpdate(erec); }else if(this.f_State=="1") //select one record { if(document.getElementById('Selection_'+this.uid).checked) { //this.appendFilter(); //To write filter fields in XML let filter=""; let nodeType=findFirstNode(this.nodeMetadata, "type"); let nodeFilter=findNodeOnPath(nodeType,"objects-list/filter"); if (nodeFilter!=null) { filter=getXMLNodeSerialisation(nodeFilter) } //Send the id of the selected record to the parent of the selected record and close the window //alert2(trt('Alert'),"id="+id+" f_PropName="+this.f_PropName+" f_TypeName="+this.f_TypeName); this.opener.setFilterObject(this.f_TypeName, this.f_PropName, id, filter); this.win.Close(); }else{ let erec = new EdtRec(""); erec.win.setParent(this.win); erec.opener=this; erec.eRecNo(this.nodeMetadata,id); //e.win.setLeftTop(pageX-10,pageY-10); if(this.onInsert!=null) this.onUpdate(erec); } }else if(this.f_State=="2") //Multiple choice (on the records of ticking TODO is not implemented) { } } //We run through the marked records and request their removal deleteRecord(recordid) { confirm2(trt('Warning'),trt("Are_you_sure_you_want_to_delete_the_entries")+"
",'' ,()=>{ for(let i=0;i',true)) { this.showProgressBar(); } } } } ,null); return false; } //Update HTML data after update record ApplyDelRec(node) { let nodeType=findFirstNode(node, "type"); let typeName=nodeType.getAttribute("n"); let id=nodeType.getAttribute("id"); deleteHTML(id+'_'+this.uid); //Rebuild sequential numbering of rows (first column) let theTable = document.getElementById('thetable'+this.uid); //data table for(let i=1;i
')) { this.showProgressBar(); } } } //Convert XML to array function nodeToTable(node) { let result=new Array(); let nType=findFirstNode(node, "type"); //Read name fields let nList=findFirstNode(node, "objects-list"); let cols=new Array(); let pos=0; let nCols=nList.firstChild; while(nCols != null) { if(nCols.nodeName=="column") { cols[pos]=nCols.getAttribute("n"); pos++; } nCols = nCols.nextSibling; } pos=0; //Line number let nRecord = nType.firstChild; while(nRecord != null) { if(nRecord.nodeName=="record") { result[pos]['id']=nRecord.getAttribute("id"); let i=0; //column number cdataNode = nRecord.firstChild; while (cdataNode!=null) { if(cdataNode.nodeName=="#cdata-section") { result[pos][cols[i]]=cdataNode.nodeValue; //alert2(trt('Alert'),pos+') '+cols[i]+' = '+cdataNode.nodeValue); i++; } cdataNode = cdataNode.nextSibling; } theTable.tBodies[0].appendChild(tr); } nodeRecord = nodeRecord.nextSibling; } return result; }