mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API CHANGE Removing ScaffoldingComplexTableField, using GridField instead to edit relationships through FormScaffolder and DataObject->scaffoldFormFields()
This commit is contained in:
parent
115ea86b0c
commit
1f01e1135d
@ -123,22 +123,17 @@ class FormScaffolder extends Object {
|
|||||||
$this->obj->fieldLabel($relationship)
|
$this->obj->fieldLabel($relationship)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$relationshipFields = singleton($component)->summaryFields();
|
$fieldClass = (isset($this->fieldClasses[$relationship])) ? $this->fieldClasses[$relationship] : 'GridField';
|
||||||
|
$grid = Object::create($fieldClass,
|
||||||
$foreignKey = $this->obj->getRemoteJoinField($relationship);
|
|
||||||
$fieldClass = (isset($this->fieldClasses[$relationship])) ? $this->fieldClasses[$relationship] : 'ComplexTableField';
|
|
||||||
$ctf = new $fieldClass(
|
|
||||||
$this,
|
|
||||||
$relationship,
|
$relationship,
|
||||||
null,
|
$this->obj->fieldLabel($relationship),
|
||||||
$relationshipFields,
|
$this->obj->$relationship(),
|
||||||
"getCMSFields"
|
GridFieldConfig_RelationEditor::create()
|
||||||
);
|
);
|
||||||
$ctf->setPermissions(TableListField::permissions_for_object($component));
|
|
||||||
if($this->tabbed) {
|
if($this->tabbed) {
|
||||||
$fields->addFieldToTab("Root.$relationship", $ctf);
|
$fields->addFieldToTab("Root.$relationship", $grid);
|
||||||
} else {
|
} else {
|
||||||
$fields->push($ctf);
|
$fields->push($grid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,22 +147,17 @@ class FormScaffolder extends Object {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$relationshipFields = singleton($component)->summaryFields();
|
$fieldClass = (isset($this->fieldClasses[$relationship])) ? $this->fieldClasses[$relationship] : 'GridField';
|
||||||
$fieldClass = (isset($this->fieldClasses[$relationship])) ? $this->fieldClasses[$relationship] : 'ComplexTableField';
|
$grid = Object::create($fieldClass,
|
||||||
$ctf = new $fieldClass(
|
|
||||||
$this,
|
|
||||||
$relationship,
|
$relationship,
|
||||||
|
$this->obj->fieldLabel($relationship),
|
||||||
$this->obj->$relationship(),
|
$this->obj->$relationship(),
|
||||||
$relationshipFields,
|
GridFieldConfig_RelationEditor::create()
|
||||||
"getCMSFields"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$ctf->setPermissions(TableListField::permissions_for_object($component));
|
|
||||||
$ctf->popupClass = "ScaffoldingComplexTableField_Popup";
|
|
||||||
if($this->tabbed) {
|
if($this->tabbed) {
|
||||||
$fields->addFieldToTab("Root.$relationship", $ctf);
|
$fields->addFieldToTab("Root.$relationship", $grid);
|
||||||
} else {
|
} else {
|
||||||
$fields->push($ctf);
|
$fields->push($grid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,93 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Used by ModelAdmin scaffolding, to manage many-many relationships.
|
|
||||||
*
|
|
||||||
* @package forms
|
|
||||||
* @subpackage fields-relational
|
|
||||||
*/
|
|
||||||
class ScaffoldingComplexTableField_Popup extends ComplexTableField_Popup {
|
|
||||||
|
|
||||||
public static $allowed_actions = array(
|
|
||||||
'filter', 'record', 'httpSubmission', 'handleAction', 'handleField'
|
|
||||||
);
|
|
||||||
|
|
||||||
function __construct($controller, $name, $fields, $validator, $readonly, $dataObject) {
|
|
||||||
$this->dataObject = $dataObject;
|
|
||||||
|
|
||||||
Requirements::clear();
|
|
||||||
|
|
||||||
$actions = new FieldList();
|
|
||||||
if(!$readonly) {
|
|
||||||
$actions->push(
|
|
||||||
$saveAction = new FormAction("saveComplexTableField", "Save")
|
|
||||||
);
|
|
||||||
$saveAction->addExtraClass('save');
|
|
||||||
}
|
|
||||||
|
|
||||||
$fields->push(new HiddenField("ComplexTableField_Path", Director::absoluteBaseURL()));
|
|
||||||
|
|
||||||
parent::__construct($controller, $name, $fields, $validator, $readonly, $dataObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle a generic action passed in by the URL mapping.
|
|
||||||
*
|
|
||||||
* @param SS_HTTPRequest $request
|
|
||||||
*/
|
|
||||||
public function handleAction($request) {
|
|
||||||
$action = str_replace("-","_",$request->param('Action'));
|
|
||||||
if(!$this->action) $this->action = 'index';
|
|
||||||
|
|
||||||
if($this->checkAccessAction($action)) {
|
|
||||||
if($this->hasMethod($action)) {
|
|
||||||
$result = $this->$action($request);
|
|
||||||
|
|
||||||
// Method returns an array, that is used to customise the object before rendering with a template
|
|
||||||
if(is_array($result)) {
|
|
||||||
return $this->getViewer($action)->process($this->customise($result));
|
|
||||||
|
|
||||||
// Method returns a string / object, in which case we just return that
|
|
||||||
} else {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// There is no method, in which case we just render this object using a (possibly alternate) template
|
|
||||||
} else {
|
|
||||||
return $this->getViewer($action)->process($this);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return $this->httpError(403, "Action '$action' isn't allowed on class $this->class");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Action to render results for an autocomplete filter.
|
|
||||||
*
|
|
||||||
* @param SS_HTTPRequest $request
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function filter($request) {
|
|
||||||
//$model = singleton($this->modelClass);
|
|
||||||
$context = $this->dataObject->getDefaultSearchContext();
|
|
||||||
$value = $request->getVar('q');
|
|
||||||
$results = $context->getResults(array("Name"=>$value));
|
|
||||||
header("Content-Type: text/plain");
|
|
||||||
foreach($results as $result) {
|
|
||||||
echo $result->Name . "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Action to populate edit box with a single data object via Ajax query
|
|
||||||
*/
|
|
||||||
function record($request) {
|
|
||||||
$type = $request->getVar('type');
|
|
||||||
$value = $request->getVar('value');
|
|
||||||
if ($type && $value) {
|
|
||||||
$record = DataObject::get_one($this->dataObject->class, "\"$type\" = '$value'");
|
|
||||||
header("Content-Type: text/plain");
|
|
||||||
echo json_encode(array("record"=>$record->toMap()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
window.onload = function() {
|
|
||||||
|
|
||||||
resourcePath = jQuery('form').attr('action');
|
|
||||||
|
|
||||||
jQuery("fieldset input:first").attr('autocomplete', 'off').autocomplete({list: ["mark rickerby", "maxwell sparks"]});
|
|
||||||
|
|
||||||
jQuery("fieldset input:first").bind('activate.autocomplete', function(e){
|
|
||||||
|
|
||||||
type = jQuery("fieldset input:first").attr('name');
|
|
||||||
value = jQuery("fieldset input:first").val();
|
|
||||||
|
|
||||||
jQuery.getJSON(resourcePath + '/record', {'type':type, 'value':value}, function(data) {
|
|
||||||
jQuery('form input').each(function(i, elm){
|
|
||||||
if(elm.name in data.record) {
|
|
||||||
val = data.record[elm.name];
|
|
||||||
if (val != null) elm.setAttribute('value', val);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user