mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
Merged [47018]: Some additions made to use Object::create to allow MemberTableField to deal with subclasses of Member. Also merged a modification to MemberTableField::__construct that allowed greater control over the details form's fields (defaults to same behaviour as trunk), and MemberTableField::DetailForm, although this might need to be removed later.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@60302 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
cc0117a307
commit
f74a39d1b0
@ -91,11 +91,25 @@ class MemberTableField extends ComplexTableField {
|
||||
}
|
||||
|
||||
if(isset($_REQUEST['ctf']['childID']) && $memberID = $_REQUEST['ctf']['childID']) {
|
||||
$SNG_member = DataObject::get_by_id($this->stat("data_class"),$_REQUEST['ctf']['childID']);
|
||||
$SNG_member = DataObject::get_by_id($this->stat("data_class"),$memberID);
|
||||
} else {
|
||||
$SNG_member = singleton(Object::getCustomClass($this->stat("data_class")));
|
||||
}
|
||||
|
||||
// If the fieldset is passed, use it, else use the formfields returned
|
||||
// from the object via a string method call.
|
||||
if(is_a($this->detailFormFields,"Fieldset")){
|
||||
$detailFormFields = $this->detailFormFields;
|
||||
} else if(is_string($this->detailFormFields)){
|
||||
$functioncall = $this->detailFormFields;
|
||||
if($SNG_member->hasMethod($functioncall)){
|
||||
$detailFields = $childData->$functioncall();
|
||||
}
|
||||
} else {
|
||||
$detailFormFields = $SNG_member->getCMSFields();
|
||||
}
|
||||
|
||||
|
||||
$this->detailFormValidator = $SNG_member->getValidator();
|
||||
|
||||
$this->pageSize = $pageLimit;
|
||||
@ -107,7 +121,7 @@ class MemberTableField extends ComplexTableField {
|
||||
|
||||
$this->hidePassword = $hidePassword;
|
||||
|
||||
parent::__construct($controller, $name, $sourceClass, $fieldList);
|
||||
parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields);
|
||||
|
||||
Requirements::javascript('cms/javascript/MemberTableField.js');
|
||||
Requirements::javascript("cms/javascript/MemberTableField_popup.js");
|
||||
@ -154,6 +168,51 @@ class MemberTableField extends ComplexTableField {
|
||||
return "{$this->Link()}&methodName=add";
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Check if this was modified as a result of the
|
||||
* Ajax changes. As a single method, it should be fairly safe
|
||||
*/
|
||||
function DetailForm() {
|
||||
$ID = Convert::raw2xml(isset($_REQUEST['ctf']['ID'])
|
||||
? $_REQUEST['ctf']['ID']
|
||||
: '');
|
||||
$childID = isset($_REQUEST['ctf']['childID']) ? Convert::raw2xml($_REQUEST['ctf']['childID']) : 0;
|
||||
$childClass = Convert::raw2xml($_REQUEST['fieldName']);
|
||||
$methodName = isset($_REQUEST['methodName']) ? $_REQUEST['methodName'] : '';
|
||||
|
||||
if($methodName == "add") {
|
||||
$parentIdName = $this->getParentIdName($childClass,$this->getParentClass());
|
||||
if(!$parentIdName) {
|
||||
user_error("ComplexTableField::DetailForm() Dataobject does not seem to have an 'has-one'-relationship", E_USER_WARNING);
|
||||
return;
|
||||
}
|
||||
$this->detailFormFields->push(new HiddenField('parentClass'," ",$this->getParentClass()));
|
||||
}
|
||||
|
||||
// the ID field confuses the Controller-logic in finding the right view for ReferencedField
|
||||
$this->detailFormFields->removeByName('ID');
|
||||
|
||||
$this->detailFormFields->push(new HiddenField("ctf[ID]"," ",$ID));
|
||||
// add a namespaced ID instead thats "converted" by saveComplexTableField()
|
||||
$this->detailFormFields->push(new HiddenField("ctf[childID]","",$childID));
|
||||
$this->detailFormFields->push(new HiddenField("ClassName","",$this->sourceClass));
|
||||
|
||||
$form = Object::create('MemberTableField_Popup', $this, "DetailForm", $this->detailFormFields, $this->sourceClass, $methodName == "show", $this->detailFormValidator);
|
||||
|
||||
if (is_numeric($childID)) {
|
||||
if ($methodName == "show" || $methodName == "edit") {
|
||||
$childData = DataObject::get_by_id($this->sourceClass, $childID);
|
||||
$form->loadDataFrom($childData);
|
||||
}
|
||||
}
|
||||
|
||||
if ($methodName == "show") {
|
||||
$form->makeReadonly();
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function SearchForm() {
|
||||
$searchFields = new FieldGroup(
|
||||
new TextField('MemberSearch', _t('MemberTableField.SEARCH', 'Search')),
|
||||
@ -208,7 +267,7 @@ class MemberTableField extends ComplexTableField {
|
||||
FormResponse::status_messsage(_t('MemberTableField.ADDINGFIELD', 'Adding failed'), 'bad');
|
||||
}
|
||||
|
||||
$className = $this->stat('data_class');
|
||||
$className = Object::getCustomClass($this->stat('data_class'));
|
||||
$record = new $className();
|
||||
|
||||
$record->update($data);
|
||||
@ -370,8 +429,10 @@ class MemberTableField_Popup extends ComplexTableField_Popup {
|
||||
* @return string
|
||||
*/
|
||||
function saveComplexTableField() {
|
||||
if(isset($_REQUEST['ctf']['childID']) && is_numeric($_REQUEST['ctf']['childID'])) {
|
||||
$childObject = DataObject::get_by_id($this->sourceClass, $_REQUEST['ctf']['childID']);
|
||||
$id = (isset($_REQUEST['ctf']['childID'])) ? Convert::raw2sql($_REQUEST['ctf']['childID']) : false;
|
||||
|
||||
if (is_numeric($id) && $id != 0) {
|
||||
$childObject = DataObject::get_by_id($this->sourceClass, $id);
|
||||
} else {
|
||||
$childObject = new $this->sourceClass();
|
||||
$this->fields->removeByName('ID');
|
||||
|
Loading…
Reference in New Issue
Block a user