// http://laurens.vd.oever.nl/weblog/items2005/closures/ Function.prototype.closure = function(obj){ // Init object storage. if (!window.__objs){ window.__objs = []; window.__funs = []; } // For symmetry and clarity. var fun = this; // Make sure the object has an id and is stored in the object store. var objId = obj.__objId; if (!objId) __objs[objId = obj.__objId = __objs.length] = obj; // Make sure the function has an id and is stored in the function store. var funId = fun.__funId; if (!funId) __funs[funId = fun.__funId = __funs.length] = fun; // Init closure storage. if (!obj.__closures) obj.__closures = []; // See if we previously created a closure for this object/function pair. var closure = obj.__closures[funId]; if (closure) return closure; // Clear references to keep them out of the closure scope. obj = null; fun = null; // Create the closure, store in cache and return result. return __objs[objId].__closures[funId] = function(){ return __funs[funId].apply(__objs[objId], arguments); }; }; Z.EditableGrid=Base.extend({ configuration: { clrHilight: 'internobianco', // class used for hilighting a selected row clrRowEven: 'internobianco', // class used for the even rows clrRowOdd: 'internobianco', // class used for the odd rows blnPointToSelect: true, // Set this to false if you want 'click to select' and 'doubleclick to Edit' mode strNoImage: "noSort.gif", // Full path of the image used to indicate that the row is not sorted. strUpImage: "up.gif", // Full path of the up image used on sort asc strDownImage: "down.gif", // Full path of the up image used on sort desc intImgWidth: 8, // The width of the images used to indicate the asc/des sort intImgHeight: 10 // The height of the images used to indicate the asc/des sort }, data:{}, constructor:function(configuration, data){ this.configuration=Z.Merge(this.configuration, configuration||{}); this.data=Z.Merge({}, data||{} ); }, //globals objLastClick: -1, blnReverse: false, // Stores the flag used by sort blnMouseOver: false, // Stores the flag used by capturemouse objDivToMove: null, // Stores the div being moved intColCount: 0, // Stores the number of coloumns objRowSelected: null, // Stores the row element currently selected clrRowSelected: '', // Store the original color of the selected row objTable: null, //THE element which holds the table... //functions buildTable: function (){ var tbl=document.createElement("TABLE"); tbl.style.width='100%'; this.objTable=tbl; tbl.id=this.data.id; var thead=tbl.createTHead(); var trow=thead.insertRow(0); for(var i=0, title,cell; title=this.data.titles[i++];){ // eslint-disable-line no-cond-assign cell=trow.insertCell(trow.cells.length); cell.innerHTML=title; cell.className="titoli" } if(tbl.tBodies.length==0) tbl.appendChild(document.createElement('TBODY')); var datarow; for(var dataref in this.data.rows.Keys()){ datarow=this.data.rows[dataref]; this.addRow(datarow).setAttribute('datarow',dataref); } return tbl; }, addRow: function(datarow){ if(!datarow) datarow=[].concat(this.data.blank); var row=document.createElement("TR"); for(var i=0, l=datarow.length, cell, cellTxt; i 0){ this.clrRowSelected = srcElem.className; srcElem.className = this.configuration.clrHilight; this.objRowSelected = srcElem; } }, getEventRow: function(e){ var srcElem = GetEventSrcElement(e); while (srcElem.tagName != "TR" && srcElem.tagName != "TABLE"){ srcElem = srcElem.parentNode; } return srcElem; }, onClickCell: function(e){ var srcElem = this.getEventRow(e); if(srcElem.tagName != "TR") return; /*Stefano if(srcElem.rowIndex == 0) sort (); */ if(srcElem.rowIndex == 0) return; else this.onEdit(srcElem, this.getEventCell(e)); }, onEdit: function(row, srcCell){ var objInput; for(var i=0, cells=row.cells, cell, input; cell=cells[i++];){ // eslint-disable-line no-cond-assign input = this.inputizeCell(cell); if(i==1 || cell==srcCell) objInput=input; } if(objInput) objInput.focus(); }, getEventCell: function(e){ var srcElem = GetEventSrcElement(e); while (srcElem.tagName != "TD" && srcElem.tagName != "TABLE"){ srcElem = srcElem.parentNode; } return srcElem; }, inputizeCell: function(srcElem){ var objInput_container = document.createElement ("DIV"); var objInput = document.createElement ("INPUT"); var objInputEdit = document.createElement ("INPUT"); var datarow; if(srcElem.parentNode.getAttribute('datarow') in this.data.rows) datarow = this.data.rows[srcElem.parentNode.getAttribute('datarow')]; else{ datarow = [].concat(this.data.blank); srcElem.parentNode.setAttribute('datarow',this.data.rows.Add(datarow)); } var optIdx=srcElem.getAttribute("dataoptions"); var txtOld = datarow[optIdx]; srcElem.innerHTML = ""; var type=srcElem.getAttribute("TCType"); var callFunc=srcElem.getAttribute("callFunc"); switch (type){ case 'combobox': objInput = document.createElement('SELECT'); var selIdx=0; for(var i=0, opt, opts=this.data.options[optIdx].values, l=opts.length; i 1) return elm.parentNode.childNodes[elm.rowIndex - 2]; else return null; }, getPrevRow: function(elm){ return elm.parentNode.childNodes[elm.rowIndex]; }, deleteRow: function(rowNum){ var tbody = this.objTable.tBodies[0]; if(!rowNum && this.objRowSelected) rowNum=this.objRowSelected.rowIndex-1; if(!tbody || rowNum < 0 || this.objRowSelected==null) return; this.removeTextNodes(tbody); var remNode; if(remNode=tbody.removeChild(tbody.childNodes[rowNum])){ // eslint-disable-line no-cond-assign this.data.rows.Remove(remNode.getAttribute('datarow')); } this.initRowColours(); //So that similar colored rows dont end up together after delete. this.clrRowSelected = this.objRowSelected.className; //Save the color only after repainting all the rows if(rowNum!=0) if(tbody.rows.length==rowNum) this.selectRow(rowNum); else this.selectRow(rowNum+1); else if(tbody.rows.length>0) this.selectRow(rowNum+1); }, selectLastRow: function(){ var idx=this.objTable.tBodies[0].rows.length; this.selectRow(idx) }, editSelectedRow: function(){ if(this.objRowSelected && this.objRowSelected.parentNode) this.onEdit(this.objRowSelected); } });