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"
|
2008-01-09 05:18:36 +01: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)
|
2007-09-15 23:36:17 +02:00
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @todo Find a less fragile solution for accessing this field through the main controller and ReferencedField, e.g.
|
2007-07-19 12:40:28 +02:00
|
|
|
* build a seperate CTF-instance (doesn't necessarly have to be connected to the original by ReferencedField)
|
2008-01-09 05:18:36 +01:00
|
|
|
* @todo Control width/height of popup by constructor (hardcoded at the moment)
|
|
|
|
* @todo Integrate search from MemberTableField.php
|
|
|
|
* @todo Less performance-hungry implementation of detail-view paging (don't return all items on a single view)
|
|
|
|
* @todo Use automatic has-many and many-many functions to return a ComponentSet rather than building the join manually
|
|
|
|
* @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
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
protected $detailFormFields, $viewAction, $sourceJoin, $sourceItems, $unpagedSourceItems;
|
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;
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* @var $detailFormValidator Validator
|
|
|
|
*/
|
|
|
|
protected $detailFormValidator = null;
|
|
|
|
|
2008-01-03 09:43:26 +01:00
|
|
|
/**
|
|
|
|
* Automatically detect a has-one relationship
|
|
|
|
* in the popup (=child-class) and save the relation ID.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2007-12-02 22:27:34 +01:00
|
|
|
protected $relationAutoSetting = true;
|
2008-08-12 01:24:54 +02:00
|
|
|
|
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',
|
|
|
|
'icon' => 'cms/images/show.png',
|
|
|
|
'class' => 'popuplink showlink',
|
|
|
|
),
|
|
|
|
'edit' => array(
|
|
|
|
'label' => 'Edit',
|
|
|
|
'icon' => 'cms/images/edit.gif',
|
|
|
|
'class' => 'popuplink editlink',
|
|
|
|
),
|
|
|
|
'delete' => array(
|
|
|
|
'label' => 'Delete',
|
|
|
|
'icon' => 'cms/images/delete.gif',
|
|
|
|
'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
|
|
|
);
|
|
|
|
|
|
|
|
function handleItem($request) {
|
|
|
|
return new ComplexTableField_ItemRequest($this, $request->param('ID'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function getViewer() {
|
2008-08-11 04:57:59 +02:00
|
|
|
return new SSViewer($this->template);
|
2008-08-09 05:29:30 +02:00
|
|
|
}
|
|
|
|
|
2007-12-02 22:27:34 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* See class comments
|
|
|
|
*
|
|
|
|
* @param ContentController $controller
|
|
|
|
* @param string $name
|
|
|
|
* @param string $sourceClass
|
|
|
|
* @param array $fieldList
|
|
|
|
* @param FieldSet $detailFormFields
|
|
|
|
* @param string $sourceFilter
|
|
|
|
* @param string $sourceSort
|
|
|
|
* @param string $sourceJoin
|
|
|
|
*/
|
2008-08-11 00:49:59 +02:00
|
|
|
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-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
Requirements::javascript("jsparty/greybox/AmiJS.js");
|
|
|
|
Requirements::javascript("jsparty/greybox/greybox.js");
|
|
|
|
Requirements::javascript('sapphire/javascript/TableListField.js');
|
|
|
|
Requirements::javascript("sapphire/javascript/ComplexTableField.js");
|
|
|
|
Requirements::css("jsparty/greybox/greybox.css");
|
|
|
|
Requirements::css("sapphire/css/ComplexTableField.css");
|
2007-12-02 22:27:34 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
parent::__construct($name, $sourceClass, $fieldList, $sourceFilter, $sourceSort, $sourceJoin);
|
2007-12-02 22:27:34 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function isComposite() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
function FieldHolder() {
|
|
|
|
// set caption if required
|
|
|
|
if($this->popupCaption) {
|
|
|
|
$id = $this->id();
|
|
|
|
if(Director::is_ajax()) {
|
|
|
|
$js = <<<JS
|
|
|
|
$('$id').GB_Caption = '$this->popupCaption';
|
|
|
|
JS;
|
|
|
|
FormResponse::add($js);
|
|
|
|
} 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
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
function sourceClass() {
|
|
|
|
return $this->sourceClass;
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* @return DataObjectSet
|
|
|
|
*/
|
|
|
|
function Items() {
|
|
|
|
$this->sourceItems = $this->sourceItems();
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if(!$this->sourceItems) {
|
|
|
|
return null;
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$pageStart = (isset($_REQUEST['ctf'][$this->Name()]['start']) && is_numeric($_REQUEST['ctf'][$this->Name()]['start'])) ? $_REQUEST['ctf'][$this->Name()]['start'] : 0;
|
|
|
|
$this->sourceItems->setPageLimits($pageStart, $this->pageSize, $this->totalCount);
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$output = new DataObjectSet();
|
|
|
|
foreach($this->sourceItems as $pageIndex=>$item) {
|
2007-09-04 04:27:55 +02:00
|
|
|
$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
|
|
|
|
*/
|
|
|
|
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
|
|
|
*/
|
2008-08-09 05:29:30 +02:00
|
|
|
function setDetailFormValidator( Validator $validator ) {
|
|
|
|
$this->detailFormValidator = $validator;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the content of this formfield without surrounding layout. Triggered by Javascript
|
|
|
|
* to update content after a DetailForm-save-action.
|
|
|
|
*
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
function ajax_render() {
|
|
|
|
return $this->renderWith($this->template);
|
|
|
|
}
|
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
|
|
|
|
*/
|
|
|
|
function ItemCount() {
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
function sourceID() {
|
|
|
|
$idField = $this->form->dataFieldByName('ID');
|
|
|
|
if(!$idField) {
|
|
|
|
user_error("ComplexTableField needs a formfield named 'ID' to be present", E_USER_ERROR);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
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
|
|
|
|
return ($idField->Value()) ? $idField->Value() : (isset($_REQUEST['ctf']['ID']) ? $_REQUEST['ctf']['ID'] : null);
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
function AddLink() {
|
|
|
|
return $this->Link() . '/add';
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
/**
|
|
|
|
* @return FieldSet
|
|
|
|
*/
|
|
|
|
function createFieldSet() {
|
|
|
|
$fieldset = new FieldSet();
|
|
|
|
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
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
/**
|
|
|
|
* Determines on which relation-class the DetailForm is saved
|
|
|
|
* by looking at the surrounding form-record.
|
|
|
|
*
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
function getParentClass() {
|
|
|
|
if($this->parentClass === false) {
|
|
|
|
// purposely set parent-relation to false
|
|
|
|
return false;
|
|
|
|
} elseif(!empty($this->parentClass)) {
|
|
|
|
return $this->parentClass;
|
|
|
|
} else {
|
|
|
|
return $this->form->getRecord()->ClassName;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-08-09 05:29:30 +02:00
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
/**
|
|
|
|
* (Optional) Setter for a correct parent-relation-class.
|
|
|
|
* Defaults to the record loaded into the surrounding form as a fallback.
|
|
|
|
* Caution: Please use the classname, not the actual column-name in the database.
|
|
|
|
*
|
|
|
|
* @param $className string
|
|
|
|
*/
|
|
|
|
function setParentClass($className) {
|
|
|
|
$this->parentClass = $className;
|
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
|
|
|
* Returns the db-fieldname of the currently used has_one-relationship.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-08-09 05:29:30 +02:00
|
|
|
function getParentIdName( $parentClass, $childClass ) {
|
|
|
|
return $this->getParentIdNameRelation( $childClass, $parentClass, 'has_one' );
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-08-09 05:29:30 +02:00
|
|
|
* Manually overwrites the parent-ID relations.
|
|
|
|
* @see setParentClass()
|
|
|
|
*
|
|
|
|
* @param String $str Example: FamilyID (when one Individual has_one Family)
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-08-09 05:29:30 +02:00
|
|
|
function setParentIdName($str) {
|
|
|
|
$this->parentIdName = $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the db-fieldname of the currently used relationship.
|
|
|
|
*/
|
|
|
|
function getParentIdNameRelation( $parentClass, $childClass, $relation ){
|
|
|
|
if($this->parentIdName) return $this->parentIdName;
|
|
|
|
|
|
|
|
$relations = singleton( $parentClass )->$relation();
|
|
|
|
$classes = ClassInfo::ancestry( $childClass );
|
|
|
|
foreach( $relations as $k => $v ) {
|
|
|
|
if( $v == $childClass )
|
|
|
|
return $k . 'ID';
|
|
|
|
else if( array_key_exists( $v, $classes ) )
|
|
|
|
return $classes[ $v ] . 'ID';
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setTemplatePopup($template) {
|
|
|
|
$this->templatePopup = $template;
|
|
|
|
}
|
2008-08-09 05:54:55 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function getFieldsFor($childData) {
|
|
|
|
// Add the relation value to related records
|
|
|
|
if(!$childData->ID && $this->getParentClass()) {
|
|
|
|
// make sure the relation-link is existing, even if we just add the sourceClass and didn't save it
|
|
|
|
$parentIDName = $this->getParentIdName( $this->getParentClass(), $this->sourceClass() );
|
|
|
|
$childData->$parentIDName = $childData->ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the fieldset is passed, use it
|
|
|
|
if(is_a($this->detailFormFields,"Fieldset")) {
|
|
|
|
$detailFields = $this->detailFormFields;
|
|
|
|
|
|
|
|
// Else use the formfields returned from the object via a string method call.
|
|
|
|
} else {
|
|
|
|
if(!is_string($this->detailFormFields)) $this->detailFormFields = "getCMSFields";
|
|
|
|
$functioncall = $this->detailFormFields;
|
|
|
|
if(!$childData->hasMethod($functioncall)) $functioncall = "getCMSFields";
|
|
|
|
|
|
|
|
$detailFields = $childData->$functioncall();
|
|
|
|
}
|
|
|
|
|
|
|
|
// the ID field confuses the Controller-logic in finding the right view for ReferencedField
|
|
|
|
$detailFields->removeByName('ID');
|
|
|
|
|
|
|
|
// only add childID if we're not adding a record
|
|
|
|
if($childData->ID) {
|
|
|
|
$detailFields->push(new HiddenField("ctf[childID]","",$childData->ID));
|
|
|
|
}
|
|
|
|
|
|
|
|
// add a namespaced ID instead thats "converted" by saveComplexTableField()
|
|
|
|
$detailFields->push(new HiddenField("ctf[ClassName]","",$this->sourceClass()));
|
|
|
|
|
|
|
|
if($this->getParentClass()) {
|
|
|
|
$parentIdName = $this->getParentIdName($this->getParentClass(), $this->sourceClass());
|
|
|
|
/*
|
|
|
|
if(!$parentIdName) {
|
|
|
|
user_error("ComplexTableField::DetailForm() Cannot automatically
|
|
|
|
determine 'has-one'-relationship to parent class " . $this->ctf->getParentClass() . ",
|
|
|
|
please use setParentClass() to set it manually",
|
|
|
|
E_USER_WARNING);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
if($parentIdName) {
|
|
|
|
// add relational fields
|
|
|
|
$detailFields->push(new HiddenField("ctf[parentClass]"," ",$this->getParentClass()));
|
|
|
|
|
2008-08-09 06:38:44 +02:00
|
|
|
if( $this->relationAutoSetting ) {
|
|
|
|
// Hack for model admin: model admin will have included a dropdown for the relation itself
|
|
|
|
$detailFields->removeByName($parentIdName);
|
|
|
|
$detailFields->push(new HiddenField("$parentIdName"," ",$this->sourceID()));
|
|
|
|
}
|
2008-08-09 05:54:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $detailFields;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getValidatorFor($childData) {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function add() {
|
|
|
|
if(!$this->can('add')) return;
|
|
|
|
|
|
|
|
return $this->customise(array(
|
|
|
|
'DetailForm' => $this->AddForm(),
|
|
|
|
))->renderWith($this->templatePopup);
|
|
|
|
}
|
|
|
|
|
|
|
|
function AddForm($childID = null) {
|
|
|
|
$className = $this->sourceClass();
|
|
|
|
$childData = new $className();
|
|
|
|
|
|
|
|
$fields = $this->getFieldsFor($childData);
|
|
|
|
$validator = $this->getValidatorFor($childData);
|
|
|
|
|
|
|
|
$form = Object::create(
|
|
|
|
$this->popupClass,
|
|
|
|
$this, "AddForm",
|
|
|
|
$fields, $validator, false, $childData);
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @see {Form::ReferencedField}).
|
|
|
|
*/
|
2008-08-09 06:38:44 +02:00
|
|
|
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);
|
2008-08-09 05:54:55 +02:00
|
|
|
$childData->write();
|
2008-08-11 04:25:44 +02:00
|
|
|
|
|
|
|
$closeLink = sprintf(
|
|
|
|
'<small><a href="' . $_SERVER['HTTP_REFERER'] . '" onclick="javascript:window.top.GB_hide(); return false;">(%s)</a></small>',
|
|
|
|
_t('ComplexTableField.CLOSEPOPUP', 'Close Popup')
|
|
|
|
);
|
|
|
|
$message = sprintf(
|
|
|
|
_t('ComplexTableField.SUCCESSADD', 'Added %s %s %s'),
|
|
|
|
$childData->singular_name(),
|
|
|
|
'<a href="' . $this->Link() . '">' . $childData->Title . '</a>',
|
|
|
|
$closeLink
|
|
|
|
);
|
|
|
|
$form->sessionMessage($message, 'good');
|
|
|
|
|
|
|
|
Director::redirectBack();
|
2008-08-09 05:54:55 +02:00
|
|
|
}
|
2008-08-09 05:29:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo Tie this into ComplexTableField_Item better.
|
|
|
|
*/
|
|
|
|
class ComplexTableField_ItemRequest extends RequestHandlingData {
|
|
|
|
protected $ctf;
|
|
|
|
protected $itemID;
|
|
|
|
protected $methodName;
|
|
|
|
|
|
|
|
static $url_handlers = array(
|
|
|
|
'$Action!' => '$Action',
|
|
|
|
'' => 'index',
|
|
|
|
);
|
|
|
|
|
|
|
|
function Link() {
|
|
|
|
return $this->ctf->Link() . '/item/' . $this->itemID;
|
|
|
|
}
|
|
|
|
|
|
|
|
function __construct($ctf, $itemID) {
|
|
|
|
$this->ctf = $ctf;
|
|
|
|
$this->itemID = $itemID;
|
|
|
|
}
|
|
|
|
|
|
|
|
function index() {
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
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";
|
|
|
|
echo $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 :-(
|
|
|
|
function Paginator() {
|
|
|
|
$paginatingSet = new DataObjectSet(array($this->dataObj()));
|
|
|
|
$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
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
2008-08-09 06:38:44 +02:00
|
|
|
echo $this->renderWith($this->ctf->templatePopup);
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2008-08-09 06:38:44 +02:00
|
|
|
function delete() {
|
|
|
|
if($this->ctf->Can('delete') !== true) {
|
|
|
|
return false;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2008-08-09 06:38:44 +02:00
|
|
|
$this->dataObj()->delete();
|
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
|
|
|
*/
|
2008-08-09 06:38:44 +02:00
|
|
|
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)) {
|
|
|
|
// we have to use the basedataclass, otherwise we might exclude other subclasses
|
|
|
|
return DataObject::get_by_id(ClassInfo::baseDataClass($this->ctf->sourceClass()), $this->itemID);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
* 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).
|
|
|
|
* <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
|
|
|
*/
|
2008-08-09 05:29:30 +02:00
|
|
|
function DetailForm($childID = null) {
|
2008-08-09 06:38:44 +02:00
|
|
|
$childData = $this->dataObj();
|
2008-08-09 05:29:30 +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");
|
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
$form = Object::create(
|
|
|
|
$this->ctf->popupClass,
|
|
|
|
$this, "DetailForm",
|
|
|
|
$fields, $validator, $readonly, $childData);
|
2008-08-09 05:29:30 +02:00
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @see {Form::ReferencedField}).
|
|
|
|
*/
|
|
|
|
function saveComplexTableField($data, $form, $request) {
|
2008-08-09 06:38:44 +02:00
|
|
|
$form->saveInto($this->dataObj());
|
|
|
|
$this->dataObj()->write();
|
2008-08-11 04:25:44 +02:00
|
|
|
|
|
|
|
$closeLink = sprintf(
|
|
|
|
'<small><a href="' . $_SERVER['HTTP_REFERER'] . '" onclick="javascript:window.top.GB_hide(); return false;">(%s)</a></small>',
|
|
|
|
_t('ComplexTableField.CLOSEPOPUP', 'Close Popup')
|
|
|
|
);
|
|
|
|
$message = sprintf(
|
|
|
|
_t('ComplexTableField.SUCCESSEDIT', 'Saved %s %s %s'),
|
|
|
|
$this->dataObj()->singular_name(),
|
|
|
|
'<a href="' . $this->Link() . '">"' . $this->dataObj()->Title . '"</a>',
|
|
|
|
$closeLink
|
|
|
|
);
|
|
|
|
$form->sessionMessage($message, 'good');
|
|
|
|
|
|
|
|
Director::redirectBack();
|
2008-08-09 05:54:55 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
function PopupCurrentItem() {
|
|
|
|
return $_REQUEST['ctf']['start']+1;
|
|
|
|
}
|
2008-08-09 06:38:44 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function PopupFirstLink() {
|
2008-08-09 06:38:44 +02:00
|
|
|
$this->ctf->LinkToItem();
|
|
|
|
|
|
|
|
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
|
|
|
$item = $this->unpagedSourceItems->First();
|
|
|
|
$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
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function PopupLastLink() {
|
2008-08-09 06:38:44 +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
|
|
|
$item = $this->unpagedSourceItems->Last();
|
|
|
|
$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
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function PopupNextLink() {
|
2008-08-09 06:38:44 +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
|
|
|
|
2008-03-11 02:31:43 +01:00
|
|
|
$item = $this->unpagedSourceItems->getIterator()->getOffset($_REQUEST['ctf']['start'] + 1);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
function PopupPrevLink() {
|
2008-08-09 06:38:44 +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
|
|
|
|
2008-03-11 02:31:43 +01:00
|
|
|
$item = $this->unpagedSourceItems->getIterator()->getOffset($_REQUEST['ctf']['start'] - 1);
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Method handles pagination in asset popup.
|
|
|
|
*
|
|
|
|
* @return Object DataObjectSet
|
|
|
|
*/
|
|
|
|
|
2007-11-05 02:38:25 +01:00
|
|
|
function Pagination() {
|
2007-11-02 03:53:53 +01:00
|
|
|
$this->pageSize = 9;
|
2007-09-14 05:12:21 +02:00
|
|
|
$currentItem = $this->PopupCurrentItem();
|
|
|
|
$result = new DataObjectSet();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
for($i = $offset;$i <= $offset + $this->pageSize && $i <= $this->totalCount;$i++) {
|
|
|
|
$start = $i - 1;
|
2008-03-11 02:31:43 +01:00
|
|
|
$item = $this->unpagedSourceItems->getIterator()->getOffset($i-1);
|
2008-08-09 06:38:44 +02:00
|
|
|
$links['link'] = Controller::join_links($this->Link() . "$this->methodName?ctf[start]={$start}");
|
2007-09-14 05:12:21 +02:00
|
|
|
$links['number'] = $i;
|
|
|
|
$links['active'] = $i == $currentItem ? false : true;
|
|
|
|
$result->push(new ArrayData($links));
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-08-09 06:38:44 +02:00
|
|
|
function ShowPagination() {
|
|
|
|
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
|
|
|
* #################################
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get part of class ancestry (even if popup is not subclassed it might be styled differently in css)
|
|
|
|
*/
|
|
|
|
function PopupClasses() {
|
|
|
|
global $_ALL_CLASSES;
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$items = array();
|
|
|
|
$parents = $_ALL_CLASSES['parents'][$this->class];
|
|
|
|
foreach($parents as $parent) {
|
|
|
|
if(!in_array($parent,$_ALL_CLASSES['parents']["TableListField"])) $items[] = $parent . "_Popup";
|
|
|
|
}
|
|
|
|
$items[] = $this->class . "_Popup";
|
|
|
|
|
|
|
|
return implode(" ", $items);
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-04 04:27:55 +02:00
|
|
|
* Returns the db-fieldname of the currently used has_one-relationship.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2007-09-04 04:27:55 +02:00
|
|
|
function getParentIdName( $parentClass, $childClass ) {
|
2007-12-02 22:27:34 +01:00
|
|
|
return $this->getParentIdNameRelation( $childClass, $parentClass, 'has_one' );
|
2007-09-04 04:27:55 +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)
|
|
|
|
*/
|
|
|
|
function setParentIdName($str) {
|
|
|
|
$this->parentIdName = $str;
|
|
|
|
}
|
|
|
|
|
2007-09-04 04:27:55 +02:00
|
|
|
/**
|
|
|
|
* Returns the db-fieldname of the currently used relationship.
|
|
|
|
*/
|
2008-04-21 07:29:59 +02:00
|
|
|
function getParentIdNameRelation($parentClass, $childClass, $relation) {
|
2007-12-04 05:54:26 +01:00
|
|
|
if($this->parentIdName) return $this->parentIdName;
|
|
|
|
|
2008-04-21 07:29:59 +02:00
|
|
|
$relations = singleton($parentClass)->$relation();
|
|
|
|
$classes = ClassInfo::ancestry($childClass);
|
|
|
|
foreach($relations as $k => $v) {
|
|
|
|
if(array_key_exists($v, $classes)) return $k . 'ID';
|
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
|
|
|
function setTemplatePopup($template) {
|
|
|
|
$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 {
|
|
|
|
/**
|
|
|
|
* Needed to transfer pagination-status from overview.
|
|
|
|
*/
|
|
|
|
protected $start;
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function __construct(DataObject $item, ComplexTableField $parent, $start) {
|
|
|
|
$this->start = $start;
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
parent::__construct($item, $parent);
|
|
|
|
}
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
function Link() {
|
|
|
|
return $this->parent->Link() . '/item/' . $this->item->ID;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function EditLink() {
|
2008-08-09 05:29:30 +02:00
|
|
|
return $this->Link() . "/edit";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function ShowLink() {
|
2008-08-09 05:29:30 +02:00
|
|
|
return $this->Link() . "/show";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function DeleteLink() {
|
2008-08-09 05:29:30 +02:00
|
|
|
return $this->Link() . "/delete";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-08-12 01:24:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param String $action
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function IsDefaultAction($action) {
|
|
|
|
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;
|
2008-08-09 05:29:30 +02:00
|
|
|
protected $dataObject;
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
function __construct($controller, $name, $fields, $validator, $readonly, $dataObject) {
|
|
|
|
$this->dataObject = $dataObject;
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* WARNING: DO NOT CHANGE THE ORDER OF THESE JS FILES
|
2007-09-15 23:36:17 +02:00
|
|
|
* Some have special requirements.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
//Requirements::css('cms/css/layout.css');
|
|
|
|
Requirements::css('jsparty/tabstrip/tabstrip.css');
|
2007-09-27 22:56:55 +02:00
|
|
|
Requirements::css('sapphire/css/Form.css');
|
2007-07-19 12:40:28 +02:00
|
|
|
Requirements::css('sapphire/css/ComplexTableField_popup.css');
|
2007-11-02 04:01:40 +01:00
|
|
|
Requirements::css('cms/css/typography.css');
|
2007-11-07 05:16:05 +01:00
|
|
|
Requirements::css('cms/css/cms_right.css');
|
2007-07-19 12:40:28 +02:00
|
|
|
Requirements::javascript("jsparty/prototype.js");
|
|
|
|
Requirements::javascript("jsparty/behaviour.js");
|
|
|
|
Requirements::javascript("jsparty/prototype_improvements.js");
|
|
|
|
Requirements::javascript("jsparty/loader.js");
|
|
|
|
Requirements::javascript("jsparty/tabstrip/tabstrip.js");
|
|
|
|
Requirements::javascript("jsparty/scriptaculous/scriptaculous.js");
|
|
|
|
Requirements::javascript("jsparty/scriptaculous/controls.js");
|
|
|
|
Requirements::javascript("jsparty/layout_helpers.js");
|
|
|
|
Requirements::javascript("cms/javascript/LeftAndMain.js");
|
|
|
|
Requirements::javascript("cms/javascript/LeftAndMain_right.js");
|
|
|
|
Requirements::javascript("sapphire/javascript/TableField.js");
|
|
|
|
Requirements::javascript("sapphire/javascript/ComplexTableField.js");
|
|
|
|
Requirements::javascript("sapphire/javascript/ComplexTableField_popup.js");
|
2007-09-15 23:36:17 +02:00
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
if($this->dataObject->hasMethod('getRequirementsForPopup')) {
|
2008-08-09 05:54:55 +02:00
|
|
|
$this->dataObject->getRequirementsForPopup();
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$actions = new FieldSet();
|
|
|
|
if(!$readonly) {
|
|
|
|
$actions->push(
|
|
|
|
$saveAction = new FormAction("saveComplexTableField", "Save")
|
|
|
|
);
|
|
|
|
$saveAction->addExtraClass('save');
|
|
|
|
}
|
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
parent::__construct($controller, $name, $fields, $actions, $validator);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function FieldHolder() {
|
|
|
|
return $this->renderWith('ComplexTableField_Form');
|
|
|
|
}
|
|
|
|
}
|
2008-08-09 05:54:55 +02:00
|
|
|
|
2008-08-11 07:41:00 +02:00
|
|
|
?>
|