fs-danaus
2022-05-25 ea472b9b5aa3629957c4e7cb698834a45adf718c
提交 | 用户 | age
25ab64 1 // -----------------------------------------------------------------------------------------------------------
F 2 // Functions for generating output XML
3 // -----------------------------------------------------------------------------------------------------------
4 var CRowAttrs = { HasIndex:1, Level:1, LevelImg:1, Hasch:1, State:1, Focused:1, CalcOrderAuto:1, Filtered:1, ExpandCol:1 } 
5
6 // -----------------------------------------------------------------------------------------------------------
7 TGP.GetUploadFormat = function(src){
8 var f = src.Format.toLowerCase(), F = { };
9 F.Dtd = f=="dtd"; F.Json = f=="json"; 
10 F.Json2 = f=="json"; 
11 F.Sep = F.Json ? "\":" : "="; F.Spc = F.Json ? ",\"" : " "; F.Spc1 = F.Json?"\"":" "; F.One = F.Json ? "\":1" : "=\"1\"";
12 F.Str = F.Json ? (src.Xml==2?StringToJsonX:StringToJson) : StringToXml;
13 F.Start = F.Json ? "{\"id\":\"" : "<I id=\""; F.End = F.Json ? "}," : "/>";
14 return F;
15 }
16 // -----------------------------------------------------------------------------------------------------------
17 // Returns next not deleted row
18 MS.Cfg$Upload;
19 TGP.NextChanges = function(row){
20 var r = row.nextSibling;
21 while(r && r.Deleted) r = r.nextSibling;
22 return r;
23 }
24 ME.Cfg$Upload;
25 // -----------------------------------------------------------------------------------------------------------
26 // Returns previous not deleted row
27 MS.Cfg$Upload;
28 TGP.PrevChanges = function(row){
29 var r = row.previousSibling;
30 while(r && r.Deleted) r = r.previousSibling;
31 return r;
32 }
33 ME.Cfg$Upload;
34 // -----------------------------------------------------------------------------------------------------------
35 // Returns string with row changes for cookies
36 MS.Cfg;
37 TGP.GetRowChangesCfg = function(row){
38 var S = "", C = this.Cols;
39 if(row.Deleted) S = "D";
40 else if(row.Added){
41    var def = row.Def, par = row.parentNode, next = this.NextChanges(row), prev = this.PrevChanges(row), ppar = Get(row,"Par");
42    S = "A&"+(ppar?ppar:"")+"&"+def.Name+"&" + (par.id ? par.id : par.Pos!=null ? par.Pos : "") + "&" + (next && next.id ? next.id : "") + "&"+(row.Copy?row.Copy:"");
43    for(var c in C){
44       if(row[c]!=null && row[c]!=def[c] && (!C[c].Formula && (!row.Calculated || !row[c+"Formula"])||this.CalculateChanges) && typeof(row[c])!="function"){ 
45          S += "&"+c+"&"+escape(row[c]);
46          }
47       }
48    }
49 else if(row.Changed || row.Moved){
50    if(row.Changed) S = "C";
51    if(row.Moved){ 
52       var par = row.parentNode, next = this.NextChanges(row), prev = this.PrevChanges(row);
53       S = "M&"+row.Moved+"&" + (par.id ? par.id : par.Pos!=null ? par.Pos : "") + "&" + (next && next.id ? next.id : "") + "'";
54       }
55    if(row.Changed){ 
56       if(row.Cells) {
57          for(var i=0;i<row.Cells.length;i++) if(row[row.Cells[i]+"Changed"]) S += "&"+c+"&"+escape(row[row.Cells[i]]);
58          }
59       else { 
60          for(var c in C) if(row[c+"Changed"]) S += "&"+c+"&"+escape(row[c]);
61          }
62       }
63    }
64 return S;
65 }
66 ME.Cfg;
67 // -----------------------------------------------------------------------------------------------------------
68 // Converts value date according to DateStrings
69 TGP.ConvertUpload = function(row,col,val,fed){//****增加全匹配,日期类型字段Orig结尾的处理,因为这个字段没有类型的,需要做以下的处理
70 MS.Date;
71 if(this.DateStrings && this.GetType(row,col)=="Date"||(col!=undefined&&col.indexOf("Orig")>0&&this.GetType(row,col.replace("Orig",""))=="Date")){ 
72    if(!val&&val!="0") return ""; 
73    MS.Hirji;
74    var hir = this.Lang.Format.Hirji;
75    if(hir){
76       if(hir==1) this.Lang.Format.Hirji = 0;
77       if(hir==2) this.Lang.Format.Hirji = 1;
78       }
79    ME.Hirji;      
80    var D = this.Lang.Format.DateToString(val,this.DateStrings==2?"yyyy-MM-dd HH:mm:ss":(this.DateStrings==1?null:this.DateStrings),this.IsRange(row,col));
81    MS.Hirji;
82    if(hir) this.Lang.Format.Hirji = hir;
83    ME.Hirji;
84    return D;
85    }
86 ME.Date;
87 if(fed==1 && row[col+"EFormula"]) {
88    val = this.Lang.Format.FormulaPrefix+row[col+"EFormula"];
89    if(this.FormulaRelative==2) val = this.ConvertEditFormula(row,col,val,this.FormulaLocal ? 6 : 4);
90    }
91 return val;
92 }
93
94 // -----------------------------------------------------------------------------------------------------------
95 MS.Upload;
96 // -----------------------------------------------------------------------------------------------------------
97 // Returns string with row changes
98 // F is object with format settings
99 // type = &1 - changes, &2 - selected, &4 - resized
100 // For alldef&1 returns for added rows also values from defaults
101 // For alldef&2 returns also calculated values
102 TGP.GetRowChanges = function(row,F,type,alldef,attrs){
103 if(Is(row,"NoUpload") && !(alldef&32)) return "";
104 var S = "", C = this.Cols, T = this, X = { id:1,Added:1,Deleted:1,Changed:1,Moved:1,Parent:1,Next:1,Prev:1,Par:1,Selected:1,Copy:1,Resized:1,Height:1 }, fed = alldef&16 ? 0 : this.FormulaEditing;
105        var isaudit=false;//****增加审计功能 by 2014-3-12
106        var au="";//
107 function SetAttr(row,c){ 
108    if(X[c]) return;
109    X[c] = 1;
110    var v = alldef&1 ? Get(row,c) : row[c]; 
111    if(row[c+"_Link"]!=undefined) v=row[c+"_Link"];//***增加处理只读超链接时需要取原始值而不是表面的值
c35f05 112    if(row[c+"_Img"]!=undefined) v=row[c+"_Img"];//***增加处理图片时需要取原始值而不是表面的值
25ab64 113     if(row[c+"_expr_val"]!=undefined) v=row[c+"_expr_val"];
F 114    if(v==null) v = "";
115   
116    v = T.ConvertUpload(row,c,v,fed);
117    if(F.Dtd) S += "<U N=\""+c+"\" V=\""+F.Str(v)+"\"/>";
118    else S += F.Spc+c+F.Sep+"\""+F.Str(v)+"\"";
119    }
120
121 function GetAttrs(row){
122    if(!attrs) return "";
123    var S = "";
124    for(var i=0;i<attrs.length;i++){
125       var c = attrs[i], v = alldef&1 ? Get(row,c) : row[c]; 
126       if(v==null || X[c]) continue;
127       if(typeof(v)=="object"){ if(c=="Def") v = v.Name; else continue; }
128       X[c] = 1;
129       if(T.FormulaEditing==2 && T.FormulaRelative==2){
130          var idx = c.indexOf("EFormula");
131          if(idx>=0 && C[c.slice(0,idx)]) v = T.ConvertEditFormula(row,c.slice(0,idx),v,T.FormulaLocal ? 6 : 4);
132          }
133       S += F.Spc+c+F.Sep+"\""+F.Str(v)+"\"";
134       }
135    return S;   
136    }   
137
138 function SetSpan(r){
139    if(r.Spanned) for(var col in C) if((r[col+"Span"]>1||r[col+"SpanOrig"]>1) && r[col+"Span"]!=r[col+"SpanOrig"] && r[col+"RowSpan"]!=0 && r[col+"Visible"]!=-2) SetAttr(r,col+"Span");
140    if(r.RowSpan) for(var col in T.SpanCols) if((r[col+"RowSpan"]>1||r[col+"RowSpanOrig"]>1) && r[col+"RowSpan"]!=r[col+"RowSpanOrig"] && r[col+"Span"]!=0) SetAttr(r,col+"RowSpan");
141    }
142   function getAudit1(y){//*****by danaus 2014-3-25,取得审计设置为1的字段的值,组装作为以后查询的条件,GT_tranCode function是作为处理双引号
143         var result="";
144          for(var A in C) {
145              if(C[A].audit==1) {
146                  result+=","+GT_tranCode(y[A])+((y[A+"Orig"]!=undefined&&y[A+"Orig"]!="")?","+GT_tranCode(y[A+"Orig"]):"");
147              }
148              
149         }
150         return result+=",";
151     };
152 if(row.Deleted) {
153    S = F.Start+F.Str(row.id)+"\""+F.Spc+"Deleted"+F.One+(row.Added?F.Spc+"Added"+F.One:"")+GetAttrs(row);
154    if(F.Dtd) S += ">";
155   //** if(alldef&2) for(var c in C) if(!C[c].NoUpload) SetAttr(row,c); 去掉
156  for(var c in C){
157   // if(!C[c].NoUpload){//***** 去掉
158         if(row[c+"_Img"]!=undefined){
159             row[c+"Orig"]=row[c+"_Img"];
160              }
161          if(row[c+"_Link"]!=undefined){
162             row[c+"Orig"]=row[c+"_Link"];
c35f05 163              }
F 164          if(row[c+"_Orig46"]!=undefined){
165             row[c+"Orig"]=row[c+"_Orig46"];
25ab64 166              }
F 167     if(row[c+ "Orig"]!=undefined) row[c]=row[c+ "Orig"];//增加处理删除前修改了内容的情况,需要把原值返原处理 by 12-11-26
168         SetAttr(row,c);
169         //****delete 
170    if(this.Cols[c].audit==2||this.Cols[c].audit==1){//****删除的情况下,只需要处理为2的情况,只是把所有为1的作为值加进去就可以了
171 var aus="";
172                     if(row[c]==undefined||row[c]=="") continue;
173 if(this.Cols[c]!=undefined&&this.Cols[c].Type=="Date"){
174                         //处理日期数值返回给面板时候,需要格式化成日期显示,因为格线内部是用毫秒表示 by2014-6-24
175                     if(row[c]!=undefined)  row[c]= DateToString(row[c],this.Cols[c].Format);
176                     if(row[c+ "Orig"]!=undefined)  row[c+ "Orig"]= DateToString(row[c+ "Orig"],this.Cols[c].Format);
177                     }
178                         var oldValue=row[c];
179                     if(oldValue!=undefined&&oldValue!=""){
180                         oldValue=(oldValue+"").replace(/\\/g, '\\\\');
181                     }
182                     var newValue=row[c+ "Orig"];
183                     if(newValue!=undefined&&newValue!=""){
184                         newValue=(newValue+"").replace(/\\/g, '\\\\');
185                     }
186                     var Header=this.Header[c];
187                     if(Header!=undefined&&Header!=""){
188                         Header=(Header+"").replace(/\\/g, '\\\\');
189                     }
190                     if(au==""){
191                       aus='{"newvalue":"'+GT_tranCode(newValue,true)+'","oldvalue":"'+GT_tranCode(oldValue,true)+ '","Fielddescr":"' + GT_tranCode(Header,true)+'","fieldname":"'+c+'","usercode":"","username":"","auditType":"delete","_YCAUDIT_":"1","formid":"'+this.formid+'","doccode":"'+(row["doccode"]==undefined?'':row["doccode"])+'","auditIndex":"'+getAudit1(row)+'"}';   
192                     }else{
193                     aus=',{"newvalue":"'+GT_tranCode(newValue,true)+'","oldvalue":"'+GT_tranCode(oldValue,true)+ '","Fielddescr":"' + GT_tranCode(Header,true)+'","fieldname":"'+c+'","usercode":"","username":"","auditType":"delete","_YCAUDIT_":"1","formid":"'+this.formid+'","doccode":"'+(row["doccode"]==undefined?'':row["doccode"])+'","auditIndex":"'+getAudit1(row)+'"}';
194                     }
195                isaudit=true;
196                au+=aus;
197 }
198  // }
199    }
200    S += F.Dtd ? "</I>" : F.End;
201        if(isaudit) S+=au+",";//****把需要审计的加到另一个新行,类型是_YCAUDIT_
202    }
203 else if(row.Added || row.Moved==2&&alldef&8){
204    var def = row.Def, par = row.parentNode, next = this.NextChanges(row), prev = this.PrevChanges(row), ppar = Get(row,"Par");
205 //*** 不需要太多参数传递
206 //  S = F.Start+F.Str(row.id)+"\""+F.Spc+"Added"+F.One+(ppar?F.Spc+"Par"+F.Sep+"\""+ppar+"\"":"")+F.Spc+"Def"+F.Sep+"\""+def.Name
207 //    + "\""+F.Spc+"Parent"+F.Sep+"\"" + (par.id ? F.Str(par.id) : par.Pos!=null ? par.Pos : "") 
208 //    + "\""+F.Spc+"Next"+F.Sep+"\"" + (next && next.id ? F.Str(next.id) : "")
209 //    + "\""+F.Spc+"Prev"+F.Sep+"\"" + (prev && prev.id ? F.Str(prev.id) : "")
210 //     + "\"";
211 //   if(type&2 && row.Selected) S += F.Spc+"Selected"+F.Sep+"\""+row.Selected+"\"";
212 //   if(type&4 && row.Resized) S += F.Spc+"Height"+F.Sep+"\""+row.Height+"\"";
213 //  if(row.Copy) S += F.Spc+"Copy"+F.Sep+"\""+row.Copy+"\"";
214    S = F.Start+F.Str(row.id)+"\""+F.Spc+"Added"+F.One;//**不需要太多参数传递 by 11-4-18
215    X.Def = 1; //*** TODO 不清楚保留最新这个有没影响,在这里做个标记,暂时保留
216    S += GetAttrs(row);
217    if(F.Dtd) S += ">";
218    
219    MS.GenId;
220    if(this.IdMore){
221       for(var i=0;i<this.IdMore;i++){
222          var n = this.IdNames[i];
223          if(row[n]==null) row[n]=def[n];
224          if(n!="Def") SetAttr(row,n);
225          }
226       }
227    ME.GenId;
228    if(type&2 && row.Selected&2) { for(var c in C) if(row[c+"Selected"]) SetAttr(row,c+"Selected"); }
229    for(var c in C){
230       if(!C[c].NoUpload && (alldef&2 || (alldef&1 || row[c]!=null && (row[c]!=def[c]||!def[c])) && !this.IdTypes[c] && (!C[c].Formula && (!row.Calculated || !row[c+"Formula"]) || this.CalculatedChanges&&(this.CalculatedChanges-0||this.CalculatedChanges[c])))){
231           //增加处理Bool类型值为0时,转为null,广陶需要这样处理
232    //if(C[c]!=undefined&&C[c].Type!=undefined&&C[c].Type=="Bool"){
233        //if(row[c]=="0") row[c]="";
234       //        }
235          SetAttr(row,c);
236            if(this.Cols[c].audit==2){//*******add 审计
237                     var aus="";
238                     if(row[c]==undefined||row[c]=="") continue;
239                     if(this.Cols[c]!=undefined&&this.Cols[c].Type=="Date"){
240                         //处理日期数值返回给面板时候,需要格式化成日期显示,因为格线内部是用毫秒表示 by2014-6-24
241                     if(row[c]!=undefined)  row[c]= DateToString(row[c],this.Cols[c].Format);
242                     if(row[c+ "Orig"]!=undefined)  row[c+ "Orig"]= DateToString(row[c+ "Orig"],this.Cols[c].Format);
243                     }
244                     var newValue=row[c];
245                     if(newValue!=undefined&&newValue!=""){
246                         newValue=(newValue+"").replace(/\\/g, '\\\\');
247                     }
248                     if(au==""){
249                       aus='{"oldvalue":"'+GT_tranCode(row[c+ "Orig"],true)+'","newvalue":"'+GT_tranCode(newValue,true)+ '","Fielddescr":"' +GT_tranCode( this.Header[c],true)+'","fieldname":"'+c+'","usercode":"","username":"","auditType":"add","_YCAUDIT_":"1","formid":"'+this.formid+'","doccode":"'+(row["doccode"]==undefined?'':row["doccode"])+'","auditIndex":"'+getAudit1(row)+'"}';  
250                     }else{
251                     aus=',{"oldvalue":"'+GT_tranCode(row[c+ "Orig"],true)+'","newvalue":"'+GT_tranCode(newValue,true)+ '","Fielddescr":"' +GT_tranCode( this.Header[c],true)+'","fieldname":"'+c+'","usercode":"","username":"","auditType":"add","_YCAUDIT_":"1","formid":"'+this.formid+'","doccode":"'+(row["doccode"]==undefined?'':row["doccode"])+'","auditIndex":"'+getAudit1(row)+'"}';
252                     }
253                isaudit=true;
254                au+=aus;
255               }
256          }
257       }
258    if(this.SaveSpan) SetSpan(row);
259    S += F.Dtd ? "</I>" : F.End;
260    if(isaudit) S+=au+",";//****把需要审计的加到另一个新行,类型是_YCAUDIT_
261    }
262 else if(row.Changed || row.Moved){
263    S = F.Start+F.Str(row.id)+"\"";
264    MS.GenId;
265    var CH = null;
266    if(alldef&4 && this.IdMore) {
267       CH = this.UpdateNewId(row,"NewId",0,row.Changed,row.Moved); 
268       if(row.NewId) S += F.Spc+"NewId"+F.Sep+"\""+row.NewId+"\"";
269       }
270    ME.GenId;
271    if(row.Changed) S += F.Spc+"Changed"+F.One;
272    if(row.Moved){ 
273       var par = row.parentNode, next = this.NextChanges(row), prev = this.PrevChanges(row);
274       S += F.Spc+"Moved"+F.Sep+"\""+row.Moved+"\""+F.Spc+"Parent"+F.Sep+"\"" 
275         + (par.id ? F.Str(par.id) : par.Pos!=null ? par.Pos : "") 
276         + "\""+F.Spc+"Next"+F.Sep+"\"" + (next && next.id ? F.Str(next.id) : "") 
277         + "\""+F.Spc+"Prev"+F.Sep+"\"" + (prev && prev.id ? F.Str(prev.id) : "")
278         + "\"";
279       }
280    if(type&2 && row.Selected) S += F.Spc+"Selected"+F.Sep+"\""+row.Selected+"\"";
281    if(type&4 && row.Resized) S += F.Spc+"Height"+F.Sep+"\""+row.Height+"\"";
282    S += GetAttrs(row);
283    if(F.Dtd) S += ">";
284    if(type&2 && row.Selected&2) { for(var c in C) if(row[c+"Selected"]) SetAttr(row,c+"Selected"); }
285    if(row.Changed || alldef&2){ 
286       if(row.Cells) {
287          for(var i=0;i<row.Cells.length;i++){
288               if(row[row.Cells[i]+"Changed"] || alldef&2){
289                    SetAttr(row,row.Cells[i]);
290                    SetAttr(row,row.Cells[i]+"Orig");//****
291               }else{
292                    SetAttr(row,row.Cells[i]);
293              }
294          }
295          }
296       else { 
297      for(var c in C){
298               if(row[c+"Changed"] || alldef&2&& !C[c].NoUpload){
299                    SetAttr(row,c);
300                    if(this.Cols[c].couter=="Img"&& row[c+"_Img"]!=undefined){
301                              row[c+"Orig"]=row[c+"_Img"];
302                              
303              }
ea472b 304              //****46控件 */
F 305              if(this.Cols[c].colType!=undefined&&this.Cols[c].colType==46&& row[c+"_Orig46"]!=undefined){
306                row[c+"Orig"]=row[c+"_Orig46"];
307              }
25ab64 308                    SetAttr(row,c+"Orig");
F 309               }else{
ea472b 310                   //****46控件 */
F 311              if(this.Cols[c].colType!=undefined&&this.Cols[c].colType==46&& row[c+"_Orig46"]!=undefined){
312                              if(row[c]==""){
313                                //*****不修改原值,但又需要把它提交到后台
314                               row[c]=row[c+"_Orig46"];
315                             }
316              } 
25ab64 317                   SetAttr(row,c);
F 318              }
319                 if(this.Cols[c].audit&&row[c + "Orig"] != undefined){
320                         if(this.Cols[c]!=undefined&&this.Cols[c].Type=="Date"){
321                         //***处理日期数值返回给面板时候,需要格式化成日期显示,因为格线内部是用毫秒表示 by2014-6-24
322                   if(row[c]!=undefined)  row[c]= DateToString(row[c],this.Cols[c].Format);
323                     if(row[c+ "Orig"]!=undefined)  row[c+ "Orig"]= DateToString(row[c+ "Orig"],this.Cols[c].Format);
324                     }
325                     var aus="";
326                     var newValue=row[c];
327                     if(newValue!=undefined&&newValue!=""){
328                         newValue=(newValue+"").replace(/\\/g, '\\\\');
329                     }
330                     var oldValue=row[c+ "Orig"];
331                     if(oldValue!=undefined&&oldValue!=""){
332                         oldValue=(oldValue+"").replace(/\\/g, '\\\\');
333                     }
334                     var Header=this.Header[c];
335                     if(Header!=undefined&&Header!=""){
336                         Header=(Header+"").replace(/\\/g, '\\\\');
337                     }
338                     if(au==""){
339                       aus='{"oldvalue":"'+GT_tranCode(oldValue,true)+'","newvalue":"'+GT_tranCode(newValue,true)+ '","Fielddescr":"' + GT_tranCode(Header,true)+'","fieldname":"'+c+'","usercode":"","username":"","auditType":"update","_YCAUDIT_":"1","formid":"'+this.formid+'","doccode":"'+(row["doccode"]==undefined?'':row["doccode"])+'","auditIndex":"'+getAudit1(row)+'"}';
340                     }else{
341                     aus=',{"oldvalue":"'+GT_tranCode(oldValue,true)+'","newvalue":"'+GT_tranCode(newValue,true)+ '","Fielddescr":"' + GT_tranCode(Header,true)+'","fieldname":"'+c+'","usercode":"","username":"","auditType":"update","_YCAUDIT_":"1","formid":"'+this.formid+'","doccode":"'+(row["doccode"]==undefined?'':row["doccode"])+'","auditIndex":"'+getAudit1(row)+'"}';
342                     }
343                isaudit=true;
344                au+=aus;
345               } 
346          }
347      }
348          }
349       
350    if(this.IdMore && row[this.IdCol+"Changed"] && !this.Cols[this.IdCol]) SetAttr(row,this.IdCol);
351    if(this.SaveSpan) SetSpan(row);
352    S += F.Dtd ? "</I>" : F.End;
353    if(isaudit) S+=au+",";//****把需要审计的加到另一个新行,类型是_YCAUDIT_
c35f05 354    MS.GenId; if(CH) for(var id in CH) S += F.Start+F.Str(id)+"\""+F.Spc+"NewId"+F.Sep+"\""+CH[id]+"\""+F.End; ME.GenId; 
25ab64 355    }
F 356 else if(type&2 && row.Selected || type&4 && row.Resized) {
357    S = F.Start+F.Str(row.id)+"\"";
358    if(type&2 && row.Selected) S += F.Spc+"Selected"+F.Sep+"\""+row.Selected+"\"";
359    if(type&4 && row.Resized) S += F.Spc+"Height"+F.Sep+"\""+row.Height+"\"";
360    S += GetAttrs(row);
361    if(F.Dtd) S += ">";
362    if(type&2 && row.Selected&2) { for(var c in C) if(row[c+"Selected"]) SetAttr(row,c+"Selected"); }
363    if(alldef&2) for(var c in C) if(!C[c].NoUpload) SetAttr(row,c);
364    }else if(this.cp&&row.Kind=="Data"&&row.id!="Fix1"){//***复单时候需要把这些数据作为新增 只有是data的行和不是统计行
365         var def = row.Def, par = row.parentNode, next = this.NextChanges(row), prev = this.PrevChanges(row), ppar = Get(row,"Par");
366    S = F.Start+F.Str(row.id)+"\""+F.Spc+"Added"+F.One;//**不需要太多参数传递 by 11-4-18
367    S += GetAttrs(row);
368    if(F.Dtd) S+=">";
369    MS.GenId;
370    if(this.IdMore){
371       for(var i=0;i<this.IdMore;i++){
372          var n = this.IdNames[i];
373          if(row[n]==null) row[n]=def[n];
374          if(n!="Def") SetAttr(row,n);
375          }
376       }
377    ME.GenId;
378    for(var c in C){
379       if(alldef&2 || (alldef&1 || row[c]!=null && (row[c]!=def[c]||!def[c])) && !this.IdTypes[c] && (!C[c].Formula && (!row.Calculated || !row[c+"Formula"])) && C[c].Type!="Gantt" && c!="_ConstWidth"){
380          SetAttr(row,c);
381          }
382       }
383    if(this.SaveSpan) SetSpan(row);
384    S += F.Dtd ? "</I>" : F.End;
385    }else if(this.btnId!=""&&row.Kind=="Data"&&row.id!="Fix1"){//***点OA按钮时需要把当前格线数据提交到后台 则只有是data的行且不是统计行
386         var def = row.Def, par = row.parentNode, next = this.NextChanges(row), prev = this.PrevChanges(row), ppar = Get(row,"Par");
387    S = F.Start+F.Str(row.id)+"\""+F.Spc+"OAChanged"+F.One;//**不需要太多参数传递 by 11-4-18
388    S += GetAttrs(row);
389    if(F.Dtd) S+=">";
390    MS.GenId;
391    if(this.IdMore){
392       for(var i=0;i<this.IdMore;i++){
393          var n = this.IdNames[i];
394          if(row[n]==null) row[n]=def[n];
395          if(n!="Def") SetAttr(row,n);
396          }
397       }
398    ME.GenId;
399    for(var c in C){
400       if(alldef&2 || (alldef&1 || row[c]!=null && (row[c]!=def[c]||!def[c])) && !this.IdTypes[c] && (!C[c].Formula && (!row.Calculated || !row[c+"Formula"])) && C[c].Type!="Gantt" && c!="_ConstWidth"){
401          SetAttr(row,c);
402          }
403       }
404    if(this.SaveSpan) SetSpan(row);
405    S += F.Dtd ? "</I>" : F.End;
406    }
407 else if(this.SaveSpan) {
408    SetSpan(row);
409    if(S) S = F.Start + F.Str(row.id) + "\"" + F.Spc + "Changed" + F.One + (F.Dtd?">":"") + S + (F.Dtd?"</I>":F.End);
410    }
411 return S;
412 }
413 // -----------------------------------------------------------------------------------------------------------
414 // Returns changes of variable rows - recursion
415 TGP.GetChildrenChanges = function(row,F,type,alldef,attrs){
416 var A = [], p = 0;
417 for(var r=row.firstChild;r;r=r.nextSibling){ 
418    A[p] = this.GetRowChanges(r,F,type,alldef,attrs); if(A[p]) p++;
419    var D = this; if(r.DetailCol){
420       for(var rr=r;rr.DetailRow;rr=rr.DetailRow[0]) if(rr.DetailGrid) D = rr.DetailGrid[0];
421       }
422    A[p] = D.GetChildrenChanges(r,F,type,alldef,attrs);
423    
424    if(A[p]) p++;
425    }
426 return A.join("");
427 }
428 // -----------------------------------------------------------------------------------------------------------
429 // Returns what changes grid contains (&1 changes, &2 selected rows)
430 TGP.HasChanges = function(row){
431 var ret = 0,max = (this.Resizing?4:0)+(this.Selecting?2:0)+1;
432 if(!row){
433    var F = this.GetFixedRows();
434    for(var i=0;i<F.length;i++) if(F[i].Kind!="Filter") ret |= this.HasChanges(F[i]);
435    for(var r=this.XS.firstChild;r;r=r.nextSibling) ret |= this.HasChanges(r);
436    for(var b=this.XB.firstChild;b&&ret!=max;b=b.nextSibling) for(var r=b.firstChild;r;r=r.nextSibling) ret |= this.HasChanges(r);
437    }
438 else {
439    if(!Is(row,"NoUpload")){
440       if(row.Added || row.Deleted || row.Changed || row.Moved) ret|=1;
441       if(row.Selected&1) ret|=2;
442       if(row.Resized) ret|=4;
443       }
444    if(ret!=max) for(var r=row.firstChild;r;r=r.nextSibling) ret |= this.HasChanges(r);
445    }
446 if(this.SaveHeights) ret&=~4;
447 if(this.SaveSelected) ret&=~2;
448 if(this.SaveValues) ret&=~1;
449 return ret;
450 }
451 // -----------------------------------------------------------------------------------------------------------
452 // Returns data of changed rows in XML in string, without root tag, row tags only
453 // If row is given, returns changes of this row only
454 // If type is given, returns tag <changes> only, cannot be used with row
455 // type = &1 - changess, &2 selected, &4 resized
456 // For alldef&1 returns for added rows also values from defaults
457 // For alldef&2 returns also calculated values
458 TGP.GetChanges = function(row,type,alldef,attrs,F){
459 if(!F) F = this.GetUploadFormat(this.Source.Upload);
460 //*** 增加 this.Ps
461 var gridstart = (F.Json?"{"+this.Ps+" \"IO\":{":"<Grid><IO")+(this.Source.Session!=null?F.Spc1+"Session"+F.Sep+"\""+this.Source.Session+"\"":"")+F.End;
462 var gridend = F.Json ? "}" : "</Grid>", chgstart = F.Json ? "\"Changes\":[" :"<Changes>", chgend = F.Json ? "]" : "</Changes>";
463 if(row) {
464    var chg = this.GetRowChanges(row,F,type,alldef,attrs); if(!chg) return "";
465    if(F.Json && chg.slice(-1)==',') chg = chg.slice(0,-1); 
466    return gridstart+chgstart + chg + chgend+gridend;
467    }
468 if(this.SaveOrder) return (type?"":gridstart+chgstart) + this.GetChangesOrder() + (type?"":chgend+gridend);
469 var A = [], p = 0;
470 var R = this.GetFixedRows();
471 for(var i=0;i<R.length;i++) if(R[i].Kind!="Filter"){ A[p] = this.GetRowChanges(R[i],F,type,alldef,attrs); if(A[p]) p++;}
472 for(var r=this.XS.firstChild;r;r=r.nextSibling){ A[p] = this.GetRowChanges(r,F,type,alldef,attrs); if(A[p]) p++; }
473 for(var b=this.XB.firstChild;b;b=b.nextSibling){ A[p] = this.GetChildrenChanges(b,F,type,alldef,attrs); if(A[p]) p++;}
474 if(F.Json && p && A[p-1].slice(-1)==',') A[p-1] = A[p-1].slice(0,-1); 
475
476 return (type?"":gridstart+chgstart) + A.join("") + (type?"":chgend+gridend);
477 }
478 // -----------------------------------------------------------------------------------------------------------
479 // Clear all modification flags in rows and rerenders them, deletes rows marked Deleted
480 // If row is given, updates this row only
481 TGP.AcceptChanges = function(row,master){
482 if(!row) { 
483    MS.Undo; 
484    if(this.Undo&32 && this.OUndo) { 
485       var OU = this.OUndo, p = OU.Pos;
486       if(p){
487          if(OU[p-1].Type=="End"){
488             if(OU[p-2].Type!="Accept"){ OU.splice(p-1,0,{Type:"Accept",Row:null}); OU.Pos++; }
489             }
490          else if(OU[p-1].Type!="Accept") { OU.splice(p-1,1,{Type:"Start"},OU[p-1],{Type:"Accept",Row:null},{Type:"End"}); OU.Pos+=3; }
491          }
492       
493       } 
494    
495    else if(!this.MasterGrid) this.ClearUndo(1); 
496    ME.Undo;
497    this.Changes = []; 
498    var F = this.GetFixedRows(),r,n,l;
499    for(r=0;r<F.length;r++) if(F[r].Kind!="Filter") this.AcceptChanges(F[r],1);
500    for(r=this.XS.firstChild;r;r=r.nextSibling) this.AcceptChanges(r,1);
501    for(r=this.GetFirst();r;){
502       if(r.Deleted){
503          n = r; l = r.Level;
504          r = this.GetNext(r);
505          if(l!=null) while (r && r.Level > l) r = this.GetNext(r); 
506          this.AcceptChanges(n,1);
507          }
508       else { 
509          this.AcceptChanges(r,1);
510          r = this.GetNext(r);
511          }
512       }
513    if(this.RefreshDetail) this.RefreshDetail();
514    MS.Pivot; if(this.PivotDetail) for(var id in this.PivotDetail) this.PivotDetail[id].AcceptChanges(null,1); ME.Pivot;
515
516    var C = this.Cols; 
517    for(var c in C) {
518       if(C[c].Deleted) this.DelCol(c);
519       else if(C[c].Added) { C[c].Added = 0; if(this.ColorState&4) this.ColorCol(c); }
520       }
521    this.SaveOrigData();
522    return;
523    }
524
525 if(row.Deleted && Get(row,"NoUpload")!=2){ 
526    if(row==this.FRow) this.FRow = null;
527    this.DelRow(row);
528    }
529 else if((row.Added || row.Changed || row.Moved) && Get(row,"NoUpload")!=2){
530    MS.GenId; if(this.IdMore) this.UpdateNewId(row,"id",this.SetIds,row.Changed,row.Moved); ME.GenId;
531      if(row.Changed){ 
532       var calcchg = this.CalculatedChanges; 
533         if(row.Cells){ 
534            for(var i=0;i<row.Cells.length;i++) if(row[row.Cells[i]+"Changed"]){ row[row.Cells[i]+"Changed"] = null; this.RefreshCell(row,row.Cells[i]); if(calcchg) row[row.Cells[i]+"Orig"] = row[row.Cells[i]]; }
535            }
536         else {
537            for(var c in this.Cols) if(row[c+"Changed"]){ row[c+"Changed"] = null; this.RefreshCell(row,c); if(calcchg) row[c+"Orig"] = row[c];  }
538            }
539         
540         }
541      if(this.IdMore && (row.Changed || row.Moved) && row[this.IdCol+"Changed"]) row[this.IdCol+"Changed"] = null;
542    MS.Gantt;
543    MS.GanttRun;
544    if(this.Gantt){
545       var col = this.GetFirstGantt(), C = this.Cols[col];
546       if(C && C.GanttRunStates&2 && this.Cols[C.GanttRun]){
547          var run = Get(row,C.GanttRun), chg = 0;
548          if(run){
549             var s1 = run.charCodeAt(0),s2 = ','; 
550             if(s1>=48&&s1<=57||s1==32||s1==45) s1 = ';';
551             else {
552                s1 = run.charAt(0);
553                s2 = run.charCodeAt(1);
554                if((s2>=48&&s2<=57||s2==45)&&s1!=32) { s2 = ','; run = run.slice(1); }
555                else { s2 = run.charAt(1); run = run.slice(2); }
556                }
557             if(s1=='['&&s2=='{'){ 
558                run = FromJSON("[{"+run);
559                if(typeof(run)!="string") {
560                   for(var i=0;i<run.length;i++){
561                      var ri = run[i];
562                      if(ri.State) {
563                         var s = C.GanttRunStates&4 ? ri.State&7 : ri.State.replace(/added|deleted|moved|resized|changed/g,"").replace(/\+[\+]+|^\+|\+$/g,""); 
564                         if(ri.State!=s){ chg = 1; if(s) ri.State = s; else delete ri.State; }
565                         }
566                      if(ri.Type=="-") { chg = 1; run.splice(i--,1); }
567                      }
568                   }
569                if(chg){
570                   for(var i=0;i<run.length;i++){
571                      var ri = run[i], s = "";
572                      for(var n in ri) s += n+":'"+((ri[n]+"").search(/[\\\']/)<0?ri[n]:ri[n].replace(/\\/g,"\\\\").replace(/\'/g,"\\'"))+"',";
573                      run[i] = s.slice(0,-1); 
574                      }
575                   row[C.GanttRun] = "[{"+run.join("},{")+"}]"; this.RefreshCell(row,C.GanttRun);
576                   }
577                }                     
578             else {  
579                run = run.split(s1);
580                for(var i=0;i<run.length;i++){
581                   var rr = run[i].split(s2);
582                   var hs = parseInt(rr[1])+1 ? 1 : 0;
583                   if(rr[7+hs]){ 
584                      var s = C.GanttRunStates&4 ? rr[7+hs]&7 : rr[7+hs].replace(/added|deleted|moved|resized|changed/g,"").replace(/\+[\+]+|^\+|\+$/g,""); 
585                      if(s!=rr[7+hs]){ 
586                         chg = 1; rr[7+hs] = s; 
587                         if(!s && rr.length==8+hs) { for(var j=6;j>=0&&!rr[j+hs]&&rr[j+hs]!="0";j--); rr.length = j+hs+1; }
588                         run[i] = rr.join(s2); 
589                         }
590                      }
591                   if(rr[1+hs]=="-") { chg = 1; run.splice(i--,1); }
592                   }
593                if(chg){ row[C.GanttRun] = (s1==';'&&s2==','?"":s1+s2)+run.join(s1); this.RefreshCell(row,C.GanttRun); }
594                }
595             }
596          }
597       }
598    ME.GanttRun;
599    ME.Gantt;
600    if(row.DetailRow) for(var i=0;i<row.DetailRow.length;i++) {
601       var r = row.DetailRow[i]; r.Added = row.Added; r.Changed = row.Changed; r.Moved = row.Moved; r.Copy = row.Copy; r.NewId = row.NewId;
602       row.DetailGrid[i].AcceptChanges(r);
603       }
604    row.Added = null; 
605    row.Changed = null;
606    row.Moved = null;
607    row.Copy = null;
608    row.NewId = null;
609    if(this.ColorState&3) this.ColorRow(row); 
610    
611    }
612
613 if(this.SaveSpan){
614    if(row.Spanned){
615       for(var c in this.Cols) {
616          if(row[c+"SpanOrig"]) row[c+"SpanOrig"] = null;
617          if(row[c+"Span"]>1 && row[c+"RowSpan"]!=0) row[c+"SpanOrig"] = row[c+"Span"];
618          }
619       }
620    if(row.RowSpan){
621       for(var c in this.SpanCols) {
622          if(row[c+"RowSpanOrig"]) row[c+"RowSpanOrig"] = null;
623          if(row[c+"RowSpan"]>1 && row[c+"Span"]!=0) row[c+"RowSpanOrig"] = row[c+"RowSpan"];
624          }
625       }
626    }
627 MS.Pivot; if(!master && this.PivotDetail) for(var id in this.PivotDetail) this.PivotDetail[id].AcceptChanges(row,1); ME.Pivot;
628 if(!master && this.RefreshDetail) this.RefreshDetail();
629 }
630 // -----------------------------------------------------------------------------------------------------------
631 // Returns all grid data
632 // type = &7 = rows, 0 - none, 1 - changed, 2 - selected, 3 - selected + changed, 5 - all fixed, 6 - all variable, 7 - all
633 // type&8 = configuration from cookies, &16 - Cfg, &32 - Def, &64 - Cols, &128 - Header, &256 - Panel+Toolbar+MenuCfg+Pager, &512 - Img
634 // type&1024 = Lang, &0x10000 - no <Grid>, &0x20000 - no <IO>
635 TGP.GetXmlData = function(type,attrs,colvis,U,row,rowvis){
636 var flags = ""; if(!U) U = this.Source.Upload;
637 if(type==null) { type = U.Type; flags = U.Flags; }
638 var names, otype = type;
639 MS.UploadType;
640 MS.Debug; names = "changes,selected,resized,expanded,hidden,body,data,all,fixed,settings,config,configxlsx,cookie,cfg,def,cols,root,menu,actions,animations,pagers,resources,zoom,calendars,media,other,lang,languages,text,complete,defaults,allcols,nodelete,noio,nogrid,gantt,span,spanned,newid,accepted,index,nogantt,autocols,focus,editattrs,cells,noempty,focused,fullmoved,noformula,noupload"; ME.Debug;
641 if(type && type-0+""==type) { 
642    var t = type&7;
643    type = this.BitArrayToFlags(type&~7,",,,settings,cfg,def,cols,,other,,lang,,cookie,,,,nogrid,noio");
644    if(t==3) { type["changed"] = 1; type["selected"] = 1; }
645    else type[["","changes","selected","","","","body","all"][t]] = 1;
646    }
647 else {
648    if(type&&typeof(type)=="string"&&type.toLowerCase().indexOf("complete")>=0) type += ",all,cols,cfg,def,calendars,resources,zoom,other,lang,text";
649    type = this.ConvertFlags((type?type:(type==null?"changes":""))+(flags&&type!=""?",":"")+(flags?flags:""),names);
650    }
651 ME.UploadType;
652 if(attrs==null) attrs = U.Attrs;
653 if(typeof(attrs)=="string") attrs = attrs.split(",");
654
655 var C = this.Cols, rspn = 0, cspn = 0, noformula = type["noformula"], fed = noformula ? 0 : this.FormulaEditing;
656 if(attrs) {
657    var A = [], p = 0;
658    for(var i=0;i<attrs.length;i++) {
659       if(attrs[i].charAt(0)=="*"){ 
660          var a = attrs[i].slice(1); 
661          if(a=="RowSpan") rspn = 1;
662          else if(a=="Span") cspn = 1;
663          for(var c in C) if(!C[c].NoUpload && (a||c!="id")) A[p++] = c+a;
664          }
665       else A[p++] = attrs[i];
666       }
667    attrs = A;
668    }
669 if(type["editattrs"]) {
670    var A = this.GetEditAttrs(fed==2?3:1); if(!attrs) attrs = [];
671    if(A.RowSpan!=null) A.splice(A.RowSpan,1);
672    if(A.Span!=null) A.splice(A.Span-(A.RowSpan!=null&&A.Span>A.RowSpan?1:0),1);
673    A.push("Img","Link");
674    for(var i=0;i<A.length;i++) {
675       var a = A[i];
676       if(a=="RowSpan") rspn = 1;
677       else if(a=="Span") cspn = 1;
678       for(var c in C) if(!C[c].NoUpload && (a||c!="id")) attrs[attrs.length] = c+a;
679       }
680    }
681 if(this.HasFiles){
682    U.Files = {};
683    for(var col in this.HasFiles){
684       var H = this.HasFiles[col];
685       for(var id in H){
686          var r = this.Rows[id];
687          if(r && r[col] && r[col+"Changed"]) {
688             for(var i=0,F=r[col];i<F.length;i++) U.Files[id+"$"+col+(i?"$"+i:"")] = r[col][i];
689 //            r[col+"Zal"] = F; r[col] = ""; 
690             }
691          }
692       }
693    }
694 else U.Files = null;
695 if(!otype && !flags) return this.GetChanges(row,null,null,attrs); 
696
697 MS.UploadType;
698 if(row) return this.GetChanges(row,1+(type["selected"]?2:0)+(type["resized"]?4:0),(type["defaults"]?1:0)+(type["allcols"]?2:0)+(type["newid"]?4:0)+(type["fullmoved"]?8:0)+(noformula?16:0)+(type["noupload"]?32:0),attrs);
699
700 var F = this.GetUploadFormat(U), O = type["cells"] ? this.OrigData : null, noempty = type["noempty"];
701 var A = [], p = 0, T = this, pp;
702
703 function GetAttr(n,v){
704    if(typeof(v)=="boolean") v=v?1:0;
705    else if(typeof(v)!="string" && typeof(v)!="number") return "";
706    if(n.charAt(0)=='_') { 
707       if(n.charAt(1)=='7'||n.search(/Formula|Enum/)<0) return "";   
708       n = n.slice(1); 
709       }
710    return F.Spc+n+F.Sep+"\""+F.Str(v)+"\"";
711    }
712
713 function SetAttr(n,v){
714    if(accept && (n=="Added"||n=="Deleted"||n=="Moved"||n=="Changed"||n=="Parent"||n=="Next"||n=="Prev")) return;
715    if(typeof(v)=="boolean") v=v?1:0;
716    else if(typeof(v)!="string" && typeof(v)!="number") return;
717    if(n.charAt(0)=='_') { 
718       if(n.charAt(1)=='7'||n.search(/Formula|Enum/)<0) return;   
719       n = n.slice(1); 
720       }
721    A[p++] = F.Spc+n+F.Sep+"\""+F.Str(v)+"\"";
722    }
723
724 function SetAttrs(nm,row,json2,reg){ 
725    var S = "";
726    if(reg) for(var n in row) { if(n.search(reg)==0) S += GetAttr(n,row[n]); }
727    else for(var n in row) S += GetAttr(n,row[n]); 
728    if(F.Json && S && S.charAt(0)==',') S = S.slice(1); 
729    A[p++] = "\n"+(json2?"{":(F.Json ? "\""+nm+"\":{" : "<"+nm))+S+F.End;
730    }
731
732 function SetCustomAttrs(row){
733    if(!attrs) return;
734    var o = O ? O[row[ridx?ridx:"id"]] : null;
735    for(var i=0;i<attrs.length;i++) {
736       var n = attrs[i], v = row[n]; 
737       MS.RowSpan; if(rspn && row.RowSpan && n.indexOf("RowSpan")>=0 && (v=="0"||v==1) && C[n.replace("RowSpan","")]) continue; ME.RowSpan;
738       MS.ColSpan; if(cspn && row.Spanned && n.indexOf("Span")>=0 && (v=="0"||v==1) && C[n.replace("Span","")]) continue; ME.ColSpan;
739       if(v==null && alldef && row.Def) { v = row.Def[n]; if(!v&&v!="0"&&C[n]) v = null; }
740       var cn = n;
741       MS.Calc;
742       if(cidx){ 
743          if(!C[n]) { var c = GetColFromCell(n); if(c&&C[c]){ if(C[c].HasIndex) cn = cidx[c]+n.slice(c.length); else if(O&&C[c].Deleted) continue; } }
744          else if(C[n].HasIndex) cn = cidx[n];
745          else if(O&&C[n].Deleted) continue;
746          }
747       ME.Calc;
748       if(C[n]&&fed==1&&row[n+"EFormula"]!=null ? o&&row[n+"EFormula"]==o[n+"EFormula"] : o ? o[cn]==v||!v&&!o[cn]&&isNaN(v)&&isNaN(o[cn]) : v==null) continue;
749       
750       if(C[n]) v = T.ConvertUpload(row,n,v,fed);
751       if(v==null) v = "";
752       SetAttr(cn,v); 
753       }
754    }
755 function SetRowAttrs(nm,row,reg){
756    if((accept||ridx) && row.Deleted) return;
757    A[p++] = F.Json ? "\n{" : "\n<"+nm;
758    var pp = p;
759    if(ridx&&row.HasIndex) SetAttr("id",row[ridx]);
760    else if(row.id) SetAttr("id",row.id);
761    if(row.Def && (row.Def.Name!="R"||alldef)) SetAttr("Def",row.Def.Name);
762    var cp = p, o = null;
763    if(O){
764       o = O[row[ridx?ridx:"id"]];
765       if(!ridx){
766          var rn = T.GetNextSibling(row), rp = T.GetPrevSibling(row), par = row.parentNode.Page?null:row.parentNode;
767          if((par?par.id:null)!=(o?o.parentNode:null)||(rn?rn.id:null)!=(o?o.nextSibling:null)||(rp?rp.id:null)!=(o?o.previousSibling:null)){
768             SetAttr("Moved",1); SetAttr("Parent",par?par.id:""); SetAttr("Next",rn?rn.id:""); SetAttr("Prev",rp?rp.id:"");
769             }
770          else if(!o) SetAttr("Added",1);
771          }
772       else if(o?row.Level!=o.Level:row.Level>0) SetAttr("Level",row.Level);
773       }
774    if(attrs||allcols) {
775       if(attrs) SetCustomAttrs(row); 
776       if(allcols) SetRowCols(row);
777       }
778    else {
779       var D = alldef ? null : row.Def;
780       for(var n in row) if(!RA[n]) {
781          var v = row[n]; if(D && (v===D[n]||CRowAttrs[n])) continue;
782          if(nogantt && n.indexOf(nogantt)==0 || ridx && n==ridx || noformula&&n.indexOf("EFormula")>0) continue;
783          MS.RowSpan; if(row.RowSpan && n.indexOf("RowSpan")>=0 && (v=="0"||v==1) && T.Cols[n.replace("RowSpan","")]) continue; ME.RowSpan; 
784          MS.ColSpan; if(row.Spanned && n.indexOf("Span")>=0 && (v=="0"||v==1) && T.Cols[n.replace("Span","")]) continue; ME.ColSpan; 
785          if(v==null && alldef && row.Def) v = row.Def[n];
786          var cn = n;
787          MS.Calc;
788          if(cidx){ 
789             if(!C[n]) { var c = GetColFromCell(n); if(c&&C[c]){ if(C[c].HasIndex) cn = cidx[c]+n.slice(c.length); else if(O&&C[c].Deleted) continue; } }
790             else if(C[n].HasIndex) cn = cidx[n];
791             else if(O&&C[n].Deleted) continue;
792             }
793          ME.Calc;
794          
795          if(o ? o[cn]==v || fed&&C[n]&&(fed==1?row[n+"EFormula"]&&row[n+"EFormula"]==o[cn+"EFormula"]:!v&&!o[cn]&&isNaN(v)&&isNaN(o[cn])) : v==null) continue;
796          if(C[n]) { if(C[n].Type!="Gantt") v = T.ConvertUpload(row,n,v,fed); }
797          else if(fed && (fed==1||T.FormulaRelative==2)){
798             var idx = n.indexOf("EFormula");
799             if(idx>0 && C[n.slice(0,idx)]){
800                if(fed==1) continue;
801                if(T.FormulaRelative==2) v = T.ConvertEditFormula(row,n.slice(0,idx),v,T.FormulaLocal ? 6 : 4);
802                }
803             }
804          if(!reg||cn.search(reg)==0&&cn!="RowSpan") { 
805             if(v==null) v = "";
806             SetAttr(cn,v); 
807             }
808          }
809       }
810    
811    if(F.Json) RemoveFirst(pp);
812    return cp!=p;
813    }
814
815 function SetRowChildren(nm,row,reg){
816    if((accept||ridx) && row.Deleted) return;
817    var noup = Get(row,"NoUpload")-0 && !type["noupload"];
818    if(!noup){ 
819       var cp = p;
820       if(!SetRowAttrs(nm,row,reg)&&noempty&&(!row.firstChild||O)) { p = cp; A.length = p; }
821       else A[p++] = row.firstChild&&!O ? (F.Json?",\"Items\":[":">") : F.End; 
822       }
823    for(var r=row.firstChild;r;r=r.nextSibling) SetRowChildren(r.tagName,r,reg);
824    if(!noup && row.firstChild && !O) {
825       if(F.Json) RemoveLast();
826       A[p++] = F.Json?"]\n},":"\n</"+nm+">";
827       }
828    }
829
830 function SetRowCols(row){
831 var o = O ? O[row[ridx?ridx:"id"]] : null;
832 for(var c in C){
833    if(c=="id" || C[c].NoUpload) continue;
834    var v = alldef&1 ? Get(row,c) : row[c]; 
835    if(v==null) v = "";
836    v = T.ConvertUpload(row,c,v,fed);
837    if(cidx && C[c].HasIndex) c = cidx[c];
838    if(o && (o[c]==v || o[c]==null&&v==="" || fed&&v&&row[c+"EFormula"]&&(v+"").slice(1)==o[c+"EFormula"])) continue;
839    A[p++] = F.Spc+c+F.Sep+"\""+F.Str(v)+"\"";
840    }
841 }
842
843 function GetAutoCols(){
844 var cnt = 0; for(var c in C) if(C[c].HasIndex) cnt++;
845 return GetAttr("AutoCols",cnt);
846 }
847
848 function RemoveLast() {
849    if(p && A[p-1] && A[p-1].slice(-1)==',') A[p-1] = A[p-1].slice(0,-1); 
850    }
851 function RemoveFirst(pp) {   
852    if(A[pp] && A[pp].charAt(0)==',') A[pp] = A[pp].slice(1); 
853    }
854
855 var RA = Grids.INames;
856 if(!type["nogrid"]) A[p++] = F.Json ? "{" : "<Grid>";
857 if(!type["noio"]) A[p++] = (F.Json?"\"IO\":{":"<IO")+(this.Source.Session!=null?F.Spc1+"Session"+F.Sep+"\""+this.Source.Session+"\"":"")+F.End;
858 var alldef = type["defaults"]?1:0, accept = type["accepted"], allcols = type["allcols"]?2:0, nogantt = this.Gantt && type["nogantt"] ? this.GetFirstGantt() : null;
859 var ridx = type["index"] ? this.RowIndex : null, rid = ridx?ridx:"id", cidx = type["index"] ? this.Rows[this.ColIndex] : null;
860
861 var grp = this.Group && (type["cfg"]||type["settings"]) && (type["body"]||type["data"]||type["all"]) && this.Paging!=3;
862 if(grp){ var zalgrp = this.Group; this.DoGrouping("",-1); this.Group = zalgrp; }
863 if(this.Img.Width!=1){
864    if(type["cols"]) this.MultiplyScale(1/this.Img.Width,9);
865    if(type["other"]) this.MultiplyScale(1/this.Img.Width,10);
866    if(type["all"]||type["fixed"]) this.MultiplyScale(1/this.Img.SpaceWidth,12);
867    if(this.Gantt&&type["cols"]) this.MultiplyScale(1/this.Img.GanttWidth,24);
868    }
869 if(type["cfg"]||type["body"]||type["data"]||type["all"]||type["fixed"]||type["other"]||type["cols"]||O){
870    var D = CDebugAttrs, B = CCellAttrs;
871    if(!D.Parsed){ for(var a in D) if(D[a]) D[a] = D[a].split(","); D.Parsed = 1; }
872    if(!B.Parsed){ for(var a in B) if(B[a]) B[a] = B[a].split(","); B.Parsed = 1; }
873    }
874
875 // --- Gantt ---
876 MS.Gantt;
877 if(type["gantt"]){
878    var col = this.GetFirstGantt(); 
879    if(col){
880       var c = C[col], N = ["Base","Finish","Exclude","Include"];
881       if(type["settings"]||type["config"]||type["configxlsx"]) {
882          N = N.concat("HideExclude","ResourcesFilter","Zoom","ZoomDate","CorrectDependencies","CheckDependencies","Strict","BaseProof","BasePreferred","CheckExclude","CorrectDependenciesFixed");
883          c.GanttZoomDate = this.GetGanttADate(col);
884          }
885       A[p++] = F.Json ?"\n\"Gantt\":{" :"\n<Gantt"; pp = p;
886       for(var i=0;i<N.length;i++) {
887          var v = c["Gantt"+N[i]];
888          A[p++] = F.Spc+"Gantt"+N[i]+F.Sep+"\""+(v?v:"")+"\"";
889          if(i==1) v = this.IncLastUnit(v,c,-1,1);
890          if(i<2 && this.DateStrings) A[p++] = F.Spc+"Gantt"+N[i]+"Date"+F.Sep+"\""+(v?this.Lang.Format.DateToString(v,this.DateStrings==2?"yyyy-MM-dd HH:mm:ss":(this.DateStrings==1?null:this.DateStrings)):"")+"\"";
891          }
892       A[p++] = F.Spc+"GanttWidthCookie"+F.Sep+"\""+c.GanttWidth/this.Img.GanttWidth+"\"";
893       //[p++] = F.Spc+"GanttExclude"+F.Sep+"\""+(c.GanttExclude?F.Str(c.GanttExclude):"")+"\"";
894       if(F.Json) RemoveFirst(pp);
895       A[p++] = F.End;   
896       }
897    }
898
899 // --- Resources ---
900
901 // --- Calendars ---
902 MS.GanttExclude; 
903 if(type["calendars"]){
904    var X = this.Calendars;
905    if(X){
906       A[p++] = F.Json ? "\n\"Calendars\":"+(F.Json2?"[":"{") : "\n<Calendars>";
907       for(var x in X) {
908          if(F.Json2) { A[p++] = "\n{\"Name\":\""+x+"\""; }
909          else if(F.Json) A[p++] = "\n\""+x+"\":{";
910          else { A[p++] = "\n<E"; SetAttr("Name",x); }
911          SetAttr("Exclude",X[x].Exclude);
912          A[p++] = F.End;   
913          }
914       if(F.Json) RemoveLast(); 
915       A[p++] = F.Json ? "\n"+(F.Json2?"]":"}")+"," : "\n</Calendars>";
916       }
917    }
918 ME.GanttExclude; 
919
920 // --- Resources ---
921 MS.GanttResources; 
922 if(type["resources"]){
923    var X = this.Resources;
924    if(X){
925       A[p++] = F.Json ? "\n\"Resources\":"+(F.Json2?"[":"{") : "\n<Resources>";
926       for(var x in X) {
927          if(F.Json2) { A[p++] = "\n{\"Name\":"+x+"\""; }
928          else if(F.Json) A[p++] = "\n\""+x+"\":{";
929          else { A[p++] = "\n<R"; SetAttr("Name",x); }
930          SetAttr("Text",X[x].Text);
931          SetAttr("Type",X[x].Type);
932          SetAttr("Price",X[x].Price);
933          SetAttr("Availability",X[x].Availability);
934          A[p++] = F.End;   
935          }
936       if(F.Json) RemoveLast(); 
937       A[p++] = F.Json ? "\n"+(F.Json2?"]":"}")+"," : "\n</Resources>";
938       }
939    }
940 ME.GanttResources; 
941
942 // --- Zoom ---
943 MS.GanttZoom;
944 if(this.GanttZoom && type["zoom"]){
945    A[p++] = F.Json ? "\n\"Zoom\":[" : "\n<Zoom>";
946    for(var n in this.GanttZoom) SetAttrs("Z",this.GanttZoom[n],F.Json);
947    if(F.Json) RemoveLast();
948    A[p++] = F.Json ? "]," :"\n</Zoom>";
949    }
950 ME.GanttZoom;
951 ME.Gantt;
952
953 var cfg = "";
954 var set = type["settings"]||type["config"]||type["configxlsx"] ? {  
955    LeftWidth:3,MidWidth:3,RightWidth:3,PrintRows:2,PrintPageBreaks:1,PrintExpanded:1,PrintFiltered:1,PrintSelected:1,PrintPageRoot:1,PDFText:1,
956    PrintPageWidth:2,PrintPageHeight:2,ExportType:2,Language:2,Style:2,GanttStyle:2,Size:2,Scale:2,ShowDeleted:1,PrintVisible:1,FormulaTip:1,
957    Sort:4,Group:4,SearchAction:4,SearchExpression:4,SearchType:4,SearchCaseSensitive:4,SearchCells:4,SearchMethod:4,SearchDefs:4,SearchCols:4,Rtl:1
958    } : {};
959 if(type["settings"]||type["config"]){ 
960    set.ReversedTree = 1; set.ReversedColTree = 1; set.DefaultBorder = 1; set.HideZero = 1; set.FormulaShow = 1;
961    }
962 if(type["settings"]) { set.Focused = 4; set.FocusedCol = 4; set.FocusedPos = 4; set.FocusedRect = 4; set.FocusedTop = 4; set.FocusedLeft = 4; }
963 else if(type["focused"]){ set.Focused = 3; set.FocusedCol = 3; set.FocusedPos = 3; set.FocusedRect = 3; set.FocusedTop = 3; set.FocusedLeft = 3; }
964 if(this.ShowPrintPageBreaks>=0) set.ShowPrintPageBreaks = 1;
965
966 // --- AutoCols ---
967 if(type["autocols"]) { cfg += GetAutoCols();  } 
968
969 // --- Expanded ---
970 if(type["expanded"]){
971    var chp = this.ChildPaging==3;
972    for(var s="",r=this.GetFirst();r;r=this.GetNext(r)) if(r.Expanded && (r.firstChild||chp&&r.Count)) s += r[rid]+",";
973    cfg += F.Spc+"Expanded"+F.Sep+"\""+F.Str(s.slice(0,-1))+"\"";
974    }
975
976 // --- Hidden ---
977 if(type["hidden"]||type["settings"]){
978    var s = "", v = "";
979    if(rowvis) for(var id in rowvis) if(rowvis[id]) v += id + ","; else s += id + ",";
980    function setvis(r){
981       var rid = ridx&&r.HasIndex?ridx:"id";
982       if((!rowvis||rowvis[r.id]==null) && Get(r,"CanHide") && (!O||!O[r[rid]]||!O[r[rid]].Visible!=!r.Visible)){
983          if(!r.Visible) s += r[rid]+","; else if(O) v += r[rid]+",";
984          }
985       }
986    if(type["hidden"]) for(var r=this.GetFirst();r;r=this.GetNext(r)) setvis(r);
987    for(var R=this.GetFixedRows(),i=0;i<R.length;i++) setvis(R[i]);
988    for(var r=this.XS.firstChild;r;r=r.nextSibling) setvis(r);
989    if(s) cfg += F.Spc+"HiddenRows"+F.Sep+"\""+F.Str(s.slice(0,-1))+"\"";
990    if(v) cfg += F.Spc+"VisibleRows"+F.Sep+"\""+F.Str(v.slice(0,-1))+"\"";
991    }
992
993 // --- Cookie ---
994 if(type["cookie"] && !type["cfg"]) cfg += GetAttr("Cookie",this.SaveCfg(1));
995
996 // --- Cfg ---
997 if(type["cfg"]){
998    this.SetFocused(type["index"]); 
999    
1000       var Reg = new RegExp("^("+CDebugAttrs.Cfg.join("|")+")$");
1001       for(var n in this) if(!set[n]&&n.search(Reg)==0) cfg += GetAttr(n,this[n]); 
1002       
1003    var SS = ["Styles","GanttStyles"];
1004    for(var i=0;i<SS.length;i++){
1005       var v = this[SS[i]], S = []; 
1006       for(var n in v) {
1007          var vv = v[n], s = [];
1008          for(var nn in vv) s[s.length] = nn+":"+(vv[nn]-0||vv[nn]=="0"?vv[nn]:"'"+vv[nn]+"'");
1009          S[S.length] = n+":{"+s.join(",")+"}";
1010          }
1011       cfg += GetAttr(SS[i],"{"+S.join(",")+"}");
1012       }
1013
1014    if(this.Sort && !type["settings"]) {
1015       cfg += GetAttr("SortCols"+this.Sort.replace(/-/g,""));
1016       cfg += GetAttr("SortTypes"+this.Sort.replace(/[^-,]/g,"").replace(/-/g,"1").replace(/,,/g,",0,").replace(/^,/,"0,").replace(/,$/,",0"));
1017       }
1018    }  
1019
1020 // --- Configuration from cookies ---
1021 if(type["settings"]||type["config"]||type["configxlsx"]||type["focused"]) {
1022    if(type["settings"]||type["focused"]) this.SetFocused(type["index"]); 
1023    for(var n in set) if(set[n]!=4&&(set[n]!=3||this[n]!=null)) cfg += F.Spc+n+F.Sep+"\""+(set[n]==1?(this[n]?1:0):this[n])+"\"";
1024    MS.Gantt;
1025    if(this.PrintVisible && this.Gantt && (type["settings"]||type["config"]||type["configxlsx"])){
1026       var col = this.GetFirstGantt(), c = this.Cols[col];
1027       var cleft = this.GetColLeft(col), left = this.GetScrollLeft(c.MainSec) - cleft;
1028       var right = left + this.GetBodyWidth(c.MainSec); if(right>c.Width+cleft) right = c.Width+cleft;
1029       if(left<0) left = 0;
1030       cfg += F.Spc+"PrintVisibleLeft"+F.Sep+"\""+left+"\"";
1031       cfg += F.Spc+"PrintVisibleRight"+F.Sep+"\""+right+"\"";
1032       }
1033    ME.Gantt;
1034    if(type["settings"]) { 
1035       cfg += F.Spc+"AllCols"+F.One; 
1036       A[p++] = "\n"+this.GetCfgRequest(F,cfg); 
1037       cfg = null; 
1038       }
1039    }
1040
1041 if(cfg) {
1042    if(cfg.charAt(0)==',') cfg = cfg.slice(1); 
1043    A[p++] = (F.Json?"\n\"Cfg\":{":"\n<Cfg")+cfg+F.End;
1044    }
1045    
1046 // --- Def ---
1047 if(type["def"]){
1048    A[p++] = F.Json ? "\n\"Def\":"+(F.Json2?"[":"{") : "\n<Def>";
1049    for(var D in this.Def) {
1050       var zu = this.Def[D].Updated; delete this.Def[D].Updated;
1051       SetAttrs("D",this.Def[D],F.Json2);
1052       this.Def[D].Updated = zu;
1053       }
1054    if(F.Json) RemoveLast();
1055    A[p++] = F.Json2 ? "]," : (F.Json ? "}," :"\n</Def>");
1056    SetAttrs("Root",this.Root);
1057    }
1058
1059 // --- DefCols ---
1060 if(type["def"] && type["cols"]){
1061    A[p++] = F.Json ? "\n\"DefCols\":"+(F.Json2?"[":"{") : "\n<DefCols>";
1062    for(var D in this.DefCols) {
1063       
1064       SetAttrs("D",this.DefCols[D],F.Json2);
1065       
1066       }
1067    if(F.Json) RemoveLast();
1068    A[p++] = F.Json2 ? "]," : (F.Json ? "}," :"\n</DefCols>");
1069    }
1070
1071 // --- Cols ---
1072 if(type["cols"]||type["settings"]||type["selected"]&&this.SelectingCols){
1073    var len = this.ColNames.length;
1074    var Cols1 = ["LeftCols"]; Cols1[len-1] = "RightCols";
1075    var Cols2 = ["LeftCols"]; Cols2[len-1] = "RightCols";
1076    var Reg = null;
1077    if(type["cols"]){
1078       var s = CDebugAttrs.C.join("|") + CCellAttrs.CCell.join("|") + CCellAttrs.CICell.join("|") + "|On\\w+";
1079       s += ("|"+CDebugAttrs.Panel.join("|")).replace(/\|\*\|/g,"|").replace(/\*/g,"\\w*") + "|Enum\\w*";
1080       if(this.Gantt) {
1081          s += "|Gantt"+CDebugAttrs.CGantt.join("|Gantt") + "|Gantt"+CCellAttrs.CCellGantt.join("|Gantt") + "|Gantt"+CCellAttrs.CCellGanttX.join("\\d*|Gantt")+"\\d*";
1082          s += "|GanttFormat\\d*|GanttHeader\\w*\\d*";
1083          }
1084       Reg = new RegExp("^("+s+")$");
1085       }
1086    for(var i=0;i<len;i++){
1087       var N = this.ColNames[i];
1088       if(i==1) A[p++] = F.Json ? "\n\"Cols\":"+(F.Json2?"[":"{") : "\n<Cols>";
1089       if(N.length){
1090          if(Cols1[i]) A[p++] = F.Json ? "\n\""+Cols1[i]+"\":"+(F.Json2?"[":"{") : "\n<"+Cols1[i]+">";
1091          for(var ci=0;ci<N.length;ci++) {
1092             var c = N[ci];
1093             if(C[c].NoUpload==2||cidx&&C[c].Deleted) continue;
1094             if(type["cols"]){ SetAttrs("C",C[c],F.Json2,Reg); continue; }
1095             if(!type["settings"] && !C[c].Selected) continue;
1096             var n = cidx && C[c].HasIndex ? cidx[c] : c;
1097             if(F.Json2) { A[p++] = "\n{\"Name\":\""+n+"\""; }
1098             else if(F.Json) A[p++] = "\n\""+n+"\":{";
1099             else { A[p++] = "\n<C"; SetAttr("Name",n); }
1100             pp = p;
1101             if(type["settings"]){
1102                var dw = this.Img.Width; if(!dw) dw = 1;
1103                SetAttr("Width",Math.round((C[c].OldWidth?C[c].OldWidth:C[c].Width)/dw));
1104                SetAttr("Visible",colvis&&colvis[c]!=null ? colvis[c] : C[c].Visible);
1105                if(C[c].Spanned) SetAttr("Spanned",C[c].Spanned);
1106                if(this.ColTree) SetAttr("Level",C[c].Level?C[c].Level:0);
1107                
1108                if(this.AutoCols && C[c].HasIndex) SetAttr("Def",C[c].Def);
1109                }
1110             if(C[c].Selected&&type["selected"]) SetAttr("Selected",1);
1111             A[p++] = F.End;
1112             if(F.Json && !F.Json2) RemoveFirst(pp);
1113             }
1114          if(F.Json&&(i==len-2||Cols1[i])) RemoveLast(); 
1115          if(Cols2[i]) A[p++] = F.Json ? "\n"+(F.Json2?"]":"}")+"," : "\n</"+Cols2[i]+">";
1116          }
1117       if(i==len-2) A[p++] = F.Json ? "\n"+(F.Json2?"]":"}")+"," : "\n</Cols>";
1118       }
1119    }     
1120
1121 if(O) A[p++] = F.Json?"\n\"Changes\":[":"\n<Changes>";
1122
1123 // --- fixed rows ---
1124 if(type["data"] || type["all"] || type["fixed"] || O){
1125    if((this.Header.id!="Header"||this.Header.Kind!="Header")&&!O) A[p++] = (F.Json?"\n\"Header\":{":"\n<Header")+F.Spc1+"id"+F.Sep+"\""+F.Str(this.Header.id)+"\""+F.Spc+"Kind"+F.Sep+"\""+F.Str(this.Header.Kind)+"\""+F.End;
1126    if((this.Toolbar.id!="Header"||this.Toolbar.Kind!="Toolbar")&&!O) A[p++] = (F.Json?"\n\"Toolbar\":{":"\n<Toolbar")+F.Spc1+"id"+F.Sep+"\""+F.Str(this.Toolbar.id)+"\""+F.Spc+"Kind"+F.Sep+"\""+F.Str(this.Toolbar.Kind)+"\""+F.End;
1127    var Rows = ["Head","Foot","Solid"], RF = [this.XH,this.XF,this.XS];
1128    for(var j=0;j<3;j++){
1129       var R = this.GetRows(RF[j]);
1130       if(R.length){
1131          var Reg = null; 
1132          
1133             s = CDebugAttrs.I.join("|") + "|\\w+On\\w+";
1134             if(j==2) {
1135                s += "|"+CDebugAttrs.Space.join("|") + "|"+CDebugAttrs.Group.join("|") + "|"+CDebugAttrs.Search.join("|") + "|"+CDebugAttrs.Toolbar.join("|");
1136                s += "|\\w*"+CCellAttrs.SpaceCell.join("|\\w*");
1137                }
1138             else {
1139                if(this.Gantt) s += "|\\w*Gantt"+CCellAttrs.CCellGantt.join("|\\w*Gantt") + "|\\w*"+CCellAttrs.CCellGanttX.join("\\d*|\\w*Gantt")+"\\d*";
1140                s += "|"+CDebugAttrs.Header.join("|") + "|\\w*"+CCellAttrs.FilterCell.join("|\\w*");
1141                s += ("|"+CDebugAttrs.Panel.join("|")).replace(/\|\*\|/g,"|").replace(/\*/g,"\\w*").replace(/\|/g,"|\\w*") + "|\\w*Enum\\w*";;
1142                var a = [], CC = this.Cols; for(var n in CC) if(CC[n].Type!="Gantt") a[a.length] = n;
1143                s += "|"+a.join("|");
1144                }
1145             s += "|\\w*"+CCellAttrs.Cell.join("|\\w*") + "|\\w*"+CCellAttrs.CCell.join("|\\w*") + "|\\w*"+CCellAttrs.CICell.join("|\\w*");
1146             
1147             Reg = new RegExp("^("+s+")$");
1148             
1149          if(!O) A[p++] = F.Json ? "\n\""+Rows[j]+"\":[" :"\n<"+Rows[j]+">";
1150          for(var i=0;i<R.length;i++) if(R[i].Kind=="Data" || type["all"] || type["fixed"]) {
1151             var Z = {};
1152             if(R[i].Kind.slice(0,7)=="Toolbar"){ 
1153                Z["Empty"] = R[i]["Empty"]; delete R[i]["Empty"]; 
1154                for(var k=0,RIC=R[i].Cells;k<RIC.length;k++) if(R[i][RIC[k]+"Formula"]) { Z[RIC[k]] = R[i][RIC[k]]; delete R[i][RIC[k]]; }
1155                }
1156             if(R[i].Cells) { 
1157                if(s) Reg = new RegExp("^("+s+"|"+R[i].Cells.join("|")+")$"); 
1158                Z.Cells = R[i].Cells; 
1159                if(R[i].Cells[0]=="Panel") {
1160                   Z.Panel = R[i].Panel; R[i].Panel = R[i]["PanelVisible"];
1161                   R[i].Cells.shift();
1162                   }
1163                R[i].Cells = R[i].Cells.join(","); 
1164                }
1165             var cp = p;
1166             if(!SetRowAttrs("I",R[i],Reg)&&noempty) { p = cp; A.length = p; }
1167             else {
1168                if(this.Gantt&&R[i].Kind=="Header"&&!R[i][this.Gantt+"GanttHeader"]) A[p++] = GetAttr(this.Gantt,R[i][this.Gantt]); 
1169                A[p++] = F.End;
1170                }
1171             for(var n in Z) { R[i][n] = Z[n]; }
1172             }
1173          if(!O) {
1174             if(F.Json) RemoveLast(); 
1175             A[p++] = F.Json ? "\n]," : "\n</"+Rows[j]+">";
1176             }
1177          }
1178       }
1179    }
1180
1181 // --- variable rows ---
1182 if(type["body"] || type["data"] || type["all"] || O){
1183    var name = "Body";
1184    if(!O) A[p++] = F.Json ? "\n\""+name+"\":[" : "\n<"+name+">";
1185    var BA = { LevelImg:1,Level:1,Hasch:1,Page:1,State:1,LastAccess:1,Visible:1 };
1186    var Reg = null; 
1187    
1188       s = CDebugAttrs.I.join("|") + "|\\w+On\\w+";
1189       if(this.Paging==3&&!O) s += "|\\w+"+CDebugAttrs.BCellICell.join("|\\w+");
1190       s += ("|"+CDebugAttrs.Panel.join("|")).replace(/\|\*\|/g,"|").replace(/\*/g,"\\w+").replace(/\|/g,"|\\w+") + "|\\w+Enum\\w+";
1191       s += "|\\w+"+CCellAttrs.Cell.join("|\\w+") + "|\\w+"+CCellAttrs.CCell.join("|\\w+") + "|\\w*"+CCellAttrs.CICell.join("|\\w*");
1192       if(this.Gantt) s += "|\\w+Gantt"+CCellAttrs.CCellGantt.join("|\\w+Gantt") + "|\\w+"+CCellAttrs.CCellGanttX.join("\\d*|\\w+Gantt")+"\\d*";
1193       var a = [], CC = this.Cols; for(var n in CC) if(CC[n].Type!="Gantt") a[a.length] = n;
1194       s += "|"+a.join("|");
1195       Reg = new RegExp("^("+s+")$");
1196       
1197    if(this.Paging==3&&!O) {
1198       for(var B=this.XB.firstChild;B;B=B.nextSibling){
1199          var S = "";
1200          if(B.id) S += GetAttr("id",B.id);
1201          for(var n in B) if(!RA[n] && !BA[n]) S += GetAttr(n,B[n]); 
1202          if(F.Json){
1203             if(S) {
1204                if(S.charAt(0)==',') S = S.slice(1);
1205                A[p++] = "\n{"+S+",\"Items\":[";
1206                }
1207             else A[p++] = "[";
1208             }
1209          else A[p++] = "\n<B" + S + ">";
1210          for(var r=B.firstChild;r;r=r.nextSibling) SetRowChildren("I",r,Reg);
1211          if(F.Json) RemoveLast();
1212          A[p++] = F.Json ? (S?"]},":"],") : "\n</B>";
1213          }
1214       if(F.Json) RemoveLast(); 
1215       }
1216    else {
1217       if(!O) A[p++] = F.Json ? "[" : "\n<B>";
1218       var lr = null; if(this.AutoPages) lr = this.GetLastDataRow((alldef?16:0)+(U&&U.Name=="ExportPDF"?32:0));
1219       for(var B=this.XB.firstChild;B;B=B.nextSibling) for(var r=B.firstChild;r;r=r.nextSibling) { SetRowChildren("I",r,Reg); if(r==lr) { B = this.XB.lastChild; break; } }
1220       if(O&&!ridx){ 
1221          var N = this.Rows; 
1222          for(var id in O) { 
1223             var n = ridx?this.GetRowByIndex(id):N[id]; if(n&&!n.Deleted) continue;
1224             A[p++] = F.Json ? "\n{" : "\n<I"; 
1225             var pp = p;
1226             if(ridx&&O[id].HasIndex) SetAttr("id",O[id][ridx]); 
1227             else if(O[id].id) SetAttr("id",O[id].id); 
1228             SetAttr("Deleted",1); 
1229             if(F.Json) RemoveFirst(pp);
1230             A[p++] = F.End; 
1231             }
1232          }
1233       if(F.Json&&!O) RemoveLast();
1234       if(!O) A[p++] = F.Json ? "]" : "\n</B>";
1235       }
1236    if(!O) A[p++] = F.Json ? "\n]," : "\n</"+name+">";
1237    }
1238
1239 // --- Selected ---
1240 var sel = (type["selected"]||type["resized"]) && !type["changes"] && (!O||attrs||allcols);
1241 if(!O&&(sel||type["changes"])) A[p++] = F.Json?"\n\"Changes\":[":"\n<Changes>";
1242 if(sel){
1243    var res = type["resized"], sel = type["selected"];
1244    
1245    var R = this.GetFixedRows(), allcols = type["allcols"];
1246    function AddSel(row){
1247       if(ridx&&row.Deleted) return;
1248       A[p++] = "\n"+F.Start+F.Str(row[rid])+"\"";
1249       if(sel && row.Selected) A[p++] = F.Spc+"Selected"+F.Sep+"\""+row.Selected+"\"";
1250       if(res && row.Resized) A[p++] = F.Spc+"Height"+F.Sep+"\""+row.Height+"\"";
1251       if(F.Dtd) A[p++] = F.End;
1252       if(allcols) SetRowCols(row); if(!O) SetCustomAttrs(row); 
1253       if(sel && row.Selected&2) { for(var c in C) if(row[c+"Selected"]) SetAttr(c+"Selected",row[c+"Selected"]); }
1254       A[p++] = F.Dtd ? "</I>" : F.End;
1255       }
1256    for(var i=0;i<R.length;i++) if(sel&&R[i].Selected||res&&R[i].Resized) AddSel(R[i]);
1257    for(var r=this.XS.firstChild;r;r=r.nextSibling) if(sel&&r.Selected||res&&r.Resized) AddSel(r);
1258    for(var r=this.GetFirst();r;r=this.GetNext(r)) if(sel&&r.Selected||res&&r.Resized) AddSel(r);
1259    if(F.Json) RemoveLast();
1260    }
1261
1262 // --- Changes ---
1263 if(type["changes"]) A[p++] = this.GetChanges(null,1+(type["selected"]?2:0)+(type["resized"]?4:0),alldef+allcols+(type["newid"]?4:0)+(type["fullmoved"]?8:0)+(noformula?16:0)+(type["noupload"]?32:0),attrs,F);
1264
1265 if(O||sel||type["changes"]) {
1266    if(F.Json) RemoveLast();
1267    A[p++] = F.Json?"],":"\n</Changes>";
1268    }
1269
1270 // --- Spanned ---
1271 if(type["span"]){
1272    A[p++] = F.Json?"\n\"Spanned\":[":"\n<Spanned>";
1273    for(var r=this.GetFirst();r;r=this.GetNext(r)){
1274       var s = "", o = O ? O[r[rid]] : null;
1275       if(r.Spanned||r.RowSpan||o&&(o.Spanned||o.RowSpan)) for(var col in C) {
1276          if((o?r[col+"Span"]!=o[col+"Span"]&&(r[col+"Span"]>1||o[col+"Span"]>1)||r[col+"RowSpan"]!=o[col+"RowSpan"]&&(r[col+"RowSpan"]>1||o[col+"RowSpan"]>1):r[col+"Span"]>1||r[col+"RowSpan"]>1) && r[col+"RowSpan"]!=0 && r[col+"Visible"]!=-2) {
1277             s += F.Spc+col+"Span"+F.Sep+"\""+F.Str(r[col+"Span"]==null?1:r[col+"Span"])+"\""+F.Spc+col+"RowSpan"+F.Sep+"\""+F.Str(r[col+"RowSpan"]==null?1:r[col+"RowSpan"])+"\"";
1278             }
1279          }
1280       
1281       if(s) A[p++] = F.Start + F.Str(r[rid]) + "\"" + s + F.End;
1282       }
1283    if(F.Json) RemoveLast();
1284    A[p++] = F.Json?"],":"\n</Spanned>";
1285    }
1286
1287 // --- Lang ---
1288 if(type["lang"]){
1289    A[p++] = F.Json ? "\n\"Lang\":{" : "\n<Lang>";
1290    for(var i in this.Lang){ 
1291       var v = this.Lang[i];
1292       A[p++] = F.Json ? "\n\""+i+"\":{" : "\n<"+i; pp = p;
1293       var reg = i=="Format" ? new RegExp("^("+CDebugAttrs.Format.join("|")+")$") : null;
1294       for(var n in v){
1295          if(v[n]==null||reg&&n.search(reg)!=0);
1296          else if(v[n].join) SetAttr(n,v[n].join(",")); 
1297          else SetAttr(n,v[n]); 
1298          }
1299       if(F.Json) RemoveFirst(pp);
1300       A[p++] = F.End;
1301       
1302       }
1303    if(F.Json) RemoveLast();
1304    A[p++] = F.Json ? "\n}," : "\n</Lang>";
1305    }
1306
1307 // --- Text ---
1308 MS.Lang;
1309 if(type["text"]) for(var xx in this.Text) {
1310    A[p++] = F.Json ? "\n\"Text"+xx+"\":{" : "\n<Text"+xx+">";
1311    var R = this.Text[xx];
1312    for(var r in R) {
1313       var Set = {}, CC = R[r], hasset = 0;
1314       for(var c in CC){
1315          var D = CC[c], P = {};
1316          for(var d in D){
1317             if(d=="set") { Set[c] = D[d]; hasset = 1; continue; }
1318             if(d=="change") { P["Change"] = D[d]; continue; }
1319             var N = D[d], Reg = null, Rep = null;
1320             for(var n in N) {
1321                if(n.charAt(n.length-1)=="@");
1322                else if(N[n+"@"]) { if(!Reg) Reg = {}; Reg[n] = N[n]; }
1323                else { if(!Rep) Rep = {}; Rep[n] = N[n]; }
1324                }
1325             if(Rep) P["Replace"] = Rep;
1326             if(Reg) P["Regex"] = Reg;
1327             }
1328          for(var d in P){
1329             var N = P[d], X = {}, T = {}, hasu = 0;
1330             if(r=="@All");
1331             else if(r=="@Space") T.Space = 1;
1332             else if(r.charAt(0)=="@") T.Kind = r.slice(1);
1333             else if(r.charAt(0)=="#") T.Def = r.slice(1);
1334             else T.Row = r;
1335             if(c=="@All");
1336             else if(c.charAt(0)=="@") T.Type = r.slice(1);
1337             else T.Col = c;
1338             for(var n in N) if(!F.Json&&n.search(/\W/)>=0) { X[n] = N[n]; hasu++; } else T[n] = N[n]; 
1339             if(hasu){
1340                var S = "\n<"+d;
1341                for(var n in T) S += GetAttr(n,T[n]); 
1342                if(hasu==1) for(var n in X) S += " N=\""+F.Str(n)+"\" V=\""+F.Str(X[n])+"\"/>";
1343                else {
1344                   S += ">";
1345                   for(var n in X) S += "<U N=\""+F.Str(n)+"\" V=\""+F.Str(X[n])+"\"/>";
1346                   S += "</"+d+">";
1347                   }
1348                A[p++] = S;
1349                }
1350             else SetAttrs(d,T);
1351             }
1352          }
1353       if(hasset) {
1354          if(r=="@All");
1355          else if(r=="@Space") Set.Space = 1;
1356          else if(r.charAt(0)=="@") Set.Kind = r.slice(1);
1357          else if(r.charAt(0)=="#") Set.Def = r.slice(1);
1358          else Set.Row = r;
1359          SetAttrs("Set",Set);
1360          }
1361       }
1362    if(F.Json) RemoveLast();
1363    A[p++] = F.Json ? "\n}," : "\n</Text"+xx+">";
1364    }
1365
1366 // --- Languages ---
1367 if(type["other"]||type["languages"]){
1368    A[p++] = F.Json ? "\n\"Languages\":{" : "\n<Languages>";
1369    for(var n in this.Languages) SetAttrs("L",this.Languages[n]); 
1370    if(F.Json) RemoveLast();
1371    A[p++] = F.Json ? "\n}," : "\n</Languages>";
1372    }
1373 ME.Lang;
1374
1375 // --- Other ---
1376 if(type["other"]||type["menu"]) {
1377    SetAttrs("MenuCfg",this.MenuCfg);
1378    SetAttrs("MenuColumns",this.MenuColumns);
1379    SetAttrs("MenuPrint",this.MenuPrint);
1380    SetAttrs("MenuExport",this.MenuExport);
1381    }
c35f05 1382 if(type["other"]) SetAttrs("GanttExport",this.GanttExport);
25ab64 1383 if(type["other"]||type["animations"]) SetAttrs("Animations",this.Animations);
F 1384
1385 // --- Actions ---
1386 if(type["other"]||type["actions"]) {
1387    var S = "";
1388    for(var n in this.Actions) S += GetAttr(n,this.Actions[n]); 
1389    for(var n in this.Mouse) S += GetAttr(n,this.Mouse[n]); 
1390    S += F.Spc+"KeyCodes9"+F.Sep+"\"";
1391       for(var n in this.KeyCodes) {
1392       S += this.KeyCodes[n]+"="+n+","; 
1393       }
1394    S = S.slice(0,-1) + "\"";
1395    if(F.Json && S && S.charAt(0)==',') S = S.slice(1); 
1396    A[p++] = "\n"+(F.Json ? "\"Actions\":{" : "<Actions")+S+F.End;
1397    }
1398
1399 // --- Pagers ---
1400 if(this.Pagers.length && (type["other"]||type["pagers"])){
1401    A[p++] = F.Json ? "\n\"Pagers\":"+(F.Json2?"[":"{") : "\n<Pagers>";
1402    
1403    var Reg = new RegExp("^("+CDebugAttrs.Pager.join("|")+"|"+CDebugAttrs.PagerXXX.join("|")+")$");
1404    for(var i=0;i<this.Pagers.length;i++) SetAttrs("P",this.Pagers[i],F.Json2,Reg);
1405    if(F.Json) RemoveLast();
1406    A[p++] = F.Json2 ? "]," : (F.Json ? "}," :"\n</Pagers>");
1407    }
1408
1409 // --- Media ---
1410 MS.Media;
1411 if(type["other"]||type["media"]){
1412    A[p++] = F.Json ? "\n\"Media\":[" : "\n<Media>";
1413    for(var i=1;i<this.Media.length;i++){ 
1414       var v = this.Media[i];
1415       A[p++] = F.Json ? "\n{" : "\n<M";
1416       var a = v.Attrs; 
1417       if(a) { 
1418          var pp = p;
1419          for(var n in a) {
1420             if(n=="Style"){
1421                var vv = a[n], s = []; for(var nn in vv) s[s.length] = nn;
1422                SetAttr(n,s.join(","))
1423                }
1424             else if(n=="Size" && typeof(a[n])=="object"){
1425                SetAttr(n,a[n].source.replace(/\|/g,","));
1426                }
1427             else SetAttr(n,a[n]); 
1428             }
1429          if(F.Json) { RemoveFirst(pp); A[p++] = ","; }
1430          }
1431       A[p++] = F.Json ? "" : ">";
1432       for(var n in v) {
1433          if(n=="Lang"){
1434             A[p++] = F.Json ? "\n\"Lang\":{" : "\n<Lang>";
1435             var vv = v[n]; for(var nn in vv) SetAttrs(nn,vv[nn]);
1436             if(F.Json) RemoveLast();
1437             A[p++] = F.Json ? "\n}," : "\n</Lang>";
1438             }
1439          else if(n=="Cols"||n=="Rows"||n=="Def"||n=="Pagers"){
1440             var vv = v[n]; 
1441             A[p++] = F.Json ? "\n\""+n+"\":[" :"\n<"+n+">";
1442             var tn = {Rows:"I",Cols:"C",Def:"D",Pagers:"Pager"}[n];
1443             
1444             for(var nn in vv) {
1445                A[p++] = F.Json ? "\n{" : "\n<"+tn;   
1446                var pp = p, vvv = vv[nn]; 
1447                if(n=="Rows"&&this.Rows[vvv.id].Space){ 
1448                   var Cells = ","+this.Rows[vvv.id].Cells.join(",")+",";
1449                   for(var nnn in vvv) SetAttr(nnn.search(/Left$/)>=0&&Cells.search(","+nnn+",")>=0&&Cells.search(","+nnn.slice(0,-4)+",")>=0?nnn+"Width":nnn,vvv[nnn]);
1450                   }
1451                else for(var nnn in vvv) SetAttr(nnn,vvv[nnn]);
1452                if(F.Json) RemoveFirst(pp);
1453                A[p++] = F.End;
1454                }
1455             if(F.Json) RemoveLast();
1456             A[p++] = F.Json ? "\n]," : "\n</"+n+">";
1457             }
1458          else if(n!="Attrs"&&n!="Media") SetAttrs(n,v[n]);
1459          }
1460       if(F.Json) RemoveLast();
1461       A[p++] = F.Json ? "}," :"\n</M>";
1462       }
1463    if(F.Json) RemoveLast();
1464    A[p++] = F.Json ? "\n]," : "\n</Media>";
1465    }
1466 ME.Media;
1467
1468 if(F.Json) RemoveLast();
1469 if(!type["nogrid"]) A[p++] = F.Json ?"\n}" :"\n</Grid>";
1470 if(grp) { var zalgrp = this.Group; this.Group = ""; this.DoGrouping(zalgrp,-1); }
1471 if(this.Img.Width!=1){
1472    if(type["cols"]) this.MultiplyScale(this.Img.Width,9);
1473    if(type["other"]) this.MultiplyScale(this.Img.Width,10);
1474    if(type["all"]||type["fixed"]) this.MultiplyScale(this.Img.SpaceWidth,12);
1475    if(this.Gantt&&type["cols"]) this.MultiplyScale(this.Img.GanttWidth,24);
1476    }
1477 this.Focused = null; 
1478 //lertTimer();
1479
1480 return A.join("");
1481 ME.UploadType;
1482 NoModule("UploadType");
1483 }
1484 // -----------------------------------------------------------------------------------------------------------
1485 TGP.GetChangesOrder = function(){
1486 var C = this.Changes, A = [], p = 0, F = this.GetUploadFormat(this.Source.Upload), ind = this.SaveOrder==2;
1487 var names;
1488 MS.Debug; names = "changes,selected,expanded,body,data,all,settings,cookie,cfg,def,cols,other,lang,defaults,allcols,nodelete,noio,nogrid,gantt,span,spanned,calendars,resources,newid"; ME.Debug;
1489 var flags = this.ConvertFlags(this.Source.Upload.Flags,names), NewId = flags["newid"];
1490 for(var i=0;i<C.length;i++){
1491    if(!C[i]) continue;
1492    var O = C[i], s = F.Start+F.Str(O.Row)+"\"", newid = null;
1493    if(O.Deleted) { A[p++] = s+F.Spc+"Deleted"+F.One+F.End; continue; }
1494    var Q = {}, U = {}, CH = null; 
1495    for(;i<C.length;i++){
1496       var P = C[i];
1497       if(P.Row!=O.Row){ i--; break; }
1498       if(P.Deleted){ Q = null; if(!O.Added) i--; break; } 
1499       if(P.Added||P.Moved) {
1500          if(P.Added) U.Added = 1;
1501          else if(P.Moved && !U.Added) U.Moved = P.Moved;
1502          if(P.Parent!=null) U.Parent = F.Str(P.Parent);
1503          if(P.Next!=null) U.Next = F.Str(P.Next);
1504          else if(U.Next) delete U.Next; 
1505          if(P.Copy) U.Copy = F.Str(P.Copy);
1506          }
1507       
1508       else U.Changed = 1;
1509       if(P.Col) Q[P.Col] = P.Val;
1510       if(P.Cols) for(var c in P.Cols) Q[c] = P.Cols[c];
1511       
1512       MS.GenId;
1513       if(NewId && this.IdMore && (U.Changed||U.Moved) && newid==null) {
1514          var row = this.Rows[P.Row];
1515          if(row){
1516             CH = this.UpdateNewId(row,"NewId",0,U.Changed,U.Moved,Q);
1517             newid = row.NewId ? row.NewId : "";
1518             }
1519          }
1520       ME.GenId;
1521       if(ind) break;
1522       }   
1523    MS.GenId; if(newid) s += F.Spc+"NewId"+F.Sep+"\""+newid+"\""; ME.GenId;
1524    for(var c in U) s += F.Spc+c+F.Sep+"\""+U[c]+"\"";
1525    if(!Q) continue; 
1526    if(F.Dtd) s += ">";
1527    for(var c in Q){    
1528       var v = Q[c]; if(v==null) continue;
1529       v = this.ConvertUpload(this.GetRowById(O.Row),c,v,this.FormulaEditing);
1530       if(F.Dtd) s += "<U N=\""+c+"\" V=\""+F.Str(v)+"\"/>";
1531       else s += F.Spc+c+F.Sep+"\""+F.Str(v)+"\"";
1532       }
1533    s += F.Dtd ? "</I>" : F.End;
1534    MS.GenId; if(CH) for(var id in CH) s += F.Start+F.Str(id)+"\""+F.Spc+"NewId"+F.Sep+"\""+CH[id]+"\""+F.End; ME.GenId; 
1535    A[p++] = s;
1536    }
1537 if(F.Json && p && A[p-1] && A[p-1].slice(-1)==',') A[p-1] = A[p-1].slice(0,-1); 
1538 return A.join("");   
1539 }
1540 // -----------------------------------------------------------------------------------------------------------
1541 ME.Upload;
1542 // -----------------------------------------------------------------------------------------------------------
1543 TGP.SetChange = function(O,fill){
1544 MS.Upload;
1545 if(!O.Row) return; 
1546 var C = this.Changes;
1547 if(fill) {
1548    O.Cols = { }; var row = this.GetRowById(O.Row);
1549    for(var c in this.Cols) if(c!="Panel" && c!="id") O.Cols[c] = Get(row,c);
1550    }
1551 if(O.Deleted==0){ 
1552    for(var i=0;i<C.length;i++){
1553       if(C[i] && C[i].Deleted&&C[i].Row==O.Row) { C[i] = null; return; };
1554       }  
1555    
1556    }   
1557 C[C.length] = O;
1558 ME.Upload;
1559 }
1560 // -----------------------------------------------------------------------------------------------------------
1561 TGP.SaveOrigData = function(){
1562 MS.Upload;
1563 var t = (this.Source.Upload.Type+this.Source.Export.Type+this.Source.ExportPDF.Type+"").toLowerCase();
1564 if(t.indexOf("cells")<0) return;
1565 var ridx = t.indexOf("index")>=0 ? this.RowIndex : null, idx = ridx ? ridx : "id", O = {}, R = this.Rows, mc = this.MainCol;
1566 for(var id in R) {
1567    var r = R[id], o = {}; if(!r[idx]) continue;
1568    for(var n in r) o[n] = r[n];
1569    if(!ridx){
1570       o.parentNode = r.parentNode.Page ? null : r.parentNode.id;
1571       if(r.nextSibling) o.nextSibling = r.nextSibling.id;
1572       else if(r.parentNode.Page && r.parentNode.nextSibling && r.parentNode.nextSibling.firstChild) o.nextSibling = r.parentNode.nextSibling.firstChild.id;
1573       if(r.previousSibling) o.previousSibling = r.previousSibling.id;
1574       else if(r.parentNode.Page && r.parentNode.previousSibling && r.parentNode.previousSibling.lastChild) o.previousSibling = r.parentNode.previousSibling.lastChild.id;
1575       }
1576    else if(mc) o.Level = r.Level;
1577    O[r[idx]] = o;
1578    }
1579 this.OrigData = O;
1580 ME.Upload;
1581 }
1582 // -----------------------------------------------------------------------------------------------------------