diff --git a/forms/ComplexTableField.php b/forms/ComplexTableField.php index 1341ac54a..07164419c 100755 --- a/forms/ComplexTableField.php +++ b/forms/ComplexTableField.php @@ -354,7 +354,7 @@ JS; function AddLink() { - return $this->Link() . '/add'; + return Controller::join_links($this->Link(), 'add'); } /** @@ -390,16 +390,18 @@ JS; } /** - * Return the record in which the CTF resides + * Return the record in which the CTF resides, if it exists. */ function getParentRecord() { if($this->form && $record = $this->form->getRecord()) { return $record; } else { - if($this->sourceID()) { - $parentClass = DataObject::get_by_id($this->getParentClass(), $this->sourceID()); - } else { - $parentClass = singleton($this->getParentClass()); + $parentID = (int)$this->sourceID(); + $parentClass = $this->getParentClass(); + + if($parentClass) { + if($parentID) return DataObject::get_by_id($parentClass, $parentID); + else return singleton($parentClass); } } } @@ -660,10 +662,12 @@ JS; _t('ComplexTableField.CLOSEPOPUP', 'Close Popup') ); + $editLink = Controller::join_links($this->Link(), 'item/' . $childData->ID . '/edit'); + $message = sprintf( _t('ComplexTableField.SUCCESSADD', 'Added %s %s %s'), $childData->singular_name(), - '' . $childData->Title . '', + '' . $childData->Title . '', $closeLink ); @@ -1007,15 +1011,15 @@ class ComplexTableField_Item extends TableListField_Item { } function EditLink() { - return $this->Link() . "/edit"; + return Controller::join_links($this->Link(), "edit"); } function ShowLink() { - return $this->Link() . "/show"; + return Controller::join_links($this->Link(), "show"); } function DeleteLink() { - return $this->Link() . "/delete"; + return Controller::join_links($this->Link(), "delete"); } /** diff --git a/forms/TableListField.php b/forms/TableListField.php index dfe80e8eb..a4bcebc8a 100755 --- a/forms/TableListField.php +++ b/forms/TableListField.php @@ -1124,7 +1124,7 @@ JS if(isset($_REQUEST['ctf'][$this->Name()]['start']) && is_numeric($_REQUEST['ctf'][$this->Name()]['start'])) { $start = ($_REQUEST['ctf'][$this->Name()]['start'] < 0) ? 0 : $_REQUEST['ctf'][$this->Name()]['start']; - $link .= "/?ctf[{$this->Name()}][start]={$start}"; + $link = Controller::join_links($link, "?ctf[{$this->Name()}][start]={$start}"); } if($this->extraLinkParams) $link .= "&" . http_build_query($this->extraLinkParams); @@ -1417,7 +1417,7 @@ class TableListField_ItemRequest extends RequestHandler { ); function Link() { - return $this->ctf->Link() . '/item/' . $this->itemID; + return Controller::join_links($this->ctf->Link(), 'item/' . $this->itemID); } function __construct($ctf, $itemID) { diff --git a/javascript/ComplexTableField.js b/javascript/ComplexTableField.js index ef48447fb..b50d9de0e 100755 --- a/javascript/ComplexTableField.js +++ b/javascript/ComplexTableField.js @@ -95,7 +95,7 @@ ComplexTableField.prototype = { var table = Event.findElement(e,"table"); if(Event.element(e).nodeName == "IMG") { link = Event.findElement(e,"a"); - popupLink = link.href+"?ajax=1"; + popupLink = link.href + (link.href.match(/\?/) ? "&ajax=1" : "?ajax=1"); } else { el = Event.findElement(e,"tr"); var link = $$("a",el)[0];