fs-danaus
2023-03-30 665b0603d09890014f982fdfbd6ec47938f504b0
提交 | 用户 | age
25ab64 1 // -----------------------------------------------------------------------------------------------------------
F 2 // Defaults dialog
3 // -----------------------------------------------------------------------------------------------------------
4 MS.Defaults;
5 // -----------------------------------------------------------------------------------------------------------
6 // Updates Items for Menu Defaults, recursion
7 TGP.UpdateMenuDefaults = function(row,col,Items,range,type){
8
9 var R = null, L = this.Lang.Format;
10 MS.Range;
11 var sep = L.ValueSeparator;
12 if(range){
13    R = Get(row,col);
14    if(R || R=="0") R = (R+"").split(sep);
15    else R = [];
16    }
17 ME.Range;
18
19 function SetBool(I){
20 if(I.Bool!=null || I.Level || I.Menu || I.Columns || I.Caption || I.Enum || I.Edit) return;
21 I.Bool = 1;
22 I.Value = 0;
23 for(var i=0;i<R.length;i++) if(R[i]==I.Name) I.Value = 1;
24 }
25
26 var N = [], p = 0, th; if(!type) type = this.GetType(row,col); if(type=="Icon") th = this.GetRowHeight(row);
27 var isfilt = row.Kind=="Filter", trans = this.Trans, fdef = null;
28 if(isfilt){
29    var white = GetWhiteChars(this.GetAttr(row,col,"WhiteChars"));
30    var codes = this.GetAttr(row,col,"CharCodes");
31    var local = this.GetAttr(row,col,"LocaleCompare");
32    var cas = this.GetAttr(row,col,"CaseSensitive");
33    }
34 for(var i=0;i<Items.length;i++){ 
35    var I = Items[i], u = I.Name;
36    if((u+"").charAt(0)=='*'){ 
37       if(u=="*All"){ I.Text = this.GetText("DefaultsAll"); if(I.Text) N[p++] = I; I.Value = 0; I.CheckAll = 1; continue; }
38       if(u=="*None"){ I.Text = this.GetText("DefaultsNone"); if(I.Text) N[p++] = I; I.Value = 1; I.CheckAll = 1; continue; }
39       if(u=="*Date"){ I.Text = this.GetText("DefaultsDate"); if(I.Text) N[p++] = I; I.Spec = 1; continue; }
40       if(u=="*Button"){ I.Text = this.GetText("DefaultsButton"); if(I.Text) N[p++] = I; I.Spec = 1; continue; }
41       if(u=="*Default") { 
42          var zv = row[col]; row[col] = null;
43          I.Text = this.GetRowHTML(row,null,10,col);
44          row[col] = zv;
45          if(I.Text){ N[p++] = I; I.Val = row.Def[col]; I.Name = I.Val; }
46          continue; 
47          }
48       if(u=="*FilterOff") {
49          if(!isfilt) I.Hidden = 1;
50          I.Text = this.GetText("DefaultsFilterOff"); 
51          if(I.Text) N[p++] = I; 
52          I.Spec = 1; 
53          continue; 
54          }
55       if(u.search(/^\*Rows/)>=0){
56          var T = this, X = {}, alp = u.search("Alphabet")>=0, Y = {},filt = u.search("CanFilter")>=0, vis = u.search("Visible")>=0, def = u.search("Def")>=0, cc=col;
57          if(def) { def = u.match(/Def(\w*)(\*|$)/); if(def) def = this.Def[def[1]]; if(!def) def = row.Def; }
58          if(alp) var ralp = new RegExp("["+this.DefaultsAlphabetWhite.replace(/(.)/g,"\\$1")+"]","g");
59          function Set(r){
60             if(r.Kind!="Data" || r.CPage || def && r.Def!=def || vis && !r.Visible || filt && (!(Get(r,"CanFilter")&1) || T.Cols[col].CanFilter==2 && Get(r,col+"CanFilter")==0)) return;
61             if(filt){
62                if(fdef==null){
63                   var FF = isfilt ? row : T.GetFilterRows()[0];
64                   fdef = FF ? T.GetAttr(FF,col,"FilterDef") : T.Cols[col].FilterDef;
65                   if(!fdef) fdef = "";
66                   else { var dd = fdef.split(","); fdef = {}; for(var d in dd) fdef[dd[d]] = 2; }
67                   }
68                if(fdef && !fdef[r.Def.Name]) return;
69                }
70             MS.RowSpan; if(r.RowSpan && r[col+"RowSpan"]==0 || r[col+"Visible"]==-2) return; ME.RowSpan;
71             if(isfilt){
72                var v = Get(r,cc+"FilterValue");
73                if(!v) v = Get(r,cc);
74                if(Grids.OnGetFilterValue) { var tmp = Grids.OnGetFilterValue(T,r,cc,v); if(tmp!=null) v = tmp; }
75                }
76             else var v = Get(r,cc); 
77             if(v!=null){
78 //                v = (v+"").replace(/\s/g,"_");
79                if(isfilt && typeof(v)=="string"){
80                   MS.CharCodes;
81                   
82                   ME.CharCodes;
83                   if(!cas&&v) v = local ? v.toLocaleLowerCase() : v.toLowerCase();
84                   if(white&&v) v = v.replace(white,"");
85                   }
86                if(T.IsRange(r,cc)){
87                   MS.Range;
88                   v = (v+"").split(sep);
89                   var t = null;
90                   for(var i=0;i<v.length;i++){
91                      if(X[v[i]]) X[v[i]]++; 
92                      else if(type=="Icon"){ X[v[i]] = 1; Y[v[i]] = "<div style='height:"+th+"px;background:url("+(this.EscapeImages?'"'+L.Escape(v[i])+'"':v[i])+") no-repeat;'></div>"; }
93                      else { 
94                         X[v[i]] = 1; 
95                         if(!t) {
96                            t = T.GetRowHTML(r,null,10,cc).split(sep);
97                            if(t.length!=v.length){ 
98                               var z = r[cc];
99                               r[cc] = (Get(r,cc)+"").replace(new RegExp(ToRegExp(sep),"g"),"$%^");
100                               t = T.GetRowHTML(r,null,10,cc).split("$%^");
101                               r[cc] = z;
102                               }
103                            }
104                         Y[v[i]] = t[i];
105                         }
106                      }
107                   ME.Range;
108                   }
109                else if(X[v]) X[v]++; 
110                else if(type=="Icon"){ X[v] = 1; Y[v] = "<div style='height:"+th+"px;background:url("+(this.EscapeImages?'"'+L.Escape(Get(r,col))+'"':Get(r,col))+") no-repeat;'></div>"; }
111                else { Y[v] = T.GetRowHTML(r,null,10,cc); if(Y[v]!=null) X[v] = 1;  } 
112                }
113             }
114          var cm = u.match(/Col(\w*)(\*|$)/);
115          if(cm) cc = cm[1];
116          var FP = null, typ = 0; if(isfilt && this.Paging==3 && this.OnePage&2 && !this.AllPages) { FP = this.GetFPage(); if(FP) typ = 2; }
117          if(u.search("All")>=0){
118             for(var r=this.GetFirst(FP);r;r=this.GetNext(r,typ)) Set(r);
119             var F = this.GetFixedRows(); for(var r=0;r<F.length;r++) Set(F[r]);
120             }
121          else if(u.search("Fixed")>=0){
122             var F = this.GetFixedRows(); for(var r=0;r<F.length;r++) Set(F[r]);
123             }
124          else if(u.search("Sibling")>=0){
125             var par = row.parentNode;
126             if(par.Page || row.Fixed) par = this.XB.firstChild;
127             for(var r=par.firstChild;r;r=this.GetNextSibling(r)) Set(r);
128             }
129          else {
130             for(var r=this.GetFirst(FP);r;r=this.GetNext(r,typ)) Set(r);
131             }
132    
133          var cnt = u.match(/\d\d*/), X1 = [], xp=0;
134          if(cnt) cnt = def&&def.Name.indexOf(cnt[0])>=0 ? 0 : cnt[0];
135          var chr = 0;
136          MS.CharCodes; if(this.Cols[cc] && this.Cols[cc].CharCodes) chr = this.Cols[cc].CharCodes; ME.CharCodes;
137          var ns = this.GetAttr(row,col,"NumberSort");
138          if(ns==null||ns==2) { var typ = this.Cols[col]?this.Cols[col].Type:"Text"; ns = CAlignRight[typ]; }
139          for(var x in X){
140             var O = {};
141             O.c = X[x];
142             O.t = Y[x];
143             O.v = isfilt && x==="" ? String.fromCharCode(160) : x;
144             O.cv = ns&&x-0 ? x-0 : (x+"").toLocaleUpperCase();
145             if(alp) O.cv = O.cv.replace(ralp,"");
146             MS.CharCodes; if(chr) O.cv = UseCharCodes(O.cv,chr); ME.CharCodes;
147             X1[xp++] = O;
148             }
149
150          if(cnt) X1.sort(function(a,b){ return a.c<b.c ? 1 :  (a.c>b.c ? -1 :(a.cv<b.cv?-1 : 1) ); });
151          else X1.sort(function(a,b){ return a.cv<b.cv ? -1 : a.cv>b.cv ? 1 : 0; });
152          if(!cnt) cnt = xp;
153          if(alp) {
154             var lc = null,P,pp,t = this.GetText("DefaultsAlphabet"), min = this.GetAttr(row,cc,"DefaultsAlphabetMin");
155             for(var j=0;j<cnt && X1[j];j++){
156                var v = X1[j].v;
157                var c = (X1[j].cv+"").charAt(0);
158                if(lc!=c){
159                   N[p++] = { Name:c,Menu:1,Items:[],Text:t?t.replace("%d",c):c};
160                   P = N[p-1].Items; pp = 0;
161                   lc = c;
162                   }
163                P[pp++] = { Text: X1[j].t, Val: v, Name: v };
164                if(R) SetBool(P[pp-1]);
165                }
166             if(min){
167                for(var j=0;j<N.length;j++){
168                   var I = N[j].Items;
169                   if(I && I.length<min){
170                      N.splice(j,1);
171                      for(var k=0;k<I.length;k++) N.splice(j++,0,I[k]);
172                      j--;
173                      }
174                   }
175                }
176             }   
177          else {    
178             for(var j=0;j<cnt && X1[j];j++){
179                var v = X1[j].v;
180                if(isfilt && v===String.fromCharCode(160)) N[p] = { Text: X1[j].t, Val: v, Name: "" };
181                else N[p] = { Text: X1[j].t, Val: v, Name: v=="-"?"--":v };
182                if(R) SetBool(N[p]);
183                p++;
184                } 
185             }   
186          
187          continue;
188          }
189       }
190    if(type=="Date" && isNaN(u-0)) { u = L.StringToDateEng(u); I.Val = u; I.Name = u; } 
191    if(isfilt && u==="") I.Val = String.fromCharCode(160);
192    if(!I.Text) { 
193       if(type=="Icon"){ I.Text = "<div style='height:"+th+"px;background:url("+(this.EscapeImages?'"'+L.Escape(Get(row,col))+'"':Get(row,col))+") no-repeat;'></div>"; }
194       else { var zal = row[col]; row[col] = u; I.Text = this.GetRowHTML(row,null,10,col); row[col] = zal;  }
195       }
196    else if(trans) I.Text = this.Translate(row,col,I.Text,type,"Menu");
197    if(isfilt && I.Text==="") I.Text = String.fromCharCode(160);  
198    
199    N[p++] = I;
200    if(R) SetBool(I);
201    if(I.Items && !I.Enum) I.Items = this.UpdateMenuDefaults(row,col,I.Items,range);
202    }
203 return N;   
204 }
205 // -----------------------------------------------------------------------------------------------------------
206 // Shows menu Defaults
207 // If set Click (Row,Col,X,Y), shows it on given position
208 TGP.ShowDefaults = function(row,col,test,noserver,Click,Caption){
209
210 MS.Ajax;
211 if(!noserver && this.GetAttr(row,col,"DefaultsServer")>0){ 
212    var T = this;
213    this.DownloadCell(row,col,function(err){
214       MS.Debug;
215       if(err<0) T.Debug(1,"Failed downloading cell [",row.id,",",col,"] from ",T.DebugDataGetName(T.Source.Cell));
216       else if(T.DebugFlags["page"]) T.Debug(3,"Downloaded cell [",row.id,",",col,"] in ",T.StopTimer("Cell"+row.id+"_"+col)," ms");
217       ME.Debug;
218       if(err>=0) T.ShowDefaults(row,col,0,1);   
219       },Get(row,col));
220    return true;
221    }
222 ME.Ajax;
223
224 var M = this.GetAttr(row,col,"Defaults");
225 if(Grids.OnGetDefaults) { var tmp = Grids.OnGetDefaults(this,row,col,M); if(tmp!=null) M = tmp; }
226 if(!M) return false;
227 M = TMenu.InitMenu(M,1);
228 MS.Debug; if(!M) this.Debug(2,"Incorrect Defaults in [",this.GetName(row),",",col,"]"); ME.Debug;
229 if(!M) return false;
230 var range = 0;
231 MS.Range;
232 if(this.IsRange(row,col)){
233    if(M.Buttons==null) M.Buttons = ["Clear","Ok"];
234    M.Texts = this.Lang.MenuButtons; 
235    M.Values = Get(row,col)+"";
236    if(M.Values==="") M.Values = null;
237    M.Separator = this.Lang.Format.ValueSeparator;
238    range = 1;
239    }
240 ME.Range;
241 M.Items = this.UpdateMenuDefaults(row,col,M.Items,range);
242 if(!M.MinWidth) M.MinWidth = 0;
243 M.CursorValue = Get(row,col);
244 if(M.Class==null) M.Class = this.Img.Style+"DefaultsMenu";
245 M = TMenu.InitMenu(M);
246 if(!M) return false;
247 if(test) return true;
248
249 M.Head = Caption;
250
251 if(Click){
252    var P = this.CellToWindow(Click.Row,Click.Col);
253    P.X = P.AbsX + Click.X;
254    P.Y = P.AbsY + Click.Y;
255    P.Align = "left below";
256    P.Width = 0; P.Height = 0;
257    M.MinWidth = null;
258    }
259 else {   
260    var P = this.CellToWindow(row,col,row.Space?4:0);
261    P.Align = "right below"; 
262    if(this.GetAttr(row,col,"Icon")=="Defaults"&&this.GetAttr(row,col,"IconAlign")!="Right") { P.Align = "left below"; M.MainClass = this.Img.Style+"DefaultsMenuMainLeft"; }
263    P.X = P.AbsX; P.Y = P.AbsY;
264    if(col==this.MainCol && !row.Fixed && !this.HideTree){
265       var left = 0, lev = row.Level; if(this.HideRootTree) lev--;
266       var lw = this.Img.Line, tw = this.Img.Tree; 
267       if(this.SpannedTree){ if(row.TreeWidthL!=null) lw = row.TreeWidthL; if(row.TreeWidthT!=null) tw = row.TreeWidthT; }
268       if(lev>=0) left += tw;
269       if(lev>0) left += lev*lw;
270       if(!this.Rtl) P.X += left; 
271       P.Width -= left;
272       }
273    
274    }
275    
276 var T = this;
277 M.OnCSave = function(I,V){
278    var val, foff = 0;   
279    if(!I){
280       val = V.join(T.Lang.Format.ValueSeparator);
281       if(!V.length) { foff = 1; val = null; } 
282       else if(val==="") val = T.Lang.Format.ValueSeparator;  
283       }
284    else if(I.Spec) { 
285       if(I.Name=="*Date") { if(T.ShowDatePicker) T.ShowDatePicker(row,col); M.OnClose = null; return; }
286       if(I.Name=="*Button") { M.Close(); if(Grids.OnButtonClick) Grids.OnButtonClick(T,row,col); return; }
287       if(I.Name=="*FilterOff") {
288          val = null;
289          
290          foff = 1;
291          }
292       }
293    else {      
294       val = I.Val; if(val==null) val = I.Value; if(val==null) val = I.Name;
295       var type = T.GetType(row,col);
c35f05 296       MS.Date; if(type=="Date") val =  val===String.fromCharCode(160)&&row.Kind=="Filter" ? "" : T.ConvertDate(val,T.GetFormat(row,col,"Date",val)); ME.Date; 
25ab64 297       if(type=="Text"||type=="Lines"||type=="Html"||type=="EHtml"){
F 298          var f = T.GetFormat(row,col,1);
299          if(f && f.charCodeAt(0)==123){ 
300             var ff = FromJSON(f,1);
301             for(var n in ff) if(ff[n]==val){ val = n; break; }
302             }
303          }
304       if(val-0+""==val) val -= 0; 
305       }
306    M.Close();
307    T.FinishEdit(row,col,val,foff);   
308    }
309    
310 this.SetDialogBase(M,row,col,"Defaults");
311 var align = this.GetAttr(row,col,"Align",null,1); if(!align && this.IsAlignRight(row,col)) align = "Right"; if(align&&!M.ItemAlign) M.ItemAlign = align;
312 if(Grids.OnShowDefaults) Grids.OnShowDefaults(this,row,col,M,P);
313 this.Dialog = ShowMenu(M,P);
314 return true;
315 }
316 // -----------------------------------------------------------------------------------------------------------
317 TGP.ActionShowDefaults = function(F,T,notest){
318 var A = this.GetACell(F); if(!A) return false; 
319 var row = A[0], col = A[1];
320 MS.RowSpan; if(row.RowSpan) row = this.GetSpanRow(row,col,0); ME.RowSpan;
321 if(this.Editing!=1&&!CEditKinds[row.Kind] || this.Locked.length&&this.IsLockedEdit(row,col)) return false;
322 if(!notest){
323    var but = this.GetAttr(row,col,"Button"), ico = this.GetAttr(row,col,"Icon");
324    if(but!="Defaults" && ico!="Defaults" && (but!="Enum" && ico!="Enum" || this.GetEnum(row,col))) return false;
325    }
326  
327 if(this.Dialog && this.Dialog.Row==row && this.Dialog.Col==col) {
328    if(T) return false;
329    this.CloseDialog();
330    return true;
331    }  
332 return this.ShowDefaults(row,col,T);
333
334 }
335 TGP.ActionShowDefaultsMenu = function(F,T){ return this.ActionShowDefaults(F,T,1); }
336 // -----------------------------------------------------------------------------------------------------------
337 TGP.InDefaults = function(row,col,val,def,range){ 
338 if(def==null) { 
339    def = row[col+"Defaults"]; if(def==null) def = row.Def[col+"Defaults"]; if(def==null&&!row.Space) def = this.Cols[col].Defaults; 
340    if(Grids.OnGetDefaults) { var tmp = Grids.OnGetDefaults(this,row,col,def); if(tmp!=null) def = tmp; }
341    }
342 if(!def) return null;
343
344 if(val==null) val = Get(row,col);
345 if(range==null) range = this.IsRange(row,col);
346
347 var sep = def.charAt(0);
348 if(sep!="{"&&def.indexOf(sep+"*")<0) {
349    def = def.split(sep);
350    if(range){
351       var v = val.split(this.Lang.Format.ValueSeparator);
352       for(var j=0;j<v.length;j++){
353          for(var i=1;i<def.length;i++) if(def[i]==v[j]) break;
354          if(i==def.length) return false;
355          }
356       return true;
357       }
358    for(var i=1;i<def.length;i++) if(def[i]==val) return true;
359    return false;
360    }
361
362 var M = TMenu.InitMenu(def,1); if(!M) return null;
363 M.Items = this.UpdateMenuDefaults(row,col,M.Items,0);
364
365 if(range){
366    var v = val.split(this.Lang.Format.ValueSeparator);
367    function checkrange(Items){
368       for(var i=0;i<Items.length;i++){ 
369          var I = Items[i]; 
370          if(I.Items && checkrange(I.Items)) return true;
371          for(var j=0;j<v.length;j++) if(I.Name==v[j]) { v.splice(j,1); break; }
372          if(!v.length) return true;
373          }
374       }
375    return checkrange(M.Items) ? 1 : 0;
376    }
377
378 function check(Items){
379    for(var i=0;i<Items.length;i++){ var I = Items[i]; if(I.Name==val||I.Items&&check(I.Items)) return true; }
380    }
381 return check(M.Items) ? 1 : 0;
382 }
383 // -----------------------------------------------------------------------------------------------------------
384 ME.Defaults;