GB_OpenerObj = {}; GB_RefreshLink = ""; ComplexTableField = Class.create(); ComplexTableField.prototype = { // TODO adjust dynamically popupWidth: 560, popupHeight: 390, initialize: function() { var rules = {}; rules['#'+this.id+' table.data a.popuplink'] = {onclick: this.openPopup.bind(this)}; rules['#'+this.id+' table.data tbody td'] = {onclick: this.openPopup.bind(this)}; // invoke row action-link based on default-action set in classname if(typeof defaultAction != 'undefined' && defaultAction) { rules['#'+this.id+' table.data tbody td'] = { onclick: function(e) { var link = $$('.'+defaultAction, Event.element(e).parentNode)[0].getAttribute('href'); this.openPopup(null, link); return false; }.bind(this) }; } Behaviour.register('ComplexTableField_'+this.id,rules); // HACK If already in a popup, we can't allow add (doesn't save existing relation correctly) if(window != top) $$('#'+this.id+' table.data a.addlink').each(function(el) {Element.hide(el);}); }, getDefaultAction: function() { // try to get link class from 0) { return true; } try { var table = Event.findElement(e,"table"); if(Event.element(e).nodeName == "IMG") { link = Event.findElement(e,"a"); popupLink = link.href+"?ajax=1"; } else { el = Event.findElement(e,"tr"); var link = $$("a",el)[0]; popupLink = link.href; } } catch(err) { // no link found Event.stop(e); return false; } // no link found if(!link || popupLink.length == 0) { Event.stop(e); return false; } } if(this.GB_Caption) { var title = this.GB_Caption; } else { // Getting the title from the URL is pretty ugly, but it works for now type = popupLink.match(/[0-9]+\/([^\/?&]*)([?&]|$)/); var title = (type && type[1]) ? type[1].ucfirst() : ""; } // reset internal greybox callbacks, they are not properly unregistered // and fire multiple times on each subsequent popup close action otherwise if(GB_ONLY_ONE) GB_ONLY_ONE.callback_fn = []; GB_show( title, popupLink, this.popupHeight, this.popupWidth, this.refresh.bind(this) ); if(e) { Event.stop(e); } return false; } } ComplexTableField.applyTo('div.ComplexTableField');