Compare commits

..

No commits in common. "0588e3a40994b2e11490bdc980408e10a451a48c" and "3e8828bdbd2e4d25acd56c5da3eb8f2fe51431a5" have entirely different histories.

2 changed files with 3 additions and 50 deletions

View File

@ -13,9 +13,10 @@
}], }],
"minimum-stability": "dev", "minimum-stability": "dev",
"require": { "require": {
"silverstripe/cms": "*", "silverstripe/cms": "^4",
"a2nt/silverstripe-elemental-basics": "*", "a2nt/silverstripe-elemental-basics": "*",
"silverstripe/widgets": "*", "silverstripe/widgets": "*",
"gorriecoe/silverstripe-embed": "*",
"gorriecoe/silverstripe-linkfield": "*" "gorriecoe/silverstripe-linkfield": "*"
}, },
"autoload": { "autoload": {

View File

@ -4,14 +4,11 @@ namespace A2nt\CMSNiceties\Ajax\Ex;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Extension; use SilverStripe\Core\Extension;
use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\Form; use SilverStripe\Forms\Form;
use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\ValidationResult;
use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator; use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator;
use SilverStripe\Security\Security; use SilverStripe\Security\Security;
use SilverStripe\View\SSViewer; use SilverStripe\View\SSViewer;
@ -197,7 +194,7 @@ class AjaxControllerEx extends Extension
return $json && $str != $json; return $json && $str != $json;
} }
public function prepareAjaxResponse(HTTPResponse $response) public function prepareAjaxResponse($response)
{ {
$ctrl = $this->owner; $ctrl = $this->owner;
@ -213,52 +210,7 @@ class AjaxControllerEx extends Extension
); );
$body = $response->getBody(); $body = $response->getBody();
if (self::isFormRequest()) {
/* @var $req \SilverStripe\Control\HTTPRequest */
$req = $ctrl->getRequest();
$sess = $req->getSession();
$formName = $req->requestVar('formid');
$data = $sess->get('FormInfo');
// form validation response
if ($formName && $data && isset($data[$formName]['result'])) {
$sess->clear('FormInfo.'.$formName);
/* @var $valid \SilverStripe\ORM\ValidationResult */
$valid = unserialize($data[$formName]['result']);
$msgs = $valid->getMessages();
$body = json_encode([
'status' => $valid->isValid()
? ValidationResult::TYPE_GOOD
: ValidationResult::TYPE_ERROR,
'msgs' => $msgs,
]);
$response->removeHeader('Location');
$response->setStatusCode(200);
$response->setBody($body);
return $response;
}
}
// ajax redirect
if ($response->isRedirect()) {
$body = json_encode([
'location' => $response->getHeader('location'),
'loadAjax' => true,
]);
$response->removeHeader('Location');
$response->setStatusCode(200);
$response->setBody($body);
return $response;
}
// render page
if (!self::isJson($body)) { if (!self::isJson($body)) {
$body = json_encode([ $body = json_encode([
'ID' => $record->ID, 'ID' => $record->ID,