/* Product Name: dhtmlxSuite Version: 5.2.0 Edition: Professional License: content of this file is covered by DHTMLX Commercial or Enterprise license. Usage without proper license is prohibited. To obtain it contact sales@dhtmlx.com Copyright UAB Dinamenta http://www.dhtmlx.com */ /** * @desc: switch current row state (collapse/expand) tree grid row * @param: obj - row object * @type: private */ dhtmlXGridObject.prototype._updateTGRState=function(z){ if (!z.update || z.id==0) return; if (this.rowsAr[z.id].imgTag) this.rowsAr[z.id].imgTag.src=this.iconTree+z.state+".gif"; z.update=false; } dhtmlXGridObject.prototype.doExpand=function(obj){ this.editStop(); var row = obj.parentNode.parentNode.parentNode; var r=this._h2.get[row.idd]; if (!this.callEvent("onOpen",[row.idd,(r.state=="plus"?-1:1)])) return; if(r.state=="plus") this.expandKids(row) else if((r.state=="minus")&&(!r._closeable)) this.collapseKids(row) } dhtmlXGridObject.prototype._createHierarchy=function(){ if (!this._emptyLineImg) this._emptyLineImg = "blank"; return new dhtmlxHierarchy({ _emptyLineImg : this._emptyLineImg }); } function dhtmlxHierarchy(config){ var z={id:0, childs:[], level:-1, parent:null, index:0, state:config._emptyLineImg}; this.order=[z]; this.get={"0":z}; this.swap=function(a,b){ var p=a.parent; var z=a.index; p.childs[z]=b; p.childs[b.index]=a; a.index=b.index; b.index=z; } this.forEachChildF=function(id,funct,that,funct2){ var z=this.get[id]; for (var i=0; i"; this.er.childNodes[0].onmousedown = function(e){(e||event).cancelBubble = true} this.er.childNodes[0].onselectstart=function(e){ if (!e) e=event; e.cancelBubble=true; return true; }; this.er.className+=" editable"; this.er.firstChild.onclick = function(e){(e||event).cancelBubble = true}; this.er.firstChild.value=this.val; this.obj=this.er.firstChild; this.er.firstChild.style.width=Math.max(0,this.cell.offsetWidth-this.er.offsetLeft-2)+"px"; this.er.firstChild.focus(); if (_isIE) this.er.firstChild.focus(); } this.detach = function(){ if (!this.er) return; this.setLabel(this.er.firstChild.value); this.er.className=this.er.className.replace("editable",""); var z=(this.val!=this.er.innerHTML); this.obj=this.er=null; return (z); } this.getValue = function(){ return this.getLabel(); } /** * @desc: get image of treegrid item * @param: content - new text of label * @type: private */ this.setImage = function(url){ this.cell.parentNode.imgTag.nextSibling.src=this.grid.iconURL+url; this.grid._h2.get[this.cell.parentNode.idd].image=url; } this.setIcon = function(icon){ this.grid._h2.get[this.cell.parentNode.idd].icon = icon; this.cell.parentNode.imgTag.nextSibling.className = "dhx_treegrid_icon fa fa-"+icon; } /** * @desc: set image of treegrid item * @param: content - new text of label * @type: private */ this.getImage = function(){ return this.grid._h2.get[this.cell.parentNode.idd].image; } this.getIcon = function(){ return this.grid._h2.get[this.cell.parentNode.idd].icon; } /** * @desc: sets text representation of cell ( setLabel doesn't triger math calculations as setValue do) * @param: val - new value * @type: public */ this.setLabel = function(val){ this.setValueA(val); } /** * @desc: sets text representation of cell ( setLabel doesn't triger math calculations as setValue do) * @param: val - new value * @type: public */ this.getLabel = function(val){ return this.cell.parentNode.valTag.innerHTML; } } /** * @desc: set value of grid item * @param: val - new value (for treegrid this method only used while adding new rows) * @type: private */ eXcell_tree.prototype = new eXcell; /** * @desc: set label of treegrid item * @param: content - new text of label * @type: private */ eXcell_tree.prototype.setValueA = function(content){ this.cell.parentNode.valTag.innerHTML=content; this.grid.callEvent("onCellChanged",[this.cell.parentNode.idd,this.cell._cellIndex,content]) } eXcell_tree.prototype.setValue = function(valAr){ if (this.cell.parentNode.imgTag) return this.setLabel(valAr); if ((this.grid._tgc.iconTree==null)||(this.grid._tgc.iconTree!=this.grid.iconTree)){ var _tgc={}; _tgc.spacer=""; _tgc.imst="" _tgc.plus=_tgc.imst+"plus.gif"+_tgc.imact; _tgc.minus=_tgc.imst+"minus.gif"+_tgc.imact; _tgc.blank=_tgc.imst+"blank.gif"+_tgc.imact; _tgc.start="
"; _tgc.itemim="' align='top' "+(this.grid._img_height?(" height=\""+this.grid._img_height+"\""):"")+(this.grid._img_width?(" width=\""+this.grid._img_width+"\""):"")+" >"; _tgc.itemne=""; _tgc.close="
"; this.grid._tgc=_tgc; } var _h2=this.grid._h2; var _tgc=this.grid._tgc; var rid=this.cell.parentNode.idd; var row=this.grid._h2.get[rid]; if (this.grid.kidsXmlFile || this.grid._slowParse) { row.has_kids=(row.has_kids||(this.cell.parentNode._attrs["xmlkids"]&&(row.state!="minus"))); row._xml_await=!!row.has_kids; } row.image=row.image||(this.cell._attrs["image"]||"leaf.gif"); row.icon=row.icon||(this.cell._attrs["icon"]||(this.grid.iconset?"file-o":"")); row.label=valAr; var html=[_tgc.start]; for(var i=0;i"); } html.push(_tgc.itemne); html.push(row.label); html.push(_tgc.close); this.cell.innerHTML=html.join(""); this.cell._treeCell=true; this.cell.parentNode.imgTag=this.cell.childNodes[0].childNodes[row.level]; this.cell.parentNode.valTag=this.cell.childNodes[0].childNodes[row.level+2]; if (_isKHTML) this.cell.vAlign="top"; if (row.parent.id!=0 && row.parent.state=="plus") { this.grid._updateTGRState(row.parent,false); this.cell.parentNode._skipInsert=true; } this.grid.callEvent("onCellChanged",[rid,this.cell._cellIndex,valAr]); } dhtmlXGridObject.prototype._process_tree_xml=function(top,pid){ this._parsing=true; var main=false; if (!pid){ this.render_row=this.render_row_tree; main=true; pid=top.getAttribute("parent")||0; if (pid=="0") pid=0; if (!this._h2) this._h2= this._createHierarchy(); if (this._fake) this._fake._h2=this._h2; } var rows=dhx4.ajax.xpath(this.xml.row, top); this._open=this._open||[]; for (var i=0; i < rows.length; i++) { var id=rows[i].getAttribute("id"); if (!id) { id=this.uid(); rows[i].setAttribute("id",id); } var row=this._h2.add(id,pid); row.buff={ idd:id, data:rows[i], _parser: this._process_xml_row, _locator:this._get_xml_data }; if (rows[i].getAttribute("open")){ row.state="minus"; this._open.push(id); } this.rowsAr[id]=row.buff; this._process_tree_xml(rows[i],id); } if (main){ if (!rows.length) this._h2.change(pid,"state",this._emptyLineImg); else if (pid!=0 && !this._srnd) { this._h2.change(pid,"state","minus"); } for (var i=0; i < this._open.length; i++) { var r=this._h2.get[this._open[i]]; if (!r.childs.length) r.state=this._emptyLineImg; }; this._updateTGRState(this._h2.get[pid]); this._h2_to_buff(); if (pid!=0 && this._srnd) this.openItem(pid); else { if (this.pagingOn) this._renderSort(); else this.render_dataset(); } if (this.kidsXmlFile){ for (var i=0; i < this._open.length; i++) { var r=this._h2.get[this._open[i]]; if (r._xml_await) this.expandKids({idd:r.id}); } } this._open=[]; if (this._slowParse===false){ this.forEachRow(function(id){ this.render_row_tree(0,id) }) } this._parsing=false; if (pid!=0 && !this._srnd) { this.callEvent("onOpenEnd",[pid,1]); } } } dhtmlXGridObject.prototype._h2_to_buff=function(top){ if (!top){ top=this._h2.get[0]; this.rowsBuffer = new dhtmlxArray(); if (this._fake && !this._realfake) this._fake.rowsBuffer = this.rowsBuffer; } for (var i=0; i < top.childs.length; i++) { this.rowsBuffer.push(top.childs[i].buff); if (top.childs[i].state == "minus") this._h2_to_buff(top.childs[i]); } }; dhtmlXGridObject.prototype.render_row_tree=function(ind,id){ if (id){ var r=this._h2.get[id]; r=r?r.buff:r; } else var r=this.rowsBuffer[ind]; if (!r) return -1; if (r._parser){ if (this.rowsAr[r.idd] && this.rowsAr[r.idd].tagName=="TR") return this._h2.get[r.idd].buff=this.rowsBuffer[ind]=this.rowsAr[r.idd]; var row=this._prepareRow(r.idd); this.rowsAr[r.idd]=row; if (!id) this.rowsBuffer[ind]=row; this._h2.get[r.idd].buff=row; //treegrid specific r._parser.call(this,row,r.data); this._postRowProcessing(row); return row; } return r; } /** * @desc: remove row from treegrid * @param: node - row object * @type: private */ dhtmlXGridObject.prototype._removeTrGrRow=function(node,x){ if(x){ this._h2.forEachChild(x.id,function(x){ this._removeTrGrRow(null,x); delete this.rowsAr[x.id]; },this); return; } var ind=this.getRowIndex(node.idd); var x=this._h2.get[node.idd]; if (ind!=-1 && ind!==this.undefined){// in case of dnd we can receive delete command for some child item, which was not rendered yet var len=1; if (x && x.state=="minus") len+=this._getOpenLenght(x.id,0) for (var i=0; i1) this._fake.rowsCol.splice(ind+1,len-1); } this.rowsCol.splice(ind,len); this.rowsBuffer.splice(ind,len); } if (!x) return; this._removeTrGrRow(null,x); delete this.rowsAr[x.id]; if (x.parent.childs.length==1){ this._h2.change(x.parent.id,"state",this._emptyLineImg); this._updateTGRState(x.parent); } this._h2.remove(x.id); } /** * @desc: expand row * @param: rowId - id of row * @type: public * @edition: Professional * @topic: 7 */ dhtmlXGridObject.prototype.openItem=function(rowId){ var y=this._h2.get[rowId||0]; var x=this.getRowById(rowId||0); if (!x) return; if (y.parent && y.parent.id!=0) this.openItem(y.parent.id); this.expandKids(x); } dhtmlXGridObject.prototype._addRowClassic=dhtmlXGridObject.prototype.addRow; /** * @desc: add new row to treeGrid * @param: new_id - new row id * @param: text - array of row label * @param: ind - position of row (set to null, for using parentId) * @param: parent_id - id of parent row * @param: img - img url for new row * @param: child - child flag [optional] * @type: public * @edition: Professional */ dhtmlXGridObject.prototype.addRow=function(new_id,text,ind,parent_id,img,child){ if (!this._h2) return this._addRowClassic(new_id,text,ind); parent_id=parent_id||0; var trcol=this.cellType._dhx_find("tree"); if (typeof(text)=="string") text=text.split(this.delim); var row=this._h2.get[new_id]; if (!row){ if (parent_id==0) ind=this.rowsBuffer.length; else{ ind=this.getRowIndex(parent_id)+1; if (this._h2.get[parent_id].state=="minus") ind+=this._getOpenLenght(parent_id,0); else this._skipInsert=true; } } row=row||this._h2.add(new_id,parent_id); row.image=img; row.has_kids=child; return row.buff=this._addRowClassic(new_id,text,ind); } /** * @desc: add new row to treeGrid, before some other row * @param: new_id - new row id * @param: text - array of row label * @param: sibl_id - id of row, related to which new one will be added * @param: img - img url for new row * @param: child - child flag [optional] * @type: public * @edition: Professional */ dhtmlXGridObject.prototype.addRowBefore=function(new_id,text,sibl_id,img,child){ var sb=this.rowsAr[sibl_id]; if (!sb) return; if (!this._h2) return this.addRow(new_id,text,this.getRowIndex(sibl_id)); var pid=this._h2.get[sibl_id].parent.id; var ind=this.getRowIndex(sibl_id); if (ind==-1) this._skipInsert=true; this._h2.addBefore(new_id,pid,sibl_id); return this.addRow(new_id,text,ind,this._h2.get[sibl_id].parent.id,img,child); } /** * @desc: add new row to treeGrid, after some other row * @param: new_id - new row id * @param: text - array of row label * @param: sibl_id - id of row, related to which new one will be added * @param: img - img url for new row * @param: child - child flag [optional] * @type: public * @edition: Professional */ dhtmlXGridObject.prototype.addRowAfter=function(new_id,text,sibl_id,img,child){ var sb=this.rowsAr[sibl_id]; if (!sb) return; if (!this._h2) return this.addRow(new_id,text,this.getRowIndex(sibl_id)+1); var pid=this._h2.get[sibl_id].parent.id; var ind=this.getRowIndex(sibl_id); if (ind==-1) this._skipInsert=true; if (this._h2.get[sibl_id].state=="minus") ind+=this._getOpenLenght(sibl_id,0)+1; else ind++; this._h2.addAfter(new_id,pid,sibl_id); return this.addRow(new_id,text,ind,pid,img,child); } dhtmlXGridObject.prototype.enableSmartXMLParsing=function(mode) { this._slowParse=dhx4.s2b(mode); }; /** * @desc: copy content between different rows * @param: frRow - source row object * @param: from_row_id - source row id * @param: to_row_id - target row id * @type: private */ dhtmlXGridObject.prototype._copyTreeGridRowContent=function(frRow,from_row_id,to_row_id){ var z=this.cellType._dhx_find("tree"); for(i=0;i