https://web.rosknroll.fi/rosknroll/js/dhtmlxSuite/sources/dhtmlxGrid/codebase/ext/dhtmlxgrid_nxml.js
1/* 2Product Name: dhtmlxSuite 3Version: 5.1.0 4Edition: Professional 5License: content of this file is covered by DHTMLX Commercial or Enterprise license. Usage without proper license is prohibited. To obtain it contact [email protected] 6Copyright UAB Dinamenta http://www.dhtmlx.com 7*/ 8 9/** 10* @desc: load grid from CSV file 11* @param: path - path to file 12* @param: afterCall - function which will be called after xml loading 13* @type: public 14* @edition: Professional 15* @topic: 0 16*/ 17dhtmlXGridObject.prototype.loadCSVFile = function(path,afterCall){ 18 this.load(path,afterCall,"csv") 19} 20 21/** 22* @desc: enable mode, where ID for rows loaded from CSV autogenerated 23* @param: mode - true/false 24* @type: public 25* @edition: Professional 26* @topic: 0 27*/ 28dhtmlXGridObject.prototype.enableCSVAutoID = function(mode){ 29 this._csvAID=dhx4.s2b(mode); 30} 31/** 32* @desc: enable recognizing first row in CSV as header 33* @param: mode - true/false 34* @type: public 35* @edition: Professional 36* @topic: 0 37*/ 38dhtmlXGridObject.prototype.enableCSVHeader = function(mode){ 39 this._csvHdr=dhx4.s2b(mode); 40} 41 42/** 43* @desc: load grid from CSV string 44* @param: str - delimer used in CSV operations, comma by default ( only single char delimeters allowed ) 45* @type: public 46* @edition: Professional 47* @topic: 0 48*/ 49dhtmlXGridObject.prototype.setCSVDelimiter = function(str){ 50 this.csv.cell=str; 51} 52dhtmlXGridObject.prototype._csvAID = true; 53 54/** 55* @desc: load grid from CSV string 56* @param: str - CSV string 57* @type: public 58* @edition: Professional 59* @topic: 0 60*/ 61dhtmlXGridObject.prototype.loadCSVString = function(str){ 62 this.parse(str,"csv") 63} 64 65/** 66* @desc: serialize to CSV string 67* @type: public 68* @param: text only - force serialization of text values ( skip HTML elements ) ) 69* @edition: Professional 70* @topic: 0 71*/ 72dhtmlXGridObject.prototype.serializeToCSV = function(textmode){ 73 this.editStop() 74 if (this._mathSerialization) 75 this._agetm="getMathValue"; 76 else if (this._strictText || textmode) 77 this._agetm="getTitle"; 78 else this._agetm="getValue"; 79 80 var out=[]; 81 if (this._csvHdr){ 82 for (var j=1; j < this.hdr.rows.length; j++) { 83 var a=[]; 84 for (var i=0; i<this._cCount; i++) 85 if ((!this._srClmn)||(this._srClmn[i])) 86 a.push(this.getColumnLabel(i,j-1)); 87 out.push(this.csvParser.str(a,this.csv.cell, this.csv.row)); 88 } 89 } 90 91 92 //rows collection 93 var i=0; 94 var leni=this.rowsBuffer.length; 95 96 for(i; i<leni; i++){ 97 var temp=this._serializeRowToCVS(null,i) 98 if (temp!="") out.push(temp); 99 } 100 101 return this.csvParser.block(out,this.csv.row); 102} 103 104/** 105* @desc: serialize TR to CSV 106* @param: r - TR or xml node (row) 107* @retruns: string - CSV representation of passed row 108* @type: private 109*/ 110dhtmlXGridObject.prototype._serializeRowToCVS = function(r,i,start,end){ 111 var out = new Array(); 112 if (!r){ 113 r=this.render_row(i) 114 if (this._fake && !this._fake.rowsAr[r.idd]) this._fake.render_row(i); 115 } 116 117 118 if (!this._csvAID) 119 out[out.length]=r.idd; 120 121 start = start||0; 122 123 end = end||this._cCount; 124 //cells 125 var changeFl=false; 126 var ind=start; 127 //rowspans before block selection 128 while (r.childNodes[start]._cellIndex>ind && start) start--; 129 130 131 for(var jj=start;ind<end;jj++){ 132 if (!r.childNodes[jj]) break; 133 var real_ind=r.childNodes[jj]._cellIndex; 134 if (((!this._srClmn)||(this._srClmn[real_ind])) && (!this._serialize_visible || !this._hrrar[real_ind])){ 135 var cvx=r.childNodes[jj]; 136 137 var zx=this.cells(r.idd,real_ind); 138 while (ind!=real_ind){ 139 ind++; 140 out.push("") 141 if (ind>=end) break; 142 } 143 if (ind>=end) break; 144 ind++; 145 /* if (zx.getText) 146 zxVal=zx.getText(); 147 else*/ 148 if (zx.cell) 149 zxVal=zx[this._agetm](); 150 else zxVal=""; 151 152 153 if ((this._chAttr)&&(zx.wasChanged())) 154 changeFl=true; 155 156 out[out.length]=((zxVal===null)?"":zxVal) 157//#colspan:20092006{ 158 if ( this._ecspn && cvx.colSpan && cvx.colSpan >1 ){
159 cvx=cvx.colSpan-1; 160 for (var u=0; u<cvx; u++){ 161 out[out.length] = ""; 162 ind++; 163 } 164 } 165//#} 166 167 } else ind++; 168 } 169 if ((this._onlChAttr)&&(!changeFl)) return ""; 170 return this.csvParser.str(out,this.csv.cell, this.csv.row); 171} 172 173dhtmlXGridObject.prototype.toClipBoard=function(val){ 174 if (window.clipboardData) 175 window.clipboardData.setData("Text",val); 176 else 177 (new Clipboard()).copy(val); 178 179} 180dhtmlXGridObject.prototype.fromClipBoard=function(){ 181 if (window.clipboardData) 182 return window.clipboardData.getData("Text"); 183 else 184 return (new Clipboard()).paste(); 185} 186 187/** 188* @desc: copy value of cell to clipboard 189* @type: public 190* @param: rowId - id of row (optional, use selected row by default) 191* @param: cellInd - column index(optional, use selected cell by default) 192* @edition: Professional 193* @topic: 5 194*/ 195dhtmlXGridObject.prototype.cellToClipboard = function(rowId,cellInd){ 196 if ((!rowId)||(!cellInd && cellInd !== 0)){ 197 if (!this.selectedRows[0]) return; 198 rowId=this.selectedRows[0].idd; 199 cellInd=this.cell._cellIndex; 200 } 201 202 var ed=this.cells(rowId,cellInd); 203 this.toClipBoard(((ed.getLabel?ed.getLabel():ed.getValue())||"").toString()); 204} 205 206/** 207* @desc: set value of cell from clipboard 208* @type: public 209* @edition: Professional 210* @param: rowId - id of row (optional, use selected row by default) 211* @param: cellInd - column index(optional, use selected cell by default) 212* @topic: 5 213*/ 214dhtmlXGridObject.prototype.updateCellFromClipboard = function(rowId,cellInd){ 215 if ((!rowId)||(!cellInd)){ 216 if (!this.selectedRows[0]) return; 217 rowId=this.selectedRows[0].idd; 218 cellInd=this.cell._cellIndex; 219 } 220 var ed=this.cells(rowId,cellInd); 221 ed[ed.setImage?"setLabel":"setValue"](this.fromClipBoard()); 222} 223 224/** 225* @desc: copy value of row to clipboard 226* @type: public 227* @edition: Professional 228* @param: rowId - id of row (optional, use selected row by default) 229* @topic: 5 230*/ 231dhtmlXGridObject.prototype.rowToClipboard = function(rowId){ 232 var out=""; 233 if (this._mathSerialization) 234 this._agetm="getMathValue"; 235 else if (this._strictText) 236 this._agetm="getTitle"; 237 else 238 this._agetm="getValue"; 239 240 this._serialize_visible = !this._fake; 241 242 if (rowId) 243 out=this._serializeRowToCVS(this.getRowById(rowId)); 244 else { 245 var data = []; 246 for (var i=0; i<this.selectedRows.length; i++){ 247 data[data.length] = this._serializeRowToCVS(this.selectedRows[i]); 248 out = this.csvParser.block(data, this.csv.row); 249 } 250 } 251 252 this._serialize_visible = false; 253 this.toClipBoard(out); 254} 255 256/** 257* @desc: set value of row from clipboard 258* @type: public 259* @edition: Professional 260* @param: rowId - id of row (optional, use selected row by default) 261* @topic: 5 262*/ 263dhtmlXGridObject.prototype.updateRowFromClipboard = function(rowId){ 264 var csv=this.fromClipBoard(); 265 if (!csv) return; 266 if (rowId) 267 var r=this.getRowById(rowId); 268 else 269 var r=this.selectedRows[0]; 270 if (!r) return; 271 272 var parser = this.csvParser; 273 csv=parser.unblock(csv,this.csv.cell, this.csv.row)[0]; 274 if (!this._csvAID) csv.splice(0,1); 275 for (var i=0; i<csv.length; i++){ 276 var ed=this.cells3(r,i); 277 ed[ed.setImage?"setLabel":"setValue"](csv[i]); 278 } 279} 280 281dhtmlXGridObject.prototype.csvParser={ 282 block:function(data,row){ 283 return data.join(row); 284 }, 285 unblock:function(str,cell,row){ 286 var data = (str||"").split(row); 287 for (var i=0; i < data.length; i++) 288 data[i]=(data[i]||"").split(cell); 289 var last = data.length-1; 290 if (data[last].length == 1 && data[last][0]=="") 291 data.splice(last,1); 292 return data; 293 }, 294 str:function(data,cell,row){ 295 return data.join(cell); 296 } 297}; 298dhtmlXGridObject.prototype.csvExtParser={ 299 _quote:RegExp('"',"g"), 300 _quote_esc:RegExp("\"\"","g"), 301 block:function(data,row){ 302 return data.join(row); 303 }, 304 unblock:function(str,cell,row){ 305 var out = [[]]; 306 var ind = 0; 307 if (!str) return out; 308 309 var quote_start = /^[ ]*"/; 310 var quote_end = /"[ ]*$/; 311 var row_exp = new RegExp(".*"+row+".*$"); 312 313 var data = str.split(cell); 314 for (var i=0; i<data.length; i++){ 315 if (data[i].match(quote_start)){ 316 var buff = data[i].replace(quote_start, ""); 317 while (!data[i].match(quote_end)) { 318 i++; 319 buff+=data[i]; 320 } 321 out[ind].push(buff.replace(quote_end, "").replace(this._quote_esc,'"')); 322 } else if (data[i].match(row_exp)){ 323 var row_pos = data[i].indexOf(row); 324 out[ind].push(data[i].substr(0, row_pos)); 325 ind++; 326 out[ind] = []; 327 data[i]=data[i].substr(row_pos+1); i--; 328 } else { 329 if (data[i] || i!=data.length-1) 330 out[ind].push(data[i]); 331 } 332 } 333 334 var last = out.length-1; 335 if (last>0 && !out[last].length) 336 out.splice(last,1); 337 338 return out; 339 }, 340 str:function(data,cell,row){ 341 for (var i=0; i < data.length; i++) 342 data[i] = '"'+data[i].replace(this._quote, "\"\"")+'"'; 343 return data.join(cell); 344 } 345}; 346 347/** 348* @desc: add new row from clipboard 349* @type: public 350* @edition: Professional 351* @topic: 5 352*/ 353dhtmlXGridObject.prototype.addRowFromClipboard = function(){ 354 var csv=this.fromClipBoard(); 355 if (!csv) return; 356 var z=this.csvParser.unblock(csv, this.csv.cell, this.csv.row); 357 for (var i=0; i<z.length; i++) 358 if (z[i]){ 359 csv=z[i]; 360 if (!csv.length) continue; 361 if (this._csvAID) 362 this.addRow(this.getRowsNum()+2,csv); 363 else{ 364 if (this.rowsAr[csv[0]]) 365 csv[0]=this.uid(); 366 this.addRow(csv[0],csv.slice(1)); 367 } 368 } 369} 370 371/** 372* @desc: copy grid in CSV to clipboard 373* @type: public 374* @edition: Professional 375* @topic: 5 376*/ 377dhtmlXGridObject.prototype.gridToClipboard = function(){ 378 this.toClipBoard(this.serializeToCSV()); 379} 380 381/** 382* @desc: init grid from CSV stored in clipboard 383* @type: public 384* @edition: Professional 385* @topic: 5 386*/ 387dhtmlXGridObject.prototype.gridFromClipboard = function(){ 388 var csv=this.fromClipBoard(); 389 if (!csv) return; 390 this.loadCSVString(csv); 391} 392 393/** 394* @desc: get grid as XML - php required
395* @param: path - path to server side code,optional 396* @type: private 397* @edition: Professional 398* @topic: 5 399*/ 400dhtmlXGridObject.prototype.getXLS = function(path){ 401 if (!this.xslform){ 402 this.xslform=document.createElement("FORM"); 403 this.xslform.action=(path||"")+"xls.php"; 404 this.xslform.method="post"; 405 this.xslform.target=(_isIE?"_blank":""); 406 document.body.appendChild(this.xslform); 407 var i1=document.createElement("INPUT"); 408 i1.type="hidden"; 409 i1.name="csv"; 410 this.xslform.appendChild(i1); 411 var i2=document.createElement("INPUT"); 412 i2.type="hidden"; 413 i2.name="csv_header"; 414 this.xslform.appendChild(i2); 415 } 416 var cvs = this.serializeToCSV(); 417 this.xslform.childNodes[0].value = cvs; 418 var cvs_header = []; 419 var l = this._cCount; 420 for (var i=0; i<l; i++) { 421 cvs_header.push(this.getHeaderCol(i)); 422 } 423 cvs_header = cvs_header.join(','); 424 this.xslform.childNodes[1].value = cvs_header; 425 this.xslform.submit(); 426} 427 428/** 429* @desc: generate print friendly view 430* @type: public 431* @edition: Professional 432* @topic: 5 433*/ 434dhtmlXGridObject.prototype.printView = function(before,after){ 435 var html="<style>TD { font-family:Arial; text-align:center; padding-left:2px;padding-right:2px; } \n td.filter input, td.filter select { display:none; } \n </style>"; 436 var st_hr=null; 437 if (this._fake) { 438 st_hr=[].concat(this._hrrar); 439 for (var i=0; i<this._fake._cCount; i++) 440 this._hrrar[i]=null; 441 } 442 var port = document.location.port; 443 var hostname = document.location.hostname; 444 html+="<base href='"+(document.location.protocol+"//"+hostname+(port?(":"+port):"")+document.location.pathname)+"'></base>"; 445 if (!this.parentGrid) html+=(before||""); 446 html += '<table width="100%" border="2px" cellpadding="0" cellspacing="0">'; 447 var row_length = Math.max(this.rowsBuffer.length,this.rowsCol.length); //paging and smartrendering 448 var col_length = this._cCount; 449 var width = this._printWidth(); 450 html += '<tr class="header_row_1">'; 451 for (var i=0; i<col_length; i++){ 452 if (this._hrrar && this._hrrar[i]) continue; 453 var hcell=this.hdr.rows[1].cells[this.hdr.rows[1]._childIndexes?this.hdr.rows[1]._childIndexes[parseInt(i)]:i]; 454 var colspan=(hcell.colSpan||1); 455 var rowspan=(hcell.rowSpan||1); 456 457 for (var j=1; j<colspan; j++) 458 width[i]+=width[j]; 459 html += '<td rowspan="'+rowspan+'" width="'+width[i]+'%" style="background-color:lightgrey;" colspan="'+colspan+'">'+this.getHeaderCol(i)+'</td>'; 460 i+=colspan-1; 461 } 462 html += '</tr>'; 463 464 for (var i=2; i<this.hdr.rows.length; i++){ 465 if (_isIE){ 466 html+="<tr style='background-color:lightgrey' class='header_row_"+i+"'>"; 467 var cells=this.hdr.rows[i].childNodes; 468 for (var j=0; j < cells.length; j++) 469 if (!this._hrrar || !this._hrrar[cells[j]._cellIndex]){ 470 html+=cells[j].outerHTML; 471 } 472 html+="</tr>"; 473 } 474 else 475 html+="<tr class='header_row_"+i+"' style='background-color:lightgrey'>"+(this._fake?this._fake.hdr.rows[i].innerHTML:"")+this.hdr.rows[i].innerHTML+"</tr>"; 476 } 477 478 for (var i=0; i<row_length; i++) { 479 html += '<tr>'; 480 if (this.rowsCol[i] && this.rowsCol[i]._cntr){ 481 html+=this.rowsCol[i].innerHTML.replace(/<img[^>]*>/gi,"")+'</tr>'; 482 continue; 483 } 484 if (this.rowsCol[i] && this.rowsCol[i].style.display=="none") continue; 485 486 var row_id 487 if (this.rowsCol[i]) 488 row_id=this.rowsCol[i].idd; 489 else if (this.rowsBuffer[i]) 490 row_id=this.rowsBuffer[i].idd; 491 else continue; //dyn loading 492 493 for (var j=0; j<col_length; j++) { 494 if (this._hrrar && this._hrrar[j]) continue; 495 if(this.rowsAr[row_id] && this.rowsAr[row_id].tagName=="TR") { 496 var c=this.cells(row_id, j); 497 if (c._setState) var value=""; 498 else if (c.getContent) value = c.getContent(); 499 else if (c.getImage || c.combo) var value=c.cell.innerHTML; 500 else var value = c.getValue(); 501 } else 502 var value=this._get_cell_value(this.rowsBuffer[i],j); 503 var color = this.columnColor[j]?'background-color:'+this.columnColor[j]+';':''; 504 var align = this.cellAlign[j]?'text-align:'+this.cellAlign[j]+';':''; 505 var cspan = c.getAttribute("colspan"); 506 html += '<td style="'+color+align+'" '+(cspan?'colSpan="'+cspan+'"':'')+'>'+(value===""?" ":value)+'</td>'; 507 if (cspan) j+=cspan-1; 508 } 509 html += '</tr>'; 510 if (this.rowsCol[i] && this.rowsCol[i]._expanded){ 511 var sub=this.cells4(this.rowsCol[i]._expanded.ctrl); 512 if (sub.getSubGrid) 513 html += '<tr><td colspan="'+col_length+'">'+sub.getSubGrid().printView()+'</td></tr>'; 514 else 515 html += '<tr><td colspan="'+col_length+'">'+this.rowsCol[i]._expanded.innerHTML+'</td></tr>'; 516 } 517 } 518 519 if (this.ftr) 520 for (var i=1; i<this.ftr.childNodes[0].rows.length; i++) 521 html+="<tr style='background-color:lightgrey'>"+((this._fake)?this._fake.ftr.childNodes[0].rows[i].innerHTML:"")+this.ftr.childNodes[0].rows[i].innerHTML+"</tr>"; 522 523 524 html += '</table>'; 525 if (this.parentGrid) return html; 526 527 html+=(after||""); 528 var d = window.open('', '_blank'); 529 d.document.write(html); 530 d.document.write("<script>window.onerror=function(){return true;}</script>"); 531 d.document.close(); 532 if (this._fake) { 533 this._hrrar=st_hr; 534 } 535} 536dhtmlXGridObject.prototype._printWidth=function(){ 537 var width = []; 538 var total_width = 0; 539 for (var i=0; i<this._cCount; i++) { 540 var w = this.getColWidth(i); 541 width.push(w); 542 total_width += w; 543 } 544 var percent_width = []; 545 var total_percent_width = 0; 546 for (var i=0; i<width.length; i++) { 547 var p = Math.floor((width[i]/total_width)*100); 548 total_percent_width += p; 549 percent_width.push(p); 550 } 551 percent_width[percent_width.length-1] += 100-total_percent_width; 552 return percent_width; 553 }
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.