ENHANCEMENT Saving MemberTableField through new 'Groups' field added in Member->getCMSFields(). (from r98882)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@99688 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-02-23 03:34:28 +00:00 committed by Sam Minnee
parent 830fce69e9
commit 8c67b1a01e

View File

@ -304,14 +304,19 @@ class MemberTableField extends ComplexTableField {
*
* @return string
*/
function saveComplexTableField($data, $form, $params) {
function saveComplexTableField($data, $form, $params) {
$className = $this->sourceClass();
$childData = new $className();
$form->saveInto($childData);
$childData->write();
$childData->Groups()->add($data['GroupID']);
// Only write group if no specific assignments have been set
if(isset($data['Groups']) && $data['Groups']) {
$childData->Groups()->setByIDList(explode(',', $data['Groups']));
} else {
$childData->Groups()->add($data['GroupID']);
}
$closeLink = sprintf(
'<small><a href="' . $_SERVER['HTTP_REFERER'] . '" onclick="javascript:window.top.GB_hide(); return false;">(%s)</a></small>',
@ -395,6 +400,16 @@ class MemberTableField extends ComplexTableField {
* @subpackage security
*/
class MemberTableField_Popup extends ComplexTableField_Popup {
function __construct($controller, $name, $fields, $validator, $readonly, $dataObject) {
$group = ($controller instanceof MemberTableField) ? $controller->getGroup() : $controller->getParent()->getGroup();
if($group) {
$groupsField = $fields->dataFieldByName('Groups');
if($groupsField) $groupsField->setValue($group->ID);
}
parent::__construct($controller, $name, $fields, $validator, $readonly, $dataObject);
}
function forTemplate() {
$ret = parent::forTemplate();
@ -435,6 +450,20 @@ class MemberTableField_Item extends ComplexTableField_Item {
}
class MemberTableField_ItemRequest extends ComplexTableField_ItemRequest {
function saveComplexTableField($data, $form, $request) {
parent::saveComplexTableField($data, $form, $request);
$childData = $this->dataObj();
// Only write group if no specific assignments have been set
if(isset($data['Groups']) && $data['Groups']) {
$childData->Groups()->setByIDList(explode(',', $data['Groups']));
} else {
$childData->Groups()->add($data['GroupID']);
}
}
/**
* Deleting an item from a member table field should just remove that member from the group
*/
@ -458,6 +487,10 @@ class MemberTableField_ItemRequest extends ComplexTableField_ItemRequest {
$this->dataObj()->delete();
}
}
function getParent() {
return $this->ctf;
}
}
?>