123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- /*
- * Copyright DHTMLX LTD. http://www.dhtmlx.com You allowed to use this component
- * or parts of it under GPL terms To use it on other terms or get Professional
- * edition of the component please contact us at sales@dhtmlx.com
- */
- dhtmlXGridObject.prototype.useCSV = function(path) {
- if (!this._csv_loadXML) {
- this._csv_loadXML = this.loadXML;
- this._csv_loadXMLString = this.loadXMLString;
- this.loadXML = this.loadCSVFile;
- this.loadXMLString = this.loadCSVFile
- }
- };
- dhtmlXGridObject.prototype.loadCSVFile = function(path, afterCall) {
- this.xmlLoader = new dtmlXMLLoaderObject(this._onCSVFileLoad, this);
- this.xmlLoader.waitCall = afterCall;
- this.xmlLoader.loadXML(path)
- };
- dhtmlXGridObject.prototype._onCSVFileLoad = function(obj, b, c, d, xml) {
- var z = this.xmlDoc.responseText;
- obj.loadCSVString(z)
- };
- dhtmlXGridObject.prototype.enableCSVAutoID = function(mode) {
- this._csvAID = convertStringToBoolean(mode)
- };
- dhtmlXGridObject.prototype.enableCSVHeader = function(mode) {
- this._csvHdr = convertStringToBoolean(mode);
- if (this._csvHdr)
- this.enableCSVAutoID(true)
- };
- dhtmlXGridObject.prototype.setCSVDelimiter = function(str) {
- this._csvDelim = (str || this._csvDelim);
- this._csvDelimX = this._csvDelim.charCodeAt(0);
- var trans = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"];
- this._csvDelimX = "\\x" + trans[Math.floor(this._csvDelimX / 16)] + ""
- + trans[(this._csvDelimX % 16)]
- };
- dhtmlXGridObject.prototype.loadCSVString = function(str) {
- if (!this._csvDelimX)
- this.setCSVDelimiter();
- var r1 = new RegExp("^([^" + this._csvDelimX + "]+)" + this._csvDelimX);
- var r2 = new RegExp("\n([^" + this._csvDelimX + "]+)" + this._csvDelimX,
- "g");
- var r3 = new RegExp("" + this._csvDelimX + "", "g");
- if (this._csvHdr) {
- hdr = str.substr(0, str.indexOf("\n"));
- str = str.substr(str.indexOf("\n") + 1);
- hdr = "<head><beforeInit><call command='setHeader'><param>"
- + hdr.replace(new RegExp(this._csvDelimX, "g"), ",")
- + "</param></call><call command='init'></call></beforeInit></head>"
- };
- if (this._csvAID) {
- str = str
- .replace(r1, "<row><cell><![CDATA[$1]]></cell><cell><![CDATA[");
- str = str
- .replace(r2,
- "]]></cell></row><row id=''><cell><![CDATA[$1]]></cell><cell><![CDATA[")
- } else {
- str = str.replace(r1, "<row id='$1'><cell><![CDATA[");
- str = str.replace(r2, "]]></cell></row><row id='$1'><cell><![CDATA[")
- };
- str = str.replace(r3, "]]></cell><cell><![CDATA[");
- if (str.indexOf("<row") != 0)
- str = "<row><cell><![CDATA[" + str;
- str = "<?xml version='1.0'?><rows>" + (this._csvHdr ? (hdr + str) : str)
- + "]]></cell></row></rows>";
- this.xmlLoader = new dtmlXMLLoaderObject(this.doLoadDetails, window, true,
- this.no_cashe);
- this.xmlLoader.loadXMLString(str)
- };
- dhtmlXGridObject.prototype.serializeToCSV = function() {
- this.editStop();
- if (this._mathSerialization)
- this._agetm = "getMathValue";
- else
- this._agetm = "getValue";
- var out = "";
- if (this._csvHdr) {
- var a = [];
- var b = this.hdr.rows[1].cells;
- for (var i = 0; i < b.length; i++)
- if ((!this._srClmn) || (this._srClmn[i]))
- a
- .push((b[i].firstChild.tagName ? b[i].firstChild : b[i]).innerHTML);
- out = a.join(this._csvDelim) + "\n"
- };
- var i = 0;
- var leni = (this._dload)
- ? this.rowsBuffer[0].length
- : (this.rowsBuffer[0].length + this.rowsCol.length);
- for (i; i < leni; i++) {
- if (i >= this.rowsCol.length && this.pagingOn) {
- var temp = this._serializeRowToCVS(null, i - this.rowsCol.length)
- } else {
- var r = this.rowsCol[i];
- var temp = this._serializeRowToCVS(r, i)
- };
- out += temp;
- if (temp != "")
- out += "\n"
- };
- return out
- };
- dhtmlXGridObject.prototype._serializeRowToCVS = function(r, i, start, end) {
- var out = new Array();
- if ((!r) || (r._sRow) || (r._rLoad) || (r.tagName == "row")) {
- if (this.rowsBuffer[1][i]) {
- var r = this.rowsBuffer[1][i];
- if (!this._csvAID)
- out[out.length] = r.getAttribute("id");
- for (var j = 0; j < r.childNodes.length; j++) {
- if (r.childNodes[j].tagName == "cell") {
- var c = r.childNodes[j];
- out[out.length] = c.firstChild
- ? c.firstChild.nodeValue
- : ""
- }
- }
- };
- return out
- };
- if (!this._csvAID)
- out[out.length] = r.idd;
- start = start || 0;
- end = end || r.childNodes.length;
- var changeFl = false;
- for (var jj = start; jj < end; jj++)
- if ((!this._srClmn) || (this._srClmn[jj])) {
- var cvx = r.childNodes[jj];
- var zx = this.cells(r.idd, cvx._cellIndex);
- // =======2007/11/26=====add by xiaoxiao while hidden then cancel
- // copy data .....
- if (zx.cell.style.display == "") { // ��ӵ�
- if (zx.cell)
- zxVal = zx[this._agetm]();
- else
- zxVal = "";
- if ((this._chAttr) && (zx.wasChanged()))
- changeFl = true;
- out[out.length] = ((zxVal === null) ? "" : zxVal)
- if ((this._ecspn) && (cvx.colSpan)) {
- cvx = cvx.colSpan - 1;
- for (var u = 0; u < cvx; u++)
- out[out.length] = ""
- }
- }
- };
- if ((this._onlChAttr) && (!changeFl))
- return "";
- return out.join(this._csvDelim)
- };
- dhtmlXGridObject.prototype.toClipBoard = function(val) {
- if (window.clipboardData)
- window.clipboardData.setData("Text", val);
- else
- (new Clipboard()).copy(val)
- };
- dhtmlXGridObject.prototype.fromClipBoard = function() {
- if (window.clipboardData)
- return window.clipboardData.getData("Text");
- else
- return (new Clipboard()).paste()
- };
- dhtmlXGridObject.prototype.cellToClipboard = function(rowId, cellInd) {
- if ((!rowId) || (!cellInd)) {
- if (!this.selectedRows[0])
- return;
- rowId = this.selectedRows[0].idd;
- cellInd = this.cell._cellIndex
- };
- var ed = this.cells(rowId, cellInd);
- this.toClipBoard(ed.getLabel ? ed.getLabel() : ed.getValue())
- };
- dhtmlXGridObject.prototype.updateCellFromClipboard = function(rowId, cellInd) {
- if ((!rowId) || (!cellInd)) {
- if (!this.selectedRows[0])
- return;
- rowId = this.selectedRows[0].idd;
- cellInd = this.cell._cellIndex
- };
- var ed = this.cells(rowId, cellInd);
- ed[ed.setImage ? "setLabel" : "setValue"](this.fromClipBoard())
- };
- dhtmlXGridObject.prototype.rowToClipboard = function(rowId) {
- var out = "";
- if (this._mathSerialization)
- this._agetm = "getMathValue";
- else
- this._agetm = "getValue";
- if (rowId)
- out = this._serializeRowToCVS(this.getRowById(rowId));
- else
- for (var i = 0; i < this.selectedRows.length; i++) {
- if (out)
- out += "\n";
- out += this._serializeRowToCVS(this.selectedRows[i])
- };
- this.toClipBoard(out)
- };
- dhtmlXGridObject.prototype.updateRowFromClipboard = function(rowId) {
- var csv = this.fromClipBoard();
- if (!csv)
- return;
- if (rowId)
- var r = this.getRowById(rowId);
- else
- var r = this.selectedRows[0];
- if (!r)
- return;
- csv = csv.split(this._csvDelim);
- for (var i = 1; i < csv.length; i++) {
- var ed = this.cells3(r, i - 1);
- ed[ed.setImage ? "setLabel" : "setValue"](csv[i])
- }
- };
- dhtmlXGridObject.prototype.addRowFromClipboard = function() {
- var csv = this.fromClipBoard();
- if (!csv)
- return;
- var z = csv.split("\n");
- for (var i = 0; i < z.length; i++)
- if (z[i]) {
- csv = z[i].split(this._csvDelim);
- this.addRow(csv[0], csv.slice(1))
- }
- };
- dhtmlXGridObject.prototype.gridToClipboard = function() {
- this.toClipBoard(this.serializeToCSV())
- };
- dhtmlXGridObject.prototype.gridFromClipboard = function() {
- var csv = this.fromClipBoard();
- if (!csv)
- return;
- this.loadCSVString(csv)
- };
- dhtmlXGridObject.prototype.getXLS = function(path) {
- if (!this.xslform) {
- this.xslform = document.createElement("FORM");
- this.xslform.action = (path || "") + "xls.php";
- this.xslform.method = "post";
- this.xslform.target = (_isIE ? "_blank" : "");
- document.body.appendChild(this.xslform);
- var i1 = document.createElement("INPUT");
- i1.type = "hidden";
- i1.name = "csv";
- this.xslform.appendChild(i1);
- var i2 = document.createElement("INPUT");
- i2.type = "hidden";
- i2.name = "csv_header";
- this.xslform.appendChild(i2)
- };
- var cvs = this.serializeToCSV();
- this.xslform.childNodes[0].value = cvs;
- var cvs_header = [];
- var l = this._cCount;
- for (var i = 0; i < l; i++) {
- cvs_header.push(this.getHeaderCol(i))
- };
- cvs_header = cvs_header.join(',');
- this.xslform.childNodes[1].value = cvs_header;
- this.xslform.submit()
- };
- dhtmlXGridObject.prototype.printView = function(path) {
- var html = "<style>TD {font-family:Arial;text-align:center};</style>";
- html += "<base href='" + document.location.href + "'></base>";
- html += '<table width="100%" border="2px" cellpadding="0" cellspacing="0">';
- var row_length = this.rowsCol.length;
- var col_length = this._cCount;
- var width = this._printWidth();
- html += '<tr>';
- for (var i = 0; i < col_length; i++) {
- if (this._hrrar && this._hrrar[i])
- continue;
- var colspan = (this.hdr.rows[1].cells[this.hdr.rows[1]._childIndexes
- ? this.hdr.rows[1]._childIndexes[parseInt(i)]
- : i].colSpan || 1);
- for (var j = 1; j < colspan; j++)
- width[i] += width[j];
- html += '<td width="'
- + width[i]
- + '%" style="padding-left:2px;padding-right:2px;background-color:lightgray;" colspan="'
- + colspan + '">' + this.getHeaderCol(i) + '</td>';
- i += colspan - 1
- };
- html += '</tr>';
- for (var i = 2; i < this.hdr.rows.length; i++)
- html += "<tr>" + this.hdr.rows[i].innerHTML + "</tr>";
- for (var i = 0; i < row_length; i++) {
- html += '<tr>';
- for (var j = 0; j < col_length; j++) {
- if (this._hrrar && this._hrrar[j])
- continue;
- var c = this.cells(this.rowsCol[i].idd, j);
- if (c.getImage)
- var value = c.cell.innerHTML;
- else
- var value = c.getValue();
- var color = this.columnColor[j] ? 'background-color:'
- + this.columnColor[j] + ';' : '';
- var align = this.cellAlign[j] ? 'text-align:' + this.cellAlign[j]
- + ';' : '';
- html += '<td style="padding-left:2px;padding-right:2px;' + color
- + align + '">' + (value === "" ? " " : value)
- + '</td>'
- };
- html += '</tr>'
- };
- if (this.ftr)
- for (var i = 1; i < this.ftr.childNodes[0].rows.length; i++)
- html += "<tr>" + this.ftr.rows[i].innerHTML + "</tr>";
- html += '</table>';
- var d = window.open('', '_blank');
- d.document.write(html);
- d.document.close()
- };
- dhtmlXGridObject.prototype._printWidth = function() {
- var width = [];
- var total_width = 0;
- for (var i = 0; i < this._cCount; i++) {
- var w = this.getColWidth(i);
- width.push(w);
- total_width += w
- };
- var percent_width = [];
- var total_percent_width = 0;
- for (var i = 0; i < width.length; i++) {
- var p = Math.floor((width[i] / total_width) * 100);
- total_percent_width += p;
- percent_width.push(p)
- };
- percent_width[percent_width.length - 1] += 100 - total_percent_width;
- return percent_width
- };
- dhtmlXGridObject.prototype.loadObject = function(obj) {
- };
- dhtmlXGridObject.prototype.loadJSONFile = function(path) {
- };
- dhtmlXGridObject.prototype.serializeToObject = function() {
- };
- dhtmlXGridObject.prototype.serializeToJSON = function() {
- };
- if (!window.clipboardData)
- window.clipboardData = {
- _make : function() {
- var clip = Components.classes['@mozilla.org/widget/clipboard;1']
- .createInstance(Components.interfaces.nsIClipboard);
- if (!clip)
- return null;
- var trans = Components.classes['@mozilla.org/widget/transferable;1']
- .createInstance(Components.interfaces.nsITransferable);
- if (!trans)
- return null;
- trans.addDataFlavor('text/unicode');
- var str = Components.classes["@mozilla.org/supports-string;1"]
- .createInstance(Components.interfaces.nsISupportsString);
- this._p = [clip, trans, str];
- return true
- },
- setData : function(type, text) {
- netscape.security.PrivilegeManager
- .enablePrivilege('UniversalXPConnect');
- if (!this._make())
- return false;
- this._p[2].data = text;
- this._p[1].setTransferData("text/unicode", this._p[2], text.length
- * 2);
- var clipid = Components.interfaces.nsIClipboard;
- this._p[0].setData(this._p[1], null, clipid.kGlobalClipboard)
- },
- getData : function(type) {
- netscape.security.PrivilegeManager
- .enablePrivilege('UniversalXPConnect');
- if (!this._make())
- return false;
- this._p[0].getData(this._p[1], this._p[0].kGlobalClipboard);
- var strLength = new Object();
- var str = new Object();
- this._p[1].getTransferData("text/unicode", str, strLength);
- if (str)
- str = str.value
- .QueryInterface(Components.interfaces.nsISupportsString);
- if (str)
- return str.data.substring(0, strLength.value / 2);
- return ""
- }
- };
- /*
- * Copyright DHTMLX LTD. http://www.dhtmlx.com You allowed to use this component
- * or parts of it under GPL terms To use it on other terms or get Professional
- * edition of the component please contact us at sales@dhtmlx.com
- */
|