mirror of
https://github.com/a2nt/cms-niceties.git
synced 2024-10-22 11:05:46 +02:00
Compare commits
4 Commits
3e8828bdbd
...
0588e3a409
Author | SHA1 | Date | |
---|---|---|---|
0588e3a409 | |||
6a52f247d1 | |||
f2652b48c3 | |||
d65c85a192 |
@ -13,10 +13,9 @@
|
|||||||
}],
|
}],
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"require": {
|
"require": {
|
||||||
"silverstripe/cms": "^4",
|
"silverstripe/cms": "*",
|
||||||
"a2nt/silverstripe-elemental-basics": "*",
|
"a2nt/silverstripe-elemental-basics": "*",
|
||||||
"silverstripe/widgets": "*",
|
"silverstripe/widgets": "*",
|
||||||
"gorriecoe/silverstripe-embed": "*",
|
|
||||||
"gorriecoe/silverstripe-linkfield": "*"
|
"gorriecoe/silverstripe-linkfield": "*"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
@ -4,11 +4,14 @@ 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;
|
||||||
@ -194,7 +197,7 @@ class AjaxControllerEx extends Extension
|
|||||||
return $json && $str != $json;
|
return $json && $str != $json;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prepareAjaxResponse($response)
|
public function prepareAjaxResponse(HTTPResponse $response)
|
||||||
{
|
{
|
||||||
$ctrl = $this->owner;
|
$ctrl = $this->owner;
|
||||||
|
|
||||||
@ -210,7 +213,52 @@ 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,
|
||||||
|
Loading…
Reference in New Issue
Block a user