// ----------------------------------------------------------------------------------------------------------- // Functions for row manipulations - adding, deleting // ----------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------- // Add new row to parent before row nex // If next==null add it as the last row of parent's children // If next and parent are null, adds row to last of actual page // If show==true, shows the in row in table // if id is set, does not generate id, but sets it // If set Def uses this name MS.Add; TGP.AddRow = function(par,next,show,id,Def,src,master,test,A,old,noundo){ if(next) par = next.parentNode; if(!par){ if(!this.AllPages) par = GetNode(this.XB,this.FPage); else par = this.XB.lastChild; } if(!src && !Def && !par.Page && Is(par,"AddParent")) return this.AddRow(par.parentNode,Get(par,"AddParent")==2?null:par,show,id,Def,src,master,test); if(next && par.Page && this.Root.AddParent==2) next = null; var D; if(src) D = this.Def[src.Def.Name]; if(D) { if(!src.CPage && !this.TestDef(par,D.Name)&&(!old||typeof(old)!="object")) return null; } else { var def = Def; if(!def) { def = Get(par.Page?this.Root:par,"CDef"); if(!def) return null; } D = this.Def[def]; if(!D) { MS.Debug; if(!test) this.Debug(1,"Not defined default row ",def,", cannot add new row to this grid"); ME.Debug; return null; } } MS._Free; MS._Debug;if(0){ ME._Debug; var cnt = 26+7; for(var r=this.GetFirst();r;r=this.GetNext(r),cnt--) if(cnt<=1) return null; MS._Debug;} ME._Debug; ME._Free; if(!this.HasChildren(par)) par.State = 4; if(par.State<2) return null; if(test&&this.Group&&!this.MainColGroup&&par.Def&&!par.Def.Group&&this.GroupMoveFree!=2) return null; if(test) return true; if(!par.Page && Get(par,"DefParent") && !this.HasNDChildren(par)) this.ChangeDef(par,Get(par,"DefParent"),1,2); var r = old&&typeof(old)=="object" ? old : Dom.createElement("I"); if(r.Removed) delete r.Removed; if(next) par.insertBefore(r,next); else { if(this.Paging==3 && par.tagName=="BR") par = this.UpdateTagName(par); par.appendChild(r); } r.Def = D; r.Expanded = D.Expanded ? D.Expanded-0 : 0; r.Kind = D.Kind; r.Calculated = D.Calculated ? 1 : 0; r.Visible = D.Visible ? 1 : 0; r.Spanned = D.Spanned ? 1 : 0; if(r.Spanned) this.UpdateSpan(r); r.Level = par.SPage ? par.Level : par.Level+1; r.Added = 1; r.Visible = 0; r.State = r.Expanded ? 4 : 2; r.DetailCol = D.DetailCol; for(var c in this.Cols) if(c!="Panel" && !Get(r,c)) r[c] = this.GetValue(r,c); if(this.DefaultSortPos) r[this.DefaultSort] = this.DefaultSortPos++; this.LoadedCount++; MS.Master; if(D.EditCols){ var EC = (D.EditCols+"").split(','); for(var i=0;i0;i--){ var r = this.AddRow(par,next,(noupload?1:5)+(paste?0:2),id,null,src); if(!r){ this.EndUpdate(); this.ShowMessageTime(par&&!par.Page?this.GetText("ErrAdd").replace("%1",this.GetName(par)):this.GetText("ErrAddRoot"),this.EditErrorsMessageTime?this.EditErrorsMessageTime:1000); return null; } if(Grids.OnRowAdded) Grids.OnRowAdded(this,r,paste); A[p++] = r; } this.EndUpdate(A.length==1?A[0]:null); if(focus) { var r1 = A[0], r2 = A[A.length-1], G = this; while(r1&&r1.DetailRow&&r2.DetailRow&&!r1.DetailRow[0].Page) { G = r1.DetailGrid[0]; r1 = r1.DetailRow[0]; r2 = r2.DetailRow[0]; } G.FocusRows(r1,r2); } this.UndoEnd(); this.CalcTreeWidth(); //MS.Animate; if(cnt>1) this.AnimRows(A,"AddRows",1); else this.AnimRow(A[0],"Add",1); ME.Animate;//***ÔÚÁíÒ»¸öÒ³¿¨Ñ¡Ôñ·µ»ØÌî³äµ±Ç°treegridʱÔÚfrieFoxÉÏ»á³öÏÖÖ»Ìî³äÒ»ÐУ¬ÆäËûÐÐÒþ²Ø²»ÏÔʾµÄÎÊÌ⣬ËùÒÔÕâÀïÔÝʱȥµô return cnt?A:A[0]; } // ----------------------------------------------------------------------------------------------------------- TGP.GetActualPage = function(){ if(!this.Paging) return this.XB.firstChild; MS.Paging; if(this.AllPages){ if(this.FRow && !this.FRow.Fixed) return this.GetRowPage(this.FRow); var A = this.GetShowedPages(); return GetNode(this.XB,A[0]); } else return this.FPage!=null ? GetNode(this.XB,this.FPage) : null; ME.Paging; } // ----------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------- TGP.DoAddRows = function(F,T,S,below){ if(!this.Adding||this.Locked["addrow"]) return false; if(this.EditAttrsEmpty) return S&4 ? this.CopyRow2(F,1,1,0,T) : this.CopySelectedRows(F,0,1,below?1:0,S&1,T); var row = this.GetARow(F&5?F&5:5,below?2:1); MS.Master; if(F&1&&!row&&this.FocusNested(T)&&this.LastFocus[0].Adding&&!(this.LastFocus[0].Locked["addrow"])) row = this.Rows[this.LastFocus[1]]; ME.Master; if(!row||row.Fixed) return false; var cnt = 0; if(!S) cnt = 1; else { var R = this.GetARows(S); for(var id in R) if(!R[id].Deleted) cnt++; } if(!cnt) return cnt; var A = this.AddRows(cnt,row.parentNode,below?row.nextSibling:row,1,T); if(!A) return false; if(T) return cnt; if(!below && row==this.ARow) this.ARow = A[0]; return true; } // ----------------------------------------------------------------------------------------------------------- TGP.ActionAddRow = function(F,T){ return this.DoAddRows(F,T,0,0); } TGP.ActionAddRowBelow = function(F,T){ return this.DoAddRows(F,T,0,1); } TGP.ActionAddRows = function(F,T){ return this.DoAddRows(F,T,F&~5|1,0); } TGP.ActionAddRowsBelow = function(F,T){ return this.DoAddRows(F,T,F&~5|1,1); } TGP.ActionAddSelected = function(F,T){ return this.DoAddRows(F,T,F&~5|2,0); } TGP.ActionAddSelectedBelow = function(F,T){ return this.DoAddRows(F,T,F&~5|2,1); } // ----------------------------------------------------------------------------------------------------------- TGP.ActionAddRowEndPage = function(F,T){ MS.Master; if(F&1&&this.FocusNested(T)&&this.LastFocus[0].Adding&&!(this.LastFocus[0].Locked["addrow"])) return this.LastFocus[0].ActionAddRowEndGrid(0,T); ME.Master; return !!this.AddRows(1,this.GetActualPage(),null,1,T); } // ----------------------------------------------------------------------------------------------------------- TGP.ActionAddRowEndGrid = function(F,T){ MS.Master; if(F&1&&this.FocusNested(T)&&this.LastFocus[0].Adding&&!(this.LastFocus[0].Locked["addrow"])) return this.LastFocus[0].ActionAddRowEndGrid(0,T); ME.Master; var b = this.XB.lastChild; if(T) return this.AddRows(1,b,null,1,T); if(this.Paging && !this.AllPages && this.FPage!=this.XB.childNodes.length-1) this.GoToPage(b); if(b.State!=4){ if(this.AllPages && (b.State==2||b.State==0)) { this.GoToPage(b); this.ShowPages(); } T = this; setTimeout(function(){T.ActionAddRowEndGrid();},100); return true; } return !!this.AddRows(1,b,null,1); } // ----------------------------------------------------------------------------------------------------------- TGP.ActionAddRowEnd = function(F,T){ this.isCopy=false; //**** return this.AllPages ? this.ActionAddRowEndGrid(F,T) : this.ActionAddRowEndPage(F,T); } // ----------------------------------------------------------------------------------------------------------- TGP.AddChild = function(F,type,test){ var row = this.GetARow(F); MS.Master; if(F&1&&!row&&this.FocusNested(test)&&this.LastFocus[0].Adding&&!(this.LastFocus[0].Locked["addrow"])) row = this.Rows[this.LastFocus[1]]; ME.Master; if(row==null || row.Fixed || row.Page || !this.MainCol || !Is(row,"AcceptChild")) return false; var next = type ? null : row.firstChild; if(this.AddChildType&1) type = 1; MS.Paging; var fc = row.firstChild; if(fc && fc.CPage || !fc && row.Count) { if(!row.Expanded && !row.Page && !test) this.Expand(row); if(row.State<4 && !test){ var T = this; setTimeout(function(){ T.AddChild(F,type); },100); return true; } MS.CPages; if(fc){ if(type) row = row.lastChild; else { row = fc; next = fc.firstChild; } } ME.CPages; } ME.Paging; //****±£´æÉÏÒ»¼¶µÄrowid£¬µ½Ê±¸øµ±Ç°ÐеÄparentrowidÓá£ÒԱ㽨Á¢¹Øϵ this.treeParentRowid=row.rowid||""; if(!this.AddRows(1,row,next,1,test)) return false; if(test) return row.Count ? row.Count+1 : row.childNodes.length+1; return true; } // ----------------------------------------------------------------------------------------------------------- TGP.ActionAddChild = function(F,T){ return this.AddChild(F,0,T); } TGP.ActionAddChildEnd = function(F,T){ return this.AddChild(F,1,T); } // ----------------------------------------------------------------------------------------------------------- ME.Add; // ----------------------------------------------------------------------------------------------------------- MS.Master; TGP.UpdateCopyTo = function(row,par,refresh){ var ppar = par.parentNode, D = par.Def; if(ppar && ppar.Def && ppar.Def.Group) this.UpdateCopyTo(row,ppar,refresh); for(var cc in this.Cols) { var cp = par[cc+"CopyTo"]; if(cp==null) cp = D[cc+"CopyTo"]; if(!cp) continue; cp = cp.split(','); for(var i=0;i1) this.SplitSpanned(row,col); this.RemoveRowSpan([row],O,U); if(U) this.AddUndo({ Type:"RemoveSpan",Data:U }); for(var ro in O) this.RefreshRow(O[ro]); } ME.RowSpan; MS.Master; if(row.DetailRow) for(var i=0;i