TableListField = Class.create(); TableListField.prototype = { errorMessage: "Error talking to server", initialize: function() { var rules = {}; rules['#'+this.id+' table.data a.deletelink'] = { onclick: this.deleteRecord.bind(this) }; rules['#'+this.id+' th a'] = { onclick: this.refresh.bind(this) }; rules['#'+this.id+' th'] = { initialize: function() { var sortLinks = $$('span.sortLinkHidden a', this); if(sortLinks) sortLinks[0].style.visibility = 'hidden'; }, onmouseover: function(e) { var sortLinks = $$('span.sortLinkHidden a', this); if(sortLinks) sortLinks[0].style.visibility = 'visible'; }, onmouseout: function(e) { var sortLinks = $$('span.sortLinkHidden a', this); if(sortLinks) sortLinks[0].style.visibility = 'hidden'; } }; rules['#'+this.id+' div.PageControls a'] = {onclick: this.refresh.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) } }; // rules for selection options on click event rules['#'+this.id+' .selectOptions a'] = { onclick: this.markRecords.bind(this) }; // initialize summary (if needed) // TODO Breaks with nested divs var summaryCols = $$('tfoot tr.summary td', this); this._summaryDefs = []; //should check summaryCols.length, because summaryCols will always be an array, though its length could be 0. if(summaryCols && summaryCols.length) { 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) }; } Behaviour.register('TableListField_'+this.id,rules); /* if(summaryCols.length) { this._getSummaryDefs(summaryCols); } */ }, /** * Deletes the given dataobject record via an ajax request * to complextablefield->Delete() * @param {Object} e */ 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 = confirm(ss.i18n._t('TABLEFIELD.DELETECONFIRMMESSAGE', 'Are you sure you want to delete this record?')); if(confirmed) { img.setAttribute("src",'cms/images/network-save.gif'); // TODO doesn't work new Ajax.Request( link.getAttribute("href"), { method: 'post', postBody: 'forceajax=1' + ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : ''), onComplete: function(){ Effect.Fade( row, { afterFinish: function(obj) { // remove row from DOM obj.element.parentNode.removeChild(obj.element); // recalculate summary if needed (assumes that TableListField.js is present) // TODO Proper inheritance if(this._summarise) this._summarise(); // custom callback if(this.callback_deleteRecord) this.callback_deleteRecord(e); }.bind(this) } ); }.bind(this), onFailure: this.ajaxErrorHandler } ); } Event.stop(e); }, removeById: function(id) { var el =$('record-' + this.id + '-' + id); if(el) el.parentNode.removeChild(el); this._summarise(); }, /** * according to the clicked element in "Select bar", mark records that have same class as the element. */ markRecords: function(e){ var el = Event.element(e); if(el.nodeName != "a") el = Event.findElement(e,"a"); if(el.rel == "all"){ this.markAll(); }else if(el.rel == 'none') { this.unmarkAll(); }else{ this.unmarkAll(); var records = $$('#' + this.id + ' td.' + el.rel + ' input.checkbox'); var i=0; for(i; i Behaviour.apply($(this.id), true); if(oncomplete) oncomplete.apply(response); }.bind(this) } ); } if(e) Event.stop(e); return false; }, ajaxErrorHandler: function(response) { if(typeof(window.ajaxErrorHandler) == 'function') { window.ajaxErrorHandler(); } else { alert(this.errorMessage); } }, _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); if(!rows) return false; var columnData = []; // prepare the array (gets js-errors otherwise) var cols = $$('td', rows[0]); for(colPos=0; colPos