fs-danaus
2023-03-30 665b0603d09890014f982fdfbd6ec47938f504b0
提交 | 用户 | age
25ab64 1 // -----------------------------------------------------------------------------------------------------------
F 2 // Functions for selecting rows
3 // -----------------------------------------------------------------------------------------------------------
4 MS.Select;
5 // -----------------------------------------------------------------------------------------------------------
6 // If the row (cells=0) or its cells (cells=1) can be selected
7 TGP.CanSelect = function(row,cells){
8 var can = row.CanSelect; if(can==null && row.Def) can = row.Def.CanSelect;
9 return cells ? can==1||can==3 : (can==1||can==2)&&(!row.Deleted||!(this.ClearSelected&1));
10 }
11 // -----------------------------------------------------------------------------------------------------------
12 // Support function for GetSelRows, recursion
13 TGP.GetSelChildren = function(row,and,clr,attr,A,first){
14 for(var r=row.firstChild;r;r=r.nextSibling) {
15    if(r.Deleted&&clr&1 || r.Filtered&&clr&2) continue;
16    if(clr&4&&!r.Visible&&!r.Deleted&&!r.Filtered){
17       if(r.Expanded&2 && r.firstChild && this.GetSelChildren(r,and,clr,attr,A,first)) return true; 
18       continue;
19       }
20    if(r.Selected&and && (!attr||Is(r,attr)) && r!=A[0]) {
21       A[A.length] = r;
22       if(first==1 || r.firstChild && (r.Expanded||clr&8) && clr&16 && this.GetSelChildren(r,and,clr,attr,A,first)) return true;
23       }
24    else if(first==0&&this.CanSelect(r,0) || r.firstChild && (r.Expanded||clr&8) && this.GetSelChildren(r,and,clr,attr,A,first)) return true;
25    }
26 }
27 // -----------------------------------------------------------------------------------------------------------
28 // Returns array of all selected rows, in order in that are in table
29 TGP.GetSelRows = function(type,attr,first,A){
30 var clr = this.ClearSelected^8 | (type&8?0:16), and = type&3; if(and==0) and = this.SelAnd;
31 if(!A) A = [];
32 if(type&4 && this.GetSelChildren(this.XH,and,clr,attr,A,first)) return true;
33 for(var p=this.XB.firstChild;p;p=p.nextSibling) if(!(p.State<2) && this.GetSelChildren(p,and,clr,attr,A,first)) return true; 
34 if(type&4 && this.GetSelChildren(this.XF,and,clr,attr,A,first)) return true;
35 return first!=null ? false : A;
36 }
37 // -----------------------------------------------------------------------------------------------------------
38 TGP.IsSelected = function(row,col){
39 if(!row){ var C = this.Cols[col]; return C && C.Selected;  }
40 if(!col) return row.Selected&&this.SelAnd;
41 return row.Selected && row[this.ACol+"Selected"] || this.SelectingCells<3&&row.Selected==1 || this.SelectingCells==4&&(row.Selected&1||this.Cols[col]&&this.Cols[col].Selected);
42 }
43 // -----------------------------------------------------------------------------------------------------------
44 TGP.SetAllSelected = function(sel,single){
45 if(sel==this.AllSelected || !this.SelectAllType || single&&!(this.SelectAllType&(sel?4:2)) || sel==-1&&this.AllSelected==null) return;
46 if(single){
47    if(sel) this.AllSelected = !this.GetSelRows(null,null,0); 
48    else this.AllSelected = this.SelectAllType&4 ? !this.GetSelRows(null,null,0) : null; 
49    }
50 else if(sel==-1) this.AllSelected = !this.AllSelected;
51 else this.AllSelected = sel;
52 var F = this.GetFixedRows();
53 for(var i=0;i<F.length;i++) if(F[i].Kind!="Filter") this.UpdatePanel(F[i]);
54 }
55 // -----------------------------------------------------------------------------------------------------------
56 // Marks given row as Selected
57 TGP.SelectRow = function(row,sel,test,nosave,noundo,always){
58 if(!row || row.Page || row.Kind=="Header" || !this.Selecting || this.Locked["select"] || !always && !this.CanSelect(row,this.SelectingCells==2)) return false;
59 if(this.SelectingSingle&2 && row.Selected&this.SelAnd && !nosave) return false;
60 var sel3 = this.SelectingCells>=3, sel2 = this.SelectingCells==2, rsel2 = row.Selected==2 && !sel3;
61 if(sel==null) sel = row.Selected&this.SelAnd?0:1;
62 else if(!(row.Selected&this.SelAnd) == !sel && !rsel2) return false;
c35f05 63 if(Grids.OnSelect||Grids.OnSelected){ var CC = null; if(sel2) { CC = []; for(var c in this.Cols) if(row[c+"Selected"]!=sel) CC[CC.length] = c; } }
F 64 if(Grids.OnSelect&&Grids.OnSelect(this,row,!sel,CC,test)) return false;
25ab64 65 if(test) return true;
F 66 MS.Undo;
67 if(this.Undo&2&&!noundo) { 
68    if(sel2) { 
69       for(var c in this.Cols) if(row[c+"Selected"]!=sel) this.AddUndo({Type:"Select",Row:row,Col:c,Sel:sel,OSel:row[c+"Selected"]});
70       }
71    else {
72       this.AddUndo({Type:"Select",Row:row,Sel:sel,OSel:rsel2?null:!sel}); 
73       if(rsel2) for(var c in this.Cols) if(row[c+"Selected"]) this.AddUndo({Type:"Select",Row:row,Col:c,Sel:null,OSel:row[c+"Selected"]}); 
74       }
75    }
76 ME.Undo;
77 if(this.ColorCursor&8 && !sel3){
78    var C = this.Cols, CR = [];
79    if(rsel2) {
80       if(sel) for(var c in C) { if(!row[c+"Selected"] && !C[c].SelectedCells++ && !nosave) this.ColorCursorRows(c,CR,8); }
81       else for(var c in C) { if(row[c+"Selected"] && !--C[c].SelectedCells && !nosave) this.ColorCursorRows(c,CR,8); }
82       }
83    else if(this.SelectingCells){
84       if(sel) for(var c in C) { if((C[c].CanSelect==1||C[c].CanSelect==3) && !C[c].SelectedCells++ && !nosave) this.ColorCursorRows(c,CR,8); }
85       else for(var c in C) { if((C[c].CanSelect==1||C[c].CanSelect==3) && !--C[c].SelectedCells && !nosave) this.ColorCursorRows(c,CR,8); }
86       }
87    }
88 if(sel2) {
89    for(var c in this.Cols) if(row[c+"Selected"]!=sel) row[c+"Selected"] = sel;
90    row.Selected = sel ? 2 : 0;
91    }
92 else {
93    if(rsel2) for(var c in this.Cols) if(row[c+"Selected"]) row[c+"Selected"] = null;
94    row.Selected = sel3 ? sel | (row.Selected&2) : sel;
95    }
96 if(this.ColorCursor&8) this.ColorCursorCols(row,[],8);
97 if(this.SelectingSingle && sel) {
98    if(this.SelectingSingle&4 && !this.SRow) for(var r=this.GetFirstVisible();r;r=this.GetNextVisible(r)){ if (r.Selected&this.SelAnd && r!=row && this.CanSelect(r)) { this.SRow = r; break; } }
99    if(this.SRow && this.SRow!=row) this.SelectRow(this.SRow,0,0,1);
100    this.SRow = row;
101    }
102 if(this.SelectClass) this.RefreshRow(row); else this.ColorRow(row);
103 if(!nosave) this.SetAllSelected(sel,1);
104 this.UpdatePanel(row);
105 if(!nosave){
106    if(this.SaveSelected) this.SaveCfg();
107    if(this.CalculateSelected) this.Calculate(1,1);
108    else if(this.DynamicSpan||this.Undo&2) this.CalculateSpaces(1);
109    if(this.AutoUpdate && (","+this.Source.Upload.Type+",").toLowerCase().indexOf("selected")>=0) this.UploadChanges(row);
110    }
c35f05 111 if(Grids.OnSelected) Grids.OnSelected(this,row,!sel,CC);
25ab64 112 return true;
F 113 }
114 // -----------------------------------------------------------------------------------------------------------
115 // Marks all rows according to select
116 TGP.SelectAllRows = function(select,test,noundo){
117 if(!this.Selecting || this.Locked["select"]) return false;
118 if(this.SelectingSingle){
119    if(!this.SRow||test) return false;
120    if(!this.SelectRow(this.SRow,0,test)) return false;
121    this.SRow = null;
122    return true;
123    }
c35f05 124 var page = (this.Paging==3 || this.Paging&&!this.AllPages) && !(this.SelectAllType&16) ? this.GetFPage() : null;
25ab64 125
c35f05 126 var sel = 0, unsel = 0, and = this.SelAnd;
25ab64 127 var vis = (this.ClearSelected&6)==6, typ = (page?2:0)|(this.ClearSelected&8?1:0), flt = this.ClearSelected&2; 
F 128 for(var r=vis?this.GetFirstVisible(page,typ):this.GetFirst(page,typ);r;r=vis?this.GetNextVisible(r,typ):this.GetNext(r,typ)){
129    if(!this.CanSelect(r) || flt&&r.Filtered) continue; 
130    if(r.Selected&and){ sel++; if(unsel&&!test) break; }
131    else { unsel++; if(sel&&!test) break; }
132    }
133 if(this.RemovedPages&&!page){
134    for(var r=vis?this.GetFirstVisible(this.RemovedPages,typ):this.GetFirst(this.RemovedPages,typ);r;r=vis?this.GetNextVisible(r,typ):this.GetNext(r,typ)){
135       if(!this.CanSelect(r) || flt&&r.Filtered) continue; 
136       if(r.Selected&and){ sel++; if(unsel&&!test) break; }
137       else { unsel++; if(sel&&!test) break; }
138       }
139    }
140 if(select==null) select = !sel;
141 if((select==0||select==-1) && sel==0 || (select==1||select==-1) && unsel==0) return false;
c35f05 142 if(Grids.OnSelectAll && Grids.OnSelectAll(this,select,2,test)) return test ? false : true;
25ab64 143 if(test) return select==-1 ? unsel+sel : (select ? unsel : sel);
F 144 MS.Undo;
145 if(this.Undo&2&&!noundo) {
146    var aundo = this.CanUndo()+this.CanRedo()*2;
147    this.UndoStart();
c35f05 148    for(var r=this.GetFirstVisible(page,typ);r;r=this.GetNextVisible(r,typ)) {
25ab64 149       if(this.CanSelect(r) && !(r.Selected&and) == select || select==-1) this.AddUndo({Type:"Select",Row:r,OSel:!!(r.Selected&and)});
F 150       }
151    this.UndoEnd();
152    
153    this.AddUndo({Type:"Select",Sel:select}); 
154    if(this.CanUndo()+this.CanRedo()*2!=aundo) this.CalculateSpaces(1);
155    }
156 ME.Undo;
c35f05 157
25ab64 158 if(this.RowCount<this.SynchroCount) this.SelectAllRowsT(select);
F 159 else {
160    this.ShowMessage(this.GetText("SelectAll"));
161    var T = this; setTimeout(function(){ T.SelectAllRowsT(select);},10);
162    }
163 return true;
164 }   
165 // -----------------------------------------------------------------------------------------------------------
166 TGP.SelectAllRowsT = function(select,page){  
c35f05 167 var and = this.SelAnd; if(page==null && (this.Paging==3 || this.Paging&&!this.AllPages) && !(this.SelectAllType&16)) page = this.GetFPage();
25ab64 168 var vis = (this.ClearSelected&6)==6, typ = (page?2:0)|(this.ClearSelected&8?1:0), flt = this.ClearSelected&2; 
F 169 for(var r=vis?this.GetFirstVisible(page,typ):this.GetFirst(page,typ);r;r=vis?this.GetNextVisible(r,typ):this.GetNext(r,typ)){
c35f05 170       if(r.Filtered) continue;//***过滤了就不用选中,适用于多表中关联表的第二表的全选删除
25ab64 171    if(this.CanSelect(r) && (!flt||!r.Filtered) && !(r.Selected&and) == select || select==-1) this.SelectRow(r,null,0,1);
F 172    }
173 if(this.RemovedPages && !page){
174    for(var r=vis?this.GetFirstVisible(this.RemovedPages,typ):this.GetFirst(this.RemovedPages,typ);r;r=vis?this.GetNextVisible(r,typ):this.GetNext(r,typ)){
175       if(this.CanSelect(r) && (!flt||!r.Filtered) && !(r.Selected&and) == select || select==-1) r.Selected = !r.Selected;
176       }
177    }
178 if(this.ColorCursor&8 && this.SelectingCells){
179    for(var j=0,A=[this.XH,this.XF];j<2;j++) for(var r=A[j].firstChild;r;r=r.nextSibling) if(r.ColorCursor&8) { if(this.ColorCursor&16) this.RefreshRow(r); else this.ColorRow(r); }
180    }
181 this.SetAllSelected(select);
182 if(this.SaveSelected) this.SaveCfg();
183 if(this.CalculateSelected) this.Calculate(1,1);
184 if(this.AutoUpdate && (","+this.Source.Upload.Type+",").toLowerCase().indexOf("selected")>=0) this.UploadChanges();
185 this.HideMessage();
c35f05 186 if(Grids.OnSelectedAll) Grids.OnSelectedAll(this,select,2);
25ab64 187 }
F 188 // -----------------------------------------------------------------------------------------------------------
189 TGP.ActionSelectRow = function(F,T){ 
190 var row = this.GetARow(F), ret = row ? this.SelectRow(row,1,T) : false; 
191 MS.Animate; if(ret && !T) this.AnimRow(row,"Select"); ME.Animate;
192 return ret;
193 }
194 // -----------------------------------------------------------------------------------------------------------  
195 TGP.ActionDeselectRow = function(F,T){ 
196 var row = this.GetARow(F), ret = row ? this.SelectRow(row,0,T) : false; 
197 MS.Animate; if(ret && !T) this.AnimRow(row,"Deselect"); ME.Animate;
198 return ret;
199 }
200 // -----------------------------------------------------------------------------------------------------------  
201 TGP.ActionSelectRowRange = function(dummy,T){ var cnt = this.FRow ? this.SelectRange(this.FRow,null,this.ARow,null,1,null,T) : 0; return T ? cnt : !!cnt; }
202 TGP.ActionDeselectRowRange = function(dummy,T){ var cnt = this.FRow ? this.SelectRange(this.FRow,null,this.ARow,null,0,null,T) : 0; return T ? cnt : !!cnt; }
203 TGP.ActionInvertRowRangeFirst = function(dummy,T){ var cnt = this.FRow ? this.SelectRange(this.FRow,null,this.ARow,null,2,null,T) : 0; return T ? cnt : !!cnt; }
204 TGP.ActionSelectFocusedRows = function(F,T){ var A = this.GetARanges(F?F&~2:1,0,1,1), cnt = A.length ? this.SelectRange(A[0][0],null,A[0][2],null,1,null,T) : 0; return T ? cnt : !!cnt; }
205 TGP.ActionDeselectFocusedRows = function(F,T){ var A = this.GetARanges(F?F&~2:1,0,1,1), cnt = A.length ? this.SelectRange(A[0][0],null,A[0][2],null,0,null,T) : 0; return T ? cnt : !!cnt; }
206 TGP.ActionInvertFocusedRowsFirst = function(F,T){  var A = this.GetARanges(F?F&~2:1,0,1,1), cnt = A.length ? this.SelectRange(A[0][0],null,A[0][2],null,2,null,T) : 0; return T ? cnt : !!cnt; }
207 // -----------------------------------------------------------------------------------------------------------  
208 TGP.ActionSelectAll = function(dummy,T){ return this.SelectAllRows(1,T); }
209 TGP.ActionDeselectAll = function(dummy,T){ return this.SelectAllRows(0,T); }
210 TGP.ActionInvertAll = function(dummy,T){ return this.SelectAllRows(-1,T); }   
211 // -----------------------------------------------------------------------------------------------------------
212 ME.Select;