2008-08-11 07:41:00 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Used by ModelAdmin scaffolding, to manage many-many relationships.
|
|
|
|
*
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-relational
|
|
|
|
*/
|
2009-04-29 02:07:39 +02:00
|
|
|
class ScaffoldingComplexTableField_Popup extends ComplexTableField_Popup {
|
2008-08-11 07:41:00 +02:00
|
|
|
|
|
|
|
public static $allowed_actions = array(
|
|
|
|
'filter', 'record', 'httpSubmission', 'handleAction', 'handleField'
|
|
|
|
);
|
|
|
|
|
|
|
|
function __construct($controller, $name, $fields, $validator, $readonly, $dataObject) {
|
|
|
|
$this->dataObject = $dataObject;
|
|
|
|
|
2009-04-29 02:07:39 +02:00
|
|
|
Requirements::clear();
|
|
|
|
|
2008-08-11 07:41:00 +02:00
|
|
|
$actions = new FieldSet();
|
|
|
|
if(!$readonly) {
|
|
|
|
$actions->push(
|
|
|
|
$saveAction = new FormAction("saveComplexTableField", "Save")
|
|
|
|
);
|
|
|
|
$saveAction->addExtraClass('save');
|
|
|
|
}
|
|
|
|
|
|
|
|
$fields->push(new HiddenField("ComplexTableField_Path", Director::absoluteBaseURL()));
|
|
|
|
|
2009-04-29 02:07:39 +02:00
|
|
|
parent::__construct($controller, $name, $fields, $validator, $readonly, $dataObject);
|
2008-08-11 07:41:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a generic action passed in by the URL mapping.
|
|
|
|
*
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
* @param SS_HTTPRequest $request
|
2008-08-11 07:41:00 +02:00
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
* @param SS_HTTPRequest $request
|
2008-08-11 07:41:00 +02:00
|
|
|
* @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) {
|
2008-11-24 10:31:14 +01:00
|
|
|
$record = DataObject::get_one($this->dataObject->class, "\"$type\" = '$value'");
|
2008-08-11 07:41:00 +02:00
|
|
|
header("Content-Type: text/plain");
|
|
|
|
echo json_encode(array("record"=>$record->toMap()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
?>
|