2007-07-19 12:40:28 +02:00
|
|
|
GB_OpenerObj = {};
|
|
|
|
GB_RefreshLink = "";
|
|
|
|
|
|
|
|
ComplexTableField = Class.create();
|
|
|
|
ComplexTableField.prototype = {
|
|
|
|
|
2008-10-08 04:00:12 +02:00
|
|
|
// These are defaults used if setPopupSize encounters errors
|
|
|
|
defaultPopupWidth: 560,
|
|
|
|
defaultPopupHeight: 390,
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
var rules = {};
|
|
|
|
rules['#'+this.id+' table.data a.popuplink'] = {onclick: this.openPopup.bind(this)};
|
2008-10-08 04:00:12 +02:00
|
|
|
|
|
|
|
// Assume that the delete link uses the deleteRecord method
|
|
|
|
rules['#'+this.id+' table.data a.deletelink'] = {onclick: this.deleteRecord.bind(this)};
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-08-12 01:24:54 +02:00
|
|
|
// invoke row action-link based on default-action set in classname
|
2010-10-13 03:10:05 +02:00
|
|
|
var defaultAction = this.getDefaultAction();
|
|
|
|
|
2009-10-16 00:39:13 +02:00
|
|
|
if(defaultAction) {
|
2008-08-12 01:24:54 +02:00
|
|
|
rules['#'+this.id+' table.data tbody td'] = {
|
|
|
|
onclick: function(e) {
|
2009-11-30 01:44:27 +01:00
|
|
|
var elt = Event.element(e);
|
|
|
|
// Check the tag, as otherwise this
|
|
|
|
// function can take over checkbox
|
|
|
|
// click actions etc. See ticket #4737
|
|
|
|
if (elt.tagName != 'TD' && elt.tagName != 'TR') {
|
|
|
|
return;
|
|
|
|
}
|
2010-10-13 03:10:05 +02:00
|
|
|
|
2009-10-16 00:41:01 +02:00
|
|
|
var link = $$('.'+defaultAction, Event.element(e).parentNode)[0].href;
|
2008-08-12 01:24:54 +02:00
|
|
|
this.openPopup(null, link);
|
|
|
|
return false;
|
|
|
|
}.bind(this)
|
|
|
|
};
|
|
|
|
}
|
2008-08-12 06:50:00 +02:00
|
|
|
Behaviour.register('ComplexTableField_'+this.id,rules);
|
2008-08-09 08:29:50 +02:00
|
|
|
|
2008-10-08 04:00:12 +02:00
|
|
|
this.setPopupSize();
|
|
|
|
|
2008-08-09 08:29:50 +02:00
|
|
|
// 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);});
|
2007-07-19 12:40:28 +02:00
|
|
|
},
|
|
|
|
|
2008-10-08 04:00:12 +02:00
|
|
|
setPopupSize: function() {
|
|
|
|
try {
|
|
|
|
this.popupHeight = parseInt($(this.id + '_PopupHeight').value);
|
|
|
|
this.popupWidth = parseInt($(this.id + '_PopupWidth').value);
|
|
|
|
} catch (ex) {
|
|
|
|
this.popupHeight = this.defaultPopupHeight;
|
|
|
|
this.popupWidth = this.defaultPopupWidth;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-08-12 01:24:54 +02:00
|
|
|
getDefaultAction: function() {
|
|
|
|
// try to get link class from <td class="action default"><a href="...
|
|
|
|
var links = $$('#'+this.id+' table.data tbody .default a');
|
|
|
|
// fall back to first given link
|
|
|
|
if(!links || !links[0]) links = $$('#'+this.id+' table.data tbody .action a');
|
|
|
|
return (links && links[0]) ? $A(Element.classNames(links[0])).last() : false;
|
|
|
|
},
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* @param href, table Optional dom object (use for external triggering without an event)
|
|
|
|
*/
|
|
|
|
openPopup: function(e, _popupLink, _table) {
|
2008-08-09 08:29:50 +02:00
|
|
|
// If already in a popup, simply open the link instead
|
|
|
|
// of opening a nested lightwindow
|
|
|
|
if(window != top) return true;
|
|
|
|
|
2008-10-08 04:00:12 +02:00
|
|
|
this.setPopupSize();
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
var el,type;
|
|
|
|
var popupLink = "";
|
|
|
|
if(_popupLink) {
|
|
|
|
popupLink = _popupLink;
|
|
|
|
table = _table;
|
|
|
|
} else {
|
|
|
|
// if clicked item is an input-element, don't trigger popup
|
|
|
|
var el = Event.element(e);
|
|
|
|
var input = Event.findElement(e,"input");
|
|
|
|
var tr = Event.findElement(e, "tr");
|
|
|
|
|
|
|
|
// stop on non-found lines
|
|
|
|
if(tr && Element.hasClassName(tr, 'notfound')) {
|
|
|
|
Event.stop(e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// normal behaviour for input elements
|
|
|
|
if(el.nodeName == "INPUT" || input.length > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
var table = Event.findElement(e,"table");
|
|
|
|
if(Event.element(e).nodeName == "IMG") {
|
|
|
|
link = Event.findElement(e,"a");
|
2010-04-12 05:27:03 +02:00
|
|
|
popupLink = link.href + (link.href.match(/\?/) ? "&ajax=1" : "?ajax=1");
|
2007-07-19 12:40:28 +02:00
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
}
|
2007-10-26 04:23:55 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if(this.GB_Caption) {
|
|
|
|
var title = this.GB_Caption;
|
|
|
|
} else {
|
2008-08-09 06:38:44 +02:00
|
|
|
// Getting the title from the URL is pretty ugly, but it works for now
|
|
|
|
type = popupLink.match(/[0-9]+\/([^\/?&]*)([?&]|$)/);
|
2007-07-19 12:40:28 +02:00
|
|
|
var title = (type && type[1]) ? type[1].ucfirst() : "";
|
|
|
|
}
|
|
|
|
|
2008-08-11 04:25:44 +02:00
|
|
|
// 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)
|
|
|
|
);
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
if(e) {
|
|
|
|
Event.stop(e);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-30 01:44:27 +01:00
|
|
|
ComplexTableField.applyTo('div.ComplexTableField');
|