TableListField = Class.create(); TableListField.prototype = { deleteConfirmMessage: "Are you sure you want to delete this record?", initialize: function() { var rules = {}; rules['#'+this.id+' table.data a.deletelink'] = { onclick: this.deleteRecord.bind(this) }; rules['#'+this.id+' th'] = { initialize: function() { var sortLinks = $$('span.sortLinkHidden a', this); if(sortLinks) Element.hide(sortLinks[0]); }, onmouseover: function(e) { var sortLinks = $$('span.sortLinkHidden a', this); if(sortLinks) Element.show(sortLinks[0]); }, onmouseout: function(e) { var sortLinks = $$('span.sortLinkHidden a', this); if(sortLinks) Element.hide(sortLinks[0]); }, }; rules['#'+this.id+' div.PageControls a'] = {onclick: this.paginate.bind(this)}; rules['#'+this.id+' table.data tr td.markingcheckbox'] = { onclick : function(e) { // do nothing for clicks in marking box cells (e.g. if checkbox is missed) } }; // initialize summary (if needed) // TODO Breaks with nested divs var summaryCols = $$('tfoot tr.summary td', this); if(summaryCols) { rules['#'+this.id+' table.data tbody input'] = { onchange: function(e) { if (!e) e = window.event; // stupid IE // workaround for wrong scope with bind(this) and applyTo() var root = Event.findElement(e,'div'); // TODO Fix slow $$()-calls and re-enable clientside summaries //root._summarise(); } }; rules['#'+this.id+' table.data tbody select'] = { onchange: function(e) { if (!e) e = window.event; // stupid IE // workaround for wrong scope with bind(this) and applyTo() var root = Event.findElement(e,'div'); // TODO Fix slow $$()-calls and re-enable clientside summaries //root._summarise(); }.bind(this) }; this._summaryDefs = []; } Behaviour.register(rules); if(summaryCols) { //this._getSummaryDefs(summaryCols); } }, /** * TODO Evaluate server-status before visually deleting (might have caused an error) */ deleteRecord: function(e) { var img = Event.element(e); var link = Event.findElement(e,"a"); var row = Event.findElement(e,"tr"); // TODO ajaxErrorHandler and loading-image are dependent on cms, but formfield is in sapphire var confirmed = (this.deleteConfirmMessage != undefined) ? confirm(this.deleteConfirmMessage) : true; if(confirmed) { img.setAttribute("src",'cms/images/network-save.gif'); // TODO doesn't work in Firefox1.5+ new Ajax.Request( link.getAttribute("href"), { method: 'post', postBody: 'forceajax=1', onComplete: function(){ Effect.Fade(row); }.bind(this), onFailure: ajaxErrorHandler } ); } Event.stop(e); }, removeById: function(id) { var el =$('record-' + this.id + '-' + id); if(el) el.parentNode.removeChild(el); this._summarise(); }, paginate: function(e) { var el = Event.element(e); if(el.nodeName != "a") { var el = Event.findElement(e,"a"); } new Ajax.Request( el.href, { postBody: 'update=1', onComplete: Ajax.Evaluator } ); Event.stop(e); return false; }, _getSummaryDefs: function(summaryCols) { summaryCols.each(function(col, pos) { if( col ) { var func = this._getSummaryFunction(col.className); this._summaryDefs[pos] = {col: col, pos: pos, func: func}; } }.bind(this)); this._summarise(); }, _summarise: function() { var rows = $$('tbody tr', this); var columnData = []; // prepare the array (gets js-errors otherwise) var cols = $$('td', rows[0]); for(colPos=0; colPos