//OpenSCADA system module UI.WebCfgD file: VCA.js /*************************************************************************** * Copyright (C) 2008-2023 by Roman Savochenko, * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; version 2 of the License. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ //Global parameters init var MOD_ID = 'WebCfgD'; //Module identifier var stTmID = null; //Status line timer identifier var pgRefrTmID = null; //Periodic current page update timer identifier var dlgWin = null; //Opened window dialog var selPath = ''; //Selected node path var queSZ = 20; //Previous and next arrays queue size var ndPrev = new Array();//Previous nodes array var ndNext = new Array();//Next nodes array var pgInfo = document.createElement('info'); //Curent page XML tree var root = document.createElement('oscada_cntr');//Root page's node var SEC_XT = 0x01; //Extended var SEC_WR = 0x02; //Write access var SEC_RD = 0x04; //Read access var copyBuf = '0'; //Copy node address buffer var genReqs = null; //Generic request object var limTblItmCnt = 300; //Limit of the table item content var Er_NoError = 0; //Error code of no error var Er_Core_CntrWarning = 1; //Error code of warning the Control Interface //Browser type detect var isNN = navigator.appName.indexOf('Netscape') != -1; var isIE = navigator.appName.indexOf('Microsoft') != -1; var isOpera = navigator.appName.indexOf('Opera') != -1; var isKonq = navigator.userAgent.indexOf('Konqueror') != -1; var isChrome = navigator.userAgent.indexOf('Chrome') != -1; var gPrms = window.location.search || ''; /*************************************************** * strEncode - String encoding. * ***************************************************/ function strEncode( vl, tp ) { //if(!tp || tp == "html") return vl.replace(/&/g,'&').replace(/>/g,'>').replace(/': encRez += '>'; break; case '<': encRez += '<'; break; case '"': encRez += '"'; break; default: encRez += vl.charAt(iEnc); } return encRez; } /*************************************************** * pathLev - Path parsing function. * ***************************************************/ pathLev.off = 0; function pathLev( path, level, scan ) { var an_dir = scan ? pathLev.off : 0; var t_lev = 0; var t_dir; while(an_dir < path.length && path.charAt(an_dir) == '/') an_dir++; if(an_dir >= path.length) return ''; while(true) { t_dir = path.indexOf('/',an_dir); if(t_dir < 0) { pathLev.off = path.length; return (t_lev==level) ? path.substr(an_dir) : ''; } if(t_lev == level) { pathLev.off = t_dir; return path.substr(an_dir,t_dir-an_dir); } an_dir = t_dir; t_lev++; while(an_dir < path.length && path.charAt(an_dir) == '/') an_dir++; } } /***************************************************** * nodeTextByTagId - Get DOM node by tag name and id * *****************************************************/ function nodeTextByTagId( node, tag, avl ) { for(var i = 0; i < node.childNodes.length; i++) if(node.childNodes[i].nodeName == tag && node.childNodes[i].getAttribute('id') == avl) return node.childNodes[i].textContent; return null; } /*************************************************** * i2s - integer to string * ***************************************************/ function i2s( vl, base, len ) { rez = vl.toString(base); if(len) while(rez.length < len) rez = "0"+rez; return rez; } /*************************************************** * posGetX - Get absolute position * ***************************************************/ function posGetX( obj, noWScrl ) { var posX = 0; //Calc offset on blocks for(var cObj = obj; cObj != null; cObj = cObj.offsetParent) posX += cObj.offsetLeft; //Calc block's scroll if(!isOpera) for(var cObj = obj ; (cObj && cObj.nodeName != 'BODY'); cObj = cObj.parentNode) posX -= (cObj.scrollLeft?cObj.scrollLeft:0); return posX + (!noWScrl?-window.pageXOffset:0) + (isNN?5:0); } /*************************************************** * posGetY - Get absolute position * ***************************************************/ function posGetY( obj, noWScrl ) { var posY = 0; //Calc offset on blocks for(var cObj = obj; cObj != null; cObj = cObj.offsetParent) posY += cObj.offsetTop; //Calc block's scroll if(!isOpera) for(var cObj = obj ; (cObj && cObj.nodeName != 'BODY'); cObj = cObj.parentNode) posY -= (cObj.scrollTop?cObj.scrollTop:0); return posY + (!noWScrl?-window.pageYOffset:0) + (isNN?5:0); } /*************************************************** * getXmlHttp - Check and return XMLHttpRequest for* * various browsers. * ***************************************************/ function getXmlHttp( ) { if(window.XMLHttpRequest) return new XMLHttpRequest(); else if(window.ActiveXObject) { try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); } } return null; } /*************************************************** * crDoc - Create new XML document object for * * various browsers. * ***************************************************/ function crDoc( ) { var doc; if(document.implementation && document.implementation.createDocument) doc = document.implementation.createDocument("", "", null); else if(window.ActiveXObject) { for(var i = 0; i < MSXML.length; i++) try { doc = new ActiveXObject(MSXML[i]); } catch (e) { } if(!doc) { alert("Cannot create XMLDocument object"); return false; } } return doc; } /*************************************************** * realRound - Real numbers round * ***************************************************/ function realRound( val, dig, toInt ) { rez = Math.floor(val*Math.pow(10,dig?dig:0)+0.5)/Math.pow(10,dig?dig:0); if(toInt) return Math.floor(rez+0.5); return rez; } /*************************************************** * servGet - XML get request to server * ***************************************************/ function servGet( adr, prm ) { if(genReqs) { var rCom = prm.slice(4); if(genReqs.childNodes[0].getAttribute('fillMode') == '1') { var tEl = genReqs.createElement(rCom); tEl.setAttribute('path',adr); genReqs.childNodes[0].appendChild(tEl); return null; } else { var sNd = null; var c_pos = genReqs.childNodes[0].getAttribute("curPos"); if(!c_pos) c_pos = 0; for( ; c_pos < genReqs.childNodes[0].childNodes.length && !sNd; c_pos++) { var wNd = genReqs.childNodes[0].childNodes[c_pos]; if(wNd.getAttribute('path') == adr && wNd.tagName == rCom) sNd = wNd; } if(!sNd && c_pos) for(c_pos = 0; c_pos < genReqs.childNodes[0].childNodes.length && !sNd; c_pos++) { var wNd = genReqs.childNodes[0].childNodes[c_pos]; if(wNd.getAttribute('path') == adr && wNd.tagName == rCom) sNd = wNd; } if(sNd) { genReqs.childNodes[0].setAttribute('curPos',c_pos+1); return sNd; } adr = genReqs.childNodes[0].getAttribute('path')+'/'+adr; } } var req = getXmlHttp(); req.open('GET', encodeURI('/'+MOD_ID+adr+(gPrms.length?gPrms+'&':'?')+prm),false); //console.log("TEST 10: "+encodeURI('/'+MOD_ID+adr+'?'+prm)); // req.setRequestHeader('Content-Type','text/xml; charset=utf-8'); try { req.send(null); if(req.status == 200 && req.responseXML.childNodes.length) return req.responseXML.childNodes[0]; } catch(e) { window.location = '/'; } return null; } /*************************************************** * servSet - XML set request to server * ***************************************************/ function servSet( adr, prm, body, waitRez ) { var req = getXmlHttp(); req.open('POST',encodeURI('/'+MOD_ID+adr+(gPrms.length?gPrms+'&':'?')+prm),!waitRez); try { req.send(body); if(waitRez && req.status == 200 && req.responseXML.childNodes.length) return req.responseXML.childNodes[0]; } catch(e) { window.location='/'; } return null; } /*************************************************** * servReq - XML generic request to server * * body - XML document body * ***************************************************/ function servReq( body ) { var req = getXmlHttp(); req.open('POST',encodeURI('/'+MOD_ID+'/'+(gPrms.length?gPrms+'&':'?')+'com=req'),false); req.setRequestHeader("Content-Type", "application/xml;charset=UTF-8"); try { req.send(body); if(req.status == 200) return req.responseXML; } catch(e) { window.location='/'; } return null; } /*************************************************** * setStatus - Setup status message. * ***************************************************/ function setStatus( mess, tm ) { document.getElementById('status').innerText = mess ? mess : '###Ready###'; if(!mess) return; if(stTmID) clearTimeout(stTmID); if(!tm || tm > 0) stTmID = setTimeout('setStatus(null)', tm?tm:1000); } /*************************************************** * alertCntr - Control Interface specific alert. * ***************************************************/ function alertCntr( reqO ) { if(reqO) alert(reqO.getAttribute("mtxt") ? reqO.getAttribute("mtxt") : reqO.textContent); } /*************************************************** * expand - Expand/roll select subtree. * ***************************************************/ function expand( el, val, upTree ) { if(!val) { for(var i = 0; i < el.childNodes.length; i++) if(el.childNodes[i].nodeName == 'UL') { el.removeChild(el.childNodes[i]); break; } } else { var cUL = null; for(var i = 0; i < el.childNodes.length; i++) if(el.childNodes[i].nodeName == 'UL') { cUL = el.childNodes[i]; break; } if(!cUL) { cUL = document.createElement('ul'); if(el.parentNode.lastChild != el) cUL.style.backgroundImage = 'url(img_treeLine)'; el.appendChild(cUL); } if(el.grps.length > 1) { //Add and update present for(var iG = 0; iG < el.grps.length; iG++) { var liN = null; // Search present item if(upTree) for(var iIt = 0; iIt < cUL.childNodes.length; iIt++) if(cUL.childNodes[iIt].grps[0].getAttribute('id') == el.grps[iG].getAttribute('id')) { liN = cUL.childNodes[iIt]; break; } if(!liN) { liN = document.createElement('li'); if(iG >= cUL.childNodes.length) cUL.appendChild(liN); else cUL.insertBefore(liN, cUL.childNodes[iG]); liN.isExpand = false; } liN.setAttribute('id', el.getAttribute('id')); // Set group liN.grps = new Array(); liN.grps.push(el.grps[iG]); // Init links var isUsable = parseInt(liN.grps[0].getAttribute('chPresent')); var treeIco = '/'+MOD_ID+'/img_tree'+(isUsable?(liN.isExpand?'Minus':'Plus'):'')+'Up'+((iG!=(el.grps.length-1))?'Down':''); var liCont = isUsable?"":""; liCont += ""; liCont += ""+strEncode(el.grps[iG].getAttribute('dscr'))+":"; // Next node for update if(upTree && liN.isExpand) { var liNUL = null; for(var i = 0; i < liN.childNodes.length; i++) if(liN.childNodes[i].nodeName == 'UL') { liNUL = liN.childNodes[i]; break; } liN.innerHTML = liCont; if(liNUL) liN.appendChild(liNUL); expand(liN,val,upTree); } else liN.innerHTML = liCont; } //Delete no present if(upTree) for(var iIt = 0; iIt < cUL.childNodes.length; iIt++) { var iG; for(iG = 0; iG < el.grps.length; iG++) if(cUL.childNodes[iIt].grps[0].getAttribute('id') == el.grps[iG].getAttribute('id')) break; if(iG >= el.grps.length) { cUL.removeChild(cUL.childNodes[iIt]); iIt--; } } } else { var grpId = el.grps[0].getAttribute('id'); var hostN = servGet(el.getAttribute('id'),'com=chlds&grp='+grpId); if(hostN && parseInt(hostN.getAttribute('rez')) == 0) { //Add and update present for(var iE = 0; iE < hostN.childNodes.length; iE++) { var tmpNdId = el.getAttribute('id')+'/'+ (grpId+(hostN.childNodes[iE].getAttribute('id')?hostN.childNodes[iE].getAttribute('id'):hostN.childNodes[iE].textContent)); var liN = null; // Find item if(upTree) for(var iIt = 0; iIt < cUL.childNodes.length; iIt++) if(cUL.childNodes[iIt].getAttribute('id') == tmpNdId) { liN = cUL.childNodes[iIt]; break; } if(!liN) { liN = document.createElement('li'); if(iE >= cUL.childNodes.length) cUL.appendChild(liN); else cUL.insertBefore(liN, cUL.childNodes[iE]); liN.isExpand = false; } liN.setAttribute('id',tmpNdId); // Load groups liN.grps = new Array(); for(var iGrp = 0; iGrp < hostN.childNodes[iE].childNodes.length; iGrp++) if(hostN.childNodes[iE].childNodes[iGrp].nodeName == 'grp') liN.grps.push(hostN.childNodes[iE].childNodes[iGrp]); // Init links var isUsable = (liN.grps.length>1)||(liN.grps.length&&parseInt(liN.grps[0].getAttribute('chPresent'))); var treeIco = '/'+MOD_ID+'/img_tree'+(isUsable?(liN.isExpand?'Minus':'Plus'):'')+'Up'+((iE!=(hostN.childNodes.length-1))?'Down':''); var liCont = isUsable?"":""; liCont += ""; if(parseInt(hostN.childNodes[iE].getAttribute('icoSize'))) liCont += ""; //liCont += ""; liCont += ""+strEncode(hostN.childNodes[iE].textContent)+""; // Next node for update if(upTree && liN.isExpand) { var liNUL = null; for(var iEu = 0; iEu < liN.childNodes.length; iEu++) if(liN.childNodes[iEu].nodeName == 'UL') { liNUL = liN.childNodes[iEu]; break; } liN.innerHTML = liCont; if(liNUL) liN.appendChild(liNUL); expand(liN, val, upTree); } else liN.innerHTML = liCont; } //Delete no present if(upTree) for(var iIt = 0; iIt < cUL.childNodes.length; iIt++) { var iE; for(iE = 0; iE < hostN.childNodes.length; iE++) { var grpId = el.grps[0].getAttribute('id'); var tmpNdId = el.getAttribute('id')+'/'+(grpId+(hostN.childNodes[iE].getAttribute('id')?hostN.childNodes[iE].getAttribute('id'):hostN.childNodes[iE].textContent)); if(cUL.childNodes[iIt].getAttribute('id') == tmpNdId) break; } if(iE >= hostN.childNodes.length) { cUL.removeChild(cUL.childNodes[iIt]); iIt--; } } } } } if(el.isExpand != val) { //Change tree icon el.childNodes[0].childNodes[0].src = val ? el.childNodes[0].childNodes[0].src.replace('Plus','Minus') : el.childNodes[0].childNodes[0].src.replace('Minus','Plus'); el.isExpand = val; } } /*************************************************** * selectPage - Select node by user. * ***************************************************/ function selectPage( path ) { if(!path) return; //Prev and next if(selPath.length) ndPrev.push(selPath); while(ndPrev.length >= queSZ) ndPrev.shift(); ndNext = new Array(); //Page display pageDisplay(path); } /*************************************************** * pageDisplay - Display selected page. * ***************************************************/ function pageDisplay( path, isComplete ) { if(!path) return; //Chek Up actEnable('actUp', path.lastIndexOf('/') != -1 && path.lastIndexOf('/') != 0); //Check Prev and Next actEnable('actPrevious', ndPrev.length); actEnable('actNext', ndNext.length); if(path != pgInfo.getAttribute('path') || isComplete) { // Stop refresh pageCyclRefrStop(); if(selPath.length && document.getElementById(selPath)) document.getElementById(selPath).className = ''; selPath = path; document.getElementById('selPath').innerText = selPath; pgInfo = servGet(selPath, 'com=info'); if(parseInt(pgInfo.getAttribute('rez')) != Er_NoError) { alertCntr(pgInfo); return; } pgInfo.setAttribute('path', selPath); root = pgInfo.childNodes[0]; } else { // Check the new node structure and the old node var iTree = servGet(selPath,'com=info'); if(parseInt(iTree.getAttribute('rez')) != Er_NoError) { alertCntr(iTree); return; } if(chkStruct(root,iTree.childNodes[0])) { pgInfo = iTree; pgInfo.setAttribute('path',selPath); root = pgInfo.childNodes[0]; } } if(selPath.length && document.getElementById(selPath)) document.getElementById(selPath).className = 'select'; actEnable('actManual', root.getAttribute("doc")); if(root.getAttribute("doc")) actManual.setAttribute("href", servGet("/doc/"+root.getAttribute("doc").split("|")[1].replace("/","%2f")).textContent); //Complex request form and it result use genReqs = crDoc(); genReqs.appendChild(genReqs.createElement('CntrReqs')); genReqs.childNodes[0].setAttribute('path', selPath); genReqs.childNodes[0].setAttribute('fillMode', '1'); for(var genReqPrc = 0; genReqPrc < 2; genReqPrc++) { selectChildRecArea(root, '/', null); //Load and Save checking to allow var reqModif = servGet('/%2fobj', 'com=modify'); actEnable('actLoad', reqModif?parseInt(reqModif.textContent):0); actEnable('actSave', reqModif?parseInt(reqModif.textContent):0); //Send for the prepared generic request if(genReqPrc == 0) { genReqs.childNodes[0].setAttribute('fillMode', '0'); genReqs = servReq(genReqs); } } genReqs = null; //The add and the delete access allow check actEnable('actAddIt', false); for(var iCh = 0; iCh < root.childNodes.length; iCh++) if(root.childNodes[iCh].getAttribute('id') == 'br') { for(var iG = 0; iG < root.childNodes[iCh].childNodes.length; iG++) if(parseInt(root.childNodes[iCh].childNodes[iG].getAttribute('acs'))&SEC_WR) { actEnable('actAddIt',true); break; } break; } actEnable('actDelIt',parseInt(root.getAttribute('acs'))&SEC_WR) //Edit tools update editToolUpdate(); } /*************************************************** * editToolUpdate - Edit action state update. * ***************************************************/ function editToolUpdate( ) { rootAccess = root.getAttribute('acs') ? parseInt(root.getAttribute('acs')) : 0; actEnable('actCut', (selPath.length && (rootAccess&SEC_WR))); actEnable('actCopy', (rootAccess>>3)?((rootAccess>>3)&SEC_WR):selPath.length); actEnable('actPaste', false); //Src and destination elements calc if(copyBuf.length <= 1 /*|| copyBuf.substr(1) == selPath || pathLev(copyBuf.substr(1),0) != pathLev(selPath,0)*/) return; var sElp; var sEl; var tEl; pathLev.off = 0; while((tEl=pathLev(copyBuf.substr(1),0,true)).length) { sElp += ('/'+sEl); sEl = tEl; } for(var iCh = 0; iCh < root.childNodes.length; iCh++) if(root.childNodes[iCh].getAttribute('id') == 'br') { for(var iG = 0; iG < root.childNodes[iCh].childNodes.length; iG++) if(parseInt(root.childNodes[iCh].childNodes[iG].getAttribute('acs'))&SEC_WR) { actEnable('actPaste',true); break; } break; } if(rootAccess&SEC_WR) actEnable('actPaste',true); } /*************************************************** * selectChildRecArea - Make page content * ***************************************************/ function selectChildRecArea( node, aPath, cBlk ) { var iArea = 0; //View title name if(aPath == "/") { // Set node icon if(nodeTextByTagId(node,'img','ico') != null) { document.getElementById('pgIco').src = '/'+MOD_ID+selPath+'?com=ico&size=32'; document.getElementById('pgIco').style.visibility = 'visible'; } else document.getElementById('pgIco').style.visibility = 'hidden'; // Set title document.getElementById('pgTitle').innerText = node.getAttribute('dscr'); // Delete tabs of deleted areas var activeTab = null; var tabs = document.getElementById('pgTabs'); for(var iTbs = 0; iTbs < tabs.childNodes.length; iTbs++) { var iCf; for(iCf = 0; iCf < node.childNodes.length; iCf++) if(node.childNodes[iCf].nodeName.toLowerCase() == 'area' && tabs.childNodes[iTbs].innerText == node.childNodes[iCf].getAttribute('dscr')) break; if(iCf >= node.childNodes.length) { tabs.removeChild(tabs.childNodes[iTbs]); iTbs--; } else if(tabs.childNodes[iTbs].className == 'active') activeTab = tabs.childNodes[iTbs]; } // Add new tabs for(var iCf = 0; iCf < node.childNodes.length; iCf++) { if(node.childNodes[iCf].nodeName.toLowerCase() != 'area') continue; var iTbs; for(iTbs = 0; iTbs < tabs.childNodes.length; iTbs++) if(tabs.childNodes[iTbs].innerText == node.childNodes[iCf].getAttribute('dscr')) break; if(iTbs >= tabs.childNodes.length) { var itab = document.createElement('span'); itab.innerText = node.childNodes[iCf].getAttribute('dscr'); itab.onclick = function( ) { tabSelect(this); return false; } if(iArea >= tabs.childNodes.length) tabs.appendChild(itab); else tabs.insertBefore(itab,tabs.childNodes[iArea]); node.childNodes[iCf].setAttribute('qview','0'); } iArea++; } if(!activeTab && tabs.childNodes.length) { activeTab = tabs.childNodes[0]; activeTab.className = 'active'; } // Preparing of the active tab for(var iCf = 0; iCf < node.childNodes.length; iCf++) if(node.childNodes[iCf].nodeName.toLowerCase() == 'area' && activeTab.innerText == node.childNodes[iCf].getAttribute('dscr')) { var refresh = parseInt(node.childNodes[iCf].getAttribute('qview')); var cPg = document.getElementById('pgCont'); if(!refresh) { while(cPg.childNodes.length) cPg.removeChild(cPg.childNodes[0]); selectChildRecArea(node.childNodes[iCf],aPath+node.childNodes[iCf].getAttribute('id')+'/',cPg); // Mark last drawed tabs node.childNodes[iCf].setAttribute('qview','1'); } else selectChildRecArea(node.childNodes[iCf],aPath+node.childNodes[iCf].getAttribute('id')+'/',null); // Elements of scalable by vertical get and their grow up to the scroll appear in the container scrlArea = document.getElementById('gen-pnl-right'); sclIts = document.querySelectorAll(".elem textarea, .elem div.table, .elem select.list"); sclFitSz = scrlArea.clientHeight-scrlArea.children[0].offsetHeight; for(fitStp = Math.max(5,sclFitSz/(10*Math.max(1,sclIts.length))), iScN = 0; sclFitSz > fitStp; ) { sclIt = null; sclFromBeg = (iScN == 0); for( ; iScN < sclIts.length && !sclIt; iScN++) { if(sclIts[iScN].scrollHeight <= sclIts[iScN].clientHeight) continue; sclIt = sclIts[iScN]; sclIt.style.height = (sclIt.offsetHeight-((sclIt.nodeName=="SELECT")?0:getSpareHeight(sclIt))+fitStp)+'px'; sclFitSz -= fitStp; } if(!sclIt && sclFromBeg) break; if(iScN && iScN >= sclIts.length) iScN = 0; } } return; } else for(var iCf = 0; iCf < node.childNodes.length; iCf++) { var t_s = node.childNodes[iCf]; // Check access to node var wr = parseInt(t_s.getAttribute('acs'))&SEC_WR; // View areas if(t_s.nodeName.toLowerCase() == 'area') { var cntBlk = cBlk; if(cntBlk) { var cntBlk = document.createElement('fieldset'); cntBlk.className = 'elem'; cntBlk.appendChild(document.createElement('legend')); cntBlk.childNodes[0].appendChild(document.createTextNode(t_s.getAttribute('dscr'))); cBlk.appendChild(cntBlk); } selectChildRecArea(t_s,aPath+t_s.getAttribute('id')+'/',cntBlk); } // View list elements else if(t_s.nodeName.toLowerCase() == 'list') { var brPath = (aPath+t_s.getAttribute('id')).replace(/%/g,'%25').replace(/\//g,'%2f'); var lab = null; var val = null; if(cBlk) { var dBlk = document.createElement('div'); dBlk.className = 'elem'; lab = document.createElement('span'); lab.className = 'label'; dBlk.appendChild(lab); dBlk.appendChild(document.createElement('br')); val = document.createElement('select'); val.className = 'list'; val.size = 3;//10; val.srcNode = t_s; val.itPath = selPath+'/'+brPath; val.onmouseover = function() { setStatus(this.itPath,10000); } val.onclick = function(e) { e = e ? e : window.event; var popUpMenu = getPopup(); var optEl = ''; selOK = (this.selectedIndex >= 0 && this.options[this.selectedIndex].label); if(this.srcNode.getAttribute('tp') == 'br' && selOK) optEl += ""; if((parseInt(this.srcNode.getAttribute('acs'))&SEC_WR) && this.srcNode.getAttribute('s_com')) { if(this.srcNode.getAttribute('s_com').search('add') != -1) optEl += ""; if(this.srcNode.getAttribute('s_com').search('ins') != -1 && selOK) optEl += ""; if(this.srcNode.getAttribute('s_com').search('edit') != -1 && selOK) optEl += ""; if(this.srcNode.getAttribute('s_com').search('del') != -1 && selOK) optEl += ""; if(this.srcNode.getAttribute('s_com').search('move') != -1 && selOK) optEl += ""; } popUpMenu.childNodes[0].innerHTML = optEl; if(popUpMenu.childNodes[0].childNodes.length) { popUpMenu.srcNode = this.srcNode; popUpMenu.itPath = this.itPath; if(this.selectedIndex >= 0) { popUpMenu.lsId = this.options[this.selectedIndex].lsId; popUpMenu.lsText = this.options[this.selectedIndex].value; if(!popUpMenu.lsId) popUpMenu.lsId = popUpMenu.lsText; } popUpMenu.childNodes[0].size = Math.max(3,popUpMenu.childNodes[0].childNodes.length); popUpMenu.style.cssText = 'visibility: visible; left: '+(e.clientX+window.pageXOffset)+'px; top: '+(e.clientY+window.pageYOffset)+'px;'; popUpMenu.childNodes[0].focus(); popUpMenu.childNodes[0].selectedIndex = -1; popUpMenu.childNodes[0].onclick = function() { this.parentNode.style.cssText = 'visibility: hidden; left: -200px; top: -200px;'; if(this.selectedIndex < 0 || !this.options[this.selectedIndex].getAttribute('posId')) return; var idm = parseInt(this.parentNode.srcNode.getAttribute('idm')); var posId = this.options[this.selectedIndex].getAttribute('posId'); if(posId == 'go') selectPage(selPath+'/'+(this.parentNode.srcNode.getAttribute('br_pref')+this.parentNode.lsId).replace(/%/g,'%25').replace(/\//g,'%2f')); else if(posId == 'add' || posId == 'ins' || posId == 'edit') { dlgWin = ReqIdNameDlg('/'+MOD_ID+'/ico'); dlgWin.document.getElementById('wDlgHeader').innerText = '###Setting item name###'; var idSz = parseInt(this.parentNode.srcNode.getAttribute('idSz')); dlgWin.document.getElementById('wDlgId').childNodes[1].childNodes[0].maxLength = ((idSz > 0) ? idSz : 1000); dlgWin.document.getElementById('wDlgType').style.display = 'none'; dlgWin.document.getElementById('wDlgName').style.display = idm ? '' : 'none'; dlgWin.document.getElementById('wDlgName').childNodes[1].childNodes[0].maxLength = ((idm > 1) ? idm : 1000); var actOkFld = dlgWin.document.getElementById('wDlgActOk'); actOkFld.itPath = this.parentNode.itPath; actOkFld.srcNode = this.parentNode.srcNode; actOkFld.selectedIndex = this.selectedIndex; actOkFld.lsId = this.parentNode.lsId; actOkFld.lsText = this.parentNode.lsText; if(posId == 'add') { dlgWin.document.getElementById('wDlgTitle').childNodes[1].innerText = '###Adding an element.###'; actOkFld.onclick = function() { var idm = dlgWin.document.getElementById('wDlgName').style.display!='none'; var inpId = dlgWin.document.getElementById('wDlgId').childNodes[1].childNodes[0].value; var inpName = idm ? dlgWin.document.getElementById('wDlgName').childNodes[1].childNodes[0].value : inpId; var rez = servSet(this.itPath,'com=com',""+inpName+"",true); if(rez && parseInt(rez.getAttribute('rez')) != Er_NoError) alertCntr(rez); if(this.srcNode.getAttribute('tp') == 'br') treeUpdate(); pageRefresh(); document.body.dlgWin.close(); return false; } } else if(posId == 'ins') { dlgWin.document.getElementById('wDlgTitle').childNodes[1].innerText = '###Inserting an element.###'; actOkFld.onclick = function() { var idm = dlgWin.document.getElementById('wDlgName').style.display!='none'; var inpId = dlgWin.document.getElementById('wDlgId').childNodes[1].childNodes[0].value; var inpName = idm ? dlgWin.document.getElementById('wDlgName').childNodes[1].childNodes[0].value : inpId; var com = ""+inpName+""; var rez = servSet(this.itPath,'com=com',com,true); if(rez && parseInt(rez.getAttribute('rez')) != Er_NoError) alertCntr(rez); if(this.srcNode.getAttribute('tp') == 'br') treeUpdate(); pageRefresh(); document.body.dlgWin.close(); return false; } } else if(posId == 'edit') { dlgWin.document.getElementById('wDlgTitle').childNodes[1].innerText = '###Renaming the element.###'; dlgWin.document.getElementById('wDlgId').childNodes[1].childNodes[0].value = idm ? this.parentNode.lsId : this.parentNode.lsText; if(idm) dlgWin.document.getElementById('wDlgName').childNodes[1].childNodes[0].value = this.parentNode.lsText; actOkFld.onclick = function() { var idm = dlgWin.document.getElementById('wDlgName').style.display!='none'; var inpId = dlgWin.document.getElementById('wDlgId').childNodes[1].childNodes[0].value; var inpName = idm ? dlgWin.document.getElementById('wDlgName').childNodes[1].childNodes[0].value : inpId; var com = ""+inpName+""; var rez = servSet(this.itPath,'com=com',com,true); if(rez && parseInt(rez.getAttribute('rez')) != Er_NoError) alertCntr(rez); if(this.srcNode.getAttribute('tp') == 'br') treeUpdate(); pageRefresh(); document.body.dlgWin.close(); return false; } } } else if(posId == 'up' || posId == 'down') { var c_new = (posId == 'down') ? c_new = this.selectedIndex+1 : this.selectedIndex-1; var rez = servSet(this.parentNode.itPath,'com=com',"",true); if(rez && parseInt(rez.getAttribute('rez')) != Er_NoError) alertCntr(rez); pageRefresh(); } else if(posId == 'del') { var com = idm ? ("") : (""+this.parentNode.lsText+""); var rez = servSet(this.parentNode.itPath,'com=com',com,true); if(rez && parseInt(rez.getAttribute('rez')) != Er_NoError) alertCntr(rez); if(this.parentNode.srcNode.getAttribute('tp') == 'br') treeUpdate(); pageRefresh(); } return false; } } return false; } dBlk.appendChild(val); cBlk.appendChild(dBlk); t_s.addr_lab = lab; t_s.addr_val = val; } else { lab = t_s.addr_lab; val = t_s.addr_val; } // Fill list lab.innerText = t_s.getAttribute('dscr') + ': '; val.title = (tVl=t_s.getAttribute('help')) ? tVl : ""; while(val.childNodes.length) val.removeChild(val.childNodes[0]); var dataReq = servGet(brPath,'com=get'); if(!dataReq) continue; if((rezCod=parseInt(dataReq.getAttribute('rez'))) != Er_NoError) { alertCntr(dataReq); if(rezCod != Er_Core_CntrWarning) continue; } for(var iEl = 0; iEl < dataReq.childNodes.length; iEl++) if(dataReq.childNodes[iEl].nodeName.toLowerCase() == 'el') { var opt = document.createElement('option'); opt.lsId = dataReq.childNodes[iEl].getAttribute('id'); opt.innerText = dataReq.childNodes[iEl].textContent; val.appendChild(opt); } while(val.childNodes.length < 3) { var opt = document.createElement('option'); //opt.disabled = true; val.appendChild(opt); } val.size = 3; //Math.min(10,Math.max(4,val.childNodes.length)); } // View images else if(t_s.nodeName.toLowerCase() == "img") { var brPath = (aPath+t_s.getAttribute('id')).replace(/%/g,'%25').replace(/\//g,'%2f').replace(/%/g,'%25'); var lab = null; var val = null; if(cBlk) { var dBlk = document.createElement('div'); dBlk.className = 'elem'; lab = document.createElement('span'); lab.className = 'label'; dBlk.appendChild(lab); if(!t_s.getAttribute("v_sz") || parseInt(t_s.getAttribute("v_sz")) > 70) dBlk.appendChild(document.createElement('br')); val = document.createElement('img'); val.className = 'picture'; if(t_s.getAttribute('h_sz')) val.style.width = t_s.getAttribute('h_sz')+'px'; if(t_s.getAttribute("v_sz")) val.style.height = t_s.getAttribute("v_sz")+'px'; val.itPath = selPath+'/'+brPath; val.onmouseover = function( ) { setStatus(this.itPath,10000); } if(wr) { val.style.cursor = 'pointer'; val.onclick = function( ) { dlgWin = ReqIdNameDlg('/'+MOD_ID+'/img_save','###Selecting an image file for download to the picture field.###','/'+MOD_ID+this.itPath+'?com=img',true); dlgWin.document.getElementById('wDlgHeader').innerText = '###Setting an image###'; dlgWin.document.getElementById('wDlgType').style.display = 'none'; dlgWin.document.getElementById('wDlgId').style.display = 'none'; dlgWin.document.getElementById('wDlgName').style.display = ''; dlgWin.document.getElementById('wDlgActOk').type = 'submit'; if(!isKonq) dlgWin.document.getElementById('wDlgFormBlk').onsubmit = function( ) { setTimeout('document.body.dlgWin.close(); pageRefresh();',200); } else dlgWin.document.getElementById('wDlgActCancel').onclick = function( ) { setTimeout('document.body.dlgWin.close(); pageRefresh();',200); } return false; } } dBlk.appendChild(val); cBlk.appendChild(dBlk); t_s.addr_lab = lab; t_s.addr_val = val; } else { lab = t_s.addr_lab; val = t_s.addr_val; } // Set image if(lab) lab.innerText = t_s.getAttribute('dscr') + ':'; if(val) { val.title = (tVl=t_s.getAttribute('help')) ? tVl : ""; val.src = '/'+MOD_ID+selPath+'/'+brPath+'?com=img&rnd='+Math.floor(Math.random()*1000); } } else if(t_s.nodeName.toLowerCase() == 'table') { var brPath = (aPath+t_s.getAttribute('id')).replace(/%/g,'%25').replace(/\//g,'%2f'); var lab = null; var table = null; if(cBlk) { var dBlk = document.createElement('div'); dBlk.className = 'elem'; lab = document.createElement('span'); lab.className = 'label'; dBlk.appendChild(lab); dBlk.appendChild(document.createElement('div')); dBlk.childNodes[1].className = 'table'; dBlk.childNodes[1].style.width = (document.getElementById('pgCont').clientWidth-40)+'px'; table = document.createElement('table'); table.className = 'elem'; table.cellPadding = 2; table.cellSpacing = 0; table.itPath = selPath+'/'+brPath; table.onmouseover = function() { setStatus(this.itPath,10000); } if(wr) { table.srcNode = t_s; table.comSet = function(row, col, val) { var com = ""; var rez = servSet(this.itPath, 'com=com', com, true); if(rez && parseInt(rez.getAttribute('rez')) != Er_NoError) alertCntr(rez); else this.srcNode.childNodes[col].childNodes[row].innerText = val; if(!parseInt(rez.getAttribute('noReload'))) setTimeout('pageRefresh()', 500); else this.setElements(true); } } dBlk.childNodes[1].appendChild(table); cBlk.appendChild(dBlk); table.setElements = function( saveCh ) { for(var iCol = 0; iCol < this.srcNode.childNodes.length; iCol++) { var prcCol = this.srcNode.childNodes[iCol]; this.childNodes[0].childNodes[iCol+1].innerText = prcCol.getAttribute('dscr'); for(var iRow = 0; iRow < prcCol.childNodes.length; iRow++) { var tblCell = this.childNodes[iRow+1].childNodes[iCol+1]; // The list processingLoad selected list var ind_ls = new Array(); var val_ls = new Array(); var isSel = false; var isLocSel = false; if((isLocSel=(prcCol.childNodes[iRow].getAttribute('dest') == 'select' || prcCol.childNodes[iRow].getAttribute('dest') == 'sel_ed')) || prcCol.getAttribute('dest') == 'select' || prcCol.getAttribute('dest') == 'sel_ed') { isSel = true; var selO = isLocSel ? prcCol.childNodes[iRow] : prcCol; if(isLocSel || !prcCol.val_ls) { if(!selO.getAttribute('select')) { if(selO.getAttribute('sel_id')) ind_ls = selO.getAttribute('sel_id').split(';'); val_ls = selO.getAttribute('sel_list').split(';'); } else { var xLst = servGet((genReqs?'':selPath+'/')+selO.getAttribute('select').replace(/%/g,'%25').replace(/\//g,'%2f'),'com=get'); for(var iEl = 0; xLst && iEl < xLst.childNodes.length; iEl++) { if(xLst.childNodes[iEl].nodeName.toLowerCase() != 'el') continue; if(xLst.childNodes[iEl].getAttribute('id')) ind_ls.push(xLst.childNodes[iEl].getAttribute('id')); val_ls.push(xLst.childNodes[iEl].textContent); } } if(!prcCol.val_ls) prcCol.val_ls = val_ls, prcCol.ind_ls = ind_ls; } if(!isLocSel) val_ls = prcCol.val_ls, ind_ls = prcCol.ind_ls; else selO.val_ls = val_ls, selO.ind_ls = ind_ls; } // The item data if(tblCell.isEnter && tblCell.childNodes.length && saveCh) prcCol.childNodes[iRow].textContent = tblCell.childNodes[0].value; var cval = prcCol.childNodes[iRow].textContent; tblCell.isEdited = false; tblCell.cRow = iRow; tblCell.cCol = iCol; if(tblCell.isEnter) while(tblCell.childNodes.length) tblCell.removeChild(tblCell.lastChild); tblCell.isEnter = this.isEnter = false; tblCell.className = ""; if(prcCol.getAttribute('tp') == 'bool') { //tblCell.innerText = parseInt(cval) ? 'On' : 'Off'; //tblCell.style.fontWeight = parseInt(cval)?'bold':'normal'; tblCell.innerHTML = parseInt(cval) ? " " : ''; } else if(isSel) { tblCell.innerText = cval; for(var iEl = 0; iEl < val_ls.length; iEl++) if((ind_ls.length && ind_ls[iEl] == cval) || (!ind_ls.length && val_ls[iEl] == cval)) tblCell.innerText = val_ls[iEl]; } else if(prcCol.getAttribute('tp') == 'time') { var dt = new Date(parseInt(cval)*1000); tblCell.innerText = i2s(dt.getDate(),10,2)+'.'+i2s(dt.getMonth()+1,10,2)+'.'+i2s(dt.getFullYear(),10,4)+ ' '+i2s(dt.getHours(),10,2)+':'+i2s(dt.getMinutes(),10,2)+':'+i2s(dt.getSeconds(),10,2); } else { if(prcCol.getAttribute('tp') == 'hex') cval = '0x'+parseInt(cval).toString(16); else if(prcCol.getAttribute('tp') == 'oct') cval = '0'+parseInt(cval).toString(8); if(cval.length <= limTblItmCnt) tblCell.innerText = cval; else tblCell.innerText = cval.slice(0,limTblItmCnt) + "..."; } } } return false; } t_s.addr_lab = lab; t_s.addr_tbl = table; } else { table = t_s.addr_tbl; lab = t_s.addr_lab; } // Fill the table if(lab) lab.innerText = t_s.getAttribute('dscr') + ':'; if(table) { table.title = (tVl=t_s.getAttribute('help')) ? tVl : ""; var dataReq = servGet(brPath,'com=get'); if(dataReq && (rezCod=parseInt(dataReq.getAttribute('rez'))) != Er_NoError) { alertCntr(dataReq); if(rezCod != Er_Core_CntrWarning) continue; } // Copy values to the info tree for(var iCl = 0; dataReq && iCl < dataReq.childNodes.length; iCl++) { var iCli; for(iCli = 0; iCli < t_s.childNodes.length; iCli++) if(dataReq.childNodes[iCl].getAttribute('id') == t_s.childNodes[iCli].getAttribute('id')) break; if(iCli == t_s.childNodes.length) { var el = t_s.ownerDocument.createElement(dataReq.childNodes[iCl].nodeName); for(var i_a = 0; i_a < dataReq.childNodes[iCl].attributes.length; i_a++) el.setAttribute(dataReq.childNodes[iCl].attributes[i_a].name,dataReq.childNodes[iCl].attributes[i_a].value); t_s.appendChild(el); } while(t_s.childNodes[iCli].lastChild) t_s.childNodes[iCli].removeChild(t_s.childNodes[iCli].lastChild); for(var iRw = 0; iRw < dataReq.childNodes[iCl].childNodes.length; iRw++) { var el = t_s.ownerDocument.createElement(dataReq.childNodes[iCl].childNodes[iRw].nodeName); var dO = dataReq.childNodes[iCl].childNodes[iRw]; el.textContent = dO.textContent; for(iA = 0; iA < dO.attributes.length; iA++) el.setAttribute(dO.attributes[iA].name, dO.attributes[iA].value); t_s.childNodes[iCli].appendChild(el); } } // Calc rows and columns var nCol = t_s.childNodes.length; var nRow = nCol ? t_s.childNodes[0].childNodes.length : 0; // Update table structure while(table.childNodes.length > (nRow+1)) table.removeChild(table.lastChild); while(table.childNodes.length < (nRow+1)) table.appendChild(document.createElement('tr')); for(var iRw = 0; iRw < table.childNodes.length; iRw++) { while(table.childNodes[iRw].childNodes.length > (nCol+1)) table.childNodes[iRw].removeChild(table.childNodes[iRw].lastChild); while(table.childNodes[iRw].childNodes.length < (nCol+1)) { if(!table.childNodes[iRw].childNodes.length) { var cCell = document.createElement('th'); if(wr && t_s.getAttribute('s_com')) { cCell.style.cursor = 'pointer'; cCell.srcNode = t_s; cCell.onclick = function(e) { var rowP = parseInt(this.innerText); if(!e) e = window.event; var popUpMenu = getPopup(); var optEl = ''; var coms = this.srcNode.getAttribute('s_com').split(','); for(var iCom = 0; iCom < coms.length; iCom++) if((tVl=coms[iCom].split(":"))[0] == 'add') optEl += ""; else if(tVl[0] == 'ins') { if(!rowP) continue; optEl += ""; } else if(tVl[0] == 'del') { if(!rowP) continue; optEl += ""; } else if(tVl[0] == 'move') { if(!rowP) continue; optEl += ""; } // User commands else optEl += ""; popUpMenu.childNodes[0].innerHTML = optEl; if(popUpMenu.childNodes[0].childNodes.length) { popUpMenu.childNodes[0].srcNode = this.srcNode; popUpMenu.childNodes[0].itPath = this.parentNode.parentNode.itPath; popUpMenu.childNodes[0].rowP = rowP-1; popUpMenu.childNodes[0].size = Math.max(3,popUpMenu.childNodes[0].childNodes.length); popUpMenu.style.cssText = 'visibility: visible; left: '+(e.clientX+window.pageXOffset)+'px; top: '+(e.clientY+window.pageYOffset)+'px;'; popUpMenu.childNodes[0].focus(); popUpMenu.childNodes[0].selectedIndex = -1; popUpMenu.childNodes[0].onclick = function( ) { this.parentNode.style.cssText = 'visibility: hidden; left: -200px; top: -200px;'; if(this.selectedIndex < 0 || !this.options[this.selectedIndex].getAttribute('posId')) return; var posId = this.options[this.selectedIndex].getAttribute('posId'); var com = ''; if(posId == 'add') com = ""; else if(posId == 'ins') com = ""; else if(posId == 'up') com = ""; else if(posId == 'down') com = ""; else { var com; if(posId == 'del') com = ""+strEncode(selO.val_ls[iEl])+""; if((selO.ind_ls.length && selO.ind_ls[iEl] == cval) || (!selO.ind_ls.length && selO.val_ls[iEl] == cval)) sel_ok = true; } if(!sel_ok) valWCfg += ""; this.firstChild.innerHTML = valWCfg; } else if(prcCol.getAttribute('tp') == 'time') { this.apply = function( ) { var dt = new Date(0); dt.setDate(parseInt(this.childNodes[0].value)); dt.setMonth(parseInt(this.childNodes[1].value)-1); dt.setFullYear(parseInt(this.childNodes[2].value)); dt.setHours(parseInt(this.childNodes[4].value)); dt.setMinutes(parseInt(this.childNodes[5].value)); dt.setSeconds(parseInt(this.childNodes[6].value)); this.parentNode.parentNode.comSet(this.cRow,this.cCol,Math.floor(dt.getTime()/1000)); return false; } this.innerHTML = " "; this.childNodes[0].onkeyup = this.childNodes[1].onkeyup = this.childNodes[2].onkeyup = this.childNodes[4].onkeyup = this.childNodes[5].onkeyup = this.childNodes[6].onkeyup = function(e) { if(!e) e = window.event; if(e.keyCode == 13) { this.parentNode.apply(); return true; } if(e.keyCode == 27) { var val_w = this.parentNode; for(var iCh = 0; iCh < val_w.childNodes.length; iCh++) if(val_w.childNodes[iCh].defaultValue) val_w.childNodes[iCh].value = val_w.childNodes[iCh].defaultValue; val_w.removeChild(this.parentNode.childNodes[7]); return true; } return true; } var dt = new Date(parseInt(cval)*1000); this.childNodes[0].value = this.childNodes[0].defaultValue = dt.getDate(); this.childNodes[1].value = this.childNodes[1].defaultValue = dt.getMonth()+1; this.childNodes[2].value = this.childNodes[2].defaultValue = dt.getFullYear(); this.childNodes[4].value = this.childNodes[4].defaultValue = dt.getHours(); this.childNodes[5].value = this.childNodes[5].defaultValue = dt.getMinutes(); this.childNodes[6].value = this.childNodes[6].defaultValue = dt.getSeconds(); this.isEdited = false; } else { if(prcCol.getAttribute('tp') == 'hex') cval = '0x'+parseInt(cval).toString(16); else if(prcCol.getAttribute('tp') == 'oct') cval = '0'+parseInt(cval).toString(8); this.innerHTML = ""; var tp = prcCol.getAttribute('tp'); if(prcCol.getAttribute('dest') == 'sel_ed') { this.childNodes[0].size = 20; var cmbImg = document.createElement('img'); cmbImg.src = '/'+MOD_ID+'/img_combar'; cmbImg.onclick = function( ) { if(!this.parentNode.val_ls || !this.parentNode.val_ls.length) return false; var combMenu = getCombo(); var optHTML = ''; for(var iL = 0; iL < this.parentNode.val_ls.length; iL++) optHTML += ''; var edFld = this.parentNode.childNodes[0]; combMenu.childNodes[0].edFld = edFld; combMenu.childNodes[0].innerHTML = optHTML; combMenu.childNodes[0].size = Math.max(3,this.parentNode.val_ls.length); combMenu.style.cssText = 'visibility: visible; left: '+posGetX(edFld,true)+'px; '+ 'top: '+(posGetY(edFld,true)+edFld.offsetHeight)+'px; '+ 'width: '+edFld.offsetWidth+'px'; combMenu.childNodes[0].focus(); combMenu.childNodes[0].onclick = function() { this.parentNode.style.cssText = 'visibility: hidden; left: -200px; top: -200px;'; if(this.selectedIndex < 0) return; this.edFld.value = this.options[this.selectedIndex].value; this.edFld.parentNode.parentNode.parentNode.comSet(this.edFld.parentNode.cRow,this.edFld.parentNode.cCol,this.edFld.value); return false; } return false; } tblCell.appendChild(cmbImg); } else if(tp == 'dec') { this.className += ' number'; this.childNodes[0].size = 10; } else if(tp == 'hex' || tp == 'oct' || tp == 'real') { this.className += ' number'; this.childNodes[0].size = 10; } else this.innerHTML = "