2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Provides a tabuar list in your form with view, edit and add links to edit records
|
|
|
|
* with a "has-one"-relationship. Detail-views are shown in a greybox-iframe.
|
|
|
|
* Features pagination in the overview as well as the detail-views.
|
2007-09-15 23:36:17 +02:00
|
|
|
*
|
|
|
|
* CAUTION: You need to make sure that the original form-call to the main controller (e.g. EditForm())
|
|
|
|
* returns a form which includes this field even if no data is loaded,
|
2007-07-19 12:40:28 +02:00
|
|
|
* to provide a "starting point" for action_callfieldmethod and ReferencedField.
|
2007-09-15 23:36:17 +02:00
|
|
|
*
|
2007-07-19 12:40:28 +02:00
|
|
|
* All URL data sent to and from ComplexTableField is encapsulated in $_REQUEST['ctf']
|
|
|
|
* to avoid side-effects with the main controller.
|
2007-09-15 23:36:17 +02:00
|
|
|
*
|
2007-07-19 12:40:28 +02:00
|
|
|
* Example-URL for a "DetailForm"-call explained:
|
|
|
|
* "/admin/family/?executeForm=EditForm&action_callfieldmethod&fieldName=Individual&childID=7&methodName=edit"
|
2012-09-26 23:34:00 +02:00
|
|
|
* - executeForm Name of the form on the main rendering page (e.g. "FamilyAdmin")
|
|
|
|
* - action_callfieldmethod Trigger to call a method of a single field in "EditForm" instead of rendering the
|
|
|
|
* whole thing
|
|
|
|
* - fieldName Name of the targeted formField
|
|
|
|
* - methodName Method on the formfield (e.g. "ComplexTableField")
|
|
|
|
* - childID Identifier of the database-record (the targeted table is determined by the $sourceClass
|
|
|
|
* parameter)
|
2012-03-12 17:20:40 +01:00
|
|
|
*
|
|
|
|
* @deprecated 3.0 Use GridField with GridFieldConfig_RecordEditor
|
2007-09-15 23:36:17 +02:00
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @todo Control width/height of popup by constructor (hardcoded at the moment)
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-relational
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class ComplexTableField extends TableListField {
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2008-08-18 02:50:39 +02:00
|
|
|
/**
|
|
|
|
* Determines the fields of the detail pop-up form. It can take many forms:
|
2011-10-28 03:37:27 +02:00
|
|
|
* - A FieldList object: Use that field set directly.
|
2008-08-18 02:50:39 +02:00
|
|
|
* - A method name, eg, 'getCMSFields': Call that method on the child object to get the fields.
|
|
|
|
*/
|
2010-05-25 07:00:25 +02:00
|
|
|
protected $addTitle;
|
2012-12-08 12:20:20 +01:00
|
|
|
|
2008-08-18 02:50:39 +02:00
|
|
|
protected $detailFormFields;
|
|
|
|
|
2009-11-22 07:07:45 +01:00
|
|
|
protected $viewAction;
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* @var Controller
|
|
|
|
*/
|
|
|
|
protected $controller;
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* @var string Classname of the parent-relation to correctly link new records.
|
|
|
|
*/
|
2008-08-09 05:29:30 +02:00
|
|
|
public $parentClass;
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-12-04 05:54:26 +01:00
|
|
|
/**
|
|
|
|
* @var string Database column name for the used relation (e.g. FamilyID
|
|
|
|
* if one Family has_many Individuals).
|
|
|
|
*/
|
|
|
|
protected $parentIdName;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* @var array Influence output without having to subclass the template.
|
|
|
|
*/
|
|
|
|
protected $permissions = array(
|
|
|
|
"add",
|
2008-08-09 06:38:44 +02:00
|
|
|
"edit",
|
|
|
|
"show",
|
|
|
|
"delete",
|
2007-07-19 12:40:28 +02:00
|
|
|
//"export",
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2008-01-03 09:43:26 +01:00
|
|
|
* Template for main rendering
|
|
|
|
*
|
|
|
|
* @var string
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
protected $template = "ComplexTableField";
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2008-01-03 09:43:26 +01:00
|
|
|
/**
|
|
|
|
* Template for popup (form rendering)
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2008-08-09 05:29:30 +02:00
|
|
|
public $templatePopup = "ComplexTableField_popup";
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2008-01-03 09:43:26 +01:00
|
|
|
/**
|
|
|
|
* Classname for each row/item
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $itemClass = 'ComplexTableField_Item';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Classname for the popup form
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $popupClass = 'ComplexTableField_Popup';
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* @var boolean Trigger pagination (defaults to true for ComplexTableField)
|
|
|
|
*/
|
|
|
|
protected $showPagination = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string Caption the popup will show (defaults to the selected action).
|
|
|
|
* This is set by javascript and used by greybox.
|
|
|
|
*/
|
|
|
|
protected $popupCaption = null;
|
2010-05-25 07:00:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var callback A function callback invoked
|
|
|
|
* after initializing the popup and its base calls to
|
|
|
|
* the {@link Requirements} class.
|
|
|
|
*/
|
|
|
|
public $requirementsForPopupCallback = null;
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* @var $detailFormValidator Validator
|
|
|
|
*/
|
|
|
|
protected $detailFormValidator = null;
|
|
|
|
|
2008-10-08 21:22:07 +02:00
|
|
|
/**
|
|
|
|
* Default size for the popup box
|
|
|
|
*/
|
|
|
|
protected $popupWidth = 560;
|
|
|
|
protected $popupHeight = 390;
|
|
|
|
|
2008-08-12 07:20:20 +02:00
|
|
|
public $defaultAction = 'show';
|
|
|
|
|
2008-08-12 01:24:54 +02:00
|
|
|
public $actions = array(
|
|
|
|
'show' => array(
|
|
|
|
'label' => 'Show',
|
2012-07-16 05:18:31 +02:00
|
|
|
'icon' => 'framework/images/show.png',
|
|
|
|
'icon_disabled' => 'framework/images/show_disabled.png',
|
2008-08-12 01:24:54 +02:00
|
|
|
'class' => 'popuplink showlink',
|
|
|
|
),
|
|
|
|
'edit' => array(
|
|
|
|
'label' => 'Edit',
|
2012-07-16 05:18:31 +02:00
|
|
|
'icon' => 'framework/images/edit.gif',
|
|
|
|
'icon_disabled' => 'framework/images/edit_disabled.gif',
|
2008-08-12 01:24:54 +02:00
|
|
|
'class' => 'popuplink editlink',
|
|
|
|
),
|
|
|
|
'delete' => array(
|
|
|
|
'label' => 'Delete',
|
2012-07-16 05:18:31 +02:00
|
|
|
'icon' => 'framework/images/delete.gif',
|
|
|
|
'icon_disabled' => 'framework/images/delete_disabled.gif',
|
2008-08-12 01:24:54 +02:00
|
|
|
'class' => 'popuplink deletelink',
|
|
|
|
),
|
|
|
|
);
|
2008-08-09 05:29:30 +02:00
|
|
|
|
|
|
|
static $url_handlers = array(
|
|
|
|
'item/$ID' => 'handleItem',
|
2008-08-09 05:54:55 +02:00
|
|
|
'$Action!' => '$Action',
|
2008-08-09 05:29:30 +02:00
|
|
|
);
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function handleItem($request) {
|
2008-08-09 05:29:30 +02:00
|
|
|
return new ComplexTableField_ItemRequest($this, $request->param('ID'));
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getViewer() {
|
2008-08-11 04:57:59 +02:00
|
|
|
return new SSViewer($this->template);
|
2008-08-09 05:29:30 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setPopupSize($width, $height) {
|
2008-10-08 21:22:07 +02:00
|
|
|
$width = (int)$width;
|
|
|
|
$height = (int)$height;
|
|
|
|
|
|
|
|
if($width < 0 || $height < 0) {
|
|
|
|
user_error("setPopupSize expects non-negative arguments.", E_USER_WARNING);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->popupWidth = $width;
|
|
|
|
$this->popupHeight = $height;
|
|
|
|
}
|
2007-12-02 22:27:34 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function PopupWidth() {
|
2008-10-21 23:42:27 +02:00
|
|
|
return $this->popupWidth;
|
|
|
|
}
|
2012-12-08 12:20:20 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function PopupHeight() {
|
2008-10-21 23:42:27 +02:00
|
|
|
return $this->popupHeight;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* See class comments
|
|
|
|
*
|
2011-03-29 06:55:13 +02:00
|
|
|
* @param Controller $controller
|
2007-07-19 12:40:28 +02:00
|
|
|
* @param string $name
|
|
|
|
* @param string $sourceClass
|
|
|
|
* @param array $fieldList
|
2011-05-11 09:51:54 +02:00
|
|
|
* @param FieldList $detailFormFields
|
2007-07-19 12:40:28 +02:00
|
|
|
* @param string $sourceFilter
|
|
|
|
* @param string $sourceSort
|
|
|
|
* @param string $sourceJoin
|
|
|
|
*/
|
2012-09-26 23:34:00 +02:00
|
|
|
public function __construct($controller, $name, $sourceClass, $fieldList = null, $detailFormFields = null,
|
|
|
|
$sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->detailFormFields = $detailFormFields;
|
|
|
|
$this->controller = $controller;
|
|
|
|
$this->pageSize = 10;
|
2007-12-02 22:27:34 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
parent::__construct($name, $sourceClass, $fieldList, $sourceFilter, $sourceSort, $sourceJoin);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function isComposite() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return String
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function FieldHolder($properties = array()) {
|
2011-03-24 09:40:15 +01:00
|
|
|
Requirements::javascript(THIRDPARTY_DIR . "/prototype/prototype.js");
|
2012-02-16 12:27:47 +01:00
|
|
|
Requirements::javascript(THIRDPARTY_DIR . "/behaviour/behaviour.js");
|
2009-04-29 02:07:39 +02:00
|
|
|
Requirements::javascript(THIRDPARTY_DIR . "/greybox/AmiJS.js");
|
|
|
|
Requirements::javascript(THIRDPARTY_DIR . "/greybox/greybox.js");
|
2012-03-24 04:38:57 +01:00
|
|
|
Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/javascript/lang');
|
|
|
|
Requirements::javascript(FRAMEWORK_DIR . '/javascript/TableListField.js');
|
|
|
|
Requirements::javascript(FRAMEWORK_DIR . "/javascript/ComplexTableField.js");
|
2009-04-29 02:07:39 +02:00
|
|
|
Requirements::css(THIRDPARTY_DIR . "/greybox/greybox.css");
|
2012-03-24 04:38:57 +01:00
|
|
|
Requirements::css(FRAMEWORK_DIR . "/css/TableListField.css");
|
|
|
|
Requirements::css(FRAMEWORK_DIR . "/css/ComplexTableField.css");
|
2009-04-29 02:07:39 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// set caption if required
|
|
|
|
if($this->popupCaption) {
|
|
|
|
$id = $this->id();
|
|
|
|
if(Director::is_ajax()) {
|
|
|
|
$js = <<<JS
|
|
|
|
$('$id').GB_Caption = '$this->popupCaption';
|
|
|
|
JS;
|
2012-03-09 23:19:37 +01:00
|
|
|
// FormResponse::add($js);
|
2007-07-19 12:40:28 +02:00
|
|
|
} else {
|
|
|
|
$js = <<<JS
|
|
|
|
Event.observe(window, 'load', function() { \$('$id').GB_Caption = '$this->popupCaption'; });
|
|
|
|
JS;
|
|
|
|
Requirements::customScript($js);
|
|
|
|
}
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// compute sourceItems here instead of Items() to ensure that
|
|
|
|
// pagination and filters are respected on template accessors
|
|
|
|
$this->sourceItems();
|
|
|
|
|
|
|
|
return $this->renderWith($this->template);
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2011-10-26 08:09:04 +02:00
|
|
|
* @return SS_List
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Items() {
|
2009-11-22 07:07:45 +01:00
|
|
|
$sourceItems = $this->sourceItems();
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2009-11-22 07:07:45 +01:00
|
|
|
if(!$sourceItems) {
|
2007-07-19 12:40:28 +02:00
|
|
|
return null;
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2012-09-26 23:34:00 +02:00
|
|
|
|
|
|
|
if(isset($_REQUEST['ctf'][$this->getName()]['start'])) {
|
|
|
|
$pageStart = $_REQUEST['ctf'][$this->getName()]['start'];
|
|
|
|
if(!is_numeric($pageStart)) $pageStart = 0;
|
|
|
|
} else {
|
|
|
|
$pageStart = 0;
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2011-05-05 12:40:24 +02:00
|
|
|
$output = new ArrayList();
|
2009-11-22 07:07:45 +01:00
|
|
|
foreach($sourceItems as $pageIndex=>$item) {
|
|
|
|
$output->push(Object::create($this->itemClass,$item, $this, $pageStart+$pageIndex));
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Sets the popup-title by javascript. Make sure to use FormResponse in ajax-requests,
|
|
|
|
* otherwise the title-change will only take effect on items existing during page-load.
|
2007-09-15 23:36:17 +02:00
|
|
|
*
|
2007-07-19 12:40:28 +02:00
|
|
|
* @param $caption String
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setPopupCaption($caption) {
|
2007-09-15 23:36:17 +02:00
|
|
|
$this->popupCaption = Convert::raw2js($caption);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2008-08-09 05:29:30 +02:00
|
|
|
* @param $validator Validator
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setDetailFormValidator( Validator $validator ) {
|
2008-08-09 05:29:30 +02:00
|
|
|
$this->detailFormValidator = $validator;
|
|
|
|
}
|
2012-12-08 12:20:20 +01:00
|
|
|
|
|
|
|
public function setAddTitle($addTitle) {
|
2009-01-10 12:35:50 +01:00
|
|
|
if(is_string($addTitle))
|
|
|
|
$this->addTitle = $addTitle;
|
|
|
|
}
|
2012-12-08 12:20:20 +01:00
|
|
|
|
|
|
|
public function Title() {
|
2009-01-10 12:35:50 +01:00
|
|
|
return $this->addTitle ? $this->addTitle : parent::Title();
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
/**
|
|
|
|
* Calculates the number of columns needed for colspans
|
|
|
|
* used in template
|
|
|
|
*
|
|
|
|
* @return Int
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function ItemCount() {
|
2008-08-09 05:29:30 +02:00
|
|
|
return count($this->fieldList);
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
/**
|
|
|
|
* Used to toggle paging (makes no sense when adding a record)
|
|
|
|
*
|
|
|
|
* @return Boolean
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function IsAddMode() {
|
2008-08-11 04:25:44 +02:00
|
|
|
return ($this->methodName == "add" || $this->request->param('Action') == 'AddForm');
|
2008-08-09 05:29:30 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function sourceID() {
|
2012-01-02 15:03:35 +01:00
|
|
|
$idField = $this->form->Fields()->dataFieldByName('ID');
|
2008-10-03 18:19:31 +02:00
|
|
|
|
|
|
|
// disabled as it conflicts with scaffolded formfields, and not strictly necessary
|
|
|
|
// if(!$idField) user_error("ComplexTableField needs a formfield named 'ID' to be present", E_USER_ERROR);
|
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
// because action_callfieldmethod never actually loads data into the form,
|
|
|
|
// we can't rely on $idField being populated, and fall back to the request-params.
|
|
|
|
// this is a workaround for a bug where each subsequent popup-call didn't have ID
|
|
|
|
// of the parent set, and so didn't properly save the relation
|
2008-10-03 18:19:31 +02:00
|
|
|
return ($idField) ? $idField->Value() : (isset($_REQUEST['ctf']['ID']) ? $_REQUEST['ctf']['ID'] : null);
|
2012-12-08 12:20:20 +01:00
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function AddLink() {
|
2010-04-12 05:27:03 +02:00
|
|
|
return Controller::join_links($this->Link(), 'add');
|
2008-08-09 05:29:30 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
/**
|
2011-09-27 00:55:49 +02:00
|
|
|
* @return FieldList
|
2008-08-09 05:29:30 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function createFieldList() {
|
2011-05-11 09:51:54 +02:00
|
|
|
$fieldset = new FieldList();
|
2008-08-09 05:29:30 +02:00
|
|
|
foreach($this->fieldTypes as $key => $fieldType){
|
|
|
|
$fieldset->push(new $fieldType($key));
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-08-09 05:29:30 +02:00
|
|
|
return $fieldset;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setController($controller) {
|
2009-11-21 02:43:33 +01:00
|
|
|
$this->controller = $controller;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2009-11-21 02:43:33 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setTemplatePopup($template) {
|
2008-08-09 05:29:30 +02:00
|
|
|
$this->templatePopup = $template;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2008-08-09 05:29:30 +02:00
|
|
|
}
|
2008-08-09 05:54:55 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-08-18 02:50:39 +02:00
|
|
|
/**
|
|
|
|
* Return the object-specific fields for the given record, to be shown in the detail pop-up
|
|
|
|
*
|
|
|
|
* This won't include all the CTF-specific 'plumbing; this method is called by self::getFieldsFor()
|
2011-10-28 03:37:27 +02:00
|
|
|
* and the result is then processed further to get the actual FieldList for the form.
|
2008-08-18 02:50:39 +02:00
|
|
|
*
|
|
|
|
* The default implementation of this processes the value of $this->detailFormFields; consequently, if you want to
|
|
|
|
* set the value of the fields to something that $this->detailFormFields doesn't allow, you can do so by overloading
|
|
|
|
* this method.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getCustomFieldsFor($childData) {
|
2011-09-27 00:55:49 +02:00
|
|
|
if($this->detailFormFields instanceof FieldList) {
|
2008-08-18 02:50:39 +02:00
|
|
|
return $this->detailFormFields;
|
2009-02-10 07:04:36 +01:00
|
|
|
}
|
2009-05-01 05:49:34 +02:00
|
|
|
|
|
|
|
$fieldsMethod = $this->detailFormFields;
|
2009-02-10 07:04:36 +01:00
|
|
|
|
2009-05-01 05:49:34 +02:00
|
|
|
if(!is_string($fieldsMethod)) {
|
|
|
|
$this->detailFormFields = 'getCMSFields';
|
|
|
|
$fieldsMethod = 'getCMSFields';
|
2008-08-18 02:50:39 +02:00
|
|
|
}
|
2009-02-10 07:04:36 +01:00
|
|
|
|
2009-05-01 05:49:34 +02:00
|
|
|
if(!$childData->hasMethod($fieldsMethod)) {
|
|
|
|
$fieldsMethod = 'getCMSFields';
|
2009-02-10 07:04:36 +01:00
|
|
|
}
|
|
|
|
|
2009-05-01 05:49:34 +02:00
|
|
|
return $childData->$fieldsMethod();
|
2008-08-18 02:50:39 +02:00
|
|
|
}
|
2009-05-01 05:49:34 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getFieldsFor($childData) {
|
2008-08-18 02:50:39 +02:00
|
|
|
$detailFields = $this->getCustomFieldsFor($childData);
|
2008-08-09 05:54:55 +02:00
|
|
|
|
|
|
|
// the ID field confuses the Controller-logic in finding the right view for ReferencedField
|
|
|
|
$detailFields->removeByName('ID');
|
2009-02-10 07:04:36 +01:00
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
// only add childID if we're not adding a record
|
|
|
|
if($childData->ID) {
|
2009-02-10 07:04:36 +01:00
|
|
|
$detailFields->push(new HiddenField('ctf[childID]', '', $childData->ID));
|
2008-08-09 05:54:55 +02:00
|
|
|
}
|
2009-05-01 05:49:34 +02:00
|
|
|
|
2012-12-08 12:20:20 +01:00
|
|
|
/* TODO: Figure out how to implement this
|
2008-08-09 05:54:55 +02:00
|
|
|
if($this->getParentClass()) {
|
2009-05-01 05:49:34 +02:00
|
|
|
$detailFields->push(new HiddenField('ctf[parentClass]', '', $this->getParentClass()));
|
2008-08-09 05:54:55 +02:00
|
|
|
|
2009-11-22 07:07:45 +01:00
|
|
|
// Hack for model admin: model admin will have included a dropdown for the relation itself
|
2009-02-10 07:04:36 +01:00
|
|
|
$parentIdName = $this->getParentIdName($this->getParentClass(), $this->sourceClass());
|
2008-08-09 05:54:55 +02:00
|
|
|
if($parentIdName) {
|
2009-11-22 07:07:45 +01:00
|
|
|
$detailFields->removeByName($parentIdName);
|
|
|
|
$detailFields->push(new HiddenField($parentIdName, '', $this->sourceID()));
|
2008-08-09 05:54:55 +02:00
|
|
|
}
|
|
|
|
}
|
2011-03-30 03:28:50 +02:00
|
|
|
*/
|
2008-08-09 05:54:55 +02:00
|
|
|
|
|
|
|
return $detailFields;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getValidatorFor($childData) {
|
2008-08-09 05:54:55 +02:00
|
|
|
// if no custom validator is set, and there's on present on the object (e.g. Member), use it
|
|
|
|
if(!isset($this->detailFormValidator) && $childData->hasMethod('getValidator')) {
|
|
|
|
$this->detailFormValidator = $childData->getValidator();
|
|
|
|
}
|
|
|
|
return $this->detailFormValidator;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function add() {
|
2008-08-09 05:54:55 +02:00
|
|
|
if(!$this->can('add')) return;
|
2012-03-12 17:03:14 +01:00
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
return $this->customise(array(
|
|
|
|
'DetailForm' => $this->AddForm(),
|
|
|
|
))->renderWith($this->templatePopup);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function AddForm($childID = null) {
|
2008-08-09 05:54:55 +02:00
|
|
|
$className = $this->sourceClass();
|
|
|
|
$childData = new $className();
|
|
|
|
|
|
|
|
$fields = $this->getFieldsFor($childData);
|
|
|
|
$validator = $this->getValidatorFor($childData);
|
|
|
|
|
2010-04-14 04:20:13 +02:00
|
|
|
$form = new $this->popupClass(
|
2008-10-08 04:40:10 +02:00
|
|
|
$this,
|
|
|
|
'AddForm',
|
|
|
|
$fields,
|
|
|
|
$validator,
|
|
|
|
false,
|
|
|
|
$childData
|
|
|
|
);
|
2008-08-09 05:54:55 +02:00
|
|
|
|
2010-05-25 04:59:14 +02:00
|
|
|
$form->loadDataFrom($childData);
|
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
return $form;
|
|
|
|
}
|
2008-08-21 00:47:46 +02:00
|
|
|
|
2008-09-23 03:24:03 +02:00
|
|
|
/**
|
2011-10-29 01:02:11 +02:00
|
|
|
* @deprecated 3.0
|
2008-09-23 03:24:03 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setRelationAutoSetting($value) {
|
2011-10-29 01:02:11 +02:00
|
|
|
Deprecation::notice('3.0', 'Manipulate the DataList instead.');
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2008-08-21 00:47:46 +02:00
|
|
|
}
|
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
/**
|
|
|
|
* Use the URL-Parameter "action_saveComplexTableField"
|
|
|
|
* to provide a clue to the main controller if the main form has to be rendered,
|
|
|
|
* even if there is no action relevant for the main controller (to provide the instance of ComplexTableField
|
|
|
|
* which in turn saves the record.
|
|
|
|
*
|
2009-05-01 05:49:34 +02:00
|
|
|
* This is for adding new item records. {@link ComplexTableField_ItemRequest::saveComplexTableField()}
|
|
|
|
*
|
2008-10-02 02:34:16 +02:00
|
|
|
* @see Form::ReferencedField
|
2008-08-09 05:54:55 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function saveComplexTableField($data, $form, $params) {
|
2008-08-09 05:54:55 +02:00
|
|
|
$className = $this->sourceClass();
|
|
|
|
$childData = new $className();
|
2008-08-09 06:38:44 +02:00
|
|
|
$form->saveInto($childData);
|
2009-06-02 08:12:10 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
$childData->write();
|
|
|
|
} catch(ValidationException $e) {
|
|
|
|
$form->sessionMessage($e->getResult()->message(), 'bad');
|
2012-03-12 17:03:14 +01:00
|
|
|
return Controller::curr()->redirectBack();
|
2009-06-02 08:12:10 +02:00
|
|
|
}
|
2009-05-01 05:49:34 +02:00
|
|
|
|
2009-11-22 07:07:45 +01:00
|
|
|
// Save this item into the given relationship
|
|
|
|
$this->getDataList()->add($childData);
|
2009-05-01 05:49:34 +02:00
|
|
|
|
2009-05-01 00:48:21 +02:00
|
|
|
$referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
|
|
|
|
2008-08-11 04:25:44 +02:00
|
|
|
$closeLink = sprintf(
|
2009-07-16 05:44:15 +02:00
|
|
|
'<small><a href="%s" onclick="javascript:window.top.GB_hide(); return false;">(%s)</a></small>',
|
|
|
|
$referrer,
|
2008-08-11 04:25:44 +02:00
|
|
|
_t('ComplexTableField.CLOSEPOPUP', 'Close Popup')
|
|
|
|
);
|
2009-02-10 07:04:36 +01:00
|
|
|
|
2010-04-12 05:27:03 +02:00
|
|
|
$editLink = Controller::join_links($this->Link(), 'item/' . $childData->ID . '/edit');
|
|
|
|
|
2012-05-01 21:44:54 +02:00
|
|
|
$message = _t(
|
|
|
|
'ComplexTableField.SUCCESSADD2', 'Added {name}',
|
|
|
|
array('name' => $childData->singular_name())
|
2008-08-11 04:25:44 +02:00
|
|
|
);
|
2012-05-01 21:44:54 +02:00
|
|
|
$message .= '<a href="' . $editLink . '">' . $childData->Title . '</a>' . $closeLink;
|
2009-02-10 07:04:36 +01:00
|
|
|
|
2008-08-11 04:25:44 +02:00
|
|
|
$form->sessionMessage($message, 'good');
|
2011-10-29 06:06:19 +02:00
|
|
|
|
2012-03-12 17:03:14 +01:00
|
|
|
return Controller::curr()->redirectBack();
|
2008-08-09 05:54:55 +02:00
|
|
|
}
|
2008-08-09 05:29:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo Tie this into ComplexTableField_Item better.
|
2010-04-23 02:11:41 +02:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-relational
|
2008-08-09 05:29:30 +02:00
|
|
|
*/
|
2010-05-25 07:00:25 +02:00
|
|
|
class ComplexTableField_ItemRequest extends TableListField_ItemRequest {
|
2008-08-09 05:29:30 +02:00
|
|
|
protected $ctf;
|
|
|
|
protected $itemID;
|
|
|
|
protected $methodName;
|
|
|
|
|
|
|
|
static $url_handlers = array(
|
|
|
|
'$Action!' => '$Action',
|
|
|
|
'' => 'index',
|
|
|
|
);
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Link($action = null) {
|
2009-10-11 02:07:16 +02:00
|
|
|
return Controller::join_links($this->ctf->Link(), '/item/', $this->itemID, $action);
|
2008-08-09 05:29:30 +02:00
|
|
|
}
|
2008-11-04 14:52:03 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function index() {
|
2008-08-09 05:29:30 +02:00
|
|
|
return $this->show();
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Just a hook, processed in {DetailForm()}
|
2007-09-15 23:36:17 +02:00
|
|
|
*
|
2007-07-19 12:40:28 +02:00
|
|
|
* @return String
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function show() {
|
2008-08-09 05:29:30 +02:00
|
|
|
if($this->ctf->Can('show') !== true) {
|
2007-07-19 12:40:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
$this->methodName = "show";
|
2009-12-13 06:22:33 +01:00
|
|
|
return $this->renderWith($this->ctf->templatePopup);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-08-09 06:38:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a 1-element data object set that can be used for pagination.
|
|
|
|
*/
|
|
|
|
/* this doesn't actually work :-(
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Paginator() {
|
2011-05-05 12:40:24 +02:00
|
|
|
$paginatingSet = new ArrayList(array($this->dataObj()));
|
2008-08-09 06:38:44 +02:00
|
|
|
$start = isset($_REQUEST['ctf']['start']) ? $_REQUEST['ctf']['start'] : 0;
|
|
|
|
$paginatingSet->setPageLimits($start, 1, $this->ctf->TotalCount());
|
|
|
|
return $paginatingSet;
|
|
|
|
}
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Just a hook, processed in {DetailForm()}
|
2007-09-15 23:36:17 +02:00
|
|
|
*
|
2007-07-19 12:40:28 +02:00
|
|
|
* @return String
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function edit() {
|
2008-08-09 05:29:30 +02:00
|
|
|
if($this->ctf->Can('edit') !== true) {
|
2007-07-19 12:40:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->methodName = "edit";
|
2008-08-14 09:12:25 +02:00
|
|
|
|
2009-12-13 06:22:33 +01:00
|
|
|
return $this->renderWith($this->ctf->templatePopup);
|
2008-08-09 06:38:44 +02:00
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function delete($request) {
|
2010-12-05 09:26:03 +01:00
|
|
|
// Protect against CSRF on destructive action
|
|
|
|
$token = $this->ctf->getForm()->getSecurityToken();
|
|
|
|
if(!$token->checkRequest($request)) return $this->httpError(400);
|
|
|
|
|
2008-08-09 06:38:44 +02:00
|
|
|
if($this->ctf->Can('delete') !== true) {
|
|
|
|
return false;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-03-30 03:28:50 +02:00
|
|
|
|
|
|
|
$this->ctf->getDataList()->removeByID($this->itemID);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2008-08-09 05:29:30 +02:00
|
|
|
* Return the data object being manipulated
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function dataObj() {
|
2008-08-09 05:29:30 +02:00
|
|
|
// used to discover fields if requested and for population of field
|
|
|
|
if(is_numeric($this->itemID)) {
|
2012-12-08 12:20:20 +01:00
|
|
|
// we have to use the basedataclass, otherwise we might exclude other subclasses
|
|
|
|
return DataObject::get_by_id(
|
|
|
|
ClassInfo::baseDataClass(Object::getCustomClass($this->ctf->sourceClass())), $tis->itemID);
|
2008-08-09 05:29:30 +02:00
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2008-08-09 05:29:30 +02:00
|
|
|
* Renders view, edit and add, depending on the given information.
|
2012-09-26 23:34:00 +02:00
|
|
|
* The form needs several parameters to function independently of its "parent-form", some derived from the context
|
|
|
|
* into a hidden-field, some derived from the parent context (which is not accessible here) and delivered by
|
|
|
|
* GET:ID, Identifier of the currently edited record (only if record is loaded).
|
2008-08-09 05:29:30 +02:00
|
|
|
* <parentIDName>, Link back to the correct parent record (e.g. "parentID").
|
|
|
|
* parentClass, Link back to correct container-class (the parent-record might have many 'has-one'-relationships)
|
|
|
|
* CAUTION: "ID" in the DetailForm would be the "childID" in the overview table.
|
|
|
|
*
|
|
|
|
* @param int $childID
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function DetailForm($childID = null) {
|
2008-08-09 06:38:44 +02:00
|
|
|
$childData = $this->dataObj();
|
2008-10-03 18:19:31 +02:00
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
$fields = $this->ctf->getFieldsFor($childData);
|
|
|
|
$validator = $this->ctf->getValidatorFor($childData);
|
2008-08-09 05:29:30 +02:00
|
|
|
$readonly = ($this->methodName == "show");
|
|
|
|
|
2010-04-14 04:20:13 +02:00
|
|
|
$form = new $this->ctf->popupClass(
|
|
|
|
$this,
|
|
|
|
"DetailForm",
|
|
|
|
$fields,
|
|
|
|
$validator,
|
|
|
|
$readonly,
|
|
|
|
$childData
|
|
|
|
);
|
2011-10-29 07:07:22 +02:00
|
|
|
// Don't use ComplexTableField_Popup.ss
|
|
|
|
$form->setTemplate('Form');
|
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
$form->loadDataFrom($childData);
|
|
|
|
if ($readonly) $form->makeReadonly();
|
2008-08-09 05:29:30 +02:00
|
|
|
|
|
|
|
return $form;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-08-09 05:54:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use the URL-Parameter "action_saveComplexTableField"
|
|
|
|
* to provide a clue to the main controller if the main form has to be rendered,
|
|
|
|
* even if there is no action relevant for the main controller (to provide the instance of ComplexTableField
|
|
|
|
* which in turn saves the record.
|
|
|
|
*
|
2009-05-01 05:49:34 +02:00
|
|
|
* This is for editing existing item records. {@link ComplexTableField::saveComplexTableField()}
|
|
|
|
*
|
2008-10-02 02:34:16 +02:00
|
|
|
* @see Form::ReferencedField
|
2008-08-09 05:54:55 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function saveComplexTableField($data, $form, $request) {
|
2009-02-02 00:49:53 +01:00
|
|
|
$dataObject = $this->dataObj();
|
2009-12-13 06:22:32 +01:00
|
|
|
|
2009-06-02 08:12:10 +02:00
|
|
|
try {
|
2009-12-13 06:22:32 +01:00
|
|
|
$form->saveInto($dataObject);
|
2009-06-02 08:12:10 +02:00
|
|
|
$dataObject->write();
|
|
|
|
} catch(ValidationException $e) {
|
|
|
|
$form->sessionMessage($e->getResult()->message(), 'bad');
|
2012-03-12 17:03:14 +01:00
|
|
|
return Controller::curr()->redirectBack();
|
2009-06-02 08:12:10 +02:00
|
|
|
}
|
2009-11-22 07:07:45 +01:00
|
|
|
|
|
|
|
// Save this item into the given relationship
|
2011-03-30 03:28:50 +02:00
|
|
|
$this->ctf->getDataList()->add($dataObject);
|
2009-02-11 01:10:37 +01:00
|
|
|
|
2009-05-01 00:48:21 +02:00
|
|
|
$referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
|
|
|
|
2008-08-11 04:25:44 +02:00
|
|
|
$closeLink = sprintf(
|
2009-12-16 06:48:06 +01:00
|
|
|
'<small><a href="%s" onclick="javascript:window.top.GB_hide(); return false;">(%s)</a></small>',
|
|
|
|
$referrer,
|
2008-08-11 04:25:44 +02:00
|
|
|
_t('ComplexTableField.CLOSEPOPUP', 'Close Popup')
|
|
|
|
);
|
|
|
|
$message = sprintf(
|
|
|
|
_t('ComplexTableField.SUCCESSEDIT', 'Saved %s %s %s'),
|
2009-02-02 00:49:53 +01:00
|
|
|
$dataObject->singular_name(),
|
2011-04-05 22:43:22 +02:00
|
|
|
'<a href="' . $this->Link('edit') . '">"' . htmlspecialchars($dataObject->Title, ENT_QUOTES) . '"</a>',
|
2008-08-11 04:25:44 +02:00
|
|
|
$closeLink
|
|
|
|
);
|
2009-05-01 05:49:34 +02:00
|
|
|
|
2008-08-11 04:25:44 +02:00
|
|
|
$form->sessionMessage($message, 'good');
|
|
|
|
|
2012-03-12 17:03:14 +01:00
|
|
|
return Controller::curr()->redirectBack();
|
2008-08-09 05:54:55 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function PopupCurrentItem() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return $_REQUEST['ctf']['start']+1;
|
|
|
|
}
|
2008-08-09 06:38:44 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function PopupFirstLink() {
|
2008-08-09 06:38:44 +02:00
|
|
|
$this->ctf->LinkToItem();
|
|
|
|
|
2012-09-26 23:34:00 +02:00
|
|
|
if(!isset($_REQUEST['ctf']['start']) || !is_numeric($_REQUEST['ctf']['start'])
|
|
|
|
|| $_REQUEST['ctf']['start'] == 0) {
|
2007-07-19 12:40:28 +02:00
|
|
|
return null;
|
|
|
|
}
|
2009-03-04 04:44:11 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$start = 0;
|
2008-08-09 06:38:44 +02:00
|
|
|
return Controller::join_links($this->Link(), "$this->methodName?ctf[start]={$start}");
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function PopupLastLink() {
|
2012-09-26 23:34:00 +02:00
|
|
|
if(!isset($_REQUEST['ctf']['start']) || !is_numeric($_REQUEST['ctf']['start'])
|
|
|
|
|| $_REQUEST['ctf']['start'] == $this->TotalCount()-1) {
|
2007-07-19 12:40:28 +02:00
|
|
|
return null;
|
|
|
|
}
|
2009-02-02 00:49:53 +01:00
|
|
|
|
2011-03-30 03:28:50 +02:00
|
|
|
$start = $this->TotalCount - 1;
|
2008-08-09 06:38:44 +02:00
|
|
|
return Controller::join_links($this->Link(), "$this->methodName?ctf[start]={$start}");
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function PopupNextLink() {
|
2012-09-26 23:34:00 +02:00
|
|
|
if(!isset($_REQUEST['ctf']['start']) || !is_numeric($_REQUEST['ctf']['start'])
|
|
|
|
|| $_REQUEST['ctf']['start'] == $this->TotalCount()-1) {
|
2007-07-19 12:40:28 +02:00
|
|
|
return null;
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$start = $_REQUEST['ctf']['start'] + 1;
|
2008-08-09 06:38:44 +02:00
|
|
|
return Controller::join_links($this->Link(), "$this->methodName?ctf[start]={$start}");
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function PopupPrevLink() {
|
2012-09-26 23:34:00 +02:00
|
|
|
if(!isset($_REQUEST['ctf']['start']) || !is_numeric($_REQUEST['ctf']['start'])
|
|
|
|
|| $_REQUEST['ctf']['start'] == 0) {
|
2007-07-19 12:40:28 +02:00
|
|
|
return null;
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$start = $_REQUEST['ctf']['start'] - 1;
|
2008-08-09 06:38:44 +02:00
|
|
|
return Controller::join_links($this->Link(), "$this->methodName?ctf[start]={$start}");
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 05:12:21 +02:00
|
|
|
|
|
|
|
/**
|
2012-12-08 12:20:20 +01:00
|
|
|
* Method handles pagination in asset popup.
|
|
|
|
*
|
|
|
|
* @return Object SS_List
|
|
|
|
*/
|
2007-09-14 05:12:21 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Pagination() {
|
2007-11-02 03:53:53 +01:00
|
|
|
$this->pageSize = 9;
|
2007-09-14 05:12:21 +02:00
|
|
|
$currentItem = $this->PopupCurrentItem();
|
2011-05-05 12:40:24 +02:00
|
|
|
$result = new ArrayList();
|
2012-12-08 12:20:20 +01:00
|
|
|
if($currentItem < 6) {
|
|
|
|
$offset = 1;
|
|
|
|
} elseif($this->TotalCount() - $currentItem <= 4) {
|
|
|
|
$offset = $currentItem - (10 - ($this->TotalCount() - $currentItem));
|
|
|
|
$offset = $offset <= 0 ? 1 : $offset;
|
|
|
|
} else {
|
|
|
|
$offset = $currentItem - 5;
|
|
|
|
}
|
2011-03-30 03:28:50 +02:00
|
|
|
for($i = $offset;$i <= $offset + $this->pageSize && $i <= $this->TotalCount();$i++) {
|
2012-12-08 12:20:20 +01:00
|
|
|
$start = $i - 1;
|
2008-08-09 06:38:44 +02:00
|
|
|
$links['link'] = Controller::join_links($this->Link() . "$this->methodName?ctf[start]={$start}");
|
2012-12-08 12:20:20 +01:00
|
|
|
$links['number'] = $i;
|
|
|
|
$links['active'] = $i == $currentItem ? false : true;
|
|
|
|
$result->push(new ArrayData($links));
|
2007-09-14 05:12:21 +02:00
|
|
|
}
|
2012-12-08 12:20:20 +01:00
|
|
|
return $result;
|
2007-09-14 05:12:21 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function ShowPagination() {
|
2008-08-09 06:38:44 +02:00
|
|
|
return false;
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* #################################
|
2008-01-03 09:43:26 +01:00
|
|
|
* Utility
|
2007-07-19 12:40:28 +02:00
|
|
|
* #################################
|
|
|
|
*/
|
|
|
|
|
2007-12-04 05:54:26 +01:00
|
|
|
/**
|
|
|
|
* Manually overwrites the parent-ID relations.
|
|
|
|
* @see setParentClass()
|
|
|
|
*
|
|
|
|
* @param String $str Example: FamilyID (when one Individual has_one Family)
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setParentIdName($str) {
|
2012-12-08 12:20:20 +01:00
|
|
|
throw new Exception("setParentIdName is no longer necessary");
|
2007-12-04 05:54:26 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setTemplatePopup($template) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->templatePopup = $template;
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2008-01-10 01:34:18 +01:00
|
|
|
/**
|
|
|
|
* Single row of a {@link ComplexTableField}.
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-relational
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class ComplexTableField_Item extends TableListField_Item {
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Link($action = null) {
|
2009-10-11 02:07:16 +02:00
|
|
|
return Controller::join_links($this->parent->Link(), '/item/', $this->item->ID, $action);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function EditLink() {
|
2010-04-12 05:27:03 +02:00
|
|
|
return Controller::join_links($this->Link(), "edit");
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function ShowLink() {
|
2010-04-12 05:27:03 +02:00
|
|
|
return Controller::join_links($this->Link(), "show");
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function DeleteLink() {
|
2010-04-12 05:27:03 +02:00
|
|
|
return Controller::join_links($this->Link(), "delete");
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-08-12 01:24:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param String $action
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function IsDefaultAction($action) {
|
2008-08-12 01:24:54 +02:00
|
|
|
return ($action == $this->parent->defaultAction);
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ComplexTablefield_popup is rendered with a lightbox and can load a more
|
2007-09-15 23:36:17 +02:00
|
|
|
* detailed view of the source class your presenting.
|
2007-07-19 12:40:28 +02:00
|
|
|
* You can customise the fields and requirements as well as any
|
|
|
|
* permissions you might need.
|
2008-01-10 01:34:18 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-relational
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class ComplexTableField_Popup extends Form {
|
|
|
|
protected $sourceClass;
|
2009-04-29 02:07:39 +02:00
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
protected $dataObject;
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __construct($controller, $name, $fields, $validator, $readonly, $dataObject) {
|
2008-08-09 05:29:30 +02:00
|
|
|
$this->dataObject = $dataObject;
|
2009-04-29 02:07:39 +02:00
|
|
|
|
|
|
|
|
2011-05-11 09:51:54 +02:00
|
|
|
$actions = new FieldList();
|
2009-04-29 02:07:39 +02:00
|
|
|
if(!$readonly) {
|
|
|
|
$actions->push(
|
2012-04-04 16:59:30 +02:00
|
|
|
FormAction::create(
|
2009-04-29 02:07:39 +02:00
|
|
|
"saveComplexTableField",
|
2010-10-19 03:27:35 +02:00
|
|
|
_t('CMSMain.SAVE', 'Save')
|
2009-04-29 02:07:39 +02:00
|
|
|
)
|
2012-03-12 17:03:14 +01:00
|
|
|
->addExtraClass('save ss-ui-action-constructive')
|
|
|
|
->setUseButtonTag(true)
|
|
|
|
->setAttribute('data-icon', 'accept')
|
|
|
|
);
|
2009-04-29 02:07:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct($controller, $name, $fields, $actions, $validator);
|
2010-10-19 05:00:45 +02:00
|
|
|
|
|
|
|
if(!$this->dataObject->canEdit()) $this->makeReadonly();
|
2009-04-29 02:07:39 +02:00
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function forTemplate() {
|
2009-04-29 02:07:39 +02:00
|
|
|
$ret = parent::forTemplate();
|
|
|
|
|
2012-03-24 04:38:57 +01:00
|
|
|
Requirements::css(FRAMEWORK_DIR . '/css/ComplexTableField_popup.css');
|
|
|
|
Requirements::javascript(FRAMEWORK_DIR . "/thirdparty/prototype/prototype.js");
|
|
|
|
Requirements::javascript(FRAMEWORK_DIR . "/thirdparty/behaviour/behaviour.js");
|
|
|
|
Requirements::javascript(FRAMEWORK_DIR . "/thirdparty/scriptaculous/scriptaculous.js");
|
|
|
|
Requirements::javascript(FRAMEWORK_DIR . "/thirdparty/scriptaculous/scriptaculous/controls.js");
|
|
|
|
Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/javascript/lang');
|
|
|
|
Requirements::javascript(FRAMEWORK_DIR . "/javascript/ComplexTableField_popup.js");
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2010-05-25 07:00:25 +02:00
|
|
|
// Append requirements from instance callbacks
|
2010-05-25 07:01:46 +02:00
|
|
|
$parent = $this->getParentController();
|
|
|
|
if($parent instanceof ComplexTableField) {
|
|
|
|
$callback = $parent->requirementsForPopupCallback;
|
|
|
|
} else {
|
|
|
|
$callback = $parent->getParentController()->requirementsForPopupCallback;
|
|
|
|
}
|
2010-05-25 07:00:25 +02:00
|
|
|
if($callback) call_user_func($callback, $this);
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2009-04-29 02:07:39 +02:00
|
|
|
return $ret;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2012-03-12 17:03:14 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getTemplate() {
|
2012-03-12 17:03:14 +01:00
|
|
|
return 'Form';
|
|
|
|
}
|
2010-05-25 07:00:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ComplexTableField_ItemRequest
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getParentController() {
|
2010-05-25 07:00:25 +02:00
|
|
|
return $this->controller;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-08-09 05:54:55 +02:00
|
|
|
|
2012-02-12 21:22:11 +01:00
|
|
|
|